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

Adds SEPA Debit PaymentMethod #1415

Merged
merged 7 commits into from
Oct 16, 2019
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
22 changes: 20 additions & 2 deletions Example/Custom Integration.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
04D076171A69C11600094431 /* Stripe.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 04533F0C1A68812D00C7E52E /* Stripe.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
31A8934D230F6ABD007ABE37 /* FPXExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 31A8934C230F6ABD007ABE37 /* FPXExampleViewController.m */; };
366F93B0225FF2A2005CFBF6 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 366F93AF225FF2A2005CFBF6 /* README.md */; };
36B6CB5A234BE3FA00331C38 /* PaymentExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 36B6CB59234BE3FA00331C38 /* PaymentExampleViewController.m */; };
36B6CB5D234BEB8400331C38 /* SEPADebitExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 36B6CB5C234BEB8400331C38 /* SEPADebitExampleViewController.m */; };
36B6CB64234FD9AA00331C38 /* iDEALExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 36B6CB63234FD9AA00331C38 /* iDEALExampleViewController.m */; };
36D4EA6422DFEF1300619BA8 /* CardSetupIntentBackendExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 36D4EA6322DFEF1300619BA8 /* CardSetupIntentBackendExampleViewController.m */; };
8BBD79C6207FD2F900F85BED /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8BBD79C8207FD2F900F85BED /* Localizable.strings */; };
B3BDCADD20EF03010034F7F5 /* CardAutomaticConfirmationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B3BDCADB20EF03010034F7F5 /* CardAutomaticConfirmationViewController.m */; };
Expand Down Expand Up @@ -61,6 +64,12 @@
31A8934B230F6ABD007ABE37 /* FPXExampleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FPXExampleViewController.h; sourceTree = "<group>"; };
31A8934C230F6ABD007ABE37 /* FPXExampleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FPXExampleViewController.m; sourceTree = "<group>"; };
366F93AF225FF2A2005CFBF6 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = "Custom Integration/README.md"; sourceTree = "<group>"; };
36B6CB58234BE3FA00331C38 /* PaymentExampleViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PaymentExampleViewController.h; sourceTree = "<group>"; };
36B6CB59234BE3FA00331C38 /* PaymentExampleViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PaymentExampleViewController.m; sourceTree = "<group>"; };
36B6CB5B234BEB8400331C38 /* SEPADebitExampleViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SEPADebitExampleViewController.h; sourceTree = "<group>"; };
36B6CB5C234BEB8400331C38 /* SEPADebitExampleViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SEPADebitExampleViewController.m; sourceTree = "<group>"; };
36B6CB62234FD9AA00331C38 /* iDEALExampleViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = iDEALExampleViewController.h; sourceTree = "<group>"; };
36B6CB63234FD9AA00331C38 /* iDEALExampleViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = iDEALExampleViewController.m; sourceTree = "<group>"; };
36D4EA6222DFEF1300619BA8 /* CardSetupIntentBackendExampleViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CardSetupIntentBackendExampleViewController.h; sourceTree = "<group>"; };
36D4EA6322DFEF1300619BA8 /* CardSetupIntentBackendExampleViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CardSetupIntentBackendExampleViewController.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 @@ -148,13 +157,19 @@
8BBD79C8207FD2F900F85BED /* Localizable.strings */,
B607FFBB2321DA99004203E0 /* MyAPIClient.h */,
B607FFBC2321DA99004203E0 /* MyAPIClient.m */,
36B6CB58234BE3FA00331C38 /* PaymentExampleViewController.h */,
36B6CB59234BE3FA00331C38 /* PaymentExampleViewController.m */,
36B6CB5B234BEB8400331C38 /* SEPADebitExampleViewController.h */,
36B6CB5C234BEB8400331C38 /* SEPADebitExampleViewController.m */,
04533EB01A68802E00C7E52E /* ShippingManager.h */,
04533EB11A68802E00C7E52E /* ShippingManager.m */,
C1CACE921E5E3DF6002D0821 /* SofortExampleViewController.h */,
C1CACE931E5E3DF6002D0821 /* SofortExampleViewController.m */,
04533E8A1A687F5D00C7E52E /* Supporting Files */,
B65E8FCA22FA078A0057E64A /* WeChatPayExampleViewController.h */,
B65E8FCB22FA078A0057E64A /* WeChatPayExampleViewController.m */,
36B6CB62234FD9AA00331C38 /* iDEALExampleViewController.h */,
36B6CB63234FD9AA00331C38 /* iDEALExampleViewController.m */,
);
path = "Custom Integration";
sourceTree = "<group>";
Expand Down Expand Up @@ -281,6 +296,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
36B6CB64234FD9AA00331C38 /* iDEALExampleViewController.m in Sources */,
04533F191A688A0A00C7E52E /* Constants.m in Sources */,
C1CACE941E5E3DF6002D0821 /* SofortExampleViewController.m in Sources */,
C1CACE861E5DE6C3002D0821 /* CardManualConfirmationExampleViewController.m in Sources */,
Expand All @@ -290,10 +306,12 @@
36D4EA6422DFEF1300619BA8 /* CardSetupIntentBackendExampleViewController.m in Sources */,
04533E901A687F5D00C7E52E /* AppDelegate.m in Sources */,
B65E8FCC22FA078A0057E64A /* WeChatPayExampleViewController.m in Sources */,
36B6CB5A234BE3FA00331C38 /* PaymentExampleViewController.m in Sources */,
C1CACE891E5DF7A9002D0821 /* ApplePayExampleViewController.m in Sources */,
B607FFBD2321DA99004203E0 /* MyAPIClient.m in Sources */,
04533E8D1A687F5D00C7E52E /* main.m in Sources */,
31A8934D230F6ABD007ABE37 /* FPXExampleViewController.m in Sources */,
36B6CB5D234BEB8400331C38 /* SEPADebitExampleViewController.m in Sources */,
C12C50DD1E57B3C800EC6D58 /* BrowseExamplesViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -376,7 +394,7 @@
"$(inherited)",
"$(PROJECT_DIR)/**",
);
IPHONEOS_DEPLOYMENT_TARGET = 8.4;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -431,7 +449,7 @@
"$(inherited)",
"$(PROJECT_DIR)/**",
);
IPHONEOS_DEPLOYMENT_TARGET = 8.4;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
Expand Down
22 changes: 21 additions & 1 deletion Example/Custom Integration/BrowseExamplesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
#import "CardManualConfirmationExampleViewController.h"
#import "CardSetupIntentBackendExampleViewController.h"
#import "CardSetupIntentExampleViewController.h"
#import "iDEALExampleViewController.h"
#import "SofortExampleViewController.h"
#import "FPXExampleViewController.h"
#import "SEPADebitExampleViewController.h"
#import "WeChatPayExampleViewController.h"

/**
Expand All @@ -39,7 +41,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 8;
return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Expand Down Expand Up @@ -69,6 +71,12 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
case 7:
cell.textLabel.text = @"FPX";
break;
case 8:
cell.textLabel.text = @"SEPA Debit";
break;
case 9:
cell.textLabel.text = @"iDEAL";
break;
}
return cell;
}
Expand Down Expand Up @@ -124,6 +132,18 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
viewController = exampleVC;
break;
}
case 8: {
SEPADebitExampleViewController *exampleVC = [SEPADebitExampleViewController new];
exampleVC.delegate = self;
viewController = exampleVC;
break;
}
case 9: {
iDEALExampleViewController *exampleVC = [iDEALExampleViewController new];
exampleVC.delegate = self;
viewController = exampleVC;
break;
}
}
[self.navigationController pushViewController:viewController animated:YES];
}
Expand Down
30 changes: 30 additions & 0 deletions Example/Custom Integration/PaymentExampleViewController.h
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>
Copy link
Contributor Author

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


@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
97 changes: 97 additions & 0 deletions Example/Custom Integration/PaymentExampleViewController.m
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 Example/Custom Integration/SEPADebitExampleViewController.h
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
96 changes: 96 additions & 0 deletions Example/Custom Integration/SEPADebitExampleViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//
// SEPADebitExampleViewController.m
// Custom Integration
//
// Created by Cameron Sabol on 10/7/19.
// Copyright © 2019 Stripe. All rights reserved.
//

#import "SEPADebitExampleViewController.h"

#import "MyAPIClient.h"

/**
This example demonstrates using PaymentIntents to accept payments using SEPA Debit
First, we ask our server to set up a PaymentIntent. We create a PaymentMethodParams with the required
SEPA Debit details. In this example we have hard-coded a Stripe Test IBAN number, but in production
code you would collect this from your customer.
SEPA Debit also required that we provide a mandate for the user to agree to https://www.europeanpaymentscouncil.eu/what-we-do/sepa-schemes/sepa-direct-debit/sdd-mandate
Finally we call STPPaymentHandler to confirm the PaymentIntent using the Stripe API.

For more details see https://www.stripe.com/docs/sources/sepa-debit
*/
@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;
// This text is required by https://www.europeanpaymentscouncil.eu/what-we-do/sepa-schemes/sepa-direct-debit/sdd-mandate
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 = @"test@example.com";

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
17 changes: 17 additions & 0 deletions Example/Custom Integration/iDEALExampleViewController.h
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
Loading