Skip to main content

PhonePe B2B PG SDK

A python library for integrating with PhonePe APIs.

Installation

Requires python 3.9 or later

pip install phonepe-pg-sdk-python

Quick start

To get your keys, please visit the Merchant Onboarding of PhonePe PG: Merchant Onboarding You will need three things to get started: client-id, client-secret and client-version.

Create an instance of the StandardCheckoutClient class:

from phonepe.sdk.pg.payments.v2.standard_checkout_client import StandardCheckoutClient
from phonepe.sdk.pg.env import Env

client_id = "<YOUR_CLIENT_ID>"
client_secret = "<YOUR_CLIENT_SECRET>"
client_version = 1  # Insert your client version here
env = Env.SANDBOX  # Change to Env.PRODUCTION when you go live

standard_phonepe_client = StandardCheckoutClient.get_instance(client_id=client_id,
                                                              client_secret=client_secret,
                                                              client_version=client_version,
                                                              env=env)

Initiate an order using Checkout Page

To init a pay request, we make a request object using StandardCheckoutPayRequest.build_request build_request.

Code:
from uuid import uuid4
from phonepe.sdk.pg.payments.v2.models.request.standard_checkout_pay_request import StandardCheckoutPayRequest

unique_order_id = str(uuid4())
ui_redirect_url = "https://www.merchant.com/redirect"
amount = 100
standard_pay_request = StandardCheckoutPayRequest.build_request(merchant_order_id=unique_order_id,
                                                                amount=amount,
                                                                redirect_url=ui_redirect_url)
standard_pay_response = standard_phonepe_client.pay(standard_pay_request)
checkout_page_url = standard_pay_response.redirect_url

The data will be in a StandardCheckoutPayResponse object. The checkout_page_url you get can be handled by redirecting the user to that url on the front end.

Check status of order

View the state for the order we just initiated.

unique_order_id = "INSERT_YOUR_UNIQUE_ORDER_ID"  
order_status_response = standard_phonepe_client.get_order_status(merchant_order_id=unique_order_id)  
order_state = order_status_response.state

You will get the data OrderStatusResponse object.

For more details, please visit: https://developer.phonepe.com

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

phonepe_pg_sdk_python-2.3.0.tar.gz (76.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

phonepe_pg_sdk_python-2.3.0-py3-none-any.whl (195.9 kB view details)

Uploaded Python 3

File details

Details for the file phonepe_pg_sdk_python-2.3.0.tar.gz.

File metadata

  • Download URL: phonepe_pg_sdk_python-2.3.0.tar.gz
  • Upload date:
  • Size: 76.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for phonepe_pg_sdk_python-2.3.0.tar.gz
Algorithm Hash digest
SHA256 5ef4d854f199ed2b1801cd92aa4565104137875058746a17f511747415fd406a
MD5 442c5dfc3112abc50c0beaa34df40947
BLAKE2b-256 129cf970c18e414011f9e7a0be767b55e36652eb0722326e27a98e2e39d4fabd

See more details on using hashes here.

File details

Details for the file phonepe_pg_sdk_python-2.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for phonepe_pg_sdk_python-2.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a43f7ae87936e2e624122558511824227d6139874096dea7047c7f085401a4a9
MD5 1dd9af8ebe45349f213bf9dbedfaa1ea
BLAKE2b-256 a36467443566f32b953f9669f89e4fdeeba5138ea60eeab71c4d530fc6c49777

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.3.0 This release

2 files

2.2.0

2 files

2.1.9

2 files

2.1.8

2 files

2.1.7

2 files

2.1.6

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page