Skip to main content
POST
/
merchant
/
discount
/
plan_apply_preview
Plan Apply Preview
curl --request POST \
  --url https://api.unibee.dev/merchant/discount/plan_apply_preview \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "code": "<string>",
  "addonParams": [
    {
      "addonPlanId": 123,
      "quantity": 123
    }
  ],
  "currency": "<string>",
  "email": "<string>",
  "externalPlanId": "<string>",
  "isChangeToLongPlan": true,
  "isChangeToSameIntervalPlan": true,
  "isUpgrade": true,
  "planId": 123,
  "quantity": 123
}
'
{
  "code": 123,
  "data": {
    "allPlansAllowed": true,
    "allowedPlanIds": [
      123
    ],
    "discountAmount": 123,
    "discountCode": {
      "advance": true,
      "billingType": 123,
      "code": "<string>",
      "createTime": 123,
      "currency": "<string>",
      "cycleLimit": 123,
      "discountAmount": 123,
      "discountPercentage": 123,
      "discountType": 123,
      "endTime": 123,
      "id": 123,
      "isDeleted": 123,
      "merchantId": 123,
      "metadata": {},
      "name": "<string>",
      "planApplyGroup": {
        "currency": [
          "<string>"
        ],
        "groupPlanIntervalSelector": [
          {
            "intervalCount": 123,
            "intervalUnit": "<string>"
          }
        ],
        "type": [
          123
        ]
      },
      "planApplyType": 123,
      "planIds": [
        123
      ],
      "quantity": 123,
      "startTime": 123,
      "status": 123,
      "upgradeLongerOnly": true,
      "upgradeOnly": true,
      "userLimit": 123,
      "userScope": 123
    },
    "failureReason": "<string>",
    "valid": true
  },
  "merchantId": 123,
  "message": "<string>",
  "redirect": "<string>",
  "requestId": "<string>"
}

Endpoint Overview

POST https://api.unibee.dev/merchant/discount/plan_apply_preview Check discount can apply to plan, Only check rules about plan,the actual usage is subject to the subscription interface

Authorization

All UniBee Merchant API requests require authentication via API key.
HeaderRequiredDescription
AuthorizationYesBearer <your_api_key>
Content-TypeYesapplication/json (for request body)

Parameters

Parameters for this endpoint are listed below. The schema is also shown in the Try it panel.

Request body

NameTypeRequiredDescription
addonParamsarrayNoAddon list with quantity, align with subscription create preview
codestringYesThe discount’s unique code, customize by merchant
currencystringNoThe currency of plan which code to apply
emailstringNoEmail
externalPlanIdstringNoThe externalId of plan which code to apply, either planId or externalPlanId is needed
isChangeToLongPlanbooleanNoIsChangeToLongPlan
isChangeToSameIntervalPlanbooleanNoIsChangeToSameIntervalPlan
isUpgradebooleanNoIsUpgrade
planIdintegerNoThe id of plan which code to apply, either planId or externalPlanId is needed
quantityintegerNoMain plan quantity, default 1; align with subscription create preview

Request examples

cURL

curl -X POST "https://api.unibee.dev/merchant/discount/plan_apply_preview" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "addonParams": [],
  "code": "",
  "currency": "",
  "email": "user@example.com",
  "externalPlanId": "id_example",
  "isChangeToLongPlan": false,
  "isChangeToSameIntervalPlan": false,
  "isUpgrade": false,
  "planId": 0,
  "quantity": 0
}'

Sandbox

curl -X POST "https://api-sandbox.unibee.top/merchant/discount/plan_apply_preview" \
  -H "Authorization: Bearer YOUR_SANDBOX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "addonParams": [],
  "code": "",
  "currency": "",
  "email": "user@example.com",
  "externalPlanId": "id_example",
  "isChangeToLongPlan": false,
  "isChangeToSameIntervalPlan": false,
  "isUpgrade": false,
  "planId": 0,
  "quantity": 0
}'

Response

Success responses return a JSON envelope with code, data, message, redirect, and requestId. code 0 indicates success.
FieldTypeDescription
codeintegerResponse code. 0 = success
dataobjectResponse payload
data.allPlansAllowedbooleanTrue = discount applies to all plans in cart; false = only to allowedPlanIds
data.allowedPlanIdsarrayPlan ids that get this discount (when partial apply); empty or same as main+addons when all plans allowed
data.discountAmountintegerThe discount amount can apply to plan
data.discountCodeobject
data.failureReasonstringThe apply preview failure reason
data.validbooleanThe apply preview result, true or false
messagestringHuman-readable message
requestIdstringRequest ID for support

Error handling

HTTP statusMeaning
400Bad request — invalid or missing parameters. Check message in the body.
401Unauthorized — missing or invalid API key.
404Not found — invalid path or resource.
500Server error — retry with backoff.
When code in the response body is non-zero, check message for details. Use requestId when contacting support.

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json

Check discount can apply to plan, Only check rules about plan,the actual usage is subject to the subscription interface

code
string<string>
required

The discount's unique code, customize by merchant

addonParams
object[]

Addon list with quantity, align with subscription create preview

currency
string<string>

The currency of plan which code to apply

email
string<string>

Email

externalPlanId
string<string>

The externalId of plan which code to apply, either planId or externalPlanId is needed

isChangeToLongPlan
boolean<*bool>

IsChangeToLongPlan

isChangeToSameIntervalPlan
boolean<*bool>

IsChangeToSameIntervalPlan

isUpgrade
boolean<*bool>

IsUpgrade

planId
integer<int64>

The id of plan which code to apply, either planId or externalPlanId is needed

quantity
integer<int64>

Main plan quantity, default 1; align with subscription create preview

Response

200 - application/json
code
integer<int>
data
object
merchantId
integer<int64>
message
string<string>
redirect
string<string>
requestId
string<string>