The setup() method is used to start/create a new subscription using any one of the given instruments:
- UPI_INTENT
- 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
Attribute | Data Type | Mandatory | Description | Default Value |
---|---|---|---|---|
merchantOrderId | String | Yes | Unique order ID generated by merchant | – |
| String | Yes | Unique subscription ID generated by merchant | – |
amount | Long | Yes | Amount of order in Paisa FULL auth – first debit amount PENNY auth – 200 | – |
orderExpireAt | Long | 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 | – |
amountType | AmountType | Yes | Nature of redemption amount 1. FIXED 2. VARIABLE | – |
maxAmount | Long | 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 | – |
subscriptionExpireAt | Long | No | Subscription cycle expiry. No operation allowed after subscription expires | 30 Years |
targetApp | String | No | Target app for intent payment mode 1. android – package name 2. iOS – PHONEPE / GPAY / PAYTM | – |
metaInfo | MetaInfo | No | User 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:
Property | Type | Description |
---|---|---|
orderId | String | Unique order ID generated by PhonePe |
state | String | State of the order. Initially it will be PENDING. |
expireAt | Long | Order expire date in epoch |
intentUrl | 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.SubscriptionSetupUpiCollectBuilder()
Parameters
Attribute | Data Type | Mandatory | Description | Default Value |
---|---|---|---|---|
merchantOrderId | String | Yes | Unique order ID generated by merchant | |
| String | Yes | Unique subscription ID generated by merchant | |
amount | Long | Yes | Amount of order in Paisa FULL auth – first debit amount PENNY auth – 200 | |
orderExpireAt | Long | 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 | |
amountType | AmountType | Yes | Nature of redemption amount 1. FIXED 2. VARIABLE | |
maxAmount | Long | 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 | |
subscriptionExpireAt | Long | No | Subscription cycle expiry. No operation allowed after subscription expires | 30 Years |
metaInfo | MetaInfo | No | User defines fields propagated in status check & callbacks | |
vpa | String | Yes | 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:
Property | Type | Description |
---|---|---|
orderId | String | Unique order ID generated by PhonePe |
state | String | State of the order. Initially it will be PENDING. |
expireAt | Long | Order expire date in epoch |