search

JAVA SDK Integration

It is a client java library that provides an easy way to interact with the Paytm Mini App ecosystem.

Features

This client provides the following features:

  • Auth Client - It enables merchant backend services to identify the user and gain access on user details/token. Merchant can use these details to identify a user in its system or can create a new one if doesn't exist. Following methods/APIs are supported:

    • Fetch Access Token
    • Fetch User Profile
  • MiniAppCommon Client - It exposes a few common functionalities which a merchant can use to interact with Paytm backend as:

    • Fetch OpenId
    • Send payment notification
    • Send pre-payment notification

Installation Guide

Requirements

Java 1.7 or later.

 

Installing Mini Apps SDK with maven

  1. Add the below maven repository to your project's POM.
    <repository>
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
        </snapshots>
        <id>snapshots</id>
        <name>libs-snapshot</name>
        <url>https://artifactorypg.paytm.in/artifactory/libs-snapshot</url>
    </repository>
  2. Add the below maven dependency to your project's POM.
    <dependency>
        <groupId>com.paytm</groupId>
        <artifactId>miniapp-sdk-client</artifactId>
        <version>1.0.2-SNAPSHOT</version>
    </dependency>
  3. Build and install locally by executing the command below:
    $ mvn install

SDK Code

Auth Client

try {
          HTTPServiceResponse&lt;OauthTokenResponse&gt; response = oauthClient.oauthToken(oauthTokenRequest, null);
       } catch (MiniAppClientException ex) {
         ErrorResponse errorResponse = ex.getError();
         Integer errorCode = ex.getErrorCode();
       }
// User Profile
// Create fetch user profile request
    UserProfileRequest userProfileRequest = new UserProfileRequest
                                                .Builder()
                                                .setScopeCode("<received from fetch access token api response: access_token>")
                                                .build();
                                                
   try {
          HTTPServiceResponse<OAuthUserProfile> response = oAuthClient.v2UserProfile(userProfileRequest);
       } catch (MiniAppClientException ex) {
         ErrorResponse errorResponse = ex.getError();
         Integer errorCode = ex.getErrorCode();
       }

MiniApp Common Client

// Configuring MiniApp Common client.
/*To create HttpClientProperties, 4 parameters are required
        *  1. socketTimeout - Integer
        *  2. connectionTimeout - Integer
        *  3. connectionRequestTimeout - Integer
        *  4. hostUri - String
        *  5. maxConnectionPerRoute - Integer (optional: default value is 5)
        *  4. 6. maxTotalConnections - Integer (optional: default value is 10)
        * */
        HttpClientProperties httpClientProperties = new HttpClientProperties
            .Builder()
            .setSocketTimeout(5000)
            .setConnectionTimeout(5000)
            .setConnectionRequestTimeout(5000)
            .setHostUri(""https://miniapps.paytm.com"")
            .build();

        MiniAppCommonClient commonClient = MiniAppCommonClient.getInstance(httpClientProperties,"<Auth Client ID received on onboarding>");
  • Example of Fetch Open Id

PartnerOpenIdRequest partnerOpenIdRequest = new PartnerOpenIdRequest("<received from fetch access token api response: access_token>");
    try {
        HTTPServiceResponse<PartnerOpenIdResponse>; response = commonClient.getPartnerOpenId(partnerOpenIdRequest);
    } catch (MiniAppClientException ex) {
        ErrorResponse errorResponse = ex.getError();
        Integer errorCode = ex.getErrorCode();
    }
  • Example of Send Payment Notification

Map<String, String> payload = new HashMap();
    payload.put("name", "<name>");
    payload.put("vertical", "<vertical>");
    payload.put("url", "<url>");
    PartnerNotificationRequest request = new PartnerNotificationRequest.Builder()
            .setMid("<merchant mid received on onboarding>")
            .setNotificationPayload(payload)
            .setOpenId("<received from fetch open id>")
            .setOrderId("<paytm order id received after placing order>")
            .setTemplateName("<notification template name received on onboarding>").build();
    try {
        HTTPServiceResponse<PartnerNotificationResponse> response = commonClient.sendPartnerNotification(request);
    } catch (MiniAppClientException ex) {
        ErrorResponse errorResponse = ex.getError();
        Integer errorCode = ex.getErrorCode();
    }
  • Example of Send Pre-Payment Notification

Map<String, String> payload = new HashMap();
    payload.put("name", "<name>");
    payload.put("vertical", "<vertical>");
    payload.put("url", "<url>");
    PartnerPrePaymentNotificationRequest request = new PartnerPrePaymentNotificationRequest.Builder()
            .setMid("<merchant mid received on onboarding>")
            .setNotificationPayload(payload)
            .setOpenId("<received from fetch open id>")
            .setBookingId("<order/booking id of placed order>")
            .setBookingTime("<order/booking time in ms>")
            .setTemplateName("<notification template name received on onboarding>").build();
    try {
        HTTPServiceResponse<PartnerPrePaymentNotificationResponse> response = commonClient.sendPartnerPrePaymentNotification(request);
    } catch (MiniAppClientException ex) {
        ErrorResponse errorResponse = ex.getError();
        Integer errorCode = ex.getErrorCode();
    }

 

Exceptions

ERROR TYPE ERROR CODE DESCRIPTION
UNKNOWN_EXCEPTION 1000 General error code when the cause of an exception is not known
HTTP_IO_EXCEPTION 1001 Error code when there is an error in HTTP rest call
JSON_PROCESSING_EXCEPTION 1002 Error while JSON serialization or deserialization
IO_EXCEPTION 1003 Error in JSON serialization or deserialization
ERROR_RESPONSE_FROM_API 1004 API did not give success response
MANDATORY_HEADER_MISSING 1005 Validation error of missing header
INVALID_REQUEST 1006 Validation error of not valid request
INVALID_CLIENT_ATTRIBUTES 1007 Invalid attributes provided while client creation