Initialization
Merchant will initialize the mandatory parameters i.e. environment, mid, key and website, after which they can directly call the SDK methods to call APIs of payment gateway.
// For Staging
String environment = LibraryConstants.STAGING_ENVIRONMENT;
// For Production
// String environment = LibraryConstants.PRODUCTION_ENVIRONMENT;
// Find your mid, key, website in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys
String mid = "YOUR_MID_HERE";
String key = "YOUR_KEY_HERE";
String website = "YOUR_WEBSITE_NAME";
String client_id = "YOUR_CLIENT_ID_HERE";
String callbackUrl = "MERCANT_CALLBACK_URL";
MerchantProperties.setCallbackUrl(callbackUrl);
MerchantProperties.initialize(environment, mid, key, client_id, website);
// If you want to add log file to your project, use below code
LibraryConstants.LOGGER.setLevel(Level.ALL);
FileHandler fh = null;
fh = new FileHandler("/path/log/file.log");
fh.setFormatter(new SimpleFormatter());
LibraryConstants.LOGGER.addHandler(fh);
LibraryConstants.LOGGER.setUseParentHandlers(false);
Note: Make sure the log file (/path/log/file.log) has write permission.
Payments
Create Transaction Token
EChannelId channelId = EChannelId.WEB;
String orderId = "UNIQUE_ORDER_ID";
Money txnAmount = new Money(EnumCurrency.INR, "1.00");
UserInfo userInfo = new UserInfo();
userInfo.setCustId("CUSTOMER_ID");
PaymentDetail paymentDetails = new PaymentDetail.PaymentDetailBuilder
(channelId, orderId, txnAmount, userInfo).build();
SDKResponse<InitiateTransactionResponse> response = Payment.createTxnToken(paymentDetails);
Note: Make sure the log file (/path/log/file.log) has write permission.
GetPaymentStatus
String orderId = "YOUR_ORDER_ID";
Time readTimeout = new Time(5, TimeUnit.MINUTES);
PaymentStatusDetail paymentStatusDetail = new PaymentStatusDetail.PaymentStatusDetailBuilder(orderId).setReadTimeout(readTimeout).build();
SDKResponse<NativePaymentStatusResponse> response = Payment.getPaymentStatus(paymentStatusDetail);
Refunds
InitiateRefund
String orderId = "YOUR_ORDER_ID";
String refId = "REFERENCE_ID";
String txnId = "TRANSACTION_ID";
String txnType = "REFUND";
String refundAmount = "1";
Time readTimeout = new Time(5, TimeUnit.MINUTES);
RefundDetail refundDetail = new RefundDetail.RefundDetailBuilder(orderId, refId, txnId, txnType,refundAmount).setReadTimeout(readTimeout).build();
SDKResponse<AsyncRefundResponse>response = Refund.initiateRefund(refundDetail);
GetRefundStatus
String orderId = "YOUR_ORDER_ID";
String refId = "REFERENCE_ID";
Time readTimeout = new Time(5, TimeUnit.MINUTES);
RefundStatusDetail refundStatusDetail = new RefundStatusDetail.RefundStatusDetailBuilder(orderId, refId)
.setReadTimeout(readTimeout).build();
SDKResponse<NativeRefundStatusResponse> response = 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 |