PhonePe Payment Gateway Python SDK

latest (from PhonePe registry) · active · verified Wed Mar 25

Official PhonePe Payment Gateway Python SDK. NOT on PyPI — must install from PhonePe's private registry using a special pip command. TWO packages cause confusion: 'phonepe' on PyPI (1.0.1) is a community wrapper using old v1 API — NOT the official SDK. Official SDK is 'phonepe_sdk' from phonepe.mycloudrepo.io. Amount in paise (1 INR = 100 paise). Client must be initialized only ONCE — reinitializing raises PhonePeException. Mandatory status check polling after payment.

Warnings

Install

Imports

Quickstart

PhonePe Python SDK — payment creation and status check.

# Install from PhonePe registry (NOT PyPI):
# pip install --index-url https://phonepe.mycloudrepo.io/public/repositories/phonepe-pg-sdk-python --extra-index-url https://pypi.org/simple phonepe_sdk

from phonepe.sdk.pg.payments.v2.standard_checkout_client import StandardCheckoutClient
from phonepe.sdk.pg.payments.v2.models.request.standard_checkout_pay_request import StandardCheckoutPayRequest
from phonepe.sdk.pg.env import Env
import uuid

# Initialize once at app startup
client = StandardCheckoutClient(
    client_id='<client_id>',       # from PhonePe dashboard
    client_secret='<client_secret>',
    client_version=1,
    env=Env.SANDBOX
)

# Create payment
order_id = str(uuid.uuid4())
request = StandardCheckoutPayRequest.build_request(
    merchant_order_id=order_id,
    amount=50000,  # 500 INR in paise
    redirect_url=f'https://yourapp.com/callback?order_id={order_id}'
)
response = client.pay(request)

# Redirect user to response.redirect_url
print('Redirect to:', response.redirect_url)

# After redirect, check status (mandatory)
status = client.get_order_status(merchant_order_id=order_id)
print('Payment state:', status.state)  # COMPLETED, FAILED, PENDING

view raw JSON →