-
Notifications
You must be signed in to change notification settings - Fork 983
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OXXO Add to Non-Card Payment Examples sample app
- Loading branch information
1 parent
8890c1b
commit 6c00721
Showing
4 changed files
with
135 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
Example/Non-Card Payment Examples/OXXOExampleViewController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
98
Example/Non-Card Payment Examples/OXXOExampleViewController.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
6c00721
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1769