-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into convert-datacollector-viewcontroller
# Conflicts: # Demo/Demo.xcodeproj/project.pbxproj
- Loading branch information
Showing
4 changed files
with
112 additions
and
132 deletions.
There are no files selected for viewing
7 changes: 0 additions & 7 deletions
7
Demo/Application/Features/Ideal/BraintreeDemoIdealViewController.h
This file was deleted.
Oops, something went wrong.
96 changes: 0 additions & 96 deletions
96
Demo/Application/Features/Ideal/BraintreeDemoIdealViewController.m
This file was deleted.
Oops, something went wrong.
108 changes: 108 additions & 0 deletions
108
Demo/Application/Features/Ideal/BraintreeDemoIdealViewController.swift
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,108 @@ | ||
import Foundation | ||
import BraintreeLocalPayment | ||
import BraintreeCore | ||
|
||
class BraintreeDemoIdealViewController: BraintreeDemoPaymentButtonBaseViewController { | ||
|
||
var localPaymentClient: BTLocalPaymentClient! | ||
var paymentIDLabel: UILabel = UILabel() | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
progressBlock("Loading iDEAL Merchant Account...") | ||
paymentButton.isHidden = false | ||
progressBlock("Ready!") | ||
title = "iDEAL" | ||
} | ||
|
||
override func createPaymentButton() -> UIView! { | ||
let iDEALButton = UIButton(type: .custom) | ||
iDEALButton.setTitle("Pay with iDEAL", for: .normal) | ||
iDEALButton.setTitleColor(.blue, for: .normal) | ||
iDEALButton.setTitleColor(.lightGray, for: .highlighted) | ||
iDEALButton.setTitleColor(.lightGray, for: .disabled) | ||
iDEALButton.addTarget(self, action: #selector(tappedIDEAL), for: .touchUpInside) | ||
iDEALButton.translatesAutoresizingMaskIntoConstraints = false | ||
|
||
let label = UILabel() | ||
label.numberOfLines = 0 | ||
label.translatesAutoresizingMaskIntoConstraints = false | ||
|
||
self.paymentIDLabel = label | ||
|
||
let stackView = UIStackView(arrangedSubviews: [iDEALButton, label]) | ||
stackView.axis = .vertical | ||
stackView.spacing = 5 | ||
stackView.alignment = .center | ||
stackView.translatesAutoresizingMaskIntoConstraints = false | ||
|
||
NSLayoutConstraint.activate([ | ||
iDEALButton.topAnchor.constraint(equalTo: stackView.topAnchor), | ||
iDEALButton.heightAnchor.constraint(equalToConstant: 19.5), | ||
|
||
label.topAnchor.constraint(equalTo: iDEALButton.bottomAnchor, constant: 5), | ||
label.heightAnchor.constraint(equalToConstant: 19.5) | ||
]) | ||
|
||
return stackView | ||
} | ||
|
||
@objc func tappedIDEAL() { | ||
paymentIDLabel.text = nil | ||
startPaymentWithBank() | ||
} | ||
|
||
private func startPaymentWithBank() { | ||
let apiClient = BTAPIClient(authorization: "sandbox_f252zhq7_hh4cpc39zq4rgjcg")! | ||
localPaymentClient = BTLocalPaymentClient(apiClient: apiClient) | ||
|
||
let request = BTLocalPaymentRequest() | ||
request.paymentType = "ideal" | ||
request.paymentTypeCountryCode = "NL" | ||
request.currencyCode = "EUR" | ||
request.amount = "1.01" | ||
request.givenName = "Linh" | ||
request.surname = "Ngo" | ||
request.phone = "639847934" | ||
request.email = "[email protected]" | ||
request.isShippingAddressRequired = false | ||
|
||
let postalAddress = BTPostalAddress() | ||
postalAddress.countryCodeAlpha2 = "NL" | ||
postalAddress.postalCode = "2585 GJ" | ||
postalAddress.streetAddress = "836486 of 22321 Park Lake" | ||
postalAddress.locality = "Den Haag" | ||
|
||
request.address = postalAddress | ||
request.localPaymentFlowDelegate = self | ||
|
||
localPaymentClient.startPaymentFlow(request) { result, error in | ||
guard let result else { | ||
if (error as? NSError)?.code == 5 { | ||
self.progressBlock("Canceled 🎲") | ||
} else { | ||
self.progressBlock("Error: \(error?.localizedDescription ?? "")") | ||
} | ||
return | ||
} | ||
|
||
let nonce = BTPaymentMethodNonce(nonce: result.nonce) | ||
self.completionBlock(nonce) | ||
} | ||
} | ||
} | ||
|
||
// MARK: - BTLocalPaymentRequestDelegate Conformance | ||
|
||
extension BraintreeDemoIdealViewController: BTLocalPaymentRequestDelegate { | ||
|
||
func localPaymentStarted( | ||
_ request: BraintreeLocalPayment.BTLocalPaymentRequest, | ||
paymentID: String, | ||
start: @escaping () -> Void | ||
) { | ||
paymentIDLabel.text = "LocalPayment ID: \(paymentID)" | ||
start() | ||
} | ||
} |
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