[英]Create token for bank account information Stripe
I am trying to create an ios app which safely collects a user's bank account information (with the intention of paying the user) using Stripe. 我正在尝试创建一个iOS应用程序,该应用程序使用Stripe安全地收集用户的银行帐户信息(目的是向用户付款)。 Stripe recommends that I collect the bank information in an instance of
STPBankAccountParams
. Stripe建议我在
STPBankAccountParams
实例中收集银行信息。 This is not too bad: 这还不错:
var bankAccount = STPBankAccountParams()
bankAccount.routingNumber = routingNumber
bankAccount.accountNumber = accountNumber
...
Stripe then recommends that you tokenize the bankAccount
for security purposes before sending to backend. 然后,Stripe建议出于安全目的将令牌令牌
bankAccount
,然后再发送到后端。 They recommend you use this function: 他们建议您使用此功能:
func createToken(withBankAccount bankAccount: STPBankAccountParams, completion: STPTokenCompletionBlock? = nil)
The documentation on this function is a bit sparse: Docs 关于此功能的文档有点稀疏: 文档
I am not sure how to run this function in my code. 我不确定如何在我的代码中运行此功能。 I want to use this function and get the token, but I lack understanding on how to do that in code.
我想使用此功能并获取令牌,但是我对如何在代码中做到这一点缺乏了解。 I want to run something like:
我想运行类似:
token = createToken(withBankAccount: bankAccount)
But of course that and other things I have tried have not worked yet. 但是,当然,我尝试过的其他方法尚未奏效。 Does anyone have experience running the
createTokenWithBankAccount()
function in Stripe? 有没有人有在Stripe中运行
createTokenWithBankAccount()
函数的经验?
MadProgrammer's answer was very close, but did not actually work. MadProgrammer的回答非常接近,但实际上没有用。 I did talk with a representative from Stripe.
我确实与Stripe的代表进行了交谈。 For reference, he recommended the following code, which seems to work:
作为参考,他建议使用下面的代码,该代码似乎有效:
STPAPIClient.shared().createToken(withBankAccount: bankAccount) { (token, error) in
if let error = error {
print(error)
}
else {
print(token)
}
}
STPTokenCompletionBlock
is closure (or callback), when the function completes (what ever task it was doing), it will call this block, passing you a STPToken
or a Error
. STPTokenCompletionBlock
是闭包(或回调),当函数完成(无论正在执行的任务)时,它将调用此块, STPToken
您传递STPToken
或Error
。 You would use something like 您将使用类似
createToken(withBankAccount: bankAccount) { (token, error) in
// your code to check the token and error
}
This is a pretty common pattern and I suggest you take a look at something like Swift Programming Language: Closures 这是一个非常常见的模式,我建议您看一下诸如Swift编程语言:闭包之类的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.