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 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
merchantId String Kushki ID created for your merchant

Optional

Property Type Description Default Possible Values
inTestEnvironment boolean Value to define if you are in production or test environment false true , false
regional Boolean Define if use a static IP to Kushki access false true,false

Reference

Find methods available in the chart. They allow you to make this operations:

  • Create card token
  • Create a subscription token
  • Get token for subscription charge
  • Get deffered options by bin
  • Get list of banks available for transfer in PSE
  • Create a Transfer token
Kushki.js Methods
Name Parameters Returns Description
requestToken() card, amount, isDeferred currency, callback Object Returns a token of a credit card. Make sure they are outside of your main form (PCI COMPLIANT needs to be able to handle credit and debit card data) to prevent card data.
requestSubscriptionToken() card, currency, callback Object Returns a token of a subscription. Make sure they are outside of your main form (PCI COMPLIANT needs to be able to handle credit and debit card data) to prevent card data.
requestTokenCharge() subscriptionId, callback Object Returns a token of a subscription.
requestDeferred() binBody, callback Object Returns a object with deffered options that are allowed per merchant
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

requestToken()

To create a card 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.requestToken({
  amount: '49.99',
  isDeferred: false,
	currency: "USD"
  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
card Object The card data collected in an card object
callback Function(response) The created callback function() * Success : { token: "90a9f2d93ba508c38971890454897fd4"}
* Error: { message:"error-message", code:"error-code", error: "error-message"}

Optional

Property Type Description Default Possible Values
isDeferred Boolean To indicate if there is a deferred payment. false true, false

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" 
}

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
}, 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
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
subscription 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
binBody 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):

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