Skip to content

Commit

Permalink
OXXO Add to Non-Card Payment Examples sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
pololi-stripe committed Jun 19, 2020
1 parent 8890c1b commit 6c00721
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 4 deletions.
12 changes: 9 additions & 3 deletions Example/Non-Card Payment Examples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -81,10 +82,12 @@
36B6CB63234FD9AA00331C38 /* iDEALExampleViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = iDEALExampleViewController.m; sourceTree = "<group>"; };
448895B224526C6B00F7D0C2 /* Przelewy24ExampleViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Przelewy24ExampleViewController.h; sourceTree = "<group>"; };
448895B324526C6B00F7D0C2 /* Przelewy24ExampleViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Przelewy24ExampleViewController.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>"; };
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>"; };
8BBD79C9207FD31A00F85BED /* zh-Hans */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
8BBD79CA207FD32100F85BED /* nl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 = "<group>";
Expand Down Expand Up @@ -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 */,
);
Expand Down
12 changes: 11 additions & 1 deletion Example/Non-Card Payment Examples/BrowseExamplesViewController.m
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 "SofortExampleViewController.h"
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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];
}
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

1 comment on commit 6c00721

@Killionn55
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.