The setup() method is used to start/create a new subscription using any one of the given instruments:
1. Using UPI_INTENT
The setup() method is used to initiate the subscription setup, by passing the below parameter in the builder for UPI_INTENT: PgPaymentRequest.build_subscription_setup_upi_intent()
Parameters
Attribute | Data Type | Mandatory | Description | Default Value |
---|---|---|---|---|
merchant_order_id | Str | Yes | Unique order ID generated by merchant | – |
| Str | Yes | Unique subscription ID generated by merchant | – |
amount | Int | Yes | Amount of order in Paisa FULL auth – first debit amount PENNY auth – 200 | – |
order_expire_at | Int | No | Order expireAt epoch after which order will auto fail if not terminal | 10 mins |
| AuthWorkflowType | Yes | Type of setup workflow 1. TRANSACTION 2. PENNY_DROP | – |
amount_type | AmountType | Yes | Nature of redemption amount 1. FIXED 2. VARIABLE | – |
max_amount | Int | Yes | Max amount upto which redemptions will be allowed | – |
frequency | Frequency | Yes | Subscription frequency 1. DAILY 2. WEEKLY 3. MONTHLY 4. YEARLY 5. FORTNIGHTLY 6. BIMONTHLY 7. ON_DEMAND 8. QUATERLY 9. HALFYEARLY | – |
subscription_expire_at | Int | No | Subscription cycle expiry. No operation allowed after subscription expires | 30 Years |
target_app | Str | No | Target app for intent payment mode 1. android – package name 2. iOS – PHONEPE / GPAY / PAYTM | – |
meta_info | MetaInfo | No | User defines fields propagated in status check & callbacks | – |
Example:
import uuid
import time
from phonepe.sdk.pg.env import Env
from phonepe.sdk.pg.subscription.v2.subscription_client import SubscriptionClient
from phonepe.sdk.pg.subscription.v2.models.request.amount_type import AmountType
from phonepe.sdk.pg.subscription.v2.models.request.auth_workflow_type import AuthWorkflowType
from phonepe.sdk.pg.subscription.v2.models.request.frequency import Frequency
from phonepe.sdk.pg.common.models.request.pg_payment_request import PgPaymentRequest
client_id = "<clientId>"
client_secret = "<clientSecret>"
client_version = 1 # insert your client version here
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)
merchant_order_id = str(uuid.uuid4())
merchant_subscription_id = str(uuid.uuid4())
amount = 100
auth_workflow_type = AuthWorkflowType.TRANSACTION
amount_type = AmountType.FIXED
frequency = Frequency.ON_DEMAND
max_amount = 100
device_os = "IOS"
merchant_callback_scheme = ""
target_app = "PHONEPE"
subscription_expire_at = int(time.time() * 1000) + 1000000
order_expire_at = int(time.time() * 1000) + 1000000
setup_request = PgPaymentRequest.build_subscription_setup_upi_intent(
merchant_order_id=merchant_order_id,
merchant_subscription_id=merchant_subscription_id,
amount=amount,
device_os=device_os,
merchant_callback_scheme=merchant_callback_scheme,
target_app=target_app,
auth_workflow_type=auth_workflow_type,
subscription_expire_at=subscription_expire_at,
amount_type=amount_type,
frequency=frequency,
order_expire_at=order_expire_at,
max_amount=max_amount
)
setup_response = subscription_client.setup(setup_request)
intent_url = setup_response.intent_url
Extract the intent_url
from the response received
Returns:
The function returns a PgPaymentResponse
object with the following properties:
PgPaymentResponse Properties:
Here is the response property table for the given model:
Property | Type | Description |
---|---|---|
order_id | String | Unique order ID generated by PhonePe |
state | String | State of the order. Initially it will be PENDING. |
intent_url | String | Intent url according to the targetApp mentioned in the request |
2. Using UPI_COLLECT
The setup() method is used to initiate the subscription setup, by passing the below parameter in the builder for UPI_COLLECT: PgPaymentRequest.build_subscription_setup_upi_collect()
Parameters
Attribute | Data Type | Mandatory | Description | Default Value |
---|---|---|---|---|
merchant_order_id | Str | Yes | Unique order ID generated by merchant | |
| Str | Yes | Unique subscription ID generated by merchant | |
amount | Int | Yes | Amount of order in Paisa FULL auth – first debit amount PENNY auth – 200 | |
order_expire_at | Int | No | Order expireAt epoch after which order will auto fail if not terminal | 10 mins |
| AuthWorkflowType | Yes | Type of setup workflow 1. TRANSACTION 2. PENNY_DROP | |
amount_type | AmountType | Yes | Nature of redemption amount 1. FIXED 2. VARIABLE | |
max_amount | Int | Yes | Max amount upto which redemptions will be allowed | |
frequency | Frequency | Yes | Subscription frequency 1. DAILY 2. WEEKLY 3. MONTHLY 4. YEARLY 5. FORTNIGHTLY 6. BIMONTHLY 7. ON_DEMAND 8. QUATERLY 9. HALFYEARLY | |
subscription_expire_at | Int | No | Subscription cycle expiry. No operation allowed after subscription expires | 30 Years |
meta_info | MetaInfo | No | User defines fields propagated in status check & callbacks | |
vpa | Str | Yes | Vpa for which collect request will be raised |
Example:
import uuid
import time
from phonepe.sdk.pg.env import Env
from phonepe.sdk.pg.subscription.v2.subscription_client import SubscriptionClient
from phonepe.sdk.pg.subscription.v2.models.request.amount_type import AmountType
from phonepe.sdk.pg.subscription.v2.models.request.auth_workflow_type import AuthWorkflowType
from phonepe.sdk.pg.subscription.v2.models.request.frequency import Frequency
from phonepe.sdk.pg.common.models.request.pg_payment_request import PgPaymentRequest
client_id = "<clientId>"
client_secret = "<clientSecret>"
client_version = 1 # insert your client version here
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)
merchant_order_id = str(uuid.uuid4())
merchant_subscription_id = str(uuid.uuid4())
amount = 200 # In paisa
auth_workflow_type = AuthWorkflowType.TRANSACTION
amount_type = AmountType.FIXED
frequency = Frequency.ON_DEMAND
vpa = "<REPLACE_WITH_REQUIRED_VPA>"
max_amount = 200
subscription_expire_at = int(time.time() * 1000) + 1000000 # Not mandatory (default 30 years)
order_expire_at = int(time.time() * 1000) + 1000000 # Not mandatory (default 10 mins)
setup_request = PgPaymentRequest.build_subscription_setup_upi_collect(
merchant_order_id=merchant_order_id,
merchant_subscription_id=merchant_subscription_id,
amount=amount,
auth_workflow_type=auth_workflow_type,
subscription_expire_at=subscription_expire_at,
amount_type=amount_type,
frequency=frequency,
order_expire_at=order_expire_at,
max_amount=max_amount,
vpa=vpa,
)
setup_response = subscription_client.setup(setup_request)
It will raise a collect request to the mentioned VPA.
Returns:
The function returns a PgPaymentResponse
object with the following properties:
PgPaymentResponse Properties:
Here is the response property table for the given model:
Property | Type | Description |
---|---|---|
order_id | String | Unique order ID generated by PhonePe |
state | String | State of the order. Initially it will be PENDING. |