init Function
The init function creates and initializes the Paysafe Request instance. The Paysafe Request options are then validated and an asynchronous request is made to the backend to get the merchant information matching the API Key. This is the first step you should perform in your script. After calling this function - but before the user clicks the payment button - the updateOptions function can be used to change all the option parameters except environment.
The function signature is as follows:
paysafe.request.init(apikey,options);
The function parameters are described below.
Parameter | Required | Type | Description |
---|---|---|---|
apiKey | true | string | The Base64-encoded version of the single-use token API key used to authenticate with the Customer Vault REST API. This key can only be used to generate single-use tokens for use with the Card Payments API. It cannot be used for taking payments; and so can be exposed publicly in the user's browser. |
options | true | object | Settings to apply to the Paysafe Request, such as the the environment to use (Test or Live), the payment amount, the currency, the country, and parameters to personalize the payment form and provide addresses. |
{throws} | N/A | Throws an exception with the following errors: 9013, 9014, 9015, 9017, 9055, 9054, 9066, 9068, 9069, 9070, 9071. | |
{return} | false | undefined |
Init options parameters
These are the init option parameters.
Option parameter | Required | Type | Description |
amount | true | number | Payment amount in minor units to charge the customer's card. Use the correct minor units amount for the merchant account currency. For example, to process US $10.99, this value should be 1099. To process 1000 Japanese Yen, this value should be 1000. To process 10.139 Tunisian dinar, this value should be 10139. Payment amount has to be supplied as a positive number and shouldn't be longer than 9 digits. |
country | true | string | The two-uppercase-character ISO 3166 country code. |
currency | true | string | Three character code for the payment currency; for example USD for US dollars |
environment | false | string | Environment to which Paysafe Request is connected:
If you omit the environment object, by passing an empty or null value for this parameter, the Live environment will be used. You cannot change this parameter using the updateOptions function. Do not use real card numbers or other payment instrument details in the Merchant Test environment as it is not compliant with Payment Card Industry Data Security Standards (PCI-DSS), and does not protect cardholder/payee information. Any upload of real cardholder data is strictly prohibited, as described in the Terms of Use. |
label | true (Apple Pay only) | string | Label displayed immediately after the "Pay" button on the Apple Pay page. |
requestBillingAddress | false | boolean | Set to true to include the billing information in the onTokenization function callback response containing the token. The default value is false |
requestShippingAddress | false | boolean | Set to true to include the shipping information in the onTokenization function callback response containing the token. The default value is false |
supportedNetworks | false | string array | The payment networks you support. Possible values (case insensitve):
|
applePay: supportedCountries | false | two-letter ISO 3166 country code array | Limits payments to cards from specific countries. |
Apple Pay Example
This example in the TEST environment shows how to specify initialize a Paysafe Request instance. It does not include the showButtons or onTokenization code:
<html>
<head>
<script type="text/javascript" src="https://hosted.paysafe.com/request/v1/latest/paysafe.request.min.js"></script>
</head>
<body>
...
<div id="x-paysafe-apple-pay-button"></div>
...
<script>
paysafe.request.init("my API key", {
country: "US",
currency: "USD",
amount: 1234,
label: "My label",
supportedNetworks: ["VISA", "MASTERCARD"],
environment: "TEST",
applePay: {
supportedCountries: ["US", "CA"]
}
});
</script>
</body>
</html>