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 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 (Custom – UPI Intent – ANDROID)

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'

os_where_the_link_will_be_used = "ANDROID"
target_app_android_phonepe = "com.phonepe.app"  # other possible values, com.phonepe.app, net.one97.paytm
upi_intent_request = PgPayRequest.upi_intent_pay_request_builder(merchant_transaction_id=unique_transaction_id,
                                                                 amount=amount,
                                                                 target_app=target_app_android_phonepe,
                                                                 merchant_user_id=id_assigned_to_user_by_merchant,
                                                                 callback_url=s2s_callback_url,
                                                                 device_os=os_where_the_link_will_be_used)
upi_intent_response = phonepe_client.pay(upi_intent_request)
upi_intent_url = upi_intent_response.data.instrument_response.intent_url

Example (Custom – UPI Intent – iOS)

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>'

os_where_the_link_will_be_used = "IOS"
target_app_ios_gpay = "PHONEPE"  # other possible values, GPAY, PAYTM
upi_intent_request = PgPayRequest.upi_intent_pay_request_builder(merchant_transaction_id=unique_transaction_id,
                                                                 amount=amount,
                                                                 target_app=target_app_ios_gpay,
                                                                 merchant_user_id=id_assigned_to_user_by_merchant,
                                                                 callback_url=s2s_callback_url,
                                                                 device_os=os_where_the_link_will_be_used)
upi_intent_response = phonepe_client.pay(upi_intent_request)
upi_intent_url = upi_intent_response.data.instrument_response.intent_url

Returns

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