This method is used to initiate a payment via the PhonePe PG Standard Checkout
Parameters
Parameter | Type | Mandatory | Description |
---|---|---|---|
merchant_transaction_id | str | Yes | The unique transaction ID assigned by the merchant. Note: – merchantTransactionId length should be less than 35 characters – No Special characters allowed except underscore “_” and hyphen “-“ |
amount | int | Yes | The amount of the payment. In paise. Minimum 100 i.e. 1 rupee |
merchant_user_id | str | Yes | The 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_url | str | Yes | The UI URL to redirect the user after a successful payment. |
redirect_mode | str | Yes | redirectMode should be: ● REDIRECT ● POST (Should be used only if the Merchant’s URL can handle the POST method) |
callback_url | str | Yes | The S2S callback URL to which status notifications will be sent. |
callback_mode | str | Yes | The mode of callback handling. |
merchant_order_id | str | No | The ID of the order assigned by the merchant. |
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 (Pay Page)
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.PayPageInstrumentResponse;
import com.phonepe.sdk.pg.payments.v1.models.response.PgPayResponse;
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);
String merchantTransactionId = UUID.randomUUID().toString().substring(0,34);
long amount = 100;
String callbackurl = "https://www.merchant.com/callback";
String merchantUserId = "merchantUserId";
String redirecturl="https://www.merchant.com/redirect";
String redirectMode="REDIRECT";
PgPayRequest pgPayRequest = PgPayRequest.PayPagePayRequestBuilder()
.amount(amount)
.merchantId(merchantId)
.merchantTransactionId(merchantTransactionId)
.callbackUrl(callbackurl)
.merchantUserId(merchantUserId)
.redirectUrl(redirectUrl)
.redirectMode(redirectmode)
.build();
PhonePeResponse<PgPayResponse> payResponse = phonepeClient.pay(pgPayRequest);
PayPageInstrumentResponse payPageInstrumentResponse = (PayPageInstrumentResponse) payResponse.getData().getInstrumentResponse();
String url = payPageInstrumentResponse.getRedirectInfo().getUrl();
Returns
The function returns a PhonePeResponse object with the following properties:
Parameter | Type | Description |
---|---|---|
success | boolean | Success/failure of the request processing |
code | str | Response code explaining the result |
message | str | Additional information about the response |
data | PgPayResponse | Available payment options |
PgPayResponse properties
Here is the response property table for the given model:
Property | Type | Description |
---|---|---|
merchant_id | str | The ID of the merchant associated with the transaction. |
merchant_transaction_id | str | The unique identifier of the merchant transaction. |
transaction_id | str | The unique identifier of the transaction. |
InstrumentResponse | InstrumentResponse | Instrument data used in initiating the request. |