【发布时间】:2021-04-11 00:03:42
【问题描述】:
对于不需要 3D 安全性的卡片,它可以完美运行。但是对于那些需要它们的人,它会停留在incomplete 状态。
我的实现非常简单。 frontend 收集卡信息并向条带化的API 发出请求以获取token 并创建payment_method。
async submitForm(e) {
e.preventDefault();
try {
const { token } = await this.stripe.createToken(this.card);
const { paymentMethod } = await this.stripe.createPaymentMethod({
type: 'card',
card: this.card,
});
this.stripeTokenHandler(token.id, paymentMethod.id); // handles submission to backend
} catch (e) {
this.cardErrorsTarget.textContent = e.error.message;
}
}
后端部分写在rails。
customer = Stripe::Customer.create(
source: params[:stripe_token],
plan: plan_id,
# address of the customer
)
# Creating the setup intent
intent = Stripe::PaymentIntent.create(
amount: some_amount,
customer: customer.id,
payment_method_types: ["card"],
)
# After that I need to confirm the intent
confirm_intent = Stripe::PaymentIntent.confirm(intent.id, {
payment_method: params[:pm_token],
return_url: app_confirm_subscription_url # After 3D secure, it redirects to this URL
})
重定向后,
def show
intent = Stripe::PaymentIntent.retrieve(params[:payment_intent]) # stripe adds the payment_intent params
raise intent
end
通过提高intent,我明白了
{
paid: true,
status: "succeeded",
result: "authenticated",
// more data
}
但是当我转到 Stripe 的仪表板时,它显示订阅不完整。这些是降序排列的events。
The payment pi_1I6AVKCYHrwDIsnfiGm7bWUM for $29.00 USD has succeeded
example@example.com was charged $29.00 USD
The payment pi_1I6AVKCYHrwDIsnfiGm7bWUM for $29.00 USD requires you to take action in order to complete the payment
A new payment pi_1I6AVKCYHrwDIsnfiGm7bWUM for $29.00 USD was created
example@example.com attempted to subscribe to price_1I5vshCYHrwDIsnf981UpZEc
example@example.com added a new Visa ending in 3220
A card payment method ending in 3220 was attached to customer cus_IhZezT431x2G7Z
A draft invoice for $29.00 USD to example@example.com was finalized
A draft invoice was created
example@example.com is a new customer
PS:我用的卡是4000 0000 0000 3220,需要3D安全。如果我使用4242 4242 4242 4242,它可以正常工作。
我有什么遗漏的吗?
【问题讨论】:
-
从这个链接得到一个想法stackoverflow.com/questions/65391324/…
-
会调查一下,我会告诉你的。
标签: ruby-on-rails stripe-payments