Setup Function

The setup function creates and initializes the Paysafe Checkout in a overlay. It has the following parameters:

  • The Base64-encoded version of the single-use token API key used to authenticate with the Customer Vault REST API. Note that this key can only be used to generate single-use tokens for use with the Card Payments and Direct Debit APIs, and has no other API access rights, such as those required for taking payments. Consequently, this key can be exposed publicly in the user's browser.
  • An options object containing the environment to use (Test or Live), the payment amount, currency, and several parameters to personalize the payment form and customize its appearance.
  • A resultCallback function you provide to receive the Paysafe checkout instance, handle successful tokenization (by sending the token to your merchant server), or respond to any errors caused by a failed tokenization.
  • An optional closeCallback function you provide to handle the customer closing the payment overlay.

The function signature is as follows:

paysafe.checkout.setup(apikey,options,resultsCallback,closeCallback);

Environment

The options object contains a string to select the environment to use for tokenization, either LIVE (the Paysafe Production environment) and TEST (the Paysafe Merchant Test or Sandbox environment).

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.

Test

paysafe.checkout.setup("my Merchant test Base 64 encoded single-use-token API key", {
    environment: "TEST"
  },
  function(instance, error, result) {...});

Live

paysafe.checkout.setup("my Production Base64 Encoded single-use-token API key", {
    environment: "LIVE"
  },
  function(instance, error, result) {...});

If you omit the environment object, by passing an empty or null value for this parameter, the Live environment will be used.

Setup Function and Objects

Here is a full list of the setup function parameters, the JavaScript objects used by the setup function, and the parameters they contain.

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.
options true object
resultCallback true function Callback function invoked with the result or error from the payment. Returns an instance for flow control.
closeCallback false function Callback function invoked when the modal overlay is closed.
{return} false any
options
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.

currency true string Three character code for the payment currency – for example, USD for US dollars.

companyName

length <= 60 chars

true string Merchant name for display on the payment form.

holderName

length <= 160 chars

false string Name of the card holder. This parameter is used to personalize the payment form and to associate the customer's name with the payment token.
environment false string/object

Environment to use for all tokenization and logging calls.

Possible values are:

  • LIVE – used for Production
  • TEST – used for the Merchant test or sandbox environment

imageUrl

length <= 2000 chars

false string

URL for the logo to display on the payment form. Must be a publicly accessible URL using the HTTPS protocol. The logo is resized for display.

Any browser supported format is permitted.

Paysafe recommends a size of 56 x 56 pixels or a 1:1 aspect ratio (for vector images) for best results.

locale false string

Language locale for the checkout:

  • en_US
  • fr_CA

If omitted, defaults to en_US.

accounts false object

Information regarding merchant processing accounts for 3D Secure.

Add this object to support 3D Secure. If the customer's card supports 3D Secure, they may be shown an additional page from their card issuer within the overlay to authorize the payment. 3D Secure is currently supported only for Visa and Mastercard. In the merchant Test environment, a simulator is used instead to simulate different 3DS responses.

billingAddress false object Billing address for Card and Direct Debit payments. Additional details of the Customer Vault BillingAddress object are given in the Customer Vault documentation. For Direct Debit, the billing address is used to populate the Checkout form when the currency and country match. For example, if the country is USA and the currency is USD, the billing address fields in the Direct Debit Checkout form are automatically populated.
buttonColor false string

Hex color for the payment form buttons. For example,

buttonColor: "#ff0000",

preferredPaymentMethod false string

The payment method selected when Paysafe Checkout is opened. Possible values are:

  • Cards
  • DirectDebit
  • Interac

This is case-insensitive.

accounts
CC true number

The ID of the merchant account to use for 3DS processing of the payment. For information about how to select the correct accountId, see Multiple Currencies.

billingAddress
country true string Country in which the address is located.
zip true string Zip or postal code for the address.
city false string City in which the address is located.
state false string This is the state/province/region in which the customer lives. This field is ignored with Direct Debit.
street false string First line of the customer's street address.
street2 false string Second line of the customer's street address. This field is ignored with Direct Debit.

resultCallback

The result callback is invoked when a token is issued or a tokenization error occurs.

The signature is as follows:

Parameter Required Type Description
instance true object Paysafe Checkout instance.
error false object Object containing information for the error. This field is present if tokenization fails. The contents of this object are described below.
result false object

Result containing payment token. The contents of this object are described below.

{return} false undefined
instance
isOpen true function Checks if the overlay is still open.
close true function Closes the overlay without displaying result from payment.
showSuccessScreen true function Changes checkout layout to success screen.
showFailureScreen true function Changes checkout layout to failure screen.
error
code true string

Short error code identifying the error type.

displayMessage true string Provides an error message that can be displayed to users.
detailedMessage true string Provides a detailed error message that can be logged.
correlationId true string Unique ID that can be provided to the Paysafe Support team as a reference for investigation.
result
token true string Payment token representing the sensitive card and bank account details in case of successful tokenization. You will need to send this token securely to your server to make payment using the Card Payments, Direct Debit, or Alternate Payments API.
paymentMethod true string

The payment method used by the customer:

  • Cards
  • DirectDebit
  • Interac

An example is shown below:

function(instance, error, result) {        
if (result.token) {

	// Successfully tokenized card, use result.token to process a payment
             
	console.log(result.token);

	// add AJAX code to send token to your merchant server

	instance.showSuccessScreen("Your goods are now purchased. Expect them to be delivered in next 5 business days.");         
} else {

	// tokenization failed

	instance.showFailureScreen("The payment was declined. Please, try again with the same or another payment method.");          
}

}

closeCallback

Invoked when the checkout overlay is closed by the customer. This function has the following signature:

Parameter Required Type Description
stage true string

Stage during which the checkout overlay is closed. Possible values are:

  • BeforePayment
  • DuringPayment
  • AfterPayment
{return} false any

Example usage:

function(stage) {
if (stage === "BeforePayment") {
	// No payment have been made
} else if (stage === "DuringPayment") {
	// Token have been issued, but the checkout overlay was closed from the user before instance flow control method was invoked
} else if (stage === "AfterPayment") {
	// Closed either via instance.close method or by the user from the success screen
}

Setup Errors

Code
Display Message
Detailed Message
Description
9004 There was an error (9004), please contact our support. Callback should be function.
9012 There was an error (9012), please contact our support. Invalid number of arguments. Used when the supplied number of arguments is neither 3 nor 4.
9062 There was an error (9062), please contact our support. Paysafe Checkout already opened. Setup function has been invoked and Paysafe Checkout is already opened or is loading at the moment.

Errors Passed to resultCallback

Code
Display Message
Detailed Message
Description
9013 There was an error (9013), please contact our support. Invalid apiKey parameter. Used when the supplied apiKey parameter is not a string, is in invalid format, or is not configured for Paysafe Checkout.
9014 There was an error (9014), please contact our support. Unhandled error occurred. Used when an error unhandled by the Paysafe Checkout SDK is thrown.
9015 There was an error (9015), please contact our support. Invalid options argument. Used when the supplied options parameter is not an object.
9017 There was an error (9017), please contact our support. Environment options is not a string or an object. Used when the supplied environment is not a string or an object.
9018 There was an error (9018), please contact our support. Environment doesn't match any of the predefined values (possible: TEST, LIVE; actual: ${environment}).
9043 There was an error (9043), please contact our support. HolderName should be valid. Used when the supplied holderName parameter is not a string.
9044 There was an error (9044), please contact our support.

billingAddress country should be valid country code.

Used when the supplied billingAddress.country parameter is not a string.
9045 There was an error (9045), please contact our support. billingAddress zip should be valid zip code. Used when the supplied billingAddress.zip parameter is not a string.
9046 There was an error (9046), please contact our support. billingAddress state should be valid state. Used when the supplied billingAddress.state parameter is not a string.
9047 There was an error (9047), please contact our support. billingAddress city should be valid city. Used when the supplied billingAddress.city parameter is not a string.
9048 There was an error (9048), please contact our support. billingAddress street should be valid street. Used when the supplied billingAddress.street parameter is not a string.
9049 There was an error (9049), please contact our support. billingAddress street2 should be valid street. Used when the supplied billingAddress.street2 parameter is not a string.
9052 There was an error (9052), please contact our support. billingAddress should be object. Used when the supplied billingAddress parameter is not an object.
9053 There was an error (9053), please contact our support. Invalid companyName parameter. Used when the supplied companyName parameter is not a string.
9054 There was an error (9054), please contact our support. Invalid amount parameter. Used when an amount is not supplied, is not a number, is not positive, or is longer than 9 digits.
9055 There was an error (9055), please contact our support. Invalid currency parameter. Used when the supplied currency parameter is not a string.
9057 There was an error (9057), please contact our support. Invalid locale parameter. Used when the supplied locale parameter does not match the supported values.
9059 There was an error (9059), please contact our support. Accounts should be object. Used when the supplied accounts parameter is not an object.
9060 There was an error (9060), please contact our support. Close callback should be function. Used when the provided closeCallback is not a function.
9061 There was an error (9061), please contact our support. Invalid account ID for ${paymentMethod}. Used when the supplied accountId for a specific payment method is not a number or is not positive.
9063 There was an error (9063), please contact our support. Invalid buttonColor parameter. Used when the supplied color is not a valid hex color, e.g., '#ee33ee'.
9064 There was an error (9064), please contact our support. Failed to initialize Paysafe Checkout iframe. Used when the checkout iframe has failed to initialize within 5 seconds – the reason could be that the server that serves the HTML for the iframe is not available at the moment.
9065 There was an error (9065), please contact our support. Invalid payment method: ${paymentMethod}.

Used when the supplied preferredPaymentMethod is not one of the following:

  • Cards
  • DirectDebit
  • Interac
9073 There was an error (9073), please contact our support. Account not configured correctly. Used when account ID or account currency was incorrectly configured.
Did you find this page useful?