Class Initialization

The SubscriptionClient class is designed for communicating with PhonePe APIs. An instance of this class can be initialized only once, and the necessary credentials must be provided during its initialization.

Disclaimer: For production builds don’t save credentials in code.

Parameters :

Parameter NameData TypeMandatoryDescription
client_idStringYesClient ID for secure communication with PhonePe.
client_secretStringYesSecret provided by PhonePe. To be kept secure on the merchant side.
cient_versionIntegerYesClient version for secure communication with PhonePe.
envEnvYesEnvironment for the StandardCheckoutClient:

Env.PRODUCTION (Production)
Env.SANDBOX (Testing)

Throws PhonePeException:

If a new SubscriptionClient is created with credentials different from the previous instance, a PhonePeException is thrown.

Example usage:

from phonepe.sdk.pg.env import Env
from phonepe.sdk.pg.subscription.v2.subscription_client import SubscriptionClient
 
client_id = "<YOUR_CLIENT_ID>"
client_secret = "<YOUR_CLIENT_SECRET>"
client_version = "<YOUR_CLIENT_VERSION>"  # insert your client version here
should_publish_events = false
env = Env.SANDBOX  # change to Env.PRODUCTION when you go live
 
subscription_client = SubscriptionClient.get_instance(client_id=client_id,
                                                      client_secret=client_secret,
                                                      client_version=client_version,
                                                      env=env,
                                                      should_publish_events=should_publish_events)