• Getting Started
    • Mobile Integration (Android/IOS)
      Enterprise Solutions
      Retail Solutions
      Accept Payments
      Process Payments
      Disbursals
      API References
      Testing
      Refunds
      Guides
      Other Processes
      Mini Program Platform

      JAVA SDK Integration

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

      Features

      This client provides following features :

      • Auth Client - Auth client enables Merchant backend services to identify user and gain access on user details/token. Merchant can use these details to identify 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 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 Program SDK with maven

      1. Add 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 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 below command

        $ mvn install

      SDK code


      Auth Client

      // Configuring Auth client
      /*To create HttpClientProperties, 4 parameters are required
              *  1. socketTimeout - Integer
              *  2. connectionTimeout - Integer
              *  3. connectionRequestTimeout - Integer
              *  4. hostUri - String
              * */
              HttpClientProperties httpClientProperties = new HttpClientProperties
                  .Builder()
                  .setSocketTimeout(5000)
                  .setConnectionTimeout(5000)
                  .setConnectionRequestTimeout(5000)
                  .setHostUri("https://accounts.paytm.com")
                  .build();
      
          OAuthClient oAuthClient = OAuthClient.getInstance(httpClientProperties,
                                    "<Auth Client ID received on onboarding>", "<Auth Client Secret received on onboarding>");
      
      // Fetch Access Token
      // Create oauth token request
          OauthTokenRequest oauthTokenRequest = new OauthTokenRequest
                                                      .Builder()
                                                      .setCode("<Auth code received from trust login>")
                                                      .build();
      
      
          try {
                HTTPServiceResponse<OauthTokenResponse> 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)
           *  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>");
      • An 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();
          }
      • An 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();
          }
      • An 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 TypeError CodeDescription
      UNKNOWN_EXCEPTION1000General error code when cause of exception is not known
      HTTP_IO_EXCEPTION1001Error code when there is an error in HTTP rest call
      JSON_PROCESSING_EXCEPTION1002Error while json serialization or deserialization
      IO_EXCEPTION1003Error in json serialization or deserialization
      ERROR_RESPONSE_FROM_API1004API did not give success response
      MANDATORY_HEADER_MISSING1005Validation error of missing header
      INVALID_REQUEST1006Validation error of not valid request
      INVALID_CLIENT_ATTRIBUTES1007Invalid attributes provided while client creation