Documentation
Search…
Android SDK
To integrate the PayKun Payment Gateway in your mobile app which can enable you to receive payments from your customers using the Android Devices you need to follow a few easy steps.
For the video tutorial to Integrate PayKun Payment Gateway in your Android App you may click here
Get the demo app from here - Paykun Demo Android App

Checkout Android SDK requires

How to install SDK in your app?

We have distributed our SDK via Maven Central Repository. You can add our latest PayKun SDK directly to your build.gradle file in the dependency section using the below given line:
1
implementation 'com.paykun.sdk:paykun-androidx-sdk:1.1.17'
Copied!
1
allprojects {
2
repositories {
3
mavenCentral()
4
}
5
}
Copied!

Performing transaction

1
// Initiate Transaction
2
public void createPayment()
3
{
4
// Required data to be provided
5
String merchantIdLive="<Marcent Id>";
6
String accessTokenLive="<Mobile Access Token>";
7
String productName="<Product Name>";
8
String orderId= String.valueOf(System.currentTimeMillis()); // You can change this based on your requirement
9
String amount="<Amount>";
10
String customerName="<Customer Name>";
11
String customerPhone="<Customer Mobile No>";
12
String customerEmail="<Customer Email Id>";
13
14
// You can customize which payment method should be provided
15
// Here is the example for payment method customization, This is optional.
16
17
// Create Map for payment methods
18
HashMap<PaymentTypes, PaymentMethods> payment_methods = new HashMap<>();
19
20
// Create payment method object to be added in payment method Map
21
PaymentMethods paymentMethod = new PaymentMethods();
22
paymentMethod.enable=true; // True if you want to enable this method or else false, default is true
23
paymentMethod.priority=1; // Set priority for payment method order at checkout page
24
paymentMethod.set_as_prefered=true; // If you want this payment method to show in prefered payment method then set it to true
25
26
// Add payment method into our Map
27
payment_methods.put(PaymentTypes.UPI, paymentMethod);
28
29
// Example for netbanking
30
paymentMethod = new PaymentMethods();
31
paymentMethod.enable=true;
32
paymentMethod.priority=2;
33
paymentMethod.set_as_prefered=true;
34
paymentMethod.sub_methods.add(new Sub_Methods(SubPaymentTypes.SBIN,1));
35
paymentMethod.sub_methods.add(new Sub_Methods(SubPaymentTypes.HDFC,1));
36
payment_methods.put(PaymentTypes.NB, paymentMethod);
37
38
// Example for wallet
39
paymentMethod = new PaymentMethods();
40
paymentMethod.enable=false;
41
paymentMethod.priority=3;
42
paymentMethod.set_as_prefered=false;
43
payment_methods.put(PaymentTypes.WA, paymentMethod);
44
45
// Example for card payment
46
paymentMethod = new PaymentMethods();
47
paymentMethod.enable=true;
48
paymentMethod.priority=3;
49
paymentMethod.set_as_prefered=true;
50
payment_methods.put(PaymentTypes.DCCC, paymentMethod);
51
52
// Example for UPI Qr
53
paymentMethod = new PaymentMethods();
54
paymentMethod.enable=true;
55
paymentMethod.priority=3;
56
paymentMethod.set_as_prefered=true;
57
payment_methods.put(PaymentTypes.UPIQRCODE, paymentMethod);
58
59
// Example for EMI
60
paymentMethod = new PaymentMethods();
61
paymentMethod.enable=true;
62
paymentMethod.priority=3;
63
paymentMethod.set_as_prefered=true;
64
payment_methods.put(PaymentTypes.EMI, paymentMethod);
65
66
// Now, Create object for paykun transaction
67
PaykunTransaction paykunTransaction=new PaykunTransaction(merchantIdLive,accessTokenLive,true);
68
69
try {
70
// Set all request data
71
paykunTransaction.setCurrency("INR");
72
paykunTransaction.setCustomer_name(customerName);
73
paykunTransaction.setCustomer_email(customerEmail);
74
paykunTransaction.setCustomer_phone(customerPhone);
75
paykunTransaction.setProduct_name(productName);
76
paykunTransaction.setOrder_no(orderId);
77
paykunTransaction.setAmount(amount);
78
paykunTransaction.setLive(true); // Currently only live transactions is supported so keep this as true
79
80
// Optionally you can customize color and merchant logo for checkout page
81
paykunTransaction.setTheme_color("<COLOR CODE>");
82
paykunTransaction.setTheme_logo("<LOGO URL>");
83
84
// Set the payment methods Map object that we have prepared above, this is optional
85
paykunTransaction.setPayment_methods(payment_methods);
86
87
new PaykunApiCall.Builder(PaymentActivity.this).sendJsonObject(paykunTransaction);
88
} catch (Exception e) {
89
e.printStackTrace();
90
}
91
}
Copied!

Handling transaction callback (Response)

  • You will get the result in PaymentActivity class after sending your data to Paykun.
  • Handling Payment callback, This Activity/Fragment Must implement PaykunResponseListener interface
  • This interface provides callback methods ‘onPaymentSuccess’ and ‘onPaymentError’
1
public class PaymentActivity extends AppCompatActivity implements PaykunResponseListener
2
{
3
@Override
4
public void onPaymentSuccess(PaymentMessage message) {
5
Log.e("onPaymentSuccess",message.toString());
6
Toast.makeText(this,"Your Transaction is Success With Id "+message.getTransactionId(),Toast.LENGTH_SHORT).show();
7
}
8
9
@Override
10
public void onPaymentError(PaymentMessage message) {
11
if(message.getResults().equalsIgnoreCase(PaykunHelper.MESSAGE_CANCELLED)){
12
// do your stuff here
13
Toast.makeText(this,"Your Transaction is cancelled",Toast.LENGTH_SHORT).show();
14
}
15
else if(message.getResults().equalsIgnoreCase(PaykunHelper.MESSAGE_FAILED)){
16
// do your stuff here
17
Toast.makeText(this,"Your Transaction is failed",Toast.LENGTH_SHORT).show();
18
}
19
else if(message.getResults().equalsIgnoreCase(PaykunHelper.MESSAGE_NETWORK_NOT_AVAILABLE)){
20
// do your stuff here
21
Toast.makeText(this,"Internet Issue",Toast.LENGTH_SHORT).show();
22
23
}else if(message.getResults().equalsIgnoreCase(PaykunHelper.MESSAGE_SERVER_ISSUE)){
24
// do your stuff here
25
Toast.makeText(this,"Server issue",Toast.LENGTH_SHORT).show();
26
}else if(message.getResults().equalsIgnoreCase(PaykunHelper.MESSAGE_ACCESS_TOKEN_MISSING)){
27
// do your stuff here
28
Toast.makeText(this,"Access Token missing",Toast.LENGTH_SHORT).show();
29
}
30
else if(message.getResults().equalsIgnoreCase(PaykunHelper.MESSAGE_MERCHANT_ID_MISSING)){
31
// do your stuff here
32
Toast.makeText(this,"Merchant Id is missing",Toast.LENGTH_SHORT).show();
33
}
34
else if(message.getResults().equalsIgnoreCase(PaykunHelper.MESSAGE_INVALID_REQUEST)){
35
Toast.makeText(this,"Invalid Request",Toast.LENGTH_SHORT).show();
36
}
37
}
38
}
Copied!

For any Assistance :

In case of any query, please contact to [email protected]