# Init
source: https://developer.mastercard.com/mastercard-checkout-solutions/documentation/sdk-reference/init/index.md

This method initializes the JavaScript library with common state. It must be called before any other method. Without this, nothing else will work. It is asynchronous and has no response.
>
> #### Applicable Products {#applicable-products}
>
> [Click to Pay](https://developer.mastercard.com/mastercard-checkout-solutions/documentation/use-cases/click-to-pay/index.md)

## Method Signature {#method-signature}

```javascript
init ({
    required String <UUID> srcInitiatorId;
    required String <UUID> srciDpaId;
    required String <UUID> srciTransactionId;
    required DpaTransactionOptions dpaTransactionOptions;
    optional DpaData dpaData;
})

// Response - empty
```

## Code Sample {#code-sample}

This `init` method will accept parameters for XHR calls.

```JavaScript
// window.SRCSDK_MASTERCARD.init returns a promise which will:

// Resolve to indicate success. init does not return a payload.

// Reject to indicate an error was encountered
// The reject payload might include one of the reason codes listed below:

// SRCI_ID_MISSING: The identifier for the SRC Initiator is missing.
// DPA_ID_MISSING: The identifier for the DPA is missing.
// SRCI_TXID_MISSING The SRC Initiator transaction identifier is missing.
// DPA_TXOPT_MISSING: The DPA Transaction Options structure is missing.
//  Or one of the standard errors included in the Standard Errors and Business Errors section

const sampleInitParams = {
  srcInitiatorId: String, // required
  // SRCI identifier. This is generated by the Click to Pay System during onboarding.

  srciDpaId: String, // required
  // DPA Identifier. This is generated by the SRCI during registration.

  srciTransactionId: String, // required
  // A unique id used to track the user journey. This is used for analytics to
  // be able to correlate a single user "session" from button impression to the
  // end of the transaction.
  // This field may be created on the merchant page by the SRC Initiator and
  // need to be passed-through to all the networks (Click to Pay Systems). It is passed
  // all the way to the DCFs as well.


  dpaTransactionOptions: DpaTransactionOptions, // required
  // dpaTransactionOptions
  // DPA-specific preferences and transaction configuration parameters
  // Optionality note: Must be provided to init or checkout. The checkout DpaTransactionOptions
  // will override the DpaTransactionOptions provided to init
}

// Define response handlers
function promiseResolvedHandler (payload) {
  // add success handler logic here
}
function promiseRejectedHandler (payload) {
  // add error handler logic here
}

const initPromise = window.SRCSDK_MASTERCARD.init(sampleInitParams) //  returns a promise
initPromise
  .then(promiseResolvedHandler) // No other SDK methods should be invoked until `init` resolves
  .catch(promiseRejectedHandler)
// Or
async function initHandler () { // this method will return a promise
  try {
    const promiseResolvedPayload = await window.SRCSDK_MASTERCARD.init(sampleInitParams) // No other SDK methods should be invoked until `init` resolves
    // add success handler logic here
    // or
    // promiseResolvedHandler(promiseResolvedPayload)
  } catch (promiseRejectedPayload) {
    // add error handler logic here
    // or
    // promiseRejectedHandler(promiseRejectedPayload)
  }
}
```

## Request Example and Parameters {#request-example-and-parameters}

### Request Example {#request-example}

```json
{
  "srciTransactionId":"781eaff9-f72e-4365-a438-0e4c82c8ded4",
  "srcInitiatorId":"5e0d4b84-189d-4c86-822d-590602f62062",
  "srciDpaId":"7a96bc0a-1a1e-4c62-996e-2153e3302291_systemtest",

  "dpaTransactionOptions":
  {
      "transactionAmount":
      {
          "transactionAmount":"100.00",
          "transactionCurrencyCode":"USD"
      },
      "transactionType": "PURCHASE",
      "dpaBillingPreference":"FULL",
      "dpaShippingPreference":"FULL",
      "customInputData":
        {
          "com.mastercard.dcfExperience":"WITHIN_CHECKOUT"
        },
      "consumerNationalIdentifierRequested":false,
      "dpaAcceptedBillingCountries":
        [
        ],
      "dpaAcceptedShippingCountries":
        [
        ],
      "dpaLocale":"en_US",
      "consumerEmailAddressRequested":true,
      "consumerNameRequested":true,
      "consumerPhoneNumberRequested":true,
      "confirmPayment":false,
      "payloadTypeIndicatorCheckout":"PAYMENT",
      "payloadTypeIndicatorPayload":"PAYMENT",
      "paymentOptions":
        [
          {
              "dpaDynamicDataTtlMinutes":15,
              "dpaPanRequested":false,
              "dynamicDataType":"CARD_APPLICATION_CRYPTOGRAM_SHORT_FORM"
          }
       ]
  }
}
```

### Request Parameters {#request-parameters}

The request parameters are given below:

|           Name            |                                                                    Type                                                                     | Mandate  |                                                                                                                                                                              Description                                                                                                                                                                               |
|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **srcInitiatorId**        | String                                                                                                                                      | Required | Identifier for the integrator. This is generated by the Mastercard System during onboarding.                                                                                                                                                                                                                                                                           |
| **srciDpaId**             | String                                                                                                                                      | Required | DPA Identifier. This is generated by the integrator during registration.                                                                                                                                                                                                                                                                                               |
| **srciTransactionId**     | String                                                                                                                                      | Required | A unique id used to track the user journey. This is used for analytics to be able to correlate a single user "session" from button impression to the end of the transaction. This field may be created on the merchant page by the integrator and need to be passed-through to Mastercard network (Click to Pay System). It is passed all the way to the DCFs as well. |
| **dpaTransactionOptions** | [DpaTransactionOptions](https://developer.mastercard.com/mastercard-checkout-solutions/documentation/sdk-reference/common-objects/index.md) | Required | DPA-specific preferences and transaction configuration parameters. This is required for the `init` method, and may also be included in the [checkout()](https://developer.mastercard.com/mastercard-checkout-solutions/documentation/sdk-reference/checkout-method/index.md) method.                                                                                   |
| **dpaData**               | [DpaData](https://developer.mastercard.com/mastercard-checkout-solutions/documentation/sdk-reference/common-objects/index.md#dpa-data)      | Optional | May be provided, as required, to dynamically update previously registered DPA Data, e.g., presentation name.                                                                                                                                                                                                                                                           |

## Response Example and Parameters {#response-example-and-parameters}

None

## Application Errors {#application-errors}

|      Reason Code      |                     Description                      |                                                      Example                                                      |
|-----------------------|------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------|
| **SRCI_ID_MISSING**   | The identifier for the integrator (SRCI) is missing. | * Javascript ```javascript { "reason": "SRCI_ID_MISSING", "status": "400", "message": "Missing parameter" } ```   |
| **DPA_ID_MISSING**    | The identifier for the DPA is missing.               | * Javascript ```javascript { "reason": "DPA_ID_MISSING", "status": "400", "message": "Missing parameter" } ```    |
| **SRCI_TXID_MISSING** | The integrator transaction identifier is missing.    | * Javascript ```javascript { "reason": "SRCI_TXID_MISSING", "status": "400", "message": "Missing parameter" } ``` |
| **DPA_TXOPT_MISSING** | The DPA Transaction Options structure is missing.    | * Javascript ```javascript { "reason": "DPA_TXOPT_MISSING", "status": "400", "message": "Missing parameter" } ``` |

