【发布时间】:2021-11-26 04:45:21
【问题描述】:
我按照https://stripe.com/docs/billing/subscriptions/elements 中的说明创建了一个订阅,但现在我想让用户选择更改订阅的计划并使用另一种付款方式,例如 3d Secure 卡。但是,如果我更新订阅以获取新付款意图的客户端密码,如下所示:
func (c *Client) UpdateSubscription(s *models.Subscription) (*models.Subscription, error) {
sps := &stripe.SubscriptionParams{
DefaultPaymentMethod: stripe.String(s.PaymentMethodId),
CancelAtPeriodEnd: stripe.Bool(false),
ProrationBehavior: stripe.String(string(stripe.SubscriptionProrationBehaviorAlwaysInvoice)),
}
if s.CreatePaymentIntent {
s.PaymentBehavior = "allow_incomplete"
sps.PaymentBehavior = stripe.String(s.PaymentBehavior)
sps.AddExpand("latest_invoice.payment_intent")
} else if s.ItemID != "" {
sps.Items = []*stripe.SubscriptionItemsParams{
{Price: stripe.String(s.PriceID)},
{ID: stripe.String(s.ItemID), Deleted: stripe.Bool(true)},
}
}
ss, err := sub.Update(s.ID, sps)
if ss.LatestInvoice != nil && ss.LatestInvoice.PaymentIntent != nil {
s.PaymentIntentClientSecret = ss.LatestInvoice.PaymentIntent.ClientSecret
}
return s, err
}
PaymentIntentClientSecret 与订阅相同,这意味着它已被处理。
Stripe 'confirm card' API 抛出错误 payment_intent_unexpected_state https://stripe.com/docs/error-codes/payment-intent-unexpected-state 这可能是因为我之前使用该支付意图来创建订阅。但是,我仍然需要新的付款意图来授权新卡。
【问题讨论】:
标签: stripe-payments subscription