JAVA SDK – Pay Instruments

This method is used to initiate a payment via the PhonePe PG.

The pay() method is used to initiate an order via various instruments.

Instruments :

  1. UPI INTENT
  2. UPI COLLECT
  3. UPI QR
  4. NET BANKING
  5. TOKEN
  6. CARDS

UPI INTENT

Request Details

Parameter NameData TypeMandatoryDescription
merchantOrderIdStringYesUnique order ID generated by merchant
amountlongYesAmount of order in Paisa
contraintsListNoDifferent type of constraints that must be applied to the payment
deviceOSStringNoOperating system of the device. Allowed values are:
1. IOS
2. ANDROID
merchantCallbackSchemeStringNoRequired only in case targetApp = PHONEPE and deviceOS = IOS
targetAppStringNoThe target app identifier for the UPI Intent flow.
For IOS:
PHONEPE,
GPAY,
PAYTM.
For Android: com.phonepe.app, net.one97.paytm

Example

import com.phonepe.sdk.pg.common.models.request.PgPaymentRequest;
import java.util.UUID;
import com.phonepe.sdk.pg.Env;
import com.phonepe.sdk.pg.payments.v2.CustomCheckoutClient;
import com.phonepe.sdk.pg.common.models.response.PgPaymentResponse;
 
String clientId = "<clientId>";
String clientSecret = "<clientSecret>";
Integer clientVersion = 1;  //insert your client version here
Env env = Env.SANDBOX;      //change to Env.PRODUCTION when you go live
 
CustomCheckoutClient customCheckoutClient = CustomCheckoutClient.getInstance(clientId, clientSecret,
        clientVersion, env);
 
String merchantOrderId = UUID.randomUUID()
        .toString();
long amount = 100;
String deviceOS = "IOS";
String targetApp = "PHONEPE";
 
PgPaymentRequest pgPaymentRequest = PgPaymentRequest.UpiIntentPayRequestBuilder()
        .merchantOrderId(merchantOrderId)
        .amount(amount)
        .targetApp(targetApp)
        .deviceOS(deviceOS)
        .build();
 
PgPaymentResponse pgPaymentResponse = customCheckoutClient.pay(pgPaymentRequest);
String intentUrl = pgPaymentResponse.getIntentUrl();

Extract the intentUrl from the response received.

Response Details

PropertyTypeDescription
orderIdStringOrder Id created by PhonePe
stateStringState of the order. Initially it will be PENDING.
expireAtLongOrder expire date in epoch
IntentUrlStringIntent url according to the targetApp mentioned in the request

UPI COLLECT

Request Details

Parameter NameData TypeMandatoryDescription
merchantOrderIdStringyesUnique order ID generated by merchant
amountlongyesAmount of order in Paisa
contraintsListyesDifferent type of constraints that must be applied to the payment
VPAStringYesVPA against which collect request need to be raised

Example :

import com.phonepe.sdk.pg.common.models.request.PgPaymentRequest;
import com.phonepe.sdk.pg.common.models.response.PgPaymentResponse;
import java.util.UUID;
import com.phonepe.sdk.pg.Env;
import com.phonepe.sdk.pg.payments.v2.CustomCheckoutClient;
 
String clientId = "<clientId>";
String clientSecret = "<clientSecret>";
Integer clientVersion = 1;  //insert your client version here
Env env = Env.SANDBOX;      //change to Env.PRODUCTION when you go live
 
CustomCheckoutClient customCheckoutClient = CustomCheckoutClient.getInstance(clientId, clientSecret,
        clientVersion, env);
 
String merchantOrderId = UUID.randomUUID().toString();
long amount = 100;
String vpa = "<VALID_VPA>";
PgPaymentRequest pgPaymentRequest = PgPaymentRequest.UpiCollectPayViaVpaRequestBuilder()
        .vpa(vpa)
        .amount(amount)
        .merchantOrderId(merchantOrderId)
        .message("Collect Message")
        .build();
 
PgPaymentResponse pgPaymentResponse = customCheckoutClient.pay(pgPaymentRequest);

The function will raise the collect request to the above mentioned vpa.

Response Details

PropertyTypeDescription
orderIdStringOrder Id created by PhonePe
stateStringState of the order. Initially it will be PENDING.
expireAtLongOrder expire date in epoch

UPI QR

Request Details

Parameter NameData TypeMandatoryDescription
merchantOrderIdStringYesUnique order ID generated by merchant
amountlongYesAmount of order in Paisa
contraintsListNoDifferent type of constraints that must be applied to the payment

Example :

import com.phonepe.sdk.pg.common.models.request.PgPaymentRequest;
import com.phonepe.sdk.pg.common.models.response.PgPaymentResponse;
import java.util.UUID;
import com.phonepe.sdk.pg.Env;
import com.phonepe.sdk.pg.payments.v2.CustomCheckoutClient;
 
String clientId = "<clientId>";
String clientSecret = "<clientSecret>";
Integer clientVersion = 1;  //insert your client version here
Env env = Env.SANDBOX;      //change to Env.PRODUCTION when you go live
 
CustomCheckoutClient customCheckoutClient = CustomCheckoutClient.getInstance(clientId, clientSecret,
        clientVersion, env);
 
String merchantOrderId = UUID.randomUUID().toString();
long amount = 100;
 
PgPaymentRequest pgPaymentRequest = PgPaymentRequest.UpiQrRequestBuilder()
        .amount(amount)
        .merchantOrderId(merchantOrderId)
        .build();
 
PgPaymentResponse pgPaymentResponse = customCheckoutClient.pay(pgPaymentRequest);
String qrData = pgPaymentResponse.getQrData();

Extract the qrData from the response received

Response Details

PropertyTypeDescription
orderIdStringOrder Id created by PhonePe
stateStringState of the order. Initially it will be PENDING.
expireAtLongOrder expire date in epoch
IntentUrlStringIntent url for the amount mentioned
qrDataStringQR Data which will be used to generate the QR

NET BANKING

Request Details

Parameter NameData TypeMandatoryDescription
merchantOrderIdStringyesUnique order ID generated by merchant
amountlongyesAmount of order in Paisa
contraintsListyesDifferent type of constraints that must be applied to the payment
bankIdStringyesBank id from where payment will be completed.

Example :

import com.phonepe.sdk.pg.common.models.request.PgPaymentRequest;
import java.util.UUID;
import com.phonepe.sdk.pg.Env;
import com.phonepe.sdk.pg.payments.v2.CustomCheckoutClient;
import com.phonepe.sdk.pg.common.models.response.PgPaymentResponse;
 
String clientId = "<clientId>";
String clientSecret = "<clientSecret>";
Integer clientVersion = 1;  //insert your client version here
Env env = Env.SANDBOX;      //change to Env.PRODUCTION when you go live
 
CustomCheckoutClient customCheckoutClient = CustomCheckoutClient.getInstance(clientId, clientSecret,
        clientVersion, env);
 
String merchantOrderId = UUID.randomUUID().toString();
long amount = 100;
String bankId = "HDFC";
 
PgPaymentRequest pgPaymentRequest = PgPaymentRequest.NetBankingPayRequestBuilder()
        .merchantOrderId(merchantOrderId)
        .amount(amount)
        .bankId(bankId)
        .build();
 
PgPaymentResponse pgPaymentResponse = customCheckoutClient.pay(pgPaymentRequest);
String redirectUrl = pgPaymentResponse.getRedirectUrl();

Extract the redirectUrl from the response received

Response Details

PropertyTypeDescription
orderIdStringOrder Id created by PhonePe
stateStringState of the order. Initially it will be PENDING.
expireAtLongOrder expire date in epoch
redirectUrlStringRedirect url to perform the Net Banking for mentioned bankId

TOKEN

Request Details

Parameter NameData TypeMandatoryDescription
merchantOrderIdStringyesUnique order ID generated by merchant
amountlongyesAmount of order in Paisa
contraintsListNoDifferent type of constraints that must be applied to the payment
authModeStringyesDefault to 3DS
encryptionKeyIdlongyesKeyId of key which merchant uses to encrypt card number & cvv.
encryptedTokenStringyesEncrypted TOKEN number which merchant passes to process card transaction
encryptedCvvStringyesEncrypted CVV of the card with which payment is being initiated.
cryptogramStringyesThe cryptogram fetched from the gateway where the card was tokenized.
panSuffixStringyesLast four digits of card number
cardHolderNameStringyesCard Holder Name
expiryMonthStringyesToken expiry month
expiryYearStringyesToken expiry year
merchantUserIdStringNoThe unique identifier of the merchant user. It is used to associate the payment with a specific user.

Example :

import com.phonepe.sdk.pg.common.models.request.PgPaymentRequest;
import com.phonepe.sdk.pg.common.models.response.PgPaymentResponse;
import java.util.UUID;
import com.phonepe.sdk.pg.Env;
import com.phonepe.sdk.pg.payments.v2.CustomCheckoutClient;
 
String clientId = "<clientId>";
String clientSecret = "<clientSecret>";
Integer clientVersion = 1;  //insert your client version here
Env env = Env.SANDBOX;      //change to Env.PRODUCTION when you go live
 
CustomCheckoutClient customCheckoutClient = CustomCheckoutClient.getInstance(clientId, clientSecret,
        clientVersion, env);
 
String merchantOrderId = UUID.randomUUID().toString();
long amount = 100;
long encryptionKeyId = 10;
String encryptedCvv = "<encryptedCvv>";
String authMode = "3DS";
String panSuffix = "7239";
String cryptogram = "<cryptogram>";
String encryptedToken = "<encryptedToken>";
String merchantUserId = "<merchantUserId>";
String cardHolderName = "<cardHolderName>";
String expiryYear = "2050";
String expiryMonth = "08";
 
PgPaymentRequest pgPaymentRequest = PgPaymentRequest.TokenPayRequestBuilder()
        .merchantOrderId(merchantOrderId)
        .amount(amount)
        .encryptionKeyId(encryptionKeyId)
        .encryptedCvv(encryptedCvv)
        .authMode(authMode)
        .panSuffix(panSuffix)
        .cryptogram(cryptogram)
        .encryptedToken(encryptedToken)
        .merchantUserId(merchantUserId)
        .cardHolderName(cardHolderName)
        .expiryMonth(expiryMonth)
        .expiryYear(expiryYear)
        .build();
 
PgPaymentResponse pgPaymentResponse = customCheckoutClient.pay(pgPaymentRequest);
String redirectUrl = pgPaymentResponse.getRedirectUrl();

Extract the redirectUrl from the response received.

Response Details

PropertyTypeDescription
orderIdStringOrder Id created by PhonePe
stateStringState of the order. Initially it will be PENDING.
expireAtLongOrder expire date in epoch
redirectUrlStringRedirect url to perform the transaction

CARDS

Request Details

Parameter NameData TypeMandatoryDescription
merchantOrderIdStringyesUnique order ID generated by merchant
amountlongyesAmount of order in Paisa
contraintsListNoDifferent type of constraints that must be applied to the payment
authModeStringyesDefault to 3DS
encryptionKeyIdlongyesKeyId of key which merchant uses to encrypt card number & cvv.
encryptedCardNumberStringyesEncrypted 16-Digit Card Number entered by the user.
encryptedCvvStringyesEncrypted CVV of the card with which payment is being initiated.
cardHolderNameStringNoCard Holder Name
expiryMonthStringyesToken expiry month
expiryYearStringyesToken expiry year
merchantUserIdStringNoThe unique identifier of the merchant user. It is used to associate the payment with a specific user.

Example :

import com.phonepe.sdk.pg.Env;
import com.phonepe.sdk.pg.common.models.request.PgPaymentRequest;
import com.phonepe.sdk.pg.common.models.response.PgPaymentResponse;
import com.phonepe.sdk.pg.payments.v2.CustomCheckoutClient;
 
String clientId = "<clientId>";
String clientSecret = "<clientSecret>";
Integer clientVersion = 1;  //insert your client version here
Env env = Env.SANDBOX;      //change to Env.PRODUCTION when you go live
 
CustomCheckoutClient customCheckoutClient = CustomCheckoutClient.getInstance(clientId, clientSecret,
        clientVersion, env);
 
String merchantOrderId = UUID.randomUUID().toString();
long amount = 100;
long encryptionKeyId = 10;
String authMode = "3DS";
String encryptedCardNumber = "<encryptedCardNumber>";
String encryptedCvv = "<encryptedCvv>";
String merchantUserId = "<merchantUserId>";
String cardHolderName = "<cardHolderName>";
String expiryYear = "2052";
String expiryMonth = "08";
 
PgPaymentRequest pgPaymentRequest = PgPaymentRequest.CardPayRequestBuilder()
        .merchantOrderId(merchantOrderId)
        .amount(amount)
        .encryptionKeyId(encryptionKeyId)
        .encryptedCvv(encryptedCvv)
        .authMode(authMode)
        .encryptedCardNumber(encryptedCardNumber)
        .merchantUserId(merchantUserId)
        .cardHolderName(cardHolderName)
        .expiryMonth(expiryMonth)
        .expiryYear(expiryYear)
        .build();
 
PgPaymentResponse pgPaymentResponse = customCheckoutClient.pay(pgPaymentRequest);
String redirectUrl = pgPaymentResponse.getRedirectUrl();

Extract the redirectUrl from the response received

Response Details

PropertyTypeDescription
orderIdStringOrder Id created by PhonePe
stateStringState of the order. Initially it will be PENDING.
expireAtLongOrder expire date in epoch
redirectUrlStringRedirect url to perform the transaction