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 Python SDK Version **\ 0.0.3**, the imports should be:
from phonepe.sdk.pg.payments.**v1**
For Python SDK Version <= 0.0.3, the imports should be:
from phonepe.sdk.pg.payments
For Python SDK Version > 0.0.3, the imports should be:
from phonepe.sdk.pg.payments.v1
Example – RSA Encrypt Data
from phonepe.sdk.pg.payments.v1.payment_client import PhonePePaymentClient
from phonepe.sdk.pg.env import Env
merchant_id = "<YOUR_MERCHANT_ID>"
salt_key = "<YOUR_SALT_KEY>"
salt_index = 1 # insert your salt index
env = Env.UAT
should_publish_events = True
phonepe_client = PhonePePaymentClient(merchant_id, salt_key, salt_index, env, should_publish_events)
sensitive_data = "<CARD_CVV>"
public_key = "<YOUR_PUBLIC_KEY>"
encrypted_data = phonepe_client.encrypt_data(data=sensitive_data, public_key=public_key)
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)
import uuid
from phonepe.sdk.pg.payments.v1.models.request.pg_pay_request import PgPayRequest
from phonepe.sdk.pg.payments.v1.payment_client import PhonePePaymentClient
from phonepe.sdk.pg.env import Env
merchant_id = "<YOUR_MERCHANT_ID>"
salt_key = "<YOUR_SALT_KEY>"
salt_index = 1 # insert your salt index
env = Env.UAT
should_publish_events = True
phonepe_client = PhonePePaymentClient(merchant_id, salt_key, salt_index, env, should_publish_events)
unique_transaction_id = str(uuid.uuid4())[:-2]
s2s_callback_url = "https://www.merchant.com/callback"
amount = 100
id_assigned_to_user_by_merchant = "<YOUR_USER_ID>"
auth_mode = "3DS"
encrypted_cvv = "<YOUR_CVV_ENCRYPTED>" # can use payment_client.encrypt function for this
cryptogram = "<YOUR_CRYPTOGRAM>"
encrypted_token = "<YOUR_TOKEN_ENCRYPTED>" # can use payment_client.encrypt function for this
key_id_used_to_encrypt_data = -1 # replace with actual key-id
expiry_month = "<EXPIRY_MONTH>"
expiry_year = "<EXPIRY_YEAR>"
pan_suffix = "<YOUR_LAST_4_DIGITS_OF_TOKENIZED_CARD>"
card_holder_name = "<NAME_OF_TOKENIZED_CARD_HOLDER>"
token_payment_request = PgPayRequest.token_pay_request_builder(merchant_transaction_id=unique_transaction_id,
amount=amount,
auth_mode=auth_mode,
encrypted_cvv=encrypted_cvv,
cryptogram=cryptogram,
encrypted_token=encrypted_token,
encryption_key_id=key_id_used_to_encrypt_data,
expiry_month=expiry_month,
expiry_year=expiry_year,
pan_suffix=pan_suffix,
card_holder_name=card_holder_name)
token_response = phonepe_client.pay(token_payment_request)
url = token_response.data.instrument_response.redirect_info.url
Returns
The pay function returns a PgPayResponse object. With TokenInstrumentResponse object in data.