Skip to main content
POST
JavaScript

Thay đổi kế hoạch đã lên lịch

Sử dụng tham số effective_at để kiểm soát khi nào thay đổi kế hoạch có hiệu lực:
Thay đổi kế hoạch đã lên lịch là lý tưởng cho việc hạ cấp — khách hàng giữ quyền lợi kế hoạch hiện tại cho đến cuối chu kỳ thanh toán, sau đó tự động chuyển sang kế hoạch mới.
Để hủy thay đổi kế hoạch đã lên lịch trước khi có hiệu lực, sử dụng endpoint Cancel Scheduled Plan Change.

Xử lý lỗi thanh toán

Sử dụng tham số on_payment_failure để kiểm soát điều gì xảy ra khi thanh toán thay đổi kế hoạch thất bại:
Nếu on_payment_failure không được chỉ định, hành vi sẽ mặc định theo cấu hình cấp doanh nghiệp của bạn trong bảng điều khiển.
Đặt collect_via_payment_link thành true để chuyển khách hàng đến trang checkout được lưu trữ thay vì tính phí bằng phương thức thanh toán đã lưu. Sau đó, phản hồi sẽ bao gồm payment_id, payment_link, client_secret và expires_on — chuyển hướng khách hàng đến payment_link để hoàn tất thanh toán. Điều này yêu cầu: Một request không đáp ứng các điều kiện này sẽ trả về 422. Trong khi link chưa được thanh toán, subscription vẫn duy trì gói hiện tại và một request change-plan tiếp theo sẽ trả về 409, trừ khi bạn đặt cancel_older_payment_link.

Chuyển hướng sau khi thanh toán

Đặt return_url để đưa customer trở lại site của bạn sau khi thanh toán link. Redirect sẽ thêm subscription_id, payment_id và status dưới dạng query parameters.
  • status là trạng thái của khoản thanh toán thay đổi gói, không phải trạng thái của subscription.
  • Khi thanh toán thất bại, subscription vẫn hoạt động trên gói hiện tại. Để thử lại, hãy gọi lại change-plan để nhận link mới.
  • Gói mới có thể được áp dụng ngay sau redirect, khi payment webhook đến.
return_url cần collect_via_payment_link: true. Nếu thiếu, request sẽ trả về 422. Nếu customer rời checkout mà không thanh toán, hãy đặt cancel_older_payment_link thành true trong request change-plan tiếp theo. Dodo Payments sẽ hủy link chưa được thanh toán và thay đổi gói mới sẽ thay thế thay đổi đang chờ xử lý. Link đã bị hủy sẽ không còn chấp nhận thanh toán. Request được xác thực trước khi link bị hủy, vì vậy request không hợp lệ sẽ giữ lại link của customer. Link chỉ bị hủy nếu customer chưa bắt đầu thanh toán: Mỗi request change-plan sẽ tạo một invoice riêng. Thay đổi gói bị thay thế và invoice tương ứng sẽ bị hủy.
Xem Hướng dẫn nâng cấp và hạ cấp Subscription để biết toàn bộ quy trình, bao gồm các khoản thanh toán bị từ chối, việc thay thế link đang chờ xử lý và điều gì xảy ra khi link hết hạn.

Mã giảm giá

Bạn có thể áp dụng một hoặc nhiều mã giảm giá được xếp chồng khi thay đổi gói bằng cách truyền array discount_codes (tối đa 20 phần tử, được áp dụng theo thứ tự trong array). Field đơn discount_code đã deprecated nhưng vẫn hoạt động với các integration hiện có; không thể kết hợp field này với discount_codes trong cùng một request.
Sử dụng mã giảm giá khi thay đổi gói để cung cấp mức giá khuyến mãi cho các gói nâng cấp hoặc truyền mã khi chuyển customer sang một tier gói mới.
Sử dụng prevent_change cho các nâng cấp quan trọng khi bạn muốn đảm bảo thanh toán trước khi cấp quyền truy cập vào các tính năng premium.

Ủy quyền

Authorization
string
header
bắt buộc

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

Tham số đường dẫn

subscription_id
string
bắt buộc

Subscription Id

Nội dung

application/json
product_id
string
bắt buộc

Unique identifier of the product to subscribe to

proration_billing_mode
enum<string>
bắt buộc

Proration Billing Mode

Tùy chọn có sẵn:
prorated_immediately,
full_immediately,
difference_immediately,
do_not_bill,
prorated_immediately_keep_cycle
quantity
integer<int32>
bắt buộc

Number of units to subscribe for. Must be at least 1.

Phạm vi bắt buộc: x >= 0
adaptive_currency_fees_inclusive
boolean | null

Whether adaptive currency fees should be included in the price (true) or added on top (false). If not specified, uses the subscription's stored setting.

addons
Attach Addon Request · object[] | null

Addons for the new plan. Note : Leaving this empty would remove any existing addons

Cancel the payment link of a pending plan change, so that this change can replace it.

The link is cancelled only if the customer has not started to pay. A paid or in-progress payment gives a 409. A failed cancel gives a 503, and a retry is safe.

The request is validated before the cancel. A later failure, for example an amount below the minimum, leaves the subscription on its current plan with no open link. A retry is safe.

The preview route shares this request body and ignores this field.

cancel_scheduled_change_plan
boolean

Replace a scheduled plan change with this one.

The scheduled change is cancelled by the transaction that applies this change. A change that never applies leaves the schedule in place.

effective_at: next_billing_date is allowed. The new schedule then replaces the old one in the request transaction.

A pending plan change still gets a 409. This field does not affect it.

The preview route shares this request body, so a preview that sets this field also passes the scheduled-change 409.

Collect the plan-change amount with a payment link. The customer then pays on a checkout page.

The business needs the allow_plan_change_via_payment_link capability. The request needs effective_at: immediately. The request also needs on_payment_failure: prevent_change.

The preview route shares this request body and ignores this field.

discount_code
string | null
không còn sử dụng

DEPRECATED: Use discount_codes instead. Cannot be used together with discount_codes.

discount_codes
string[] | null

Stacked discount codes to apply to the new plan. Max 20. Cannot be used together with discount_code. If provided, replaces any existing discount codes. Empty array removes all discounts. If not provided (None), existing discounts with preserve_on_plan_change=true are preserved.

effective_at
enum<string>

When to apply the plan change.

  • immediately (default): Apply the plan change right away
  • next_billing_date: Schedule the change for the next billing date
Tùy chọn có sẵn:
immediately,
next_billing_date
metadata
null | Metadata · object

Metadata for the payment. If not passed, the metadata of the subscription will be taken

on_payment_failure
null | enum<string>

Controls behavior when the plan change payment fails.

  • prevent_change: Keep subscription on current plan until payment succeeds
  • apply_change (default): Apply plan change immediately regardless of payment outcome

If not specified, uses the business-level default setting.

Tùy chọn có sẵn:
prevent_change,
apply_change
return_url
string | null

The URL that receives the customer after they pay the payment link. Needs collect_via_payment_link: true. Without it, the request gets a 422. A change that collects no money issues no link and does not use the URL. The preview route validates this field but does not use it.

The redirect adds subscription_id, payment_id and status. The status value is the status of the plan-change payment. It is not the status of the subscription. When that payment fails, the subscription stays active on its current plan. To try again, call this endpoint again to get a new link. The new plan can apply after the redirect, when the payment webhook arrives.

Phản hồi

Subscription plan changed. A link request can return checkout details. A pending plan change applies after payment succeeds.

Handles for a hosted checkout page that settles a plan change.

The four fields repeat UpdatePaymentMethodResponse and a subset of CreateSubscriptionResponse. A shared type would rename the generated SDK types for all three routes, so each route keeps its own.

client_secret
string | null

Client secret for an embedded checkout.

expires_on
string<date-time> | null

When the link stops working.

payment_id
string | null

Id of the payment that settles the plan change.

Checkout page URL. Give this to the customer.

Lần sửa đổi cuối 8 tháng 10, 2026