Sequence
- RSA Encrypt Data
- Custom – Token
RSA Encrypt Data
This method is used to RSA Encrypt the data with the provided public key.
Parameters
Parameter | Type | Mandatory | Description |
---|---|---|---|
data | str | Yes | The data to encrypt, generally it is the card number, token or the card cvv. |
public_key | str | Yes | The public key provided by PhonePe. |
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 – RSA Encrypt Data
Javaimport com.phonepe.sdk.pg.Env; import com.phonepe.sdk.pg.common.http.PhonePeResponse; import com.phonepe.sdk.pg.payments.v1.PhonePePaymentClient; 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 data= "105"; String publicKey = "<publicKey>"; String encryptedData = phonepeClient.encryptData(data, publicKey);
Returns
The encrypted data.
Custom – Token
This method is used to initiate Token pay requests via the PhonePe PG Custom 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 |
auth_mode | str | Yes | The authentication mode for the card payment. Generally 3DS is used. |
encrypted_cvv | str | Yes | The encrypted CVV of the card. |
cryptogram | str | Yes | The cryptogram value associated with the token. |
encrypted_token | str | Yes | The encrypted token value. |
encryption_key_id | int | Yes | The ID of the encryption key used for encrypting the card details. |
expiry_month | str | Yes | The expiration month of the card. |
expiry_year | str | Yes | The expiration year of the card. |
pan_suffix | str | Yes | The last four digits (suffix) of the card PAN. |
card_holder_name | str | Yes | The name of the cardholder |
merchant_user_id | str | No | 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 | No | The UI URL to redirect the user after a successful payment. |
redirect_mode | str | No | The mode of redirection after payment completion. |
callback_url | str | No | The S2S callback URL to which status notifications will be sent. |
callback_mode | str | No | The mode of callback handling. |
merchant_order_id | str | No | The ID of the order assigned by the merchant. |
device_os | str | No | The operating system of the device used for the payment. Possible values: ANDROID or IOS. |
address_line1 | str | No | The first line of the cardholder’s billing address. |
address_line2 | str | No | The second line of the cardholder’s billing address. |
address_city | str | No | The city of the cardholder’s billing address. |
address_state | str | No | The state of the cardholder’s billing address. |
address_zip | str | No | The ZIP or postal code of the cardholder’s billing address. |
address_country | str | No | The country of the cardholder’s billing address. |
Example (Custom – Token)
Javaimport 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.TokenInstrumentResponse; 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 encryptedCvv="encryptedCvv"; String encryptedToken="encryptedToken"; String cryptogram="cryptogram"; String expiryYear="2099"; String expiryMonth="01"; String panSuffix="1234"; Long encryptionKeyid=20L; String cardHolderName="cardHolderName"; PgPayRequest pgPayRequest = PgPayRequest.TokenPayRequestBuilder() .amount(amount) .merchantId(merchantId) .merchantTransactionId(merchantTransactionId) .callbackUrl(callbackurl) .redirectUrl(redirecturl) .merchantUserId(merchantUserId) .cryptogram(cryptogram) .encryptedToken(encryptedToken) .encryptedCvv(encryptedCvv) .expiryMonth(expiryMonth) .expiryYear(expiryYear) .panSuffix(panSuffix) .encryptionKeyId(encryptionKeyid) .authMode("3DS") .build(); PhonePeResponse<PgPayResponse> payResponse = phonepeClient.pay(pgPayRequest); TokenInstrumentResponse tokenInstrumentResponse = (TokenInstrumentResponse) payResponse.getData().getInstrumentResponse(); String url = tokenInstrumentResponse.getRedirectInfo().getUrl();
Returns
The pay function returns a PgPayResponse object. With TokenInstrumentResponse object in data.