Stripe's iOS SDK's "STPPaymentCardTextField" has only 4 fields for generating a token for a card : 1. credit card number 2. expiration month 3. expiration year 4. CVC field
Is there another field available for programmatically adding zip/postal code to the STPPaymentCardTextField?
Or should I use a separate textfield(s) to handle additional parameters (and possibly other fields for the STPCard)?
The stripe SDK repo is a pretty good resource for this sort of question: https://github.com/stripe/stripe-ios/blob/master/Stripe/STPCardParams.m
You can set the zipcode with the addressZip
field as in:
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)
}
}
}
There's not currently a field on STPPaymentCardTextField
allowing for zip entry; see this response from the repo maintainers suggesting you use a separate UITextField to capture the data - 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)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.