Skip to content

Commit

Permalink
Przelewy24 PaymentMethod bindings (#1556)
Browse files Browse the repository at this point in the history
  • Loading branch information
vineet-stripe authored May 13, 2020
1 parent 3521bd4 commit 0849bf5
Show file tree
Hide file tree
Showing 22 changed files with 547 additions and 22 deletions.
6 changes: 6 additions & 0 deletions Example/Non-Card Payment Examples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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 */; };
448895B424526C6B00F7D0C2 /* Przelewy24ExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 448895B324526C6B00F7D0C2 /* Przelewy24ExampleViewController.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 @@ -76,6 +77,8 @@
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>"; };
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>"; };
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 @@ -162,6 +165,8 @@
B6C1FC812330432E0097FC4C /* Non-Card Payment Examples-Bridging-Header.h */,
36B6CB58234BE3FA00331C38 /* PaymentExampleViewController.h */,
36B6CB59234BE3FA00331C38 /* PaymentExampleViewController.m */,
448895B224526C6B00F7D0C2 /* Przelewy24ExampleViewController.h */,
448895B324526C6B00F7D0C2 /* Przelewy24ExampleViewController.m */,
36B6CB5B234BEB8400331C38 /* SEPADebitExampleViewController.h */,
36B6CB5C234BEB8400331C38 /* SEPADebitExampleViewController.m */,
04533EB01A68802E00C7E52E /* ShippingManager.h */,
Expand Down Expand Up @@ -316,6 +321,7 @@
36B6CB5D234BEB8400331C38 /* SEPADebitExampleViewController.m in Sources */,
C12C50DD1E57B3C800EC6D58 /* BrowseExamplesViewController.m in Sources */,
364FC2D024201F62002879EB /* AUBECSDebitExampleViewController.m in Sources */,
448895B424526C6B00F7D0C2 /* Przelewy24ExampleViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
16 changes: 13 additions & 3 deletions Example/Non-Card Payment Examples/BrowseExamplesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@

#import "ApplePayExampleViewController.h"
#import "AUBECSDebitExampleViewController.h"
#import "iDEALExampleViewController.h"
#import "SofortExampleViewController.h"
#import "FPXExampleViewController.h"
#import "GiropayExampleViewController.h"
#import "iDEALExampleViewController.h"
#import "Przelewy24ExampleViewController.h"
#import "SEPADebitExampleViewController.h"
#import "SofortExampleViewController.h"
#import "WeChatPayExampleViewController.h"

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 11;
return 12;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Expand Down Expand Up @@ -79,6 +80,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
case 10:
cell.textLabel.text = @"giropay";
break;
case 11:
cell.textLabel.text = @"Przelewy24";
break;
}
return cell;
}
Expand Down Expand Up @@ -159,6 +163,12 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
viewController = exampleVC;
break;
}
case 11: {
Przelewy24ExampleViewController *exampleVC = [Przelewy24ExampleViewController new];
exampleVC.delegate = self;
viewController = exampleVC;
break;
}
}
[self.navigationController pushViewController:viewController animated:YES];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Przelewy24ExampleViewController.h
// Non-Card Payment Examples
//
// Created by Vineet Shah on 4/23/20.
// Copyright © 2020 Stripe. All rights reserved.
//

#import "PaymentExampleViewController.h"

NS_ASSUME_NONNULL_BEGIN

@interface Przelewy24ExampleViewController : PaymentExampleViewController

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// Przelewy24ExampleViewController.m
// Non-Card Payment Examples
//
// Created by Vineet Shah on 4/23/20.
// Copyright © 2020 Stripe. All rights reserved.
//

#import "Przelewy24ExampleViewController.h"

#import "MyAPIClient.h"

NS_ASSUME_NONNULL_BEGIN

@interface Przelewy24ExampleViewController ()

@end

@implementation Przelewy24ExampleViewController {
UITextField *_emailField;
}

- (void)viewDidLoad {
[super viewDidLoad];

self.title = @"Przelewy24";

_emailField = [[UITextField alloc] init];
_emailField.borderStyle = UITextBorderStyleRoundedRect;
_emailField.textContentType = UITextContentTypeEmailAddress;
_emailField.placeholder = @"Email";
_emailField.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:_emailField];

[self.payButton setTitle:@"Pay with Przelewy24" forState:UIControlStateNormal];
[self.payButton sizeToFit];

[NSLayoutConstraint activateConstraints:@[
[_emailField.centerXAnchor constraintEqualToAnchor:self.payButton.centerXAnchor],
[_emailField.bottomAnchor constraintEqualToAnchor:self.payButton.topAnchor constant:-12.f],
[_emailField.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.email = self->_emailField.text;


STPPaymentMethodPrzelewy24Params *przelewy24 = [[STPPaymentMethodPrzelewy24Params alloc] init];

// Przelewy24 does not require additional parameters so we only need to pass the init-ed
// STPPaymentMethodPrzelewy24Params instance to STPPaymentMethodParams
paymentIntentParams.paymentMethodParams = [STPPaymentMethodParams paramsWithPrzelewy24:przelewy24
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=pl"];
}

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 0849bf5

Please sign in to comment.