[英]Customizing Stripe UI integration to save and fetch user card information
I am using stripe to allow users to send payments to each other.我正在使用 Stripe 来允许用户相互付款。 I have run into an error and I am pretty sure it is because the user doesn't have their payment types saved.
我遇到了一个错误,我很确定这是因为用户没有保存他们的付款类型。 I was wondering if it is possible to manipulate stripes STPPaymentOptionsViewController UI to save the customer info?
我想知道是否可以操纵条纹 STPPaymentOptionsViewController UI 来保存客户信息? Or if I would have to customize my own controller to do this.
或者如果我必须自定义我自己的控制器来做到这一点。
It is possible to store users' credit card information.可以存储用户的信用卡信息。
On your server, you need to call stripe.paymentMethods.attach()
method to save a payment method (represented by a stripeID
, we'll talk about that later).在您的服务器上,您需要调用
stripe.paymentMethods.attach()
方法来保存付款方式(由stripeID
表示,我们稍后会讨论)。
Example:例子:
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()
});
});
There are two parameters needed for the above code, customer_id
and stripe_id
.上述代码需要两个参数,
customer_id
和stripe_id
。 I assume you are already familiar with customer_id
, so let's talk about how to gather users' card information and get the stripe_id
that represents the payment method.我假设您已经熟悉
customer_id
,那么我们来谈谈如何收集用户的卡信息并获取代表付款方式的stripe_id
。
STPAddCardViewController
(same UI as the add card screen in STPPaymentOptionsViewController
)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
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)
}
Now the card info is saved, and you can view it in your Stripe console:现在卡信息已保存,您可以在 Stripe 控制台中查看它:
Stripe documentation:条纹文档:
我不认为这是 Stripe 可以支持的用例,因此您可能需要与他们联系以确认: https : //support.stripe.com/contact/email
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.