It is easy to integrate the JS Checkout into your website. It provides an efficient way to collect online payments with multiple payment options from your customer. Also, it adds to customer satisfaction because while making the payment he remains on the merchant website. This boosts the trust and confidence of the customer to proceed with the checkout process and pay with their preferred payment method.
Following things will be required before you can begin integration:
Merchant ID
Access Token & API Secret (See how to generate)
In the given order include these two JS in your HTML script
<script src="https://checkout.paykun.com/checkout/plugin/crypt/crypto-js.min.js"></script><script src="https://checkout.paykun.com/checkout/js/paykun.js"></script>
Note : Jquery is required to make sure that you have included Jquery before including above js files
The given below is the Sample JS Code to initialize the payment -
// Create Paykun object// Currently Sandbox does not support JS checkout, and so you will not be able to test JS integration,// isLive can only be true for nowconst pk = new PayKun({ merchantId : "merchantId", accessToken: "accessToken", isLive: true});// Add this function in your javascript tag or your js file// This method can be called to initialize payment, It can be any event User Generated Or system Generatedfunction initPayment() {let order = {amount: "10", // Amount to collectorderId: "ORD" + (new Date).getTime(), // Unique order id, You can use your custom login here, but make sure it generates unique ID everytimeproductName: "Mobile", // Name of the productcustomerName: "Test name", // Name of the customercustomerEmail: "test@gmail.com", // Email of the customercustomerMobile: "9999999999", // Mobile of customercurrency: "INR", //set your 3 digit currency code here// Following are callback function and will be called when any result is received after payment,// If payment is success then onSuccess method will be called Or else onCancelled method will be calledonSuccess: function (transactionId) {// You can use 'transactionId' variable to process payment at your server side if you like,// In that case you can call our transaction status API on your server to get transaction information Or// You can get complete transaction details by calling the following function// WARNING: It is advisable to verify transaction amount and status at your server side using Transaction ID before delivering any service for security reasonvar transaction = pk.getTransactionDetail(transactionId, function(transaction) {// You can show payment success message to user here, Also process this payment success at your server side to deliver services to customerconsole.log(transaction);alert('Payment is success, Your transaction ID : ' + transaction.transaction.payment_id);});},onCancelled: function (transactionId) {// You can use 'transactionId' variable to process payment at your server side if you like,// In that case you can call our transaction status API on your server to get transaction information Or// You can get complete transaction details by calling following functionvar transaction = pk.getTransactionDetail(transactionId, function(transaction) {// You can show payment canceled message to user here, Also mark this payment as failed/cancelled at your server sideconsole.log(transaction);alert('Payment is cancelled, Your transaction ID : ' + transaction.transaction.payment_id);});}};//Init Paykun Payment and open checkout popuppk.init(order);}
3. Pay Button
Place this button in your HTML code, so a user can click on it and proceed to pay. Similarly, you can call initPayment() anywhere to initiate the payment.
<button onclick="initPayment()">Pay ₹10</button>
Sample Transaction Response
{"message": "Record retrieved successfully","transaction": {"payment_id": "55873-83139-75447-76995","merchant_email": "merchantemail@test.com","merchant_id": "123456789012345","status": "Failed","status_flag": 0,"payment_mode": null,"order": {"order_id": "DEMO_ORD1560424646862","product_name": "Test Checkout","gross_amount": 10,"gateway_fee": null,"tax": null},"customer": {"name": "Customer Name","email_id": "customeremail@gmail.com","mobile_no": "1234567890"},"shipping": {"address": null,"city": null,"state": null,"country": null,"pincode": null},"billing": {"address": null,"city": null,"state": null,"country": null,"pincode": null},"custom_field_1": "","custom_field_2": "","custom_field_3": "","custom_field_4": "","custom_field_5": "","date": "1560424703"}}