ruby-on-rails - Stripe.js 是否应该捕获所有可能发生的错误?
问题描述
用户可以通过Stripe订阅我的 Rails 应用:
class Subscription::CreditCardController < Subscription::PaymentController
def new
stripe_customer = Customers::FindOrCreate.call(current_account)
if stripe_customer
@stripe_subscription = Subscriptions::Create.call(current_account, @price, :payment_behavior => "default_incomplete")
@client_secret = @stripe_subscription.latest_invoice.payment_intent.client_secret
else
flash[:notice] = "An error occurred."
redirect_to plans_path
end
end
def create
flash[:success] = "Subscription created."
redirect_to plans_path
end
end
我依靠 Stripe.js 来捕捉可能发生的任何错误:
form.addEventListener('submit', function(e) {
e.preventDefault();
handlePayment();
});
function handlePayment() {
stripe.confirmCardPayment(clientSecret.value, {
payment_method: {
card: card,
billing_details: {
name: name.value,
email: email.value
}
}
}).then(function(result) {
if (result.error) {
displayError(result.error);
} else {
form.submit();
}
});
}
到目前为止,这适用于所有测试用例的 99%。Stripe.js 捕获了几乎所有可能发生的错误。但在极少数情况下它不会,因此当 Stripe 尝试创建订阅时,服务器上会发生错误,使其处于某种incomplete
状态。
这是一个主要问题,因为我现在没有在我的create
控制器操作中处理这些类型的错误。
那么,为什么 Stripe 会捕获大多数这些错误而不是全部?作为开发人员,我是否应该在服务器上使用 Stripe.js 验证用户输入?还是两者中的一个就足够了?阅读 Stripe 的文档后,我的印象是 Stripe.js 将为我处理所有事情,而且我不必在服务器级别添加额外的检查。
这不正确吗?
解决方案
推荐阅读
- php - Debian - Apache MySQL PDO 问题,但所有日志都是空的
- amazon-web-services - RedShift - update table with date from a timestamp column
- java - 如何将 Web 元素的名称存储转换为字符串?
- python - ImportError:无法从“contacts.api.serializers”导入名称“CustomerIdNameSerializer”
- python-3.x - matplotlib 在我的 x 轴上自动生成日期
- regex - 在 linux shell 中使用正则表达式从文本文件中提取字符串、grep IP 地址但使用 CIDR 排除子网
- php - 带有额外字段的 Laravel PIVOT 表
- python - 下载多个列表
- c - 我想用 printf 打印上标和下标,比如 x¹?
- c++ - 如何测量macos中线程的执行时间?