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'追加的這個表達式的結果。 –