Sequence
- RSA Encrypt Data
- Custom – Card
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 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
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 – Card
This method is used to initiate a Card 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. |
save_card | bool | Yes | Indicates whether to save the card details for future use. |
encrypted_card_number | str | Yes | The encrypted card number. |
encryption_key_id | int | Yes | The ID of the encryption key used for encrypting the card details. |
card_holder_name | str | Yes | The name of the card holder. |
expiry_month | str | Yes | The expiration month of the card. |
expiry_year | str | Yes | The expiration year of the card. |
encrypted_cvv | str | Yes | The encrypted CVV (Card Verification Value) of the card. |
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 – Card)
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_transcation_id = str(uuid.uuid4())[:-2]
amount = 100
auth_mode = "3DS"
save_card = True
encrypted_card_number = "<ENCRYPTED_CARD_NUMBER>" # can use encrypt_data function to encrypt this
encrypted_cvv = "<ENCRYPTED_CVV>" # can use encrypt_data function to encrypt this
encryption_key_id = -1 # update with your public key id
card_holder_name = "<CARD_HOLDER_NAME>"
expiry_month = "<CARD_EXPIRY_MONTH>"
expiry_year = "<CARD_EXPIRY_YEAR>"
merchant_user_id = "YOUR_USER_ID"
ui_redirect_url = "https://www.merchant.com/success"
s2s_callback_url = "https://www.merchant.com/callback"
merchant_order_id = "<YOUR_ORDER_ID>"
cancel_ui_redirect_url = "https://www.merchant.com/cancel"
address_line1 = "<ADDRESS_LINE_1>"
address_line2 = "<ADDRESS_LINE_2>"
address_city = "<CITY>"
address_state = "<STATE>"
address_zip = "<ZIP>"
address_country = "<COUNTRY>"
card_request = PgPayRequest.card_pay_request_builder(merchant_transaction_id=unique_transcation_id,
amount=amount,
auth_mode=auth_mode,
save_card=save_card,
encrypted_card_number=encrypted_card_number,
encryption_key_id=encryption_key_id,
card_holder_name=card_holder_name,
expiry_month=expiry_month,
expiry_year=expiry_year,
encrypted_cvv=encrypted_cvv,
merchant_user_id=merchant_user_id,
redirect_url=ui_redirect_url,
callback_url=s2s_callback_url,
merchant_order_id=merchant_order_id,
cancel_redirect_url=cancel_ui_redirect_url,
address_line1=address_line1,
address_line2=address_line2,
address_city=address_city,
address_state=address_state,
address_zip=address_zip,
address_country=address_country)
card_response = phonepe_client.pay(card_request)
Returns
The pay function returns a PgPayResponse object. With CardInstrumentResponse object in data.