PayJunction JavaScript SDK

Use PayJunction's JavaScript SDK to securely tokenize sensitive customer information on the web.

Getting Started

First, include the PayJunction SDK by adding the script tag to the head of your HTML page.

<html>
<head>
...
<script type="text/javascript" src="https://www.payjunctionlabs.com/trinity/js/sdk.js"></script>
...
</head>

Next, create an instance of the PayJunction object by providing your publishable key as the first parameter.

var payjunction = PayJunction('YOUR_PUBLISHABLE_KEY');

Finally, send the card details entered by the customer to receive the single-use token.

payjunction.createToken({
cardNumber: '4444333322221111',
cardExpMonth: '12',
cardExpYear: '30',
cardCvv: '999'
})
.then(function(result) {
if (result.tokenId) {
...
}
});

SDK Reference

Introduction

This is a reference of all the resources available in our client-side JavaScript SDK, sdk.js.

Including sdk.js

sdk.js is available at the following URLs:

  • Test https://www.payjunctionlabs.com/trinity/js/sdk.js
  • Production https://www.payjunction.com/trinity/js/sdk.js

Add the script to the pages of your website that need it (for example, your checkout page).

Always load the script directly from our servers rather than hosting it on your website to receive security updates and new features.

Initializing sdk.js

PayJunction(publishableKey)

This method returns an instance of the PayJunction SDK object. You can access all other PayJunction SDK methods through this object.

A valid publishable key is required to call this method. Test and Production environments use different publishable keys, so remember to replace the test key with the production key before going live.

Method Parameters

Required Name Format Description
* publishableKey string A valid publishable key.

Returns

  • PayJunction - A PayJunction SDK instance.

Example Usage

var payjunction = PayJunction('YOUR_PUBLISHABLE_KEY');

Tokens

payjunction.createToken(cardPaymentData)

Use payJunction.createToken to transform sensitive card information into a single-use token. A token is represented by a token id. You can safely pass the token id to your server and use it with the PayJunction API.

Method Parameters

Required Name Format Description
* cardPaymentData object An object containing sensitive payment information.

cardPaymentData Properties

Required Name Format Description
* cardNumber string The credit card number used for payment.
* cardExpMonth string, 1-12 The credit card expiration month.
* cardExpYear string, 2 or 4 digits The credit card expiration year.
  cardCvv string, 3 or 4 digits The credit card verification value.

Returns

  • Promise<TokenResponse|ErrorsResponse>.

payjunction.createToken returns a Promise which resolves with a result object. This object will be either:

  • A Token Response - A token was successfully created.
  • An Errors Response - An error occurred. Error responses follow the PayJunction API Error format.

Example Usage

payjunction.createToken({
cardNumber: '4444333322221111',
cardExpMonth: '12',
cardExpYear: '30',
cardCvv: '999'
})
.then(function(result) {
// Handle result.errors or result.tokenId
});

Example Token Response

{
"tokenId" : "nX83miVXaCz5HvGSKufnow",
"brand" : "VISA",
"cardExpMonth" : 12,
"cardExpYear" : 2030,
"lastFour" : "1111"
}

Example Errors Response

{
"errors" : [ {
"message" : "This field is required.",
"parameter" : "cardExpMonth",
"type" : "required"
}, {
"message" : "This field is required.",
"parameter" : "cardExpYear",
"type" : "required"
}, {
"message" : "This field is required.",
"parameter" : "cardNumber",
"type" : "required"
} ]
}

Token Response

Field Type Description
brand string Card brand.
cardExpMonth number Card expiration month.
cardExpYear number Card expiration year.
lastFour string Last four digits of the card number.
tokenId string

Random sequence of characters representing the card details.

No sensitive information can be extracted from this string.

Browser Support

PayJunction SDK is supported on recent versions of all major browsers. We do not support Internet Explorer.