跳转到主要内容
POST
/
subscriptions
/
{subscription_id}
/
update-payment-method
JavaScript
import DodoPayments from 'dodopayments';

const client = new DodoPayments({
  bearerToken: process.env['DODO_PAYMENTS_API_KEY'], // This is the default and can be omitted
});

const response = await client.subscriptions.updatePaymentMethod('subscription_id', { type: 'new' });

console.log(response.payment_id);
{
  "client_secret": "<string>",
  "expires_on": "2023-11-07T05:31:56Z",
  "payment_id": "<string>",
  "payment_link": "<string>"
}
更新订阅的支付方式。此端点支持处于 on_hold 状态的活跃订阅和订阅。
对于处于 on_hold 状态的订阅,更新支付方式会自动创建剩余欠款的收费,生成发票,并在成功付款后将订阅重新激活为 active 状态。

用例

  • 活跃订阅:当卡片过期或客户想使用不同的支付方式时更新支付方式
  • 暂停订阅:通过更新支付方式重新激活因付款失败而暂停的订阅
  • 支付方式管理:在保存的支付方式之间切换或添加新方式
要列出客户的现有支付方式,请使用 列出支付方式 API。这有助于您在使用 type: "existing" 更新订阅的支付方式时检索可用的支付方式 ID。

活跃订阅的行为

更新活跃订阅的支付方式时:
  • 支付方式立即更新
  • 不会创建收费
  • 订阅保持活跃
  • 未来的续订将使用新的支付方式

暂停订阅的行为

更新处于 on_hold 状态的订阅的支付方式时:
  1. 自动为剩余欠款创建收费
  2. 为收费生成发票
  3. 使用新的支付方式处理付款
  4. 成功付款后,订阅重新激活为 active 状态
  5. 您将收到 webhook 事件: payment.succeeded,随后是 subscription.active
如果在更新 on_hold 订阅的支付方式后付款失败,订阅将保持在 on_hold 状态。请监控 webhook 事件以跟踪付款状态。

Webhook 事件

更新 on_hold 订阅的支付方式时,您将收到以下 webhook 事件:
  1. payment.succeeded - 剩余欠款的收费成功
  2. subscription.active - 订阅已重新激活

Authorizations

Authorization
string
header
required

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

Path Parameters

subscription_id
string
required

Subscription Id

Body

application/json
type
enum<string>
required
可用选项:
new
return_url
string | null

Response

Payment method updated

client_secret
string | null
expires_on
string<date-time> | null
payment_id
string | null