﻿# Update Subscription

After the subscription plan is successfully activated, merchants can process package upgrades, downgrades, billing cycle switches (monthly/annual), and seat additions/removals for users. The overall operation is divided into two steps: **Update Preview** (calculate the prorated amount and generate a preview order) and **Confirm Update** (submit the formal change).

::: warning Note:
Only subscriptions created based on Price support updates!
:::

## 1. Subscription Update Instructions

### 1.1 Upgrade Subscription

The following situations are generally considered upgrades:

- Switch to a product with higher entitlements: Plus upgraded to Pro

- Switch from monthly to annual or another longer-cycle plan with higher value: monthly to annual

- Increase the number of seats: add seats

**Effective Time and Billing Period Handling**

When the upgrade takes effect and how the amount is prorated depend on the logic of the following three dimensions.

| Effective Time / effectiveMode              | Billing Cycle Handling / billingCycleAnchor  | Amount Proration Rule                                                                                |
| ------------------------------------------- | -------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| Take effect immediately / `immediate`       | Keep the original billing date / `unchanged` | Actual amount payable = remaining period amount of the new plan - unused amount of the original plan |
|                                             | Update billing date / `now`                  | Actual amount payable = price of the new plan - unused amount of the original price                  |
| Take effect in the next cycle / `nextCycle` | /                                            | No proration; after the current cycle ends, deduct directly at the new plan price                    |

Recommendations for effective time and fee handling:

|**Scenario**|**Effective Time**|**Billing Cycle Handling**|**Fee Handling**|
|---|---|---|---|
|Basic upgraded to Plus|Take effect immediately|Keep the original billing date|Pay the difference after proration|
|Monthly changed to annual|Take effect immediately|Update billing date|Pay the difference after proration|
|Add seats|Take effect immediately|Keep the original billing date|Pay the difference after proration|

Example:

  
    **📌 Product Package Upgrade**
    Current plan: Basic $10/month
    Target plan: Pro $30/month
    Apply for upgrade when 15 days remain in the cycle; takes effect immediately
    

    Remaining value of original plan: 10 × 15/30 = $5
    Remaining price of new plan: 30 × 15/30 = $15
    **User needs to pay the difference: $15 - $5 = $10**
  
  
    **📌 Seat Addition**
    Current plan: Pro $30/seat/month * 10
    Target plan: Pro $30/seat/month * 15
    10 days remain in the current cycle; apply for seat addition
    

    Amount payable for new seats: 30*5*10/30=$50
    **Amount payable for the next cycle: 30*15=$450**
  

### 1.2 Downgrade Subscription

::: tip  
🎁 Downgrades take effect by default in the **next cycle**. The current billing period is not refunded, and the user can continue to use the original package and original number of seats until the current billing period ends.
:::

The following situations are generally considered downgrades:

- Switch to a Product with lower entitlements, e.g., Pro downgraded to Plus;

- Switch from annual to monthly or another shorter-cycle plan;

- Reduce the number of seats.

**Recommended effective time and fee handling methods**:

|**Scenario**|**Effective Time**|**Fee Handling**|
|---|---|---|
|Pro downgraded to Basic|Next cycle|No refund for the current billing period|
|Annual changed to monthly|After the current annual cycle ends|No refund for the remaining fees of the current annual cycle|
|Reduce seats|Next cycle|No refund for the current billing period|

::: tip Example:
The current billing period is from May 1 to May 31. The user reduces seats from 15 to 12 on May 12:

- 15 seats can still be used until May 31;

- From June 1, service is provided and renewed based on 12 seats.

:::

### 1.3 Change Restrictions

In a single update, the change direction of each dimension should be kept consistent as much as possible. For example, upgrading "Basic Monthly" to "Pro Annual" means both Product and billing cycle are in the upgrade direction.

To improve user experience, it is recommended to restrict complex subscription plan update scenarios, such as package upgrade but billing cycle downgrade. If such updates need to be supported, please split them into two update submissions, or guide users to choose a target plan with a consistent change direction.

## 2. Overall Flow

The following figure shows the complete sequence from initial subscription creation, activation, subsequent automatic deductions, to initiating a subscription plan update (upgrade/downgrade/seat change) and automatic deductions again after the update:

```mermaid
%%{init: {
  'theme': 'base',
  'themeVariables': {
    'primaryColor': '#e6f0ff',
    'primaryTextColor': '#333',
    'primaryBorderColor': '#5b9bd5',
    'lineColor': '#888',
    'actorMargin': 40,
    'noteBkgColor': '#0056b3',
    'noteTextColor': '#ffffff',
    'noteBorderColor': '#004a99'
  }
}}%%
sequenceDiagram
    participant User as User
    participant MServer as Merchant Server
    participant PM as PayerMax

    rect rgb(235, 245, 255)
        Note over User, PM: Initial Payment
        User->>MServer: 1. User confirms the subscription plan
and initiates a payment request
        MServer->>PM: 2. Merchant initiates a create subscription plan request to PayerMax
        PM-->>MServer: Return Subscription ID
        MServer->>PM: 3. Activate subscription
        PM-->>MServer: PayerMax completes payment or binding and returns payment and binding success information
        MServer->>User: 4. Notify user of payment or binding success
Subscription plan activated successfully
    end

    rect rgb(235, 245, 255)
        Note over User, PM: Subsequent Payments
        PM->>MServer: 1. PayerMax periodically deducts payment according to the subscription plan and returns payment success information
        MServer->>User: 2. Notify user of payment success
    end

    rect rgb(240, 230, 250)
        Note over User, PM: Subscription Plan Update
        User->>MServer: 1. Select upgrade/downgrade/seat change
        MServer->>PM: Call subscription update preview API
subscriptionUpdatePreview
        PM-->>MServer: Return preview result
        MServer-->>User: Display change confirmation page
        User->>MServer: 2. Confirm change
        MServer->>PM: Call subscription update confirmation API
subscriptionUpdate
        PM-->>MServer: Return result
(if user verification is required, a redirect URL will be returned)
        MServer-->>User: Display payment result
    end

    rect rgb(235, 245, 255)
        Note over User, PM: Subsequent Payments
        PM->>MServer: 1. PayerMax periodically deducts payment according to the updated subscription rules
and returns payment success information
        MServer->>User: 2. Notify user of payment success
    end
```

**Key Restrictions**:

- After initiating an update preview, please complete the confirmation update within **30 minutes**; if not confirmed within 30 minutes, the preview order expires and a new preview is required.

- The subscription plan must be in the `ACTIVE` status to initiate a preview.

- If there is currently a bill in the process of renewal payment, preview or confirmation update is not allowed.

- If there is already a change request being processed, you must wait for it to complete before initiating a preview or confirmation again. During this period, canceling the subscription plan is also not allowed.

- If `effectiveMode=IMMEDIATE` and `billingCycleAnchor=UNCHANGED` (take effect immediately, keep the original billing date), the billing cycle of the target price must also be consistent with the billing cycle of the original plan.

- In a single change request, the change direction of each dimension (product, cycle, seats) should be kept consistent; combination changes with opposite directions are not supported.

## 3. Update Preview

Call the update preview API to obtain information such as the prorated amount after the change and the estimated next bill for user confirmation.

- Test environment: `https://pay-gate-uat.payermax.com/aggregate-pay/api/gateway/subscriptionUpdatePreview`

- Production environment: `https://pay-gate.payermax.com/aggregate-pay/api/gateway/subscriptionUpdatePreview`

### 3.1 Request Example

```json
{
    "version": "1.5",
    "keyVersion": "1",
    "requestTime": "2026-04-10T05:00:00+00:00",
    "appId": "6666c8b036a245799744912345a123456",
    "merchantNo": "P00213827211234",
    "data": {
        "subscriptionNo": "SUB20250417120949065211234",
        "userId": "testUserId",
        "effectiveMode": "IMMEDIATE",  // Effective mode: IMMEDIATE (take effect immediately), NEXT_CYCLE (take effect in the next cycle)
        "billingCycleAnchor": "UNCHANGED",  // Billing cycle handling method: UNCHANGED (keep the original billing date), NOW (recalculate the cycle)
        "callbackUrl": "http://yourDomain1.com/xxxx1",
        "frontCallbackUrl": "http://yourDomain2.com/xxxx2",
        "subscriptionPlan": {
            "subject": "subjectTest",
            "description": "descriptionTest",
            "totalPeriods": 12,
            "prices": [
                {
                    "quantity": 1,
                    "priceId": "PRICE0029177685919882013650001"
                }
            ]
        }
    }
}
```

### 3.2 Response Example

```json
{
    "code": "APPLY_SUCCESS",
    "msg": "Success.",
    "data": {
        "previewId": "PVI202504171209490652111234",
        "subscriptionNo": "SUB20250417120949065211234",
        "userId": "xxx",
        "currentSubscriptionPlan": {
            "periodAmount": {
                "amount": 3000,
                "currency": "KRW"
            },
            "periodRule": {
                "periodCount": 1,
                "periodUnit": "M"
            },
            "prices": [
                {
                    "priceId": "PRICE0029177685919882013650001",
                    "quantity": 1
                }
            ]
        },
        "targetSubscriptionPlan": {
            "periodAmount": {
                "amount": 4200,
                "currency": "KRW"
            },
            "periodRule": {
                "periodCount": 1,
                "periodUnit": "M"
            },
            "prices": [
                {
                    "priceId": "PRICE0029177685919882013650002",
                    "quantity": 2
                }
            ]
        },
        "billingPeriod": {
            "periodStartTime": "2026-04-10T00:00:00+0000",  // Current billing start time
            "periodEndTime": "2026-05-10T23:59:59+0000",  // Current billing end time
            "previewTime": "2026-04-20T15:59:59+0000",  // Preview time
            "remainingDays": 20,  // Remaining days in the current cycle
            "totalPeriodDays": 30,  // Total days in the current cycle
            "remainingRatio": 0.6667  // Remaining ratio of the current cycle (4 decimal places)
        },
        "proration": {  // Proration information
            "billingCycleAnchor": "UNCHANGED",
            "unusedCurrentAmount": 2000,
            "remainingTargetAmount": 2800,
            "netProrationAmount": 800,
            "currency": "KRW"
        },
        "amountSummary": {  // Amount summary
            "subTotalAmount": 2800,
            "creditAmount": 2000,
            "payableAmount": 800,
            "currency": "KRW"
        },
        "nextInvoice": {  // Next invoice
            "amount": 4200,
            "currency": "KRW",
            "periodStartTime": "2026-05-10T23:59:59+0000",
            "periodEndTime": "2026-06-10T23:59:59+0000"
        }
    }
}
```

It is recommended to display `targetSubscriptionPlan` (changed package), `amountSummary.payableAmount` (amount payable this time), and `nextInvoice` (next bill amount) to the user for confirmation before submitting the confirmation update.

## 4. Confirm Update

After the user confirms the preview result, call the confirmation update API (`subscriptionUpdate`) with `previewId` to submit the formal change.

- Test environment: `https://pay-gate-uat.payermax.com/aggregate-pay/api/gateway/subscriptionUpdate`

- Production environment: `https://pay-gate.payermax.com/aggregate-pay/api/gateway/subscriptionUpdate`

### 4.1 Request Example

```json
{
    "version": "1.5",
    "keyVersion": "1",
    "requestTime": "2025-02-26T05:00:00+00:00",
    "appId": "<your-app-id>",
    "merchantNo": "<your-merchant-no>",
    "data": {
        "subscriptionNo": "SUB20250417120949065211234",
        "subscriptionRequestId": "requestId_test001",
        "priceUpdateInfo": {
            "previewId": "UPD2038911684354984654"
        }
    }
}
```

### 4.2 Response Example

```json
{
    "code": "APPLY_SUCCESS",
    "msg": "Success.",
    "data": {
        "subscriptionRequestId": "requet_id_00002",
        "merchantNo": "P0014894534684",
        "subscriptionPlan": {
            "subscriptionNo": "SUB20250417120949065211234",
            "subscriptionStatus": "ACTIVE"
        },
        "priceUpdateInfo": {
            "previewId": "UPD2038911684354984654",
            "status": "PENDING",  // Processing result of this update request
            "redirectUrl": "https://xxx.com"  // If user verification is required, this URL will be returned, and the user needs to be redirected externally to complete payment
        }
    }
}
```

> If `redirectUrl` is returned in the response, it indicates that this change requires the user to complete additional identity verification or payment confirmation. The user should be guided to redirect to this URL to complete subsequent operations.

### 4.3 Special Notes

- If there is currently a bill in the process of renewal payment, submitting a confirmation update is not allowed;

- If there is already a change request being processed, confirmation is not allowed again. You must wait for the change being processed to complete before previewing and confirming again;

- While a change request is being processed, canceling the subscription plan is not allowed.

## 5. Update Result Notification

The final processing result of the update request will be asynchronously notified to the merchant through the `callbackUrl` passed in the update preview, so the result can be known without polling the query API.

Notification Example

```json
{
    "code": "APPLY_SUCCESS",
    "msg": "",
    "keyVersion": "1",
    "appId": "<your-app-id>",
    "merchantNo": "<your-merchant-no>",
    "notifyTime": "2026-01-17T09:33:54.540+00:00",
    "notifyType": "SUBSCRIPTION_UPDATE",
    "data": {
        "subscriptionRequestId": "testRequestId0001",
        "userId": "sub_test_001",
        "updateType": "UPDATE_SUBSCRIPTION_PRICE",
        "updateDetail": {
            "priceUpdateInfo": {  // Details of the price update
                "previewId": "UDG260923095235208131000928A04",
                "status": "SUCCESS"  // Processing result of this update request
            }
        },
        "subscriptionPlan": {
            "subscriptionStatus": "ACTIVE",
            "subscriptionNo": "SUB20250417120949065211234"
        }
    }
}
```

After receiving the notification, please update the local order status based on `priceUpdateInfo.status`; when `status=SUCCESS`, update the user's service entitlements according to the new Product/Price/number of seats.
