Setup Subscription using API


This API is used to set up a subscription for a customer.

EnvironmentHTTP MethodAPI
SandboxPOSThttps://api-preprod.phonepe.com/apis/pg-sandbox/checkout/v2/pay
ProductionPOSThttps://api.phonepe.com/apis/pg/checkout/v2/pay
Header NameHeader ValueDescription
Content-Typeapplication/json
AuthorizationO-Bearer <access_token>Pass access_token received in Authorization call
Request Parameters
Parameter NameData TypeDescriptionMandatoryConstraints
merchantOrderIdStringUnique merchant order id generated by merchant.YesMax Length = 63 characters.
No Special characters allowed except underscore “_” and hyphen “-“
amountLongOrder amount in paisa.Yes
Min value = 100 paise
expireAtDateTimeOrder expiry in seconds. If not passed default value will be used.NoMin Value = 300, Max Value = 3600
metaInfoObjectMerchant defined meta info to store additional information.
Same data will be returned in status and callback response.
NoFor udf1 to udf10, there is no constraint.
For udf11 to udf15, alphanumeric values with _-+@. are allowed.
paymentFlowObjectAdditional details required by this flowYes

The metaInfo object contains additional parameters, which are explained in the table below.

Request Parameters of metoInfo Object:
Parameter NameData TypeDescriptionMandatory (Yes/No)Constraints
metaInfo.udf1-15StringOptional details you can add for more informationNoMaximum length for Udf1-10 = 256 characters
Maximum length for Udf11-15 = 50 characters

⚠️ Do Not Rename metainfo Parameters!


It is mandatory to keep the parameter names udf1, udf2, etc., exactly as they are in the metainfo block. Renaming these key values will result in a production error.

The paymentFlow object contains additional parameters, which are explained in the table below.

Request Parameters of paymentFlow Object:
Parameter NameData TypeMandatory (Yes/No)DescriptionConstraints
paymentFlow.typeStringYesType of payment flow. Valued Allowed = [SUBSCRIPTION_CHECKOUT]
paymentFlow.messageStringNoMessage to be displayed to user on paypageAllowed Characters = [ A-Za-z0-9+-_ ] Max Length = 128
paymentFlow.merchantUrlsObjectYesObject to store different merchant Urls 
paymentFlow.merchantUrls.redirectUrlStringYesUrl where user will be redirected after success/failed payment.
paymentFlow.merchantUrls.cancelUrlStringNoUrl where user will be redirected after cancelled payment.
paymentFlow.subscriptionDetailsObjectYessubscription details
paymentFlow.subscriptionDetails.subscriptionTypeStringYesRECURRING, ONE_TIME etc
paymentFlow.subscriptionDetails.merchantSubscriptionIdStringYesmerchant subscription Id
paymentFlow.subscriptionDetails.authWorkflowTypeStringYesTRANSACTION / PENNY DROP
paymentFlow.subscriptionDetails.amountTypeStringYesFIXED/ VARIABLE
paymentFlow.subscriptionDetails.maxAmountLongYesmax redemption amount. The amount must be in paisa. Max Limit: 1500000 paisa
paymentFlow.subscriptionDetails.frequencyStringYesRedemption Frequency.
Supported values:
Daily
Weekly
Monthly
Bi-monthly
Fortnightly
Quaterly
Half-Yearly
Annual
On-Demand
paymentFlow.subscriptionDetails.expireAtepochNoSubscription Expiry
paymentFlow.subscriptionDetails.productTypeStringYesUPI_MANDATE

Sample Request
{
    "merchantOrderId": "{{merchantOrderId}}",
    "amount": 47900,
    "paymentFlow": {
        "type": "SUBSCRIPTION_CHECKOUT_SETUP",
        "message": "Payment message used for collect requests",
        "merchantUrls": {
            "redirectUrl": "www.google.com",
            "cancelRedirectUrl": "www.google.com"
        },
        "subscriptionDetails": {
            "subscriptionType": "RECURRING",
            "merchantSubscriptionId": "{{merchantSubId}}",
            "authWorkflowType": "TRANSACTION",
            "amountType": "FIXED",
            "maxAmount": 47900,
            "frequency": "ON_DEMAND",
	    "productType": "UPI_MANDATE",
            "expireAt": 1779689282000
        }
    },
    "expireAfter": 3000,
    "metaInfo": {
        "udf1": "some meta info of max length 256",
        "udf2": "some meta info of max length 256",
        "udf3": "some meta info of max length 256",
        "udf4": "some meta info of max length 256",
        "udf5": "some meta info of max length 256",
        "udf6": "some meta info of max length 256",
        "udf7": "some meta info of max length 256",
        "udf8": "some meta info of max length 256",
        "udf10": "some meta info of max length 256",
        "udf11": "some meta info of max length 50",
        "udf12": "some meta info of max length 50",
        "udf13": "some meta info of max length 50",
        "udf14": "some meta info of max length 50",
        "udf15": "some meta info of max length 50"
    }
}
Sample Response
{
    "orderId": "OMO123456789",
    "state": "PENDING",
    "expireAt": 1703756259307,     
    "redirectUrl": "../transact/pgv2?token=<token>" 
}

In the next section, you will learn how to you check whether the subscription has been successfully created, is still pending user action, has failed, or is complete.

Is this article helpful?