Subscription Setup
The Subscription Setup process allows you to initiate a subscription. By calling the setup() method, you can create a subscription with either UPI_INTENT or UPI_COLLECT payment methods. The setup requires specific parameters such as the order ID, subscription ID, amount, frequency, and expiration details. The response from the setup contains essential information like the order state and intent URL for further payment processing.
Setting Up Subscription with UPI_INTENT
The setup() method is used to initiate the subscription setup with UPI_INTENT. Use the builder PgPaymentRequest.build_subscription_setup_upi_intent() to start the process.
Required Parameters for UPI_INTENT Setup
| Attribute | Data Type | Mandatory | Description | Default Value |
merchant_order_id | String | Yes | Unique order ID generated by the merchant. | |
merchant_subscription_id | String | Yes | Unique subscription ID generated by the merchant. | |
| Int | Yes | Amount in Paisa (FULL auth – first debit amount, PENNY auth – 200). | |
| Int | No | Epoch timestamp; the order will automatically fail if not completed within the given time (default is 10 minutes). | 10 mins |
auth_workflow_type | AuthWorkflowType | Yes | Type of setup workflow (TRANSACTION or PENNY_DROP) | |
amount_type | AmountType | Yes | Redemption amount type (FIXED or VARIABLE). | |
max_amount | Int | Yes | Maximum amount up to which redemptions will be allowed. | |
frequency | Frequency | Yes | Subscription frequency (DAILY, WEEKLY, MONTHLY, etc.) | |
subscription_expire_at | Int | No | Subscription expiration timestamp (No operations allowed after expiry, default is 30 years). | |
target_app | String | No | Target app for intent payment mode: • Android – package name • iOS – PHONEPE / GPAY / PAYTM | |
meta_info | MetaInfo | No | User-defined fields for status checks and callbacks |
Example Code for UPI_INTENT Setup
import com.phonepe.sdk.pg.common.models.response.PgPaymentResponse;
import com.phonepe.sdk.pg.subscription.v2.SubscriptionClient;
import com.phonepe.sdk.pg.subscription.v2.models.request.AmountType;
import com.phonepe.sdk.pg.subscription.v2.models.request.AuthWorkflowType;
import com.phonepe.sdk.pg.subscription.v2.models.request.Frequency;
import java.util.UUID;
String clientId = "<clientId>";
String clientSecret = "<clientSecret>";
Integer clientVersion = <clientVersion>;
Env env = Env.SANDBOX; //change to Env.PRODUCTION when you go live
SubscriptionClient subscriptionClient = SubscriptionClient.getInstance(clientId, clientSecret, clientVersion, env);
String merchantOrderId = UUID.randomUUID().toString();
String merchantSubscriptionId = UUID.randomUUID().toString();
long amount = 200; //In paisa
AuthWorkflowType authWorkFlowType = AuthWorkflowType.TRANSACTION; //It can also be AuthWorkFlowType.PENNY_DROP
AmountType amountType = AmountType.FIXED; //It can also be AmountType.VARIBALE
Frequency frequency = Frequency.ON_DEMAND;
long maxAmount = 200;
PgPaymentRequest setupRequest = PgPaymentRequest.SubscriptionSetupUpiIntentBuilder()
.merchantOrderId(merchantOrderId)
.merchantSubscriptionId(merchantSubscriptionId)
.amount(amount)
.authWorkflowType(authWorkFlowType)
.amountType(amountType)
.maxAmount(maxAmount)
.frequency(frequency)
.build();
PgPaymentResponse setupResponse = subscriptionClient.setup(setupRequest);
String intentUrl = setupResponse.getIntentUrl();Return Values for UPI_INTENT
The function returns a PgPaymentResponse object with the following properties:
| Parameter Name | Data Type | Description |
order_id | String | Unique order ID generated by PhonePe. |
| String | State of the order. Initially it will be PENDING. |
expireAt | Long | Order expire date in epoch. |
| String | Intent url according to the targetApp mentioned in the request. |
Setting Up Subscription with UPI_COLLECT
The setup() method can also initiate the subscription setup with UPI_COLLECT. Use the builder PgPaymentRequest.build_subscription_setup_upi_collect() to begin.
| Attribute | Data Type | Mandatory | Description | Default Value |
merchant_order_id | String | Yes | Unique order ID generated by the merchant. | |
merchant_subscription_id | String | Yes | Unique subscription ID generated by the merchant. | |
| Int | Yes | Amount in Paisa (FULL auth – first debit amount, PENNY auth – 200). | |
| Int | No | Epoch timestamp; the order will automatically fail if not completed within the given time (default is 10 minutes). | 10 mins |
auth_workflow_type | AuthWorkflowType | Yes | Type of setup workflow (TRANSACTION or PENNY_DROP) | |
amount_type | AmountType | Yes | Redemption amount type (FIXED or VARIABLE). | |
max_amount | Int | Yes | Maximum amount up to which redemptions will be allowed. | |
frequency | Frequency | Yes | Subscription frequency (DAILY, WEEKLY, MONTHLY, etc.) | |
subscription_expire_at | Int | No | Subscription expiration timestamp (No operations allowed after expiry, default is 30 years). | |
target_app | String | No | Target app for intent payment mode: • Android – package name • iOS – PHONEPE / GPAY / PAYTM | |
meta_info | MetaInfo | No | User-defined fields for status checks and callbacks. | |
vpa | String | Yes | Virtual Payment Address (VPA) for which the collect request will be raised. |
import com.phonepe.sdk.pg.common.models.request.PgPaymentRequest;
import com.phonepe.sdk.pg.common.models.response.PgPaymentResponse;
import com.phonepe.sdk.pg.subscription.v2.SubscriptionClient;
import com.phonepe.sdk.pg.subscription.v2.models.request.AmountType;
import com.phonepe.sdk.pg.subscription.v2.models.request.AuthWorkflowType;
import com.phonepe.sdk.pg.subscription.v2.models.request.Frequency;
import java.util.UUID;
String clientId = "<clientId>";
String clientSecret = "<clientSecret>";
Integer clientVersion = 1; //insert your client version here
Env env = Env.SANDBOX; //change to Env.PRODUCTION when you go live
SubscriptionClient subscriptionClient = SubscriptionClient.getInstance(clientId, clientSecret, clientVersion, env);
String merchantOrderId = UUID.randomUUID().toString();
String merchantSubscriptionId = UUID.randomUUID().toString();
long amount = 200; //In paisa
AuthWorkflowType authWorkFlowType = AuthWorkflowType.TRANSACTION; //It can also be AuthWorkFlowType.PENNY_DROP
AmountType amountType = AmountType.FIXED; //It can also be AmountType.VARIBALE
Frequency frequency = Frequency.ON_DEMAND;
String vpa = "VALID_VPA";
long maxAmount = 200;
PgPaymentRequest setupRequest = PgPaymentRequest.SubscriptionSetupUpiCollectBuilder()
.merchantOrderId(merchantOrderId)
.merchantSubscriptionId(merchantSubscriptionId)
.amount(amount)
.authWorkflowType(authWorkFlowType)
.amountType(amountType)
.maxAmount(maxAmount)
.frequency(frequency)
.vpa(vpa)
.build();
PgPaymentResponse setupResponse = subscriptionClient.setup(setupRequest);Return Values for UPI_COLLECT
The function will raise a collect request to the provided VPA.
The function returns a PgPaymentResponse object with the following properties:
| Parameter Name | Data Type | Description |
order_id | String | Unique order ID generated by PhonePe. |
| String | State of the order. Initially it will be PENDING. |
expireAt | Long | Order expire date in epoch. |
What’s Next ?
After setting up the subscription, the next step is to check the Order Status. Head over to the next section to learn how to check the status of an order.