Subscription Setup

The setup() method is used to start/create a new subscription using any one of the given instruments:

  1. UPI_INTENT
  2. UPI_COLLECT

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.SubscriptionSetupUpiIntentBuilder()

Parameters

AttributeData TypeMandatoryDescriptionDefault Value
merchantOrderIdStringYes
Unique order ID generated by merchant
merchantSubscriptionIdStringYes
Unique subscription ID generated by merchant
amountLongYes
Amount of order in Paisa
FULL auth – first debit amount
PENNY auth – 200
orderExpireAtLongNoOrder expireAt epoch after which order will auto fail if not terminal10 mins
authWorkflowTypeAuthWorkflowTypeYesType of setup workflow
1. TRANSACTION
2. PENNY_DROP
amountTypeAmountTypeYesNature of redemption amount
1. FIXED
2. VARIABLE
maxAmountLongYesMax amount upto which redemptions will be allowed
frequencyFrequencyYesSubscription frequency
1. DAILY
2. WEEKLY
3. MONTHLY
4. YEARLY
5. FORTNIGHTLY
6. BIMONTHLY
7. ON_DEMAND
8. QUATERLY
9. HALFYEARLY
subscriptionExpireAtLongNoSubscription cycle expiry. No operation allowed after subscription expires30 Years
targetAppStringNoTarget app for intent payment mode
1. android – package name
2. iOS – PHONEPE / GPAY / PAYTM
metaInfoMetaInfoNoUser defines fields propagated in status check & callbacks

Example:

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;
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();

Extract the intentUrl 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:

PropertyTypeDescription
orderIdStringUnique order ID generated by PhonePe
stateStringState of the order. Initially it will be PENDING.
expireAtLongOrder expire date in epoch
intentUrlStringIntent 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.SubscriptionSetupUpiCollectBuilder()

Parameters

AttributeData TypeMandatoryDescriptionDefault Value
merchantOrderIdStringYes
Unique order ID generated by merchant
merchantSubscriptionIdStringYes
Unique subscription ID generated by merchant
amountLongYes
Amount of order in Paisa
FULL auth – first debit amount
PENNY auth – 200
orderExpireAtLongNoOrder expireAt epoch after which order will auto fail if not terminal10 mins
authWorkflowTypeAuthWorkflowTypeYesType of setup workflow
1. TRANSACTION
2. PENNY_DROP
amountTypeAmountTypeYesNature of redemption amount
1. FIXED
2. VARIABLE
maxAmountLongYesMax amount upto which redemptions will be allowed
frequencyFrequencyYesSubscription frequency
1. DAILY
2. WEEKLY
3. MONTHLY
4. YEARLY
5. FORTNIGHTLY
6. BIMONTHLY
7. ON_DEMAND
8. QUATERLY
9. HALFYEARLY
subscriptionExpireAtLongNoSubscription cycle expiry. No operation allowed after subscription expires30 Years
metaInfoMetaInfoNoUser defines fields propagated in status check & callbacks
vpaStringYes
Vpa for which collect request will be raised

Example:

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);

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:

PropertyTypeDescription
orderIdStringUnique order ID generated by PhonePe
stateStringState of the order. Initially it will be PENDING.
expireAtLongOrder expire date in epoch