STPPaymentCardTextField字段是只读的,您只能从这些属性中“获取”。
STPPaymentCardTextField用于收集信用卡信息。在你的情况下,你已经在使用CardIOCreditCardInfo来做这件事。获得信用卡详细信息后,您可以将数据组装到STPCardParams对象中。
收集卡号,到期时间和CVC后,将它们打包在STPCardParams对象中,并调用STPAPIClient类的createTokenWithCard:方法。现在
你的方法可能看上去像这样...
func userDidProvideCreditCardInfo(cardInfo: CardIOCreditCardInfo!, inPaymentViewController paymentViewController: CardIOPaymentViewController!) {
let card: STPCardParams = STPCardParams()
card.number = info.cardNumber
card.expMonth = info.expiryMonth
card.expYear = info.expiryYear
card.cvc = info.cvv
STPAPIClient.sharedClient().createTokenWithCard(card, completion: {(result, error) -> Void in
if error == nil {
// Either save the card token with your customer data or charge them right away
//createBackendChargeWithToken(token)
}
else {
//handleError(error)
}
})
}
paymentViewController?.dismissViewControllerAnimated(true, completion: nil)
}
更新可能是正确的回答你的问题。
import Stripe
class PaymentCardEditorField: STPPaymentCardTextField {
func setExistingCard(card: STPCardParams) {
replaceField("numberField", withValue: card.number!)
replaceField("expirationField", withValue: String(format: "%02d/%02d", card.expMonth, (card.expYear % 100)))
replaceField("cvcField", withValue: card.cvc!)
}
func replaceField(memberName: String, withValue value: String) {
let field = self.valueForKey(memberName) as! UITextField
let delegate = self as! UITextFieldDelegate
let len = field.text?.characters.count
if delegate.textField?(field, shouldChangeCharactersInRange: NSMakeRange(0, len!), replacementString: value) ?? false {
field.text = value
}
}
}
,然后调用setExistingCard
func userDidProvideCreditCardInfo(cardInfo: CardIOCreditCardInfo!, inPaymentViewController paymentViewController: CardIOPaymentViewController!) {
let card: STPCardParams = STPCardParams()
card.number = info.cardNumber
card.expMonth = info.expiryMonth
card.expYear = info.expiryYear
card.cvc = info.cvv
paymentTextField.setExistingCard(card)
}
就像一个魅力。
按照这个线程的潜在更新条纹SDK在未来的内置支持。
https://github.com/stripe/stripe-ios/issues/127
是吗?我不明白为什么它不应该工作...什么是你的问题,到底是什么? – mattt
我有一个错误'不能分配给每个'paymentField'追加的这个表达式的结果。 –