INITIAL GUIDE
Libraries
COLLECTING PAYMENTS
CHARGES

Kushki.js

Kushki.js is our JavaScript library for building payment flows with your own style. You can collect all the card information from your client and generate a token that will safely save and send that data to your servers.

We make it easier!

Import Kushki.js

  • Option 1 - CDN

Use a script tag inside your page to add the features. When adding the following code to your page it will be imported.

<script src="https://cdn.kushkipagos.com/kushki.min.js"></script>
  • Option 2 - NPM

Install the npm with the following code:

npm install --save @kushki/js

Then import it to your development workspace with the following code:

import { Kushki } from “@kushki/js”;

Usage

Begin creating your Kushki, it will allow you to perform all the functions available in Kushki.js.

var kushki = new Kushki({
  merchantId: 'public-merchant-id', 
  inTestEnvironment: false,
  regional:false
});

Required

Property Type Description Default Possible Values
merchantId String Kushki ID created for your merchant
inTestEnvironment boolean Value to define if you are in production or test environment false true , false

Optional

Property Type Description Default Possible Values
regional Boolean Define if use a static IP to Kushki access false true,false

Reference

Find all the methods available in the chart below. They allow you to make the following operations:

  • Create a card token.
  • Get deffered options by bin
  • Request an OTP validation. If you want more information about this feature, please go to our One Time Password section.
  • Create a subscription token
  • Get token for subscription charge
  • Get list of banks available for transfer in PSE
  • Create a Transfer token
  • Get the status of all the payment methods configured for a specific merchant
Kushki.js Methods
Name Parameters Returns Description
requestToken() card, amount, isDeferred, currency, months, callback Object Returns a token of a credit card. Make sure they are outside of your main form (PCI COMPLIANCE). If the merchant has the OTP validation activated, this method will return also a secureId and a secureService that can later be used to validate the OTP.
requestDeferred() binBody, callback Object Returns an object with deferred options that are allowed for Ecuadorian merchants.
requestSecureServiceValidation() secureServiceId, otpValue Object Returns whether the OTP is valid or not.
requestSubscriptionToken() card, currency, callback Object Returns a token of a subscription. Make sure they are outside of your main form (PCI COMPLIANCE).
requestTokenCharge() subscriptionId, callback Object Returns a token of a subscription.
requestTransferToken() bankId, amount, callbackUrl, documentType, documentNumber, referenceNumber, paymentDesc, userType, callback Object Returns a transfer token
requestPseBankList() callback Object Returns a list of banks available for transfer in PSE
getStatusGateway() callback Object Returns the status of all the payment methods configured for a specific merchant

requestToken()

To create a card token you can use this function:

Request

var callback = function(response) {
  if(!response.code){
    console.log(response);
  } else {
    console.error('Error: ',response.error, 'Code: ', response.code, 'Message: ',response.message);
  }
}

kushki.requestToken({
  amount: '49.99',
  currency: "USD",
  months: '3',
  card: {
    name: "Juan Guerra",
    number: "4544980425511225",
    cvc: "345",
    expiryMonth: "12",
    expiryYear: "28"
},
}, callback); // Also you can set the function directly

Required

Property Type Description Default Possible Values
amount String The amount you are going to collect as a string
currency String Code of currency used USD USD, COP, CLP, UF
card Object The card data collected in an card object
callback Function(response) The created callback function() * Success : { token: "90a9f2d93ba508c38971890454897fd4"}
* With OTP validation activated : { token: "90a9f2d93ba508c38971890454897fd4", secureId: “5e44449e-869b-4fed-bbca-e1bfa5af53c3”, secureService: “KushkiOTP”}
* Error: { message:"error-message", code:"error-code", error: "error-message"}

Optional

Property Type Description Default Possible Values
months Integer Number of months. Only available in Chile for deferred transactions. Minimum: 2

Response

Successful response will be in the function (callback):

{ 
    token: "90a9f2d93ba508c38971890454897fd4"
}

The following is a response when the merchant has the OTP validation activated:

{ 
    token: "90a9f2d93ba508c38971890454897fd4",
    secureId: "5e44449e-869b-4fed-bbca-e1bfa5af53c3",
    secureService: "KushkiOTP"
}

The following is a response for Chilean merchants. You will receive also de amount that has to be paid every month for deferred transactions:

{ 
    token: "90a9f2d93ba508c38971890454897fd4",
    settlement: 6000
}
Error response will be in the function (callback):
{ 
  message:"error-message", 
  code:"error-code",
  error: "error-message"
}

requestSecureServiceValidation()

To validate the OTP entered by the client:

Request

var callback = function(response) {
  if(!response.code){
    console.log(response);
  } else {
    console.error('Error: ',response.error, 'Code: ', response.code, 'Message: ',response.message);
  }
}

kushki.requestSecureServiceValidation({
 secureServiceId: "5e44449e-869b-4fed-bbca-e1bfa5af53c3",
 otpValue: 155
}, callback);

Required

Property Type Description Possible Values
secureServiceId String The secureId you get from the token request
otpValue Number Three-digit number that corresponds to the OTP For the OTP sandbox, the value will change depending on the credit card currency: 155 for USD, 555 for COP
callback Function(response) The created callback function() * Success : { isValid: true}
* Error: { message:"error-message", code:"error-code", error: "error-message"}

Response

Successful response will be in the function (callback):

{ 
    isValid: true
}
Error response will be in the function (callback):
{ 
  message:"error-message", 
  code:"error-code",
  error: "error-message"
}

requestSubscriptionToken()

To create a subscription token you can use this function:

Request

var callback = function(response) {
  if(!response.code){
    console.log(response.token);
  } else {
    console.error('Error: ',response.error, 'Code: ', response.code, 'Message: ',response.message);
  }
}

kushki.requestSubscriptionToken({
  card: {
    name: "Juan Guerra",
    number: "4544980425511225",
    cvc: "345",
    expiryMonth: "12",
    expiryYear: "28"
},
  currency: "USD"
}, callback); // Also you can set the function directly

Required

Property Type Description Default Possible Values
card Object The card data collected in an card object
currency String Code of currency used USD USD, COP, CLP, UF
callback Function(response) The created callback function() * Success : { token: "90a9f2d93ba508c38971890454897fd4"}
* Error: { message:"error-message", code:"error-code", error: "error-message"}

Response

Successful response will be in the function (callback):

{ 
  token: "90a9f2d93ba508c38971890454897fd4"
}
Error response will be in the function (callback):
{ 
  message:"error-message", 
  code:"error-code",
  error: "error-message" 
}

requestTokenCharge()

Get customer subscription fingerprint, to validate payment frauds.

Once a customer create a subscription, to validate if is the same customer use the requestTokenCharge() to get fingerprint information.

Request

var callback = function(response) {
  if(!response.code){
    console.log(response.token);
  } else {
    console.error('Error: ',response.error, 'Code: ', response.code, 'Message: ',response.message);
  }
}

kushki.requestTokenCharge({
  subscriptionId: "1543267242354000"
}, callback); // Also you can set the function directly

Required

Property Type Description Default Possible Values
subscriptionId String SubscriptionId that was previously created
callback Function(response) The created callback function() * Success : { token: "90a9f2d93ba508c38971890454897fd4"}
* Error: { message:"error-message", code:"error-code", error: "error-message"}

Response

Successful response will be in the function (callback):

{ 
  token: "90a9f2d93ba508c38971890454897fd4"
}
Error response will be in the function (callback):
{ 
  message:"error-message", 
  code:"error-code",
  error: "error-message" 
}

requestDeferred()

To get deferred options according to merchant deffered configurations made in Backoffice:

Request

var callback = function(response) {
  if(!response.code){
    console.log(response.token);
  } else {
    console.error('Error: ',response.error, 'Code: ', response.code, 'Message: ',response.message);
  }
}

kushki.requestDeferred(
{
bin: "424242"
},
callback);// Also you can set the function directly

Required

Property Type Description
bin Object The bin that is going to be validated for deffered options
callback Function(response) The created callback function()

Response

Successful response will be in the function (callback):

[
    {
      name: "Diferido con intereses",
      type: "002",
      months: ["3", "6"],
      monthsOfGrace: ["1", "2", "3"]
    }
]
Error response will be in the function (callback):
{ 
  code:"error-code",
  message:"error-message",
}

getStatusGateway()

To get the status of all the payment methods configured for a specific merchant:

Request

var callback = function (response) {
  if(!response.code){
    console.log(response);
  } else {
    console.error('Error: ',response.error, 'Code: ', response.code, 'Message: ',response.message);
  }
};

function getStatusGateway() {
  kushki.checkStatus(callback);
}

Required

Property Type Description
callback Function(response) The created callback function()

Response

The response will be in the function (callback):

[
    {
      card: true,
      transfer: true,
      cash: true
    }
]