Skip to content

Commit

Permalink
GrabPay (#1627)
Browse files Browse the repository at this point in the history
* GrabPay

* Fix ci scripts

* PR feedback
  • Loading branch information
yuki-stripe authored Aug 19, 2020
1 parent d01a014 commit ad9aca8
Show file tree
Hide file tree
Showing 21 changed files with 471 additions and 12 deletions.
14 changes: 9 additions & 5 deletions Example/Non-Card Payment Examples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
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 */; };
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 */; };
B68882D323FC5BD30057C5AD /* BacsDebitViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B68882D223FC5BD30057C5AD /* BacsDebitViewController.swift */; };
B6B0BB2E24C8A21A0000998E /* GrabPayExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6B0BB2D24C8A21A0000998E /* GrabPayExampleViewController.swift */; };
B6C1FC832330432E0097FC4C /* AlipayExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6C1FC822330432E0097FC4C /* AlipayExampleViewController.swift */; };
C12C50DD1E57B3C800EC6D58 /* BrowseExamplesViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C12C50DC1E57B3C800EC6D58 /* BrowseExamplesViewController.m */; };
C1CACE891E5DF7A9002D0821 /* ApplePayExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C1CACE881E5DF7A9002D0821 /* ApplePayExampleViewController.m */; };
Expand Down Expand Up @@ -81,10 +82,10 @@
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>"; };
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 All @@ -100,6 +101,7 @@
B65E8FCA22FA078A0057E64A /* WeChatPayExampleViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WeChatPayExampleViewController.h; sourceTree = "<group>"; };
B65E8FCB22FA078A0057E64A /* WeChatPayExampleViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WeChatPayExampleViewController.m; sourceTree = "<group>"; };
B68882D223FC5BD30057C5AD /* BacsDebitViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BacsDebitViewController.swift; sourceTree = "<group>"; };
B6B0BB2D24C8A21A0000998E /* GrabPayExampleViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GrabPayExampleViewController.swift; sourceTree = "<group>"; };
B6C1FC812330432E0097FC4C /* Non-Card Payment Examples-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Non-Card Payment Examples-Bridging-Header.h"; sourceTree = "<group>"; };
B6C1FC822330432E0097FC4C /* AlipayExampleViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlipayExampleViewController.swift; sourceTree = "<group>"; };
C12C50DB1E57B3C800EC6D58 /* BrowseExamplesViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BrowseExamplesViewController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -159,10 +161,13 @@
C12C50DC1E57B3C800EC6D58 /* BrowseExamplesViewController.m */,
04533F171A688A0A00C7E52E /* Constants.h */,
04533F181A688A0A00C7E52E /* Constants.m */,
69A6C304246E6225005FF304 /* EPSExampleViewController.h */,
69A6C305246E63A2005FF304 /* EPSExampleViewController.m */,
31A8934B230F6ABD007ABE37 /* FPXExampleViewController.h */,
31A8934C230F6ABD007ABE37 /* FPXExampleViewController.m */,
361962572450DA280025D60B /* GiropayExampleViewController.h */,
361962582450DA280025D60B /* GiropayExampleViewController.m */,
B6B0BB2D24C8A21A0000998E /* GrabPayExampleViewController.swift */,
36B6CB62234FD9AA00331C38 /* iDEALExampleViewController.h */,
36B6CB63234FD9AA00331C38 /* iDEALExampleViewController.m */,
04533E971A687F5D00C7E52E /* Images.xcassets */,
Expand All @@ -184,8 +189,6 @@
04533E8A1A687F5D00C7E52E /* Supporting Files */,
B65E8FCA22FA078A0057E64A /* WeChatPayExampleViewController.h */,
B65E8FCB22FA078A0057E64A /* WeChatPayExampleViewController.m */,
69A6C304246E6225005FF304 /* EPSExampleViewController.h */,
69A6C305246E63A2005FF304 /* EPSExampleViewController.m */,
);
path = "Non-Card Payment Examples";
sourceTree = "<group>";
Expand Down Expand Up @@ -319,6 +322,7 @@
04533EB21A68802E00C7E52E /* ShippingManager.m in Sources */,
361962592450DA280025D60B /* GiropayExampleViewController.m in Sources */,
31C108D823677C0100FE91B7 /* KlarnaExampleViewController.swift in Sources */,
B6B0BB2E24C8A21A0000998E /* GrabPayExampleViewController.swift in Sources */,
04533E901A687F5D00C7E52E /* AppDelegate.m in Sources */,
44BDCFE4245A4CAE007EE6D5 /* BancontactExampleViewController.m in Sources */,
B65E8FCC22FA078A0057E64A /* WeChatPayExampleViewController.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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 +91,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
case 13:
cell.textLabel.text = @"EPS";
break;
case 14:
cell.textLabel.text = @"GrabPay";
}
return cell;
}
Expand Down Expand Up @@ -189,6 +191,12 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
viewController = exampleVC;
break;
}
case 14: {
GrabPayExampleViewController *exampleVC = [GrabPayExampleViewController 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
Expand Up @@ -26,7 +26,7 @@ - (void)viewDidLoad {
[super viewDidLoad];

self.title = @"EPS";

_nameField = [[UITextField alloc] init];
_nameField.borderStyle = UITextBorderStyleRoundedRect;
_nameField.textContentType = UITextContentTypeName;
Expand Down
101 changes: 101 additions & 0 deletions Example/Non-Card Payment Examples/GrabPayExampleViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
//
// GrabPayExampleViewController.swift
// Non-Card Payment Examples
//
// Created by Yuki Tokuhiro on 7/22/20.
// Copyright © 2020 Stripe. All rights reserved.
//

import UIKit
import Stripe

/**
An example of accepting GrabPay payments.
See https://stripe.com/docs/payments/grabpay/accept-a-payment
*/
class GrabPayExampleViewController: UIViewController {
@objc weak var delegate: ExampleViewControllerDelegate?
var inProgress: Bool = false {
didSet {
navigationController?.navigationBar.isUserInteractionEnabled = !inProgress
payButton.isEnabled = !inProgress
inProgress ? activityIndicatorView.startAnimating() : activityIndicatorView.stopAnimating()
}
}

// UI
lazy var activityIndicatorView = {
return UIActivityIndicatorView(style: .gray)
}()
lazy var payButton: UIButton = {
let button = UIButton(type: .roundedRect)
button.setTitle("Pay with GrabPay", for: .normal)
button.addTarget(self, action: #selector(didTapPayButton), for: .touchUpInside)
return button
}()

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
title = "GrabPay"
[payButton, activityIndicatorView].forEach { subview in
view.addSubview(subview)
subview.translatesAutoresizingMaskIntoConstraints = false
}

let constraints = [
payButton.centerXAnchor.constraint(equalTo: view.centerXAnchor),
payButton.centerYAnchor.constraint(equalTo: view.centerYAnchor),

activityIndicatorView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
activityIndicatorView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
]
NSLayoutConstraint.activate(constraints)
}

@objc func didTapPayButton(sender: UIButton) {
inProgress = true

let grabPayParams = STPPaymentMethodGrabPayParams()

let billingDetails = STPPaymentMethodBillingDetails()
billingDetails.name = "Chiaki"
billingDetails.email = "email@email.com"

let paymentMethodParams = STPPaymentMethodParams(grabPay: grabPayParams, billingDetails: billingDetails, metadata: nil)

MyAPIClient.shared().createPaymentIntent(completion: { (result, clientSecret, error) in
guard let clientSecret = clientSecret else {
self.delegate?.exampleViewController(self, didFinishWithError: error)
return
}

let paymentIntentParams = STPPaymentIntentParams(clientSecret: clientSecret)
paymentIntentParams.paymentMethodParams = paymentMethodParams
paymentIntentParams.returnURL = "payments-example://stripe-redirect"

STPPaymentHandler.shared().confirmPayment(withParams: paymentIntentParams, authenticationContext: self) { (status, intent, error) in
switch (status) {
case .canceled:
self.delegate?.exampleViewController(self, didFinishWithMessage: "Canceled.")
return
case .failed:
self.delegate?.exampleViewController(self, didFinishWithMessage: "Payment failed. \(String(describing: error?.localizedDescription))")
return
case .succeeded:
self.delegate?.exampleViewController(self, didFinishWithMessage: "Your order was received and is awaiting payment confirmation.")
@unknown default:
fatalError()
}
}
}, additionalParameters: "country=sg")
}
}

// MARK: -
extension GrabPayExampleViewController: STPAuthenticationContext {
func authenticationPresentingViewController() -> UIViewController {
self
}
}
Loading

0 comments on commit ad9aca8

Please sign in to comment.