• Getting Started
    • Website Integration
      Mobile Integration (Android/IOS)
      Enterprise Solutions
      Accept Payments
      Process Payments
      Disbursals
      API References
      Webhooks
      Testing
      Refunds
      Guides
      Other Processes

      JAVA SDK Integration

      Installation Guide


      Requirements

      Java 1.7 or later.

      Installing Paytm's payment gateway SDK with maven

      1. Add below maven repository to your project's POM

        <repositories>
            <repository>
                <id>my-repo1</id>
                <url> http://artifactorypg.paytm.in/artifactory/libs-release </url>
            </repository>
        </repositories>
      2. Add below maven dependency to your project's POM

        <dependency>
                <groupId>com.paytm.pg</groupId>
                <artifactId>paytm-pg</artifactId>
                <version>0.0.1</version>
        </dependency>
      3. Build and install locally by executing below command

        $ mvn install

      Generate API Keys


      ATTRIBUTEDESCRIPTION
      MIDA unique merchant identifier issued by Paytm for your account.
      Merchant KeyA 16-digit unique merchant identifier issued by Paytm for your account.

      Note: Merchant Key is a secret key used for encryption so never share this with anyone. And, You have to generate separate API Keys for test and production environment.


      Steps to generate API keys

      1. Log into your Dashboard.
      2. Select the environment (Test/Production) for which you want to generate the API key.
      3. For Test mode, click Generate Key to generate key under Test API details tab.
      4. For Production mode, activate your account here to generate Production API details.

      SDK code


      Initialization

      Merchant will initialize the following mandatory parameters: environment, mid, key and website, after which merchant can directly call 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";
      MerchantProperties.initialize(environment, mid, key, 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 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 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

      ClassMethodsHTTP requestDescription

      Payments

      createTxnToken POST /theia/api/v1/initiateTransaction Returns a token which will be used in further frontend Payment calls
      getPaymentStatusPOST /merchant-status/api/v1/getPaymentStatus Returns the Payment status

      Refunds

      initiateRefundPOST /refund/api/v1/async/refundInitiates the Refund
      getRefundStatusPOST /refund/api/v1/refundStatusReturns the Refund status

      Downloads


      Download the sample application

      Download the SDK

      Models