Initialization
Merchant will initialize the mandatory parameters i.e. environment, mid, key, and website, after which merchant can directly call SDK methods to call APIs of payment gateway.
// For Staging
var environment = Paytm.LibraryConstants.STAGING_ENVIRONMENT;
// For Production
// var environment = Paytm.LibraryConstants.PRODUCTION_ENVIRONMENT;
// Find your mid, key, website in your Paytm Dashboard at https://dashboard.paytmpayments.com/next/apikeys
var mid = "YOUR_MID_HERE";
var key = "YOUR_KEY_HERE";
var website = "YOUR_WEBSITE_NAME";
var client_id = "YOUR_CLIENT_ID_HERE";
var callbackUrl = "MERCHANT_CALLBACK_URL";
Paytm.MerchantProperties.setCallbackUrl(callbackUrl);
Paytm.MerchantProperties.initialize(environment, mid, key, client_id, website);
// If you want to add log file to your project, use below code
Paytm.Config.logName = "[PAYTM]";
Paytm.Config.logLevel = Paytm.LoggingUtil.LogLevel.INFO;
Paytm.Config.logfile = "/path/log/file.log";
Note: Make sure the log file (/path/log/file.log) has write permission.
Payments
Create Transaction Token
var channelId = Paytm.EChannelId.WEB;
var orderId = "UNIQUE_ORDER_ID";
var txnAmount = Paytm.Money.constructWithCurrencyAndValue(Paytm.EnumCurrency.INR, "1.00");
var userInfo = new Paytm.UserInfo("CUSTOMER_ID");
userInfo.setAddress("CUSTOMER_ADDRESS");
userInfo.setEmail("CUSTOMER_EMAIL_ID");
userInfo.setFirstName("CUSTOMER_FIRST_NAME");
userInfo.setLastName("CUSTOMER_LAST_NAME");
userInfo.setMobile("CUSTOMER_MOBILE_NO");
userInfo.setPincode("CUSTOMER_PINCODE");
var paymentDetailBuilder = new Paytm.PaymentDetailBuilder(channelId, orderId, txnAmount, userInfo);
var paymentDetail = paymentDetailBuilder.build();
var response = Paytm.Payment.createTxnToken(paymentDetail);
GetPaymentStatus
var orderId = "YOUR_ORDER_ID";
var readTimeout = 80000;
var paymentStatusDetailBuilder = new Paytm.PaymentStatusDetailBuilder(orderId);
var paymentStatusDetail = paymentStatusDetailBuilder.setReadTimeout(readTimeout).build();
var response = Paytm.Payment.getPaymentStatus(paymentStatusDetail);
Refunds
InitiateRefund
var orderId = "YOUR_ORDER_ID";
var refId = "REFERENCE_ID";
var txnId = "TRANSACTION_ID";
var txnType = "REFUND";
var refundAmount = "1";
var readTimeout = 80000;
var subWalletAmount = {};
var extraParamsMap = {};
subWalletAmount[Paytm.UserSubWalletType.FOOD] = 1.00;
subWalletAmount[Paytm.UserSubWalletType.GIFT] = 1.00;
var refund = new Paytm.RefundDetailBuilder(orderId, refId, txnId, txnType, refundAmount);
var refundDetail = refund.setReadTimeout(readTimeout).setSubwalletAmount(subWalletAmount).setExtraParamsMap(extraParamsMap).build();
var response = Paytm.Refund.initiateRefund(refundDetail);
GetRefundStatus
var orderId = "YOUR_ORDER_ID";
var refId = "REFERENCE_ID";
var readTimeout = 8000;
var refundStatusDetailBuilder = new Paytm.RefundStatusDetailBuilder(orderId, refId);
var refundStatusDetail = refundStatusDetailBuilder.setReadTimeout(readTimeout).build();
var response = Paytm.Refund.getRefundStatus(refundStatusDetail);
SDK Method References
Class |
Methods |
HTTP request |
Description |
Payments
|
createTxnToken |
POST/theia/api/v1/initiateTransaction |
Returns a token which will be used in further frontend payment calls |
getPaymentStatus |
POST/merchant-status/api/v1/getPaymentStatus |
Returns the payment status |
Refunds
|
initiateRefund |
POST/refund/api/v1/async/refund |
Initiates the refund |
getRefundStatus |
POST/refund/api/v1/refundStatus |
Returns the refund status |