-
Notifications
You must be signed in to change notification settings - Fork 997
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
Adds SEPA Debit PaymentMethod #1415
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
80a5b29
Adds bindings for SEPA Debit PaymentMethod type
csabol-stripe 9ea0a4c
Adds SEPA Debit example
csabol-stripe bab3de7
Update SetupIntent and add auth text to example.
csabol-stripe 36769cd
Adds example iDEAL page.
csabol-stripe 94456c0
Adds missing comments and moves public headers to correct folder
csabol-stripe 165bacb
Fix headers for obsolete static build
csabol-stripe d469d9a
Adds comments from review.
csabol-stripe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,30 @@ | ||
// | ||
// PaymentExampleViewController.h | ||
// Custom Integration | ||
// | ||
// Created by Cameron Sabol on 10/7/19. | ||
// Copyright © 2019 Stripe. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
#import <Stripe/Stripe.h> | ||
|
||
#import "BrowseExamplesViewController.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface PaymentExampleViewController : UIViewController <STPAuthenticationContext> | ||
|
||
@property (nonatomic, weak) id<ExampleViewControllerDelegate> delegate; | ||
|
||
@property (nonatomic, weak) UIButton *payButton; | ||
@property (nonatomic, weak) UILabel *waitingLabel; | ||
@property (nonatomic, weak) UIActivityIndicatorView *activityIndicator; | ||
|
||
- (void)payButtonSelected; | ||
- (void)updateUIForPaymentInProgress:(BOOL)paymentInProgress; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
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,97 @@ | ||
// | ||
// PaymentExampleViewController.m | ||
// Custom Integration | ||
// | ||
// Created by Cameron Sabol on 10/7/19. | ||
// Copyright © 2019 Stripe. All rights reserved. | ||
// | ||
|
||
#import "PaymentExampleViewController.h" | ||
|
||
@interface PaymentExampleViewController () | ||
|
||
@end | ||
|
||
@implementation PaymentExampleViewController | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
self.view.backgroundColor = [UIColor whiteColor]; | ||
#ifdef __IPHONE_13_0 | ||
if (@available(iOS 13.0, *)) { | ||
self.view.backgroundColor = [UIColor systemBackgroundColor]; | ||
} | ||
#endif | ||
self.title = @"Payment Example"; | ||
self.edgesForExtendedLayout = UIRectEdgeNone; | ||
|
||
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; | ||
[button setTitle:@"Pay" forState:UIControlStateNormal]; | ||
[button sizeToFit]; | ||
[button addTarget:self action:@selector(payButtonSelected) forControlEvents:UIControlEventTouchUpInside]; | ||
self.payButton = button; | ||
[self.view addSubview:button]; | ||
|
||
UILabel *label = [UILabel new]; | ||
label.text = @"Waiting for payment authorization"; | ||
[label sizeToFit]; | ||
label.textColor = [UIColor grayColor]; | ||
#ifdef __IPHONE_13_0 | ||
if (@available(iOS 13.0, *)) { | ||
label.textColor = [UIColor secondaryLabelColor]; | ||
} | ||
#endif | ||
label.alpha = 0; | ||
[self.view addSubview:label]; | ||
self.waitingLabel = label; | ||
|
||
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; | ||
activityIndicator.hidesWhenStopped = YES; | ||
self.activityIndicator = activityIndicator; | ||
[self.view addSubview:activityIndicator]; | ||
} | ||
|
||
- (void)viewDidLayoutSubviews { | ||
[super viewDidLayoutSubviews]; | ||
CGFloat padding = 15; | ||
CGRect bounds = self.view.bounds; | ||
self.payButton.center = CGPointMake(CGRectGetMidX(bounds), CGRectGetHeight(bounds)/3.0); | ||
self.activityIndicator.center = CGPointMake(CGRectGetMidX(bounds), | ||
CGRectGetMaxY(self.payButton.frame) + padding*2); | ||
self.waitingLabel.center = CGPointMake(CGRectGetMidX(bounds), | ||
CGRectGetMaxY(self.activityIndicator.frame) + padding*2); | ||
} | ||
|
||
- (void)updateUIForPaymentInProgress:(BOOL)paymentInProgress { | ||
self.navigationController.navigationBar.userInteractionEnabled = !paymentInProgress; | ||
self.payButton.enabled = !paymentInProgress; | ||
[UIView animateWithDuration:0.2 animations:^{ | ||
self.waitingLabel.alpha = paymentInProgress ? 1 : 0; | ||
}]; | ||
if (paymentInProgress) { | ||
[self.activityIndicator startAnimating]; | ||
} else { | ||
[self.activityIndicator stopAnimating]; | ||
} | ||
} | ||
|
||
- (void)payButtonSelected { | ||
if (![Stripe defaultPublishableKey]) { | ||
[self.delegate exampleViewController:self didFinishWithMessage:@"Please set a Stripe Publishable Key in Constants.m"]; | ||
return; | ||
} | ||
// no-op, to be implemented by subclasses | ||
} | ||
|
||
|
||
#pragma mark - STPAuthenticationContext | ||
|
||
- (UIViewController *)authenticationPresentingViewController { | ||
return self.navigationController.topViewController; | ||
} | ||
|
||
- (void)authenticationContextWillDismissViewController:(UIViewController *)viewController { | ||
// no-op, to be implemented by subclasses as needed | ||
} | ||
|
||
@end |
17 changes: 17 additions & 0 deletions
17
Example/Custom Integration/SEPADebitExampleViewController.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 @@ | ||
// | ||
// SEPADebitExampleViewController.h | ||
// Custom Integration | ||
// | ||
// Created by Cameron Sabol on 10/7/19. | ||
// Copyright © 2019 Stripe. All rights reserved. | ||
// | ||
|
||
#import "PaymentExampleViewController.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface SEPADebitExampleViewController : PaymentExampleViewController | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
85 changes: 85 additions & 0 deletions
85
Example/Custom Integration/SEPADebitExampleViewController.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,85 @@ | ||
// | ||
// SEPADebitExampleViewController.m | ||
// Custom Integration | ||
// | ||
// Created by Cameron Sabol on 10/7/19. | ||
// Copyright © 2019 Stripe. All rights reserved. | ||
// | ||
|
||
#import "SEPADebitExampleViewController.h" | ||
|
||
#import "MyAPIClient.h" | ||
|
||
@interface SEPADebitExampleViewController () | ||
csabol-stripe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@end | ||
|
||
@implementation SEPADebitExampleViewController | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
// Do any additional setup after loading the view. | ||
self.title = @"SEPA Debit"; | ||
|
||
[self.payButton setTitle:@"Pay with SEPA Debit" forState:UIControlStateNormal]; | ||
[self.payButton sizeToFit]; | ||
|
||
UILabel *mandateAuthLabel = [[UILabel alloc] init]; | ||
mandateAuthLabel.numberOfLines = 0; | ||
mandateAuthLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleCallout]; | ||
mandateAuthLabel.textAlignment = NSTextAlignmentCenter; | ||
mandateAuthLabel.text = @"By providing your IBAN and confirming this payment, you are authorizing EXAMPLE COMPANY NAME and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited."; | ||
csabol-stripe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mandateAuthLabel.translatesAutoresizingMaskIntoConstraints = NO; | ||
[self.view addSubview:mandateAuthLabel]; | ||
|
||
[NSLayoutConstraint activateConstraints:@[ | ||
[mandateAuthLabel.leadingAnchor constraintEqualToSystemSpacingAfterAnchor:self.view.safeAreaLayoutGuide.leadingAnchor multiplier:2], | ||
[self.view.safeAreaLayoutGuide.trailingAnchor constraintEqualToSystemSpacingAfterAnchor:mandateAuthLabel.trailingAnchor multiplier:2], | ||
|
||
[mandateAuthLabel.topAnchor constraintEqualToSystemSpacingBelowAnchor:self.view.safeAreaLayoutGuide.topAnchor multiplier:2], | ||
]]; | ||
} | ||
|
||
- (void)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 = @"SEPA Test Customer"; | ||
billingDetails.email = @"[email protected]"; | ||
|
||
STPPaymentMethodSEPADebitParams *sepaDebitDetails = [[STPPaymentMethodSEPADebitParams alloc] init]; | ||
sepaDebitDetails.iban = @"DE89370400440532013000"; | ||
|
||
paymentIntentParams.paymentMethodParams = [STPPaymentMethodParams paramsWithSEPADebit:sepaDebitDetails | ||
billingDetails:billingDetails | ||
metadata:nil]; | ||
|
||
paymentIntentParams.returnURL = @"payments-example://stripe-redirect"; | ||
[[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=nl"]; | ||
|
||
} | ||
|
||
@end |
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 @@ | ||
// | ||
// iDEALExampleViewController.h | ||
// Custom Integration | ||
// | ||
// Created by Cameron Sabol on 10/10/19. | ||
// Copyright © 2019 Stripe. All rights reserved. | ||
// | ||
|
||
#import "PaymentExampleViewController.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface iDEALExampleViewController : PaymentExampleViewController | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
so we can stop just copy-pasting as we add view controllers. Should definitely modernize this code more though