Stripe - STPPaymentCardTextField - 如何添加 zip/postal 代码字段?
Stripe - STPPaymentCardTextField - How to add zip/postal code field?
Stripe 的 iOS SDK 的 "STPPaymentCardTextField" 只有 4 个字段用于为卡片生成令牌:
1. 信用卡号
2.到期月份
3. 有效期
4. CVC字段
是否有另一个字段可用于以编程方式将 zip/postal 代码添加到 STPPaymentCardTextField?
或者我应该使用单独的文本字段来处理其他参数(可能还有 STPCard 的其他字段)?
stripe SDK repo 是解决这类问题的很好的资源:
https://github.com/stripe/stripe-ios/blob/master/Stripe/STPCardParams.m
您可以使用 addressZip
字段设置邮政编码,如:
public func submitForm(cardHolderName: String, ccNumber: String, securityCode: String, expirationDate: String, zipcode: String) {
let stripeCard = STPCardParams()
let expirationDateSplit = expirationDate.componentsSeparatedByString("/")
let expMonth = UInt(Int(expirationDateSplit[0])!)
let expYear = UInt(Int(expirationDateSplit[1])!)
stripeCard.number = ccNumber
stripeCard.cvc = securityCode
stripeCard.expMonth = expMonth
stripeCard.expYear = expYear
stripeCard.addressZip = zipcode
STPAPIClient.sharedClient().createTokenWithCard(stripeCard) { (token:STPToken?, error:NSError?) -> Void in
if let err = error {
self.handleError(err)
} else if let toke = token {
self.sendTokenToBackend(toke)
}
}
}
目前 STPPaymentCardTextField
上没有允许输入 zip 的字段;请参阅 repo 维护者的回复,建议您使用单独的 UITextField 来捕获数据 - https://github.com/stripe/stripe-ios/issues/264.
//let s = STPCardParams()
let paymentConfig = STPPaymentConfiguration()
paymentConfig.publishableKey = "Your Public Key here"
paymentConfig.requiredBillingAddressFields = STPBillingAddressFields.full
let theme = STPTheme.default()
// let addCardViewController = STPAddCardViewController.init(configuration: paymentConfig, theme: theme);
let addCardViewController = STPAddCardViewController.init(configuration: paymentConfig, theme: theme)
addCardViewController.delegate = self
// Present add card view controller
let navigationController = UINavigationController(rootViewController: addCardViewController)
DispatchQueue.main.async {
self.present(navigationController, animated: true)
}
Stripe 的 iOS SDK 的 "STPPaymentCardTextField" 只有 4 个字段用于为卡片生成令牌: 1. 信用卡号 2.到期月份 3. 有效期 4. CVC字段
是否有另一个字段可用于以编程方式将 zip/postal 代码添加到 STPPaymentCardTextField?
或者我应该使用单独的文本字段来处理其他参数(可能还有 STPCard 的其他字段)?
stripe SDK repo 是解决这类问题的很好的资源: https://github.com/stripe/stripe-ios/blob/master/Stripe/STPCardParams.m
您可以使用 addressZip
字段设置邮政编码,如:
public func submitForm(cardHolderName: String, ccNumber: String, securityCode: String, expirationDate: String, zipcode: String) {
let stripeCard = STPCardParams()
let expirationDateSplit = expirationDate.componentsSeparatedByString("/")
let expMonth = UInt(Int(expirationDateSplit[0])!)
let expYear = UInt(Int(expirationDateSplit[1])!)
stripeCard.number = ccNumber
stripeCard.cvc = securityCode
stripeCard.expMonth = expMonth
stripeCard.expYear = expYear
stripeCard.addressZip = zipcode
STPAPIClient.sharedClient().createTokenWithCard(stripeCard) { (token:STPToken?, error:NSError?) -> Void in
if let err = error {
self.handleError(err)
} else if let toke = token {
self.sendTokenToBackend(toke)
}
}
}
目前 STPPaymentCardTextField
上没有允许输入 zip 的字段;请参阅 repo 维护者的回复,建议您使用单独的 UITextField 来捕获数据 - https://github.com/stripe/stripe-ios/issues/264.
//let s = STPCardParams()
let paymentConfig = STPPaymentConfiguration()
paymentConfig.publishableKey = "Your Public Key here"
paymentConfig.requiredBillingAddressFields = STPBillingAddressFields.full
let theme = STPTheme.default()
// let addCardViewController = STPAddCardViewController.init(configuration: paymentConfig, theme: theme);
let addCardViewController = STPAddCardViewController.init(configuration: paymentConfig, theme: theme)
addCardViewController.delegate = self
// Present add card view controller
let navigationController = UINavigationController(rootViewController: addCardViewController)
DispatchQueue.main.async {
self.present(navigationController, animated: true)
}