[英]Customizing Stripe UI integration to save and fetch user card information
我正在使用 Stripe 来允许用户相互付款。 我遇到了一个错误,我很确定这是因为用户没有保存他们的付款类型。 我想知道是否可以操纵条纹 STPPaymentOptionsViewController UI 来保存客户信息? 或者如果我必须自定义我自己的控制器来做到这一点。
可以存储用户的信用卡信息。
在您的服务器上,您需要调用stripe.paymentMethods.attach()
方法来保存付款方式(由stripeID
表示,我们稍后会讨论)。
例子:
app.post('/attach_card', (req, res) => {
const customerID = req.body.customer_id;
const cardStripeID = req.body.stripe_id;
stripe.paymentMethods.attach(
cardStripeID,
{ customer: customerID }
).then(value => {
res.status(200).send(value);
}).catch(err => {
console.log(err);
res.status(500).end()
});
});
上述代码需要两个参数, customer_id
和stripe_id
。 我假设您已经熟悉customer_id
,那么我们来谈谈如何收集用户的卡信息并获取代表付款方式的stripe_id
。
STPAddCardViewController
(相同的用户界面作为附加卡屏STPPaymentOptionsViewController
)let config = STPPaymentConfiguration()
config.requiredBillingAddressFields = .full
let viewController = STPAddCardViewController(configuration: config, theme: STPTheme.default())
viewController.delegate = self
let navigationController = UINavigationController(rootViewController: viewController)
present(navigationController, animated: true, completion: nil)
STPAddCardViewControllerDelegate
func addCardViewControllerDidCancel(_ addCardViewController: STPAddCardViewController) {
// Handle cancel action if needed
}
func addCardViewController(_ addCardViewController: STPAddCardViewController, didCreatePaymentMethod paymentMethod: STPPaymentMethod, completion: @escaping STPErrorBlock) {
completion(nil)
print("--- created payment method with stripe ID: \(paymentMethod.stripeId)")
// Call the previous server code to store card info with Alamofire
let url = YOUR_SERVER_BASE_URL.appendingPathComponent("attach_card")
AF.request(url, method: .post, parameters: [
"customer_id": YOUR_CUSTOMER_ID,
"stripe_id": paymentMethod.stripeId
])
// Dismiss the modally presented VC
dismiss(animated: true, completion: nil)
}
现在卡信息已保存,您可以在 Stripe 控制台中查看它:
条纹文档:
我不认为这是 Stripe 可以支持的用例,因此您可能需要与他们联系以确认: https : //support.stripe.com/contact/email
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.