INITIAL GUIDE
Libraries
COLLECTING PAYMENTS
CHARGES

JAVA

Once you have tokenized your client’s credit card using one of our collecting payments you can begin the charge process.

Kushki has created a Java library for your backend development, allowing you to easily submit payments.

Install and configure

Dependencies

  • Option 1 - GRADLE

Declare dependency from jcenter() or mavenCentral()

repositories {
    jcenter() // or mavenCentral()
}
dependencies {
    compile "com.kushkipagos:kushkipagos:1.3.0"
}

Option 2 - MAVEN

Add a Kushki dependency through Maven

<dependencies>
    <dependency>
        <groupId>com.kushkipagos</groupId>
        <artifactId>kushkipagos</artifactId>
        <version>1.3.0</version>
    </dependency>
</dependencies>

Import

Import Kushki to you project

package com.kushkipagos.example;
import com.kushkipagos.Amount;
import com.kushkipagos.Kushki;
import com.kushkipagos.KushkiEnvironment;
import com.kushkipagos.Transaction;
import com.kushkipagos.ExtraTaxes; // Only required for Colombian transactions

Usage

Begin creating your Kushki object, it will allow you to perform all the methods available in our Java Library.

String merchantId = "<private-merchant-id>";
String language = "es";
String currency = "USD";

KushkiEnvironment environment = KushkiEnvironment.PRODUCTION;

Kushki kushki = new Kushki(merchantId, language, currency, environment);

Required

Property Type Description Default Possible Values
merchantId String Kushki private ID created for your merchant

Optional

Property Type Description Default Possible Values
language String Language to be display es es,en
currency String Code of currency used USD USD, COP
environment boolean Value to define if you are in production or test environment KushkiEnvironment.PRODUCTION KushkiEnvironment.PRODUCTION , KushkiEnvironment.TESTING

Reference

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

  • Create a payment transaction
  • Cancel a payment transaction
  • Refund a payment transaction
  • Create a subscription
  • Create a subscription payment transaction
  • Update a subscription
  • Update a credit card subscription
  • Adjust a subscription
  • Delete a subscription
Java Methods
Name Parameters Returns Description
charge() token, amount, metadata months Object Charge the card
voidCharge() ticket Object Cancel a charge transaction
refundCharge() ticket Object Refund a transaction
subscription() token, amount, metadata, subscriptionInf Object Create a subscription
updateSubscription() amount, metadata, subscriptionInfo, subscriptionId Object Update a created subscription
updateSubscriptionCard() newToken, subscriptionId Object Update the client’s card information with a new token
adjustSubscription() subscriptionId, date, periods, amount, adjustPeriod Object Adjust an amount you can charge or make a discount
subscriptionCharge() cvv,amount, metadata, subscriptionId Object Charge a subscription
deleteSubscription() subscriptionId Object Allow you to delete a created subscription

charge()

Charge the card using the following code:

Request

String token = "< token enviado desde el navegador en el parametro kushkiToken >";
Integer meses = 3; // Number of months sent from the browser in the kushkiDeferred parameter, converted to Integer
Double subtotalIva = 10.0;
Double iva = 1.20;
Double subtotalIva0 = 5.0;
Double ice = 1.50;
Amount monto = new Amount(subtotalIva, iva, sutotalIva0, ice);
JSONObject basicJSON  = new JSONObject("{\"data\":\"test\");
Transaction transaccion;


// transaction without metadata and deferer
transaccion = kushki.charge(token, monto,  null, null ); 

// transaction with metadata and without deferer
transaccion = kushki.charge(token, monto, meses, null, basicJSON ); 

// transaction with metadata and  deferer
transaccion = kushki.charge(token, monto, meses basicJSON ); 


Required

Property Type Description
token String Value obtained in the front-end
amount Object Value that is going to be charged.

Check Amount in Java

Optional

Property Type Description
months Integer Number of months if selected deffered and it defines the use of charge
metadata JSONObject Optional variable which contains a json object

Remember import org.json.JSONObject if you want to add metadata.

Response

Check if the transaction was successful or not, and retreive relevant data.

Check Transaction in Java

if (transaction.isSuccessful()) {
    System.out.println("Número de ticket:  " + transaccion.getTicketNumber());
} else {
    System.out.println("Error " + transaccion.getResponseCode() + ": " + transaccion.getResponseText());
}

voidCharge()

It allows you to cancel a previous payment

Transaction charge = kushki.charge(token, amount, null, null);
            if(charge.isSuccessful()) {
                 Transaction voidCharge = kushki.voidCharge(charge.getTicketNumber());
            }

Required

Property Type Description
ticket String Ticket number obtained in the charge method

refundCharge()

It allows to refund a previous payment

Transaction charge = kushki.charge(token, amount, null, null);
            if(charge.isSuccessful()) {
                 Transaction voidCharge = kushki.refundCharge(charge.getTicketNumber());
            }
              

Required

Property Type Description
ticket String Ticket number obtained in the charge method

subscription()

Create a subscription with an amount to charge

Amount amount = new Amount(100d, 12d, 0d, 0d);
 ContactDetail contactDetail =  new ContactDetail("Heidi", "Nino", "heidi@nino.com");
 JSONObject metadata  = new JSONObject("{\"data\":\"test\");
 Date startDate = new Date();
 SuscriptionInfo subscriptionInfo = new SuscriptionInfo("standard", 
 KushkiPeriodicitySubscriptionType.MONTLY,startDate,contactDetail);
 
//create the subscription
 Transaction transaction = kushki.subscription(token, amount, metadata, new subscriptionInfo);
if (transaction.isSuccessful()) {
    System.out.println("Subscription ID:  " + transaccion.getSubscriptionId());
} else {
    System.out.println("Error " + transaccion.getResponseCode() + ": " + transaccion.getResponseText());
}

Required

Property Type Description
token String Token generated in front-end
amount Object Contain all values to charge
SubscriptionInfo Object Contains subscription details

Check Amount and SubscriptionInfo in Java

Optional

Property Type Description
metadata JSONObject Additional infomation for business

Remember import org.json.JSONObject to add metadata elements

subscriptionCharge()

Use this kind of charge over created subscriptions

Double subtotalIva = 10.0;
Double iva = 1.20;
Double subtotalIva0 = 5.0;
Double ice = 1.50;
String cvv = "123";
Amount amount = new Amount(subtotalIva, iva, sutotalIva0, ice); //use the same Amount class as in subscription 
JSONObject metadata  = new JSONObject("{\"data\":\"test\");

Transaction transaction = kushki.subscriptionCharge(cvv, amount, metadata, subscriptionId);
 if (transaction.isSuccessful()) {
    System.out.println("Ticket #:  " + transaccion.getTicketNumber());
} else {
    System.out.println("Error " + transaccion.getResponseCode() + ": " + transaccion.getResponseText());
}

Required

Property Type Description
cvv String Credit Card CVV
amount Object Contain all values to charge
subscriptionId String Subscription Id created in subscription()

Check amount in Java

Optional

Property Type Description
metadata JSONObject Additional infomation for business

Remember import org.json.JSONObject to add metadata elements

updateSubscription()

Update any subscription parameter

 Amount amount = new Amount(100d, 12d, 0d, 0d); //use the same Amount class as in subscription 
 ContactDetail contactDetail =  new ContactDetail("Heidi", "Nino", "heidi@nino.com");
 JSONObject metadata  = new JSONObject("{\"data\":\"test\");
 Date startDate = new Date();
 SuscriptionInfo subscriptionInfo = new SuscriptionInfo("standard", 
 KushkiPeriodicitySubscriptionType.MONTLY,startDate,contactDetail);

Transaction transaction = kushki.updateSubscription( amount, metadata, subscriptionInfo, subscriptionId);

 if (transaction.isSuccessful()) {
     System.out.println("Subscription updated");
} else {
    System.out.println("Error " + transaccion.getResponseCode() + ": " + transaccion.getResponseText());
}

Required

Property Type Description
amount Object Contain all values to charge
SubscriptionInfo Object Contains subscription details
subscriptionId String Subscription Id created in subscription()

Check Amount and SubscriptionInfo in Java

Optional

Property Type Description
metadata JSONObject Additional infomation for business

Remember import org.json.JSONObject to add metadata elements

updateSubscriptionCard()

Create a new token that will contain the updated card information

// create a new token subscription in the front 
String token = "90a9f2d93ba508c38971890454897fd4";

Transaction transaction = kushki.updateSubscriptionCard( token , subscriptionId);
 if (transaction.isSuccessful()) {
    System.out.println("Subscription updated");
} else {
    System.out.println("Error " + transaccion.getResponseCode() + ": " + transaccion.getResponseText());
}
 
Property Type Description
token String Token generated in front-end
subscriptionId String Subscription Id created in subscription()

adjustSubscription()

Use this kind of adjust over created subscriptions

Double subtotalIva = 10.0;
Double iva = 1.20;
Double subtotalIva0 = 5.0;
Double ice = 1.50;
String cvv = "123";
Date startDate = new Date();
Int periods = 3;
Amount amount = new Amount(subtotalIva, iva, sutotalIva0, ice);

Transaction transaction = kushki.adjustSubscription(subscriptionId, startDate, amount, periods, amount, KushkiAdjustSubscription.CHARGE);
 if (transaction.isSuccessful()) {
    System.out.println("Adjust Ok");
} else {
    System.out.println("Error " + transaccion.getResponseCode() + ": " + transaccion.getResponseText());
}

Required

Property Type Description Possible Values
subscriptionId String Subscription ID created in subscription()
startDate Date Subscription start date
periods Integer Numbers of periods
amount Object Contain all values to charge
adjustPeriod Enum KushkiAdjustSubscription to define if is a charge or discount KushkiAdjustSubscription.CHARGE, KushkiAdjustSubscription.DISCOUNT

Check Amount and SubscriptionInfo in Java

deleteSubscription()

To delete a created subscription

Transaction transaction = kushki.deleteSubscription(subscriptionId);
 if (transaction.isSuccessful()) {
    System.out.println("Subscription was delete");
} else {
    System.out.println("Error " + transaccion.getResponseCode() + ": " + transaccion.getResponseText());
}
Property Type Description
subscriptionId String Subscription ID created in subscription()

Classes available

Methods

Name Parameters Returns Description
isSuccessful() boolean Returns true when the transaction was successful, false otherwise
getTicketNumber() String Returns the ticket number of a charge or deferred charge transaction in order to cancel or reimburse it
getResponseText() String Returns the response text. In case of successful transactions, successful transaction. In case of transactions with error, this text describes the problem
getApprovedAmount() Double Returns the approved amount of the transaction for Colombia
getResponseCode() String Returns the response code. In case of successful transactions, 000. In case of transactions with error, a numeric code