我从
SetupIntentParams
开始:
piparams := &stripe.SetupIntentParams{
Customer: stripe.String(cID),
PaymentMethodTypes: stripe.StringSlice([]string{"card"}),
}
si, _ := setupintent.New(piparams)
这有效,我可以通过以下方式将 JSON 发送到 ios:
send["setup_intent"] = si.ID
send["client_secret"] = si.ClientSecret
send["ephemeral_key"] = ek.Secret
send["customer_id"] = cID
send["publishable_key"] = PK
ios 使用此功能向客户的帐户添加新的付款方式。
然后 ios 向 go 发送新的 payment_method_id 并使用它来制作
PaymentIntent
:
piparams := &stripe.PaymentIntentParams{
Amount: stripe.Int64(5000),
Currency: stripe.String(string(stripe.CurrencyUSD)),
Customer: stripe.String(cID),
PaymentMethod: stripe.String(pmid),
Confirm: stripe.Bool(false),
SetupFutureUsage: stripe.String("off_session"),
ConfirmationMethod: stripe.String(string(stripe.PaymentIntentConfirmationMethodAutomatic)),
}
pi, _ := paymentintent.New(piparams)
我小心翼翼地将
SetupFutureUsage
设置为off_session
,并成功达成付款意向。我还不想获取最终金额。需要一段时间才能知道向用户收取什么费用,然后我想打电话:
p, _ := paymentintent.Get(pi, nil)
_, err = paymentintent.Capture(p.ID, &stripe.PaymentIntentCaptureParams{
AmountToCapture: stripe.Int64(4000),
})
但我收到以下错误之一:
This PaymentIntent could not be captured because it has a status of requires_confirmation.
或
"This PaymentIntent could not be captured because it has already been captured.
或
This PaymentIntent could not be captured because it has a status of requires_action.
取决于我如何设置
Confirm: stripe.Bool(false),
ConfirmationMethod: stripe.String(string(stripe.PaymentIntentConfirmationMethodAutomatic)),
ios 是否确认。我缺少什么?为什么我不能进入 ios 使 PaymentIntent 全部确认并准备好进入 Capture 的状态?