Stripe-ios: Setting a Value STPPaymentCardTextField on viewDidLoad

Created on 17 Sep 2015  Â·  6Comments  Â·  Source: stripe/stripe-ios

How can i set a value for cardNumber,expirationMonth and expirationYear when the STPPaymentCardTextField is loaded instead of typing it manually? I tried

var paymentField = STPPaymentCardTextField() override func viewDidLoad() { super.viewDidLoad()

    paymentField.frame = CGRectMake(15, 110, CGRectGetWidth(self.view.frame) - 30, 44)
    paymentField.delegate = self
    paymentField.cardNumber = "42424242424242424242"
    self.view.addSubview(paymentField)
}

But this gives me an error "Cannot assign to the result of this expression" on this line paymentField.cardNumber = "42424242424242424242

Most helpful comment

Hey @mobiwebshweta – you can do this by setting the field's cardParams:

let cardParams = STPCardParams()
cardParams.number = "4242424242424242"
self.paymentField.cardParams = cardParams

https://github.com/stripe/stripe-ios/blob/c6330c36800734b23f76fa016dc482fa0df637a1/Stripe/PublicHeaders/STPPaymentCardTextField.h#L259-L265

All 6 comments

This isn't currently supported, but something we'll look into in the future. I'm closing this as a duplicate of #219.

Hi,
is there any solution for set a value for cardNumber,expirationMonth and expirationYear with STPPaymentCardTextField when loaded?

paymentField.cardNumber = "42424242424242424242";

Hey @mobiwebshweta – you can do this by setting the field's cardParams:

let cardParams = STPCardParams()
cardParams.number = "4242424242424242"
self.paymentField.cardParams = cardParams

https://github.com/stripe/stripe-ios/blob/c6330c36800734b23f76fa016dc482fa0df637a1/Stripe/PublicHeaders/STPPaymentCardTextField.h#L259-L265

Doesn't seems to reload an UI properly =/

Doesn't seems to reload an UI properly =/

Hi @zykis

Could you make a new issue with repro steps for what you're seeing? Thanks!

Hey, @yuki-stripe !
Sure.
https://github.com/stripe/stripe-ios/issues/1451
Thanks for such beautiful framework!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

todesignandconquer picture todesignandconquer  Â·  5Comments

provTheodoreNewell picture provTheodoreNewell  Â·  5Comments

coolcool1994 picture coolcool1994  Â·  4Comments

tommanuel92 picture tommanuel92  Â·  4Comments

chrismanderson picture chrismanderson  Â·  4Comments