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
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:
// Initiate TransactionpublicvoidcreatePayment(){// Required data to be providedString merchantIdLive="<Marcent Id>";String accessTokenLive="<Mobile Access Token>";String productName="<Product Name>";String orderId=String.valueOf(System.currentTimeMillis()); // You can change this based on your requirementString amount="<Amount>";String customerName="<Customer Name>";String customerPhone="<Customer Mobile No>";String customerEmail="<Customer Email Id>";// You can customize which payment method should be provided// Here is the example for payment method customization, This is optional.// Create Map for payment methodsHashMap<PaymentTypes,PaymentMethods> payment_methods =newHashMap<>();// Create payment method object to be added in payment method MapPaymentMethods paymentMethod =newPaymentMethods();paymentMethod.enable=true; // True if you want to enable this method or else false, default is truepaymentMethod.priority=1; // Set priority for payment method order at checkout pagepaymentMethod.set_as_prefered=true; // If you want this payment method to show in prefered payment method then set it to true// Add payment method into our Mappayment_methods.put(PaymentTypes.UPI, paymentMethod);// Example for netbanking paymentMethod =newPaymentMethods();paymentMethod.enable=true;paymentMethod.priority=2;paymentMethod.set_as_prefered=true;paymentMethod.sub_methods.add(newSub_Methods(SubPaymentTypes.SBIN,1));paymentMethod.sub_methods.add(newSub_Methods(SubPaymentTypes.HDFC,1));payment_methods.put(PaymentTypes.NB, paymentMethod);// Example for wallet paymentMethod =newPaymentMethods();paymentMethod.enable=false;paymentMethod.priority=3;paymentMethod.set_as_prefered=false;payment_methods.put(PaymentTypes.WA, paymentMethod);// Example for card payment paymentMethod =newPaymentMethods();paymentMethod.enable=true;paymentMethod.priority=3;paymentMethod.set_as_prefered=true;payment_methods.put(PaymentTypes.DCCC, paymentMethod);// Example for UPI Qr paymentMethod =newPaymentMethods();paymentMethod.enable=true;paymentMethod.priority=3;paymentMethod.set_as_prefered=true;payment_methods.put(PaymentTypes.UPIQRCODE, paymentMethod);// Example for EMI paymentMethod =newPaymentMethods();paymentMethod.enable=true;paymentMethod.priority=3;paymentMethod.set_as_prefered=true;payment_methods.put(PaymentTypes.EMI, paymentMethod);// Now, Create object for paykun transactionPaykunTransaction paykunTransaction=newPaykunTransaction(merchantIdLive,accessTokenLive,true);try {// Set all request datapaykunTransaction.setCurrency("INR");paykunTransaction.setCustomer_name(customerName);paykunTransaction.setCustomer_email(customerEmail);paykunTransaction.setCustomer_phone(customerPhone);paykunTransaction.setProduct_name(productName);paykunTransaction.setOrder_no(orderId);paykunTransaction.setAmount(amount);paykunTransaction.setLive(true); // Currently only live transactions is supported so keep this as true// Optionally you can customize color and merchant logo for checkout pagepaykunTransaction.setTheme_color("<COLOR CODE>");paykunTransaction.setTheme_logo("<LOGO URL>");// Set the payment methods Map object that we have prepared above, this is optionalpaykunTransaction.setPayment_methods(payment_methods);new PaykunApiCall.Builder(PaymentActivity.this).sendJsonObject(paykunTransaction); } catch (Exception e) {e.printStackTrace(); }}
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’
publicclassPaymentActivityextendsAppCompatActivityimplementsPaykunResponseListener{ @OverridepublicvoidonPaymentSuccess(PaymentMessage message) {Log.e("onPaymentSuccess",message.toString());Toast.makeText(this,"Your Transaction is Success With Id "+message.getTransactionId(),Toast.LENGTH_SHORT).show(); } @OverridepublicvoidonPaymentError(PaymentMessage message) {if(message.getResults().equalsIgnoreCase(PaykunHelper.MESSAGE_CANCELLED)){// do your stuff hereToast.makeText(this,"Your Transaction is cancelled",Toast.LENGTH_SHORT).show(); }elseif(message.getResults().equalsIgnoreCase(PaykunHelper.MESSAGE_FAILED)){// do your stuff hereToast.makeText(this,"Your Transaction is failed",Toast.LENGTH_SHORT).show(); }elseif(message.getResults().equalsIgnoreCase(PaykunHelper.MESSAGE_NETWORK_NOT_AVAILABLE)){// do your stuff hereToast.makeText(this,"Internet Issue",Toast.LENGTH_SHORT).show(); }elseif(message.getResults().equalsIgnoreCase(PaykunHelper.MESSAGE_SERVER_ISSUE)){// do your stuff hereToast.makeText(this,"Server issue",Toast.LENGTH_SHORT).show(); }elseif(message.getResults().equalsIgnoreCase(PaykunHelper.MESSAGE_ACCESS_TOKEN_MISSING)){// do your stuff hereToast.makeText(this,"Access Token missing",Toast.LENGTH_SHORT).show(); }elseif(message.getResults().equalsIgnoreCase(PaykunHelper.MESSAGE_MERCHANT_ID_MISSING)){// do your stuff hereToast.makeText(this,"Merchant Id is missing",Toast.LENGTH_SHORT).show(); }elseif(message.getResults().equalsIgnoreCase(PaykunHelper.MESSAGE_INVALID_REQUEST)){Toast.makeText(this,"Invalid Request",Toast.LENGTH_SHORT).show(); } }}