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”;
Important to consider

Please add the following lines to your code only if you are using Angular 6 or a higher version along with Kushki’s npm package. This will help with the issue when it is not possibe to resolve ‘net’/‘global’ or other node globals. Find more information in Angular GitHub repository.

Add the following code in your project:

const fs = require('fs');
const f =
  'node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js';

fs.readFile(f, 'utf8', function(err, data) {
  if (err) {
    return console.log(err);
  }
  var result = data.replace(
    /node: false/g,
    "node: {crypto: true, stream: true, fs: 'empty', net: 'empty', tls: 'empty'}"
  );

  fs.writeFile(f, result, 'utf8', function(err) {
    if (err) return console.log(err);
  });
});

Every time you run npm install, include the following code in your package.json as a part of the postinstall scripts:

"scripts": {
	"postinstall": "node patch.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
  • Request an OTP validation. If you want more information about this feature, please go to our One Time Password section
  • Get deferred options by bin
  • Get Bin Info
  • Create a subscription token
  • Get token for subscription charge
  • Get list of banks available for transfer in PSE
  • Create a Transfer token
  • Create a Cash token
  • Create a Card Async 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.
requestSecureServiceValidation() secureServiceId, otpValue, callback Object Returns whether the OTP is valid or not.
requestDeferred() binBody, callback Object Returns an object with deferred options that are allowed for Ecuadorian, Mexican, and Peruvian merchants.
requestBinInfo() binBody, callback Object Returns an object with the information related to the credit card bin.
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.
requestPseBankList() callback Object Returns a list of banks available for transfer in PSE
requestTransferToken() bankId, amount, callbackUrl, documentType, documentNumber, referenceNumber, paymentDesc, userType, callback Object Returns a transfer token
requestCashToken() name, lastName,documentType, identification, email, totalAmount, currency,description, callback Object Returns a cash token
cardAsyncTokenRequest() totalAmount, currency, returnUrl, email, description, callback Object Returns a card async token
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', //for Chilean merchants only
  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, PEN, MXN
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 String 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"
}

requestDeferred()

To get deferred options according to merchant deferred configurations specified 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 String 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",
}

requestBinInfo()

Returns an object with the information related to the credit-card bin (first six digits). For Chilean merchants, the response is helpfull to decide wheter to continue with the request of a card token (when cardType is CREDIT), or with the request of a card async token (when cardType is DEBIT):

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.requestBinInfo(
{
bin: "415788"
},
callback);// Also you can set the function directly

Required

Property Type Description
bin String The first six digits of the credit card
callback Function(response) The created callback function()

Response

Successful response will be in the function (callback):

{
    bank: "BANCO DE LA PRODUCCION S.A. (PRODUBANCO)",
    brand: "visa",
    cardType: "debit"
}
Error response will be in the function (callback):
{ 
  code:"error-code",
  message:"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" 
}

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);
  }
};

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