Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OXXO Payment Method #1592

Merged
merged 19 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Example/Non-Card Payment Examples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
36B6CB64234FD9AA00331C38 /* iDEALExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 36B6CB63234FD9AA00331C38 /* iDEALExampleViewController.m */; };
448895B424526C6B00F7D0C2 /* Przelewy24ExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 448895B324526C6B00F7D0C2 /* Przelewy24ExampleViewController.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 */; };
Expand Down Expand Up @@ -87,6 +88,8 @@
448895B324526C6B00F7D0C2 /* Przelewy24ExampleViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Przelewy24ExampleViewController.m; sourceTree = "<group>"; };
44BDCFE2245A4CAE007EE6D5 /* BancontactExampleViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BancontactExampleViewController.h; sourceTree = "<group>"; };
44BDCFE3245A4CAE007EE6D5 /* BancontactExampleViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BancontactExampleViewController.m; sourceTree = "<group>"; };
45DB4549249BD97B00DE45DE /* OXXOExampleViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OXXOExampleViewController.h; sourceTree = "<group>"; };
45DB454A249BD97B00DE45DE /* OXXOExampleViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OXXOExampleViewController.m; sourceTree = "<group>"; };
69A6C304246E6225005FF304 /* EPSExampleViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EPSExampleViewController.h; sourceTree = "<group>"; };
69A6C305246E63A2005FF304 /* EPSExampleViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EPSExampleViewController.m; sourceTree = "<group>"; };
8BBD79C7207FD2F900F85BED /* en */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -194,6 +197,10 @@
04533E8A1A687F5D00C7E52E /* Supporting Files */,
B65E8FCA22FA078A0057E64A /* WeChatPayExampleViewController.h */,
B65E8FCB22FA078A0057E64A /* WeChatPayExampleViewController.m */,
69A6C304246E6225005FF304 /* EPSExampleViewController.h */,
69A6C305246E63A2005FF304 /* EPSExampleViewController.m */,
45DB4549249BD97B00DE45DE /* OXXOExampleViewController.h */,
45DB454A249BD97B00DE45DE /* OXXOExampleViewController.m */,
);
path = "Non-Card Payment Examples";
sourceTree = "<group>";
Expand Down Expand Up @@ -319,6 +326,7 @@
36B6CB5D234BEB8400331C38 /* SEPADebitExampleViewController.m in Sources */,
69A6C306246E63A2005FF304 /* EPSExampleViewController.m in Sources */,
C12C50DD1E57B3C800EC6D58 /* BrowseExamplesViewController.m in Sources */,
45DB454B249BD97B00DE45DE /* OXXOExampleViewController.m in Sources */,
3171D89A24DDECD80038A218 /* SofortExampleViewController.m in Sources */,
364FC2D024201F62002879EB /* AUBECSDebitExampleViewController.m in Sources */,
448895B424526C6B00F7D0C2 /* Przelewy24ExampleViewController.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#import "FPXExampleViewController.h"
#import "GiropayExampleViewController.h"
#import "iDEALExampleViewController.h"
#import "OXXOExampleViewController.h"
#import "Przelewy24ExampleViewController.h"
#import "SEPADebitExampleViewController.h"
#import "SofortSourcesExampleViewController.h"
Expand Down Expand Up @@ -44,7 +45,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 16;
return 17;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Expand Down Expand Up @@ -93,9 +94,12 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell.textLabel.text = @"EPS";
break;
case 14:
cell.textLabel.text = @"Sofort (PaymentMethods)";
cell.textLabel.text = @"OXXO";
break;
case 15:
cell.textLabel.text = @"Sofort (PaymentMethods)";
break;
case 16:
cell.textLabel.text = @"GrabPay";
break;
}
Expand Down Expand Up @@ -197,12 +201,18 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
break;
}
case 14: {
SofortExampleViewController *exampleVC = [SofortExampleViewController new];
OXXOExampleViewController *exampleVC = [OXXOExampleViewController new];
exampleVC.delegate = self;
viewController = exampleVC;
break;
}
case 15: {
SofortExampleViewController *exampleVC = [SofortExampleViewController new];
exampleVC.delegate = self;
viewController = exampleVC;
break;
}
case 16: {
GrabPayExampleViewController *exampleVC = [GrabPayExampleViewController new];
exampleVC.delegate = self;
viewController = exampleVC;
Expand Down
17 changes: 17 additions & 0 deletions Example/Non-Card Payment Examples/OXXOExampleViewController.h
Original file line number Diff line number Diff line change
@@ -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
98 changes: 98 additions & 0 deletions Example/Non-Card Payment Examples/OXXOExampleViewController.m
Original file line number Diff line number Diff line change
@@ -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
Loading