Stripe - STPPaymentCardTextField - 如何添加邮政编码字段?

时间:2015-09-17 03:05:49

标签: ios stripe-payments

Stripe的iOS SDK“STPPaymentCardTextField”只有4个字段用于为卡片生成令牌: 信用卡号码 到期月份 到期年份 4. CVC字段

是否有其他字段可用于以编程方式将邮政编码添加到STPPaymentCardTextField?

或者我应该使用单独的文本字段来处理其他参数(以及可能的STPCard的其他字段)?

3 个答案:

答案 0 :(得分:1)

条纹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)
        }
    }
}

答案 1 :(得分:1)

目前STPPaymentCardTextField上没有允许输入zip的字段;请参阅repo维护者的回复,建议您使用单独的UITextField来捕获数据 - https://github.com/stripe/stripe-ios/issues/264

答案 2 :(得分:0)

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

    }