IOS stripe integration - add zip code to PTKView

I can fully integrate Stripe with my iOS code. PTKView shows card number, month / year expiration, CVV number. In PTKView, I do not see the zip code text field, but I see the addressZip property.

Is it possible to write a ZIP code with a view in the iOS strip?

Thanks in advance.

+5
source share
1 answer

It doesn't seem like PTKView has an address user interface component (though). However, they give you the type PTKAddressZip to check if the entered zip code is valid.

I created my own mail field, which looks exactly like the Credit card field, using the provided textField.png image that comes with PaymentKit.

Here it is, both in Objective-C examples and in Swift ...

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 ) 
+1
source

Source: https://habr.com/ru/post/1205711/


All Articles