Custom – UPI Intent

This method is used to initiate a UPI Intent via the PhonePe PG Custom Checkout

Parameters

ParameterTypeMandatoryDescription
merchant_transaction_idstrYesThe unique transaction ID assigned by the merchant.
Note:
– merchantTransactionId length should be less than 35 characters
– No Special characters allowed except underscore “_” and hyphen “-“
amountintYesThe amount of the payment. In paise. Minimum 100 i.e. 1 rupee
target_appstrYesThe target app identifier for the UPI Intent flow.
For IOS: PHONEPE, GPAY, PAYTM
For Android: com.phonepe.app, net.one97.paytm
merchant_user_idstrNoThe ID assigned to the user by the merchant.
Note:
– merchantUserId length should be less than 36 characters
– No Special characters allowed except underscore “_” and hyphen “-“
redirect_urlstrNoThe UI URL to redirect the user after a successful payment.
redirect_modestrNoThe mode of redirection after payment completion.
callback_urlstrNoThe S2S callback URL to which status notifications will be sent.
callback_modestrNoThe mode of callback handling.
merchant_order_idstrNoThe ID of the order assigned by the merchant.
device_osstrNoThe operating system of the device used for the payment. Possible values: ANDROID or IOS.

For Java SDK Version <= 1.0.1, the imports should be:
from phonepe.sdk.pg.payments

For Java SDK Version > 1.0.1, the imports should be:
from phonepe.sdk.pg.payments.v1

Example (Custom – UPI Intent – ANDROID)

import com.phonepe.sdk.pg.Env;
import com.phonepe.sdk.pg.common.http.PhonePeResponse;
import com.phonepe.sdk.pg.payments.v1.PhonePePaymentClient;
import com.phonepe.sdk.pg.payments.v1.models.request.PgPayRequest;
import com.phonepe.sdk.pg.payments.v1.models.response.PgPayResponse;
import com.phonepe.sdk.pg.payments.v1.models.response.UpiIntentInstrumentResponse;
import java.util.UUID;

String merchantId = "<merchantId>";
String saltKey = "<saltKey>";
Integer saltIndex = "<saltIndex>";
Env env = Env.UAT;
boolean shouldPublishEvents = true;
PhonePePaymentClient phonepeClient = new PhonePePaymentClient(merchantId, saltKey, saltIndex, env, shouldPublishEvents);

long amount = 100;
String merchantTransactionId = UUID.randomUUID().toString().substring(0,34);
String redirecturl = "https://merchant.com/redirectUrl";
String callbackurl = "https://www.merchant.com/callback";
String merchantUserId = "merchantUserId";
String deviceOS = "ANDROID";
String targetApp = "com.phonepe.app";

PgPayRequest pgPayRequest = PgPayRequest.UPIIntentPayRequestBuilder()
        .amount(amount)
        .merchantId(merchantId)
        .merchantTransactionId(merchantTransactionId)
        .callbackUrl(callbackurl)
        .redirectUrl(redirecturl)
        .merchantUserId(merchantUserId)
        .deviceOS(deviceOS)
        .targetApp(targetApp)
        .build();

PhonePeResponse<PgPayResponse> payResponse = phonepeClient.pay(pgPayRequest);
UpiIntentInstrumentResponse upiIntentInstrumentResponse  = (UpiIntentInstrumentResponse) payResponse.getData().getInstrumentResponse();
String intentUrl = upiIntentInstrumentResponse.getIntentUrl();

Example (Custom – UPI Intent – iOS)

import com.phonepe.sdk.pg.Env;
import com.phonepe.sdk.pg.common.http.PhonePeResponse;
import com.phonepe.sdk.pg.payments.v1.PhonePePaymentClient;
import com.phonepe.sdk.pg.payments.v1.models.request.PgPayRequest;
import com.phonepe.sdk.pg.payments.v1.models.response.PgPayResponse;
import com.phonepe.sdk.pg.payments.v1.models.response.UpiIntentInstrumentResponse;
import java.util.UUID;

String merchantId = "<merchantId>";
String saltKey = "<saltKey>";
Integer saltIndex = "<saltIndex>";
Env env = Env.UAT;
boolean shouldPublishEvents = true;
PhonePePaymentClient phonepeClient = new PhonePePaymentClient(merchantId, saltKey, saltIndex, env, shouldPublishEvents);

long amount = 100;
String merchantTransactionId = UUID.randomUUID().toString().substring(0,34);
String redirecturl = "https://merchant.com/redirectUrl";
String callbackurl = "https://www.merchant.com/callback";
String merchantUserId = "merchantUserId";
String deviceOS = "IOS";
String targetApp = "GPAY";

PgPayRequest pgPayRequest = PgPayRequest.UPIIntentPayRequestBuilder()
        .amount(amount)
        .merchantId(merchantId)
        .merchantTransactionId(merchantTransactionId)
        .callbackUrl(callbackurl)
        .redirectUrl(redirecturl)
        .merchantUserId(merchantUserId)
        .deviceOS(deviceOS)
        .targetApp(targetApp)
        .build();

PhonePeResponse<PgPayResponse> payResponse = phonepeClient.pay(pgPayRequest);
UpiIntentInstrumentResponse upiIntentInstrumentResponse  = (UpiIntentInstrumentResponse) payResponse.getData().getInstrumentResponse();
String intentUrl = upiIntentInstrumentResponse.getIntentUrl();

Returns

The pay function returns a PgPayResponse object. With UpiIntentInstrumentResponse object in data.