From 6c007211002fc2c9827391361c42050f193e61cd Mon Sep 17 00:00:00 2001 From: Polo Li Date: Wed, 17 Jun 2020 00:03:41 -0700 Subject: [PATCH] OXXO Add to Non-Card Payment Examples sample app --- .../project.pbxproj | 12 ++- .../BrowseExamplesViewController.m | 12 ++- .../OXXOExampleViewController.h | 17 ++++ .../OXXOExampleViewController.m | 98 +++++++++++++++++++ 4 files changed, 135 insertions(+), 4 deletions(-) create mode 100644 Example/Non-Card Payment Examples/OXXOExampleViewController.h create mode 100644 Example/Non-Card Payment Examples/OXXOExampleViewController.m diff --git a/Example/Non-Card Payment Examples.xcodeproj/project.pbxproj b/Example/Non-Card Payment Examples.xcodeproj/project.pbxproj index 28e64f42c7d..ac0abac69e5 100644 --- a/Example/Non-Card Payment Examples.xcodeproj/project.pbxproj +++ b/Example/Non-Card Payment Examples.xcodeproj/project.pbxproj @@ -25,8 +25,9 @@ 36B6CB5D234BEB8400331C38 /* SEPADebitExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 36B6CB5C234BEB8400331C38 /* SEPADebitExampleViewController.m */; }; 36B6CB64234FD9AA00331C38 /* iDEALExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 36B6CB63234FD9AA00331C38 /* iDEALExampleViewController.m */; }; 448895B424526C6B00F7D0C2 /* Przelewy24ExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 448895B324526C6B00F7D0C2 /* Przelewy24ExampleViewController.m */; }; - 69A6C306246E63A2005FF304 /* EPSExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 69A6C305246E63A2005FF304 /* EPSExampleViewController.m */; }; 44BDCFE4245A4CAE007EE6D5 /* BancontactExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 44BDCFE3245A4CAE007EE6D5 /* BancontactExampleViewController.m */; }; + 45DB454B249BD97B00DE45DE /* OXXOExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 45DB454A249BD97B00DE45DE /* OXXOExampleViewController.m */; }; + 69A6C306246E63A2005FF304 /* EPSExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 69A6C305246E63A2005FF304 /* EPSExampleViewController.m */; }; 8BBD79C6207FD2F900F85BED /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8BBD79C8207FD2F900F85BED /* Localizable.strings */; }; B607FFBD2321DA99004203E0 /* MyAPIClient.m in Sources */ = {isa = PBXBuildFile; fileRef = B607FFBC2321DA99004203E0 /* MyAPIClient.m */; }; B65E8FCC22FA078A0057E64A /* WeChatPayExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B65E8FCB22FA078A0057E64A /* WeChatPayExampleViewController.m */; }; @@ -81,10 +82,12 @@ 36B6CB63234FD9AA00331C38 /* iDEALExampleViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = iDEALExampleViewController.m; sourceTree = ""; }; 448895B224526C6B00F7D0C2 /* Przelewy24ExampleViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Przelewy24ExampleViewController.h; sourceTree = ""; }; 448895B324526C6B00F7D0C2 /* Przelewy24ExampleViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Przelewy24ExampleViewController.m; sourceTree = ""; }; - 69A6C304246E6225005FF304 /* EPSExampleViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EPSExampleViewController.h; sourceTree = ""; }; - 69A6C305246E63A2005FF304 /* EPSExampleViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EPSExampleViewController.m; sourceTree = ""; }; 44BDCFE2245A4CAE007EE6D5 /* BancontactExampleViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BancontactExampleViewController.h; sourceTree = ""; }; 44BDCFE3245A4CAE007EE6D5 /* BancontactExampleViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BancontactExampleViewController.m; sourceTree = ""; }; + 45DB4549249BD97B00DE45DE /* OXXOExampleViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OXXOExampleViewController.h; sourceTree = ""; }; + 45DB454A249BD97B00DE45DE /* OXXOExampleViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OXXOExampleViewController.m; sourceTree = ""; }; + 69A6C304246E6225005FF304 /* EPSExampleViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EPSExampleViewController.h; sourceTree = ""; }; + 69A6C305246E63A2005FF304 /* EPSExampleViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EPSExampleViewController.m; sourceTree = ""; }; 8BBD79C7207FD2F900F85BED /* en */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; 8BBD79C9207FD31A00F85BED /* zh-Hans */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = ""; }; 8BBD79CA207FD32100F85BED /* nl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/Localizable.strings; sourceTree = ""; }; @@ -186,6 +189,8 @@ B65E8FCB22FA078A0057E64A /* WeChatPayExampleViewController.m */, 69A6C304246E6225005FF304 /* EPSExampleViewController.h */, 69A6C305246E63A2005FF304 /* EPSExampleViewController.m */, + 45DB4549249BD97B00DE45DE /* OXXOExampleViewController.h */, + 45DB454A249BD97B00DE45DE /* OXXOExampleViewController.m */, ); path = "Non-Card Payment Examples"; sourceTree = ""; @@ -332,6 +337,7 @@ 36B6CB5D234BEB8400331C38 /* SEPADebitExampleViewController.m in Sources */, 69A6C306246E63A2005FF304 /* EPSExampleViewController.m in Sources */, C12C50DD1E57B3C800EC6D58 /* BrowseExamplesViewController.m in Sources */, + 45DB454B249BD97B00DE45DE /* OXXOExampleViewController.m in Sources */, 364FC2D024201F62002879EB /* AUBECSDebitExampleViewController.m in Sources */, 448895B424526C6B00F7D0C2 /* Przelewy24ExampleViewController.m in Sources */, ); diff --git a/Example/Non-Card Payment Examples/BrowseExamplesViewController.m b/Example/Non-Card Payment Examples/BrowseExamplesViewController.m index 6032ddad4f0..0a2e126b229 100644 --- a/Example/Non-Card Payment Examples/BrowseExamplesViewController.m +++ b/Example/Non-Card Payment Examples/BrowseExamplesViewController.m @@ -17,6 +17,7 @@ #import "FPXExampleViewController.h" #import "GiropayExampleViewController.h" #import "iDEALExampleViewController.h" +#import "OXXOExampleViewController.h" #import "Przelewy24ExampleViewController.h" #import "SEPADebitExampleViewController.h" #import "SofortExampleViewController.h" @@ -43,7 +44,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return 14; + return 15; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { @@ -91,6 +92,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N case 13: cell.textLabel.text = @"EPS"; break; + case 14: + cell.textLabel.text = @"OXXO"; + break; } return cell; } @@ -189,6 +193,12 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath viewController = exampleVC; break; } + case 14: { + OXXOExampleViewController *exampleVC = [OXXOExampleViewController new]; + exampleVC.delegate = self; + viewController = exampleVC; + break; + } } [self.navigationController pushViewController:viewController animated:YES]; } diff --git a/Example/Non-Card Payment Examples/OXXOExampleViewController.h b/Example/Non-Card Payment Examples/OXXOExampleViewController.h new file mode 100644 index 00000000000..7dd39428816 --- /dev/null +++ b/Example/Non-Card Payment Examples/OXXOExampleViewController.h @@ -0,0 +1,17 @@ +// +// OXXOExampleViewController.h +// Non-Card Payment Examples +// +// Created by Polo Li on 6/18/20. +// Copyright © 2020 Stripe. All rights reserved. +// + +#import "PaymentExampleViewController.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface OXXOExampleViewController : PaymentExampleViewController + +@end + +NS_ASSUME_NONNULL_END diff --git a/Example/Non-Card Payment Examples/OXXOExampleViewController.m b/Example/Non-Card Payment Examples/OXXOExampleViewController.m new file mode 100644 index 00000000000..478243e83a4 --- /dev/null +++ b/Example/Non-Card Payment Examples/OXXOExampleViewController.m @@ -0,0 +1,98 @@ +// +// OXXOExampleViewController.m +// Non-Card Payment Examples +// +// Created by Polo Li on 6/18/20. +// Copyright © 2020 Stripe. All rights reserved. +// + +#import "OXXOExampleViewController.h" + +#import "MyAPIClient.h" + +@interface OXXOExampleViewController () + +@end + +@implementation OXXOExampleViewController { + UITextField *_nameField; + UITextField *_emailField; +} + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view. + + self.title = @"OXXO"; + + _nameField = [[UITextField alloc] init]; + _nameField.borderStyle = UITextBorderStyleRoundedRect; + _nameField.textContentType = UITextContentTypeName; + _nameField.placeholder = @"Full name"; + _nameField.translatesAutoresizingMaskIntoConstraints = NO; + [self.view addSubview:_nameField]; + + _emailField = [[UITextField alloc] init]; + _emailField.borderStyle = UITextBorderStyleRoundedRect; + _emailField.textContentType = UITextContentTypeEmailAddress; + _emailField.placeholder = @"Email address"; + _emailField.translatesAutoresizingMaskIntoConstraints = NO; + [self.view addSubview:_emailField]; + + [self.payButton setTitle:@"Pay with OXXO" forState:UIControlStateNormal]; + [self.payButton sizeToFit]; + + [NSLayoutConstraint activateConstraints:@[ + [_emailField.centerXAnchor constraintEqualToAnchor:self.payButton.centerXAnchor], + [_emailField.widthAnchor constraintEqualToConstant:240.f], + [_emailField.bottomAnchor constraintEqualToAnchor:self.payButton.topAnchor constant:-12.f], + [_nameField.centerXAnchor constraintEqualToAnchor:self.payButton.centerXAnchor], + [_nameField.bottomAnchor constraintEqualToAnchor:self->_emailField.topAnchor constant:-12.f], + [_nameField.widthAnchor constraintEqualToConstant:240.f], + ]]; +} + +- (void)payButtonSelected { + [super payButtonSelected]; + [self updateUIForPaymentInProgress:YES]; + + [[MyAPIClient sharedClient] createPaymentIntentWithCompletion:^(MyAPIClientResult status, NSString *clientSecret, NSError *error) { + if (status == MyAPIClientResultFailure || clientSecret == nil) { + [self.delegate exampleViewController:self didFinishWithError:error]; + return; + } + + STPPaymentIntentParams *paymentIntentParams = [[STPPaymentIntentParams alloc] initWithClientSecret:clientSecret]; + + STPPaymentMethodBillingDetails *billingDetails = [[STPPaymentMethodBillingDetails alloc] init]; + billingDetails.name = self->_nameField.text; + billingDetails.email = self->_emailField.text; + + + STPPaymentMethodOXXOParams *oxxo = [[STPPaymentMethodOXXOParams alloc] init]; + + // OXXO does not require additional parameters so we only need to pass the init-ed + // STPPaymentMethodOXXOParams instance to STPPaymentMethodParams + paymentIntentParams.paymentMethodParams = [STPPaymentMethodParams paramsWithOXXO:oxxo + billingDetails:billingDetails + metadata:nil]; + + [[STPPaymentHandler sharedHandler] confirmPayment:paymentIntentParams + withAuthenticationContext:self.delegate + completion:^(STPPaymentHandlerActionStatus handlerStatus, STPPaymentIntent * handledIntent, NSError * _Nullable handlerError) { + switch (handlerStatus) { + case STPPaymentHandlerActionStatusFailed: + [self.delegate exampleViewController:self didFinishWithError:handlerError]; + break; + case STPPaymentHandlerActionStatusCanceled: + [self.delegate exampleViewController:self didFinishWithMessage:@"Canceled"]; + break; + case STPPaymentHandlerActionStatusSucceeded: + [self.delegate exampleViewController:self didFinishWithMessage:@"Payment successfully created"]; + break; + } + }]; + } additionalParameters:@"country=mx"]; +} + +@end