0
votes

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)?

3

3 Answers

1
votes

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)
        }
    }
}
1
votes

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.

0
votes
   //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)

    }