Create Order with Python SDK


The Create SDK Order is used to generate a payment token when the backend is built in Python and integrated with any PhonePe Mobile SDK. This token enables secure payment processing within the mobile app.

Use the CreateSdkOrderRequest.build_standard_checkout_request()  to create the request and the following are the attributes that you can pass:

Parameter NameData TypeMandatory
(Yes/No)
DescriptionConstraints
merchant_order_idStringYesUnique order ID assigned by you.Max length: 63 characters, no special characters except “_” and “-”
amountIntegerYesOrder amount in paisa.Minimum value: 100 (in paisa)
redirect_urlStringNoURL to which the user will be redirected after the payment (success or failure).
Sample Request
from uuid import uuid4
from phonepe.sdk.pg.payments.v2.standard_checkout_client import StandardCheckoutClient
from from phonepe.sdk.pg.payments.v2.models.request.create_sdk_order_request import CreateSdkOrderRequest
from phonepe.sdk.pg.common.models.request.meta_info import MetaInfo
from phonepe.sdk.pg.env import Env
 
client_id = "<YOUR_CLIENT_ID>"
client_secret = "<YOUR_CLIENT_SECRET>"
client_version = <CLIENT_VERSION>  # Insert your client version here
env = Env.SANDBOX  # Change to Env.PRODUCTION when you go live
should_publish_events = False
 
client = StandardCheckoutClient.get_instance(client_id=client_id,
                                                              client_secret=client_secret,
                                                              client_version=client_version,
                                                              env=env,
                                                              should_publish_events=should_publish_events)

unique_merchant_order_id = str(uuid4())
ui_redirect_url = "https://www.merchant.com/redirect"
amount = 100
meta_info = MetaInfo(udf1="udf1", udf2="udf2", udf3="udf3") 

sdk_order_request = CreateSdkOrderRequest.build_standard_checkout_request(merchant_order_id=unique_merchant_order_id,
                                                                    amount=amount,
                                                                    meta_info=meta_info,
                                                                    redirect_url=ui_redirect_url)
create_order_response = client.create_sdk_order(sdk_order_request=sdk_order_request)
ui_accepted_token = create_order_response.token

The function returns a CreateOrderResponse object with the following properties:

Parameter NameData TypeDescription
order_idStringOrder ID generated by PhonePe PG.
stateStringState of the Order. Initially it will be PENDING.
expire_atLongExpiry time in epoch.
tokenStringToken used by the merchant UI to initiate order.

Now that you have understood how to generate a payment token when the backend is built in Python and integrated with any PhonePe Mobile SDK. Let’s proceed to check the status of the order.

Is this article helpful?