Official java bindings for the Paytm API. [Api Link]
Documentation of Paytm's API and their usage is available at Paytm Docs
Java 1.7 or later
Add this dependency to your project's POM:
<dependency>
<groupId>com.paytm.pg</groupId>
<artifactId>pg-java</artifactId>
<version>0.0.6</version>
</dependency>
Add this dependency to your project's build file:
compile "com.paytm.pg:pg-java:0.0.6"
Merchant will integrate Paytm Payment Gateway from below 2 steps:
Merchant will initialize initial parameters (environment, mid, key, clientId, website) by calling MerchantProperties.initialize() method.
Environment should be "STAGE" for Staging/Testing and "PROD" for Production. You can obtain mid, key, clientId, website from Dashboard [Link/Documents]
// imports
// import com.paytm.pg.constants.MerchantProperties;
/** Setting Initial Parameters */
MerchantProperties.initialize("environment", "mid", "key", "clientId", "website");
Setting Callback URL
Callback URL will set by using MerchantProperties.setCallbackUrl() method. This url will be used in initiateTransaction API call.
// imports
// import com.paytm.pg.constants.MerchantProperties;
/** Setting Callback URL */
MerchantProperties.setCallbackUrl(callbackUrl);
Add custom Connection Timeout for request (optional)
// imports
// import com.paytm.pg.constants.MerchantProperties;
// import com.paytm.merchant.models.Time;
// import java.util.concurrent.TimeUnit;
/** Setting timeout for connection i.e. Connection Timeout */
MerchantProperties.setConnectionTimeout(new Time(5, TimeUnit.MINUTES));
Set java logger level and log file path for sdk logs (optional)
// imports
// import com.paytm.pg.constants.LibraryConstants;
// import java.util.logging.FileHandler;
// import java.util.logging.Level;
// import java.util.logging.SimpleFormatter;
/** Set Logger Level for Paytm logs */
LibraryConstants.LOGGER.setLevel(Level.ALL);
/** setting log file path "/paytm/MyLogFile.log" */
try {
FileHandler fh = null;
fh = new FileHandler("/paytm/MyLogFile.log");
fh.setFormatter(new SimpleFormatter());
LibraryConstants.LOGGER.addHandler(fh);
/** Removing console handler from logger */
LibraryConstants.LOGGER.setUseParentHandlers(false);
} catch (IOException e) {
LibraryConstants.LOGGER.log(Level.SEVERE, e.toString(), e);
}
After initializing the initial parameters, Merchant can call SDK methods to call Payment Gateway API's.
Class | Method | HTTP request | Description |
---|---|---|---|
Payment | createTxnToken | POST /theia/api/v1/initiateTransaction | Create Transaction Token |
Payment | getPaymentStatus | POST /merchant-status/api/v1/getPaymentStatus | Get Payment Status |
Refund | initiateRefund | POST /refund/api/v1/async/refund | Initiate Refund |
Refund | getRefundStatus | POST /refund/api/v1/refundStatus | Get Refund Status |
- AsyncRefundResponse
- AsyncRefundResponseBody
- BaseResponseBody
- ChildTransaction
- ExtraParameterMap
- InitiateTransactionResponse
- InitiateTransactionResponseBody
- NativePaymentStatusResponse
- NativePaymentStatusResponseBody
- NativeRefundStatusResponse
- NativeRefundStatusResponseBody
- PaymentDetail
- PaymentStatusDetail
- RefundDetail
- RefundStatusDetail
- ResponseHeader
- ResultInfo
- SDKResponse
- SecureResponseHeader
- Time