I am able to integrate the Stripe with my iOS code perfectly. The PTKView shows card number, expiry month/year, CVV number. In PTKView, I don't see ZIP Code text field, but I can see addressZip property.
Is it possible to capture the ZIP Code with iOS Stripe view?
Thanks in advance.
It doesn't look like PTKView has an address UI component out-of-the-box (yet). However, they give you the PTKAddressZip type to validate whether or not the entered ZIP code is valid.
I made my own ZIP field that looks exactly like the Credit Card field, using the supplied "textField.png" image that comes with PaymentKit.
Here it is, in both Objective C and Swift examples...
OBJECTIVE-C:
UITextField *zipTextField;
zipTextField = [[UITextField alloc] initWithFrame: CGRectMake(15,170,290,55)];
zipTextField.keyboardType = UIKeyboardTypeNumberPad;
zipTextField.placeholder = @"ZIP Code";
//Left padding
UIView *paddingView = [[UIView alloc ] initWithFrame:CGRectMake(0, 0, 5, 20)];
zipTextField.leftView = paddingView;
zipTextField.leftViewMode = UITextFieldViewModeAlways;
//Make it look like the CC box
UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:zipTextField.bounds];
backgroundImageView.image = [[UIImage imageNamed: @"textField"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 8, 0, 8)];
[zipTextField addSubview:backgroundImageView];
//Add the ZIP field finally
[self.view addSubview:zipTextField];
//Validate the zip - Put this code in your Submit button
PTKAddressZip *zip = [[PTKAddressZip alloc] initWithString:zipTextField.text];
NSLog( zip.isValid ? @"ZIP is valid" : @"ZIP is invalid");
SWIFT:
//Setup ZIP field
self.zipTextField = UITextField(frame: CGRectMake(15,170,290,45))
self.zipTextField.keyboardType = UIKeyboardType.NumberPad
self.zipTextField.placeholder = "ZIP Code"
//Left padding
var paddingView = UIView(frame:CGRectMake(0, 0, 5, 20))
self.zipTextField.leftView = paddingView
self.zipTextField.leftViewMode = UITextFieldViewMode.Always
//Make it look like the CC box
var backgroundImageView = UIImageView(frame:self.zipTextField.bounds)
backgroundImageView.image = UIImage(named: "textField")
backgroundImageView.image = backgroundImageView.image?.resizableImageWithCapInsets(UIEdgeInsetsMake(0,8,0,8))
self.zipTextField.addSubview(backgroundImageView)
//Validate the zip - Put this code in your Submit button
self.view.addSubview(self.zipTextField)
var zip = PTKAddressZip(string: "15227")
NSLog( zip.isValid().description )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With