Skip to content

Subscription Create

Request URL

HTTP
https://{{gateway_domain}}/pg/v2/payment/subscription/create

Request Parameters

HTTP Method

POST

HTTP Header

FieldData TypeLength LimitRequiredDescription
Content-TypeStringN/AYESThis field value only supports application/json.
AcceptStringN/AYESThis field value only supports application/json.
AuthorizationStringYESAuthorization: {type} {credentials}, refer to the Signature specification

HTTP Body

FieldData TypeLength LimitRequiredDescription
merchantSubscriptionNoString50YESMerchant-generated subscription number. Uniqueness is recommended.
descriptionString80YESOrder title. In some scenarios, if the consumer sees the order information, this field content may show.
payerJSON ObjectYESPayer information. Refer to the payer parameter description below.
billingModelJSON ObjectYESUser subscription model. Refer to Billing Models.
scheduleUnitString20YESSubscription period unit. Refer to Schedule Unit.
scheduleLengthString20YESSubscription period step length, indicating how many units in one period.
marketingStrategyJSON ObjectYESMarketing strategy data.
tradeEnvJSON ObjectUser trade environment information.
merchantAttachString255NOIf used, this field will be returned as-is in sync/async notifications and order query responses.
notifyUrlString255YESWhen the order payment is successful, the platform will notify the merchant by calling this URL.
returnUrlString255YESIf the upstream supports synchronous redirection, the platform will redirect the user's page to this URL.
  • billingModel parameter structure description
    • billingModel is dynamic, containing a fixed field type, and different fields depending on type.
FieldData TypeLength LimitRequiredDescription
typeString20YES
amountString18YESAmount per period. Integer part 1-15 digits with 2 decimals, e.g. "100.05".
currencyString3YESISO currency code of the amount. Refer to the currency list.
  • marketingStrategy parameter structure description
    • marketingStrategy is dynamic, containing a fixed field type, and different fields depending on type.
FieldData TypeLength LimitRequiredDescription
typeString20YES
  • payer parameter notes
    • Choose one of email or phone.
FieldData TypeLength LimitRequiredDescription
userIdString64NOPayer ID
nameString80NOPayer name
emailString80NOPayer email. At least one of email or phone is required.
phoneString20NOPayer phone. At least one of email or phone is required.
  • tradeEnv parameter description
FieldData TypeLength LimitRequiredDescription
deviceIdString50Payer device ID
ipString32Payer device IP

Response Data

HTTP Header

FieldData TypeRequiredDescription
Content-TypeStringYESThis field value only supports application/json.
AuthorizationStringYESAuthorization: {type} {credentials}, refer to the Signature specification

HTTP Body

FieldData TypeRequiredDescription
codeStringYES
errorMessageStringNOError message
dataJSON ObjectNO

Description of data field

FieldData TypeRequiredDescription
subscriptionNoStringYESSubscription number
merchantSubscriptionNoStringYESMerchant subscription number
actionJSON ObjectYESVariant return fields

Description of action field

  • payUrl is the payment link generated by the platform. Users click it to be redirected to the platform to pay.
JSON
{
    "action": {
        "payUrl": "https://xxx.yy"
    }
}

::::

Examples

Request

HTTP
curl https://{{gateway_domain}}/pg/v2/payment/subscription/create \
  -X POST \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H 'Authorization: V2_SHA256 appId=1111b620f93b48c5904210ff47bb1111,sign=9e494e8a91bcdd08f18ad5b2cfdbfd5654f5c00c89f8216eebd7c1637b6ce01b,timestamp=1714128828114,nonce=C7CA27DC6D55DA935DFC8450C721CC99' \
  -d '{
  "merchantSubscriptionNo": "MSN-1161",
  "description": "subscription test",
  "payer": {
    "userId": "test_id",
    "name": "testName",
    "email": "[email protected]",
    "phone": "00000000"
  },
  "billingModel": {
    "type": "FIXED_SCHEDULE_AND_FIXED_AMOUNT",
    "amount": "10.00",
    "currency": "RUB"
  },
  "scheduleUnit": "MONTH",
  "scheduleLength": "1",
  "marketingStrategy": {
    "type": "DEFAULT"
  },
  "tradeEnv": {
    "ip": "127.0.0.1",
    "deviceId": "02efc74d-3988-4f0d-8cc8-0cb78bded719"
  },
  "merchantAttach": "merchant attach",
  "notifyUrl": "https://example.com/notifyurl",
  "returnUrl": "https://example.com/returnurl"
}'

Response

HTTP
HTTP/1.1 200 OK
Content-Type: application/json
Server: nginx/1.18.0
Date: Mon, 06 Mar 2024 12:00:00 GMT
Authorization: V2_SHA256 appId=1111b620f93b48c5904210ff47bb1111,sign=ac6ae72f8c46f5c2092c3dab9bb0e08b6cdb6d5e7ff8ad190499a8955d57f297,timestamp=1714128245401,nonce=28FA11BF8FD1309767551B4FD8A57BD5

{
    "code": "OK",
    "errorMessage": null,
    "data": {
        "subscriptionNo": "20240423220624300800001097000004",
        "merchantSubscriptionNo": "MSN-1161",
        "action": {
            "payUrl": "https://xxx.yy"
        }
    }
}

Notes

If subsequent debits fail, there are several scenarios:

  • If the user cancels the authorization at the bank side, do not retry and close the subscription directly.
  • If the user has not canceled the authorization but has insufficient balance, retry three times, once per day. If unsuccessful after three tries, stop retrying.