Skip to content

Commit

Permalink
Tabby, Paypal & GooglePay
Browse files Browse the repository at this point in the history
  • Loading branch information
OsamaRabie committed Nov 2, 2023
1 parent 2e84d3d commit c88d75e
Show file tree
Hide file tree
Showing 16 changed files with 735 additions and 66 deletions.
Binary file not shown.
2 changes: 1 addition & 1 deletion Pay-Button-iOS.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Pay-Button-iOS'
s.version = '0.0.2'
s.version = '0.0.3'
s.summary = 'From the shelf card processing library provided by Tap Payments'
s.homepage = 'https://github.com/Tap-Payments/Pay-Button-iOS'
s.license = { :type => 'MIT', :file => 'LICENSE' }
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,16 @@
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "22B7BADF-8FB1-4B54-B595-4B5987F062FB"
shouldBeEnabled = "No"
uuid = "EFE591B1-0307-45DE-84FF-AF7FDF8F212D"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "../Sources/Pay-Button-iOS/Logic/SdkBasedButtons/BenefitPay/views/private/TapBenefitPayView.swift"
filePath = "../Sources/Pay-Button-iOS/Logic/SdkBasedButtons/GooglePay/views/private/TapGooglePayView.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "75"
endingLineNumber = "75"
landmarkName = "openUrl(url:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "DAF23ED6-8F49-48B4-BB71-7817D15BB15E"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "../Sources/Pay-Button-iOS/Logic/SdkBasedButtons/BenefitPay/private/extensions/TapBenefitPay+WebDelegate.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "48"
endingLineNumber = "48"
landmarkName = "webView(_:decidePolicyFor:decisionHandler:)"
startingLineNumber = "142"
endingLineNumber = "142"
landmarkName = "passToSDK(googlePayToken:fullUrl:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
Expand Down
63 changes: 27 additions & 36 deletions PayButtonSDK/PayButtonSDK/PayButtonExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,75 +15,64 @@ class PayButtonExample: UIViewController {

@IBOutlet weak var refreshButton: UIButton!

var selectedButtonType:PayButtonTypeEnum = .BenefitPay
var selectedButtonType:PayButtonTypeEnum = .GooglePay
var dictConfig:[String:Any] = [
"operator": ["publicKey": "pk_test_YhUjg9PNT8oDlKJ1aE2fMRz7"],
"scope": "AuthenticatedToken",
"purpose": "Transaction",
"operator": ["publicKey": "pk_test_6jdl4Qo0FYOSXmrZTR1U5EHp", "hashString": ""],
"scope": "charge",
"transaction": [
"authentication": true,
"authorize": [
"type": "VOID",
"time": 12,
],
"paymentAgreement": [
"id": "",
"contract": ["id": ""],
]
],
"reference": "trx",
"metadata": [:],
],
"order": [
"id": "",
"amount": 1,
"currency": "SAR",
"amount": 0.1,
"currency": "KWD",
"description": "Authentication description",
"reference": "",
"metadata": ["key": "value"],
"reference": "ordRef",
"metadata": [:],
],
"invoice": ["id": ""],
"merchant": ["id": ""],
"customer": [
"id": "",
"name": [["lang": "en", "first": "TAP", "middle": "", "last": "PAYMENTS"]],
"nameOnCard": "TAP PAYMENTS",
"editable": true,
"contact": [
"email": "[email protected]",
"phone": ["countryCode": "+965", "number": "88888888"],
],
],
"features": [
"alternativeCardInputs": [
"cardScanner": true,
"cardNFC": false,
],
"acceptanceBadge": true,
"customerCards": [
"saveCard": false,
"autoSaveCard": false,
],

],
"acceptance": [
"supportedSchemes": ["AMERICAN_EXPRESS", "VISA", "MASTERCARD", "OMANNET", "MADA"],
"supportedFundSource": ["CREDIT", "DEBIT"],
"supportedPaymentAuthentications": ["3DS"],
],
"fieldVisibility": [
"card": [
"cvv": true,
"cardHolder": true,
]
],
"supportedSchemes": ["AMERICAN_EXPRESS", "VISA", "MASTERCARD", "OMANNET", "MADA"],
"supportedFundSource": ["CREDIT", "DEBIT"],
"supportedPaymentAuthentications": ["3DS"],
],
"interface": [
"locale": "en",
"theme": UIView().traitCollection.userInterfaceStyle == .dark ? "dark" : "light",
"edges": "curved",
"cardDirection": "dynamic",
"powered": true,
"colorStyle": UIView().traitCollection.userInterfaceStyle == .dark
? "monochrome" : "colored",
"loader": true,
"colorStyle": UIView().traitCollection.userInterfaceStyle == .dark ? "monochrome" : "colored",
"powered":true
],
"post": ["url": ""],
]

override func viewDidLoad() {
super.viewDidLoad()
setupPayButton()
if let jsonData = try? JSONSerialization.data(withJSONObject: dictConfig, options: .prettyPrinted) {
print(String(decoding: jsonData, as: UTF8.self))
}
}

@IBAction func refreshButtonClicked(_ sender: Any) {
Expand Down Expand Up @@ -149,6 +138,8 @@ class PayButtonExample: UIViewController {
let signature = HMAC<SHA256>.authenticationCode(for: Data(toBeHashed.utf8), using: key)
let hashedString = Data(signature).map { String(format: "%02hhx", $0) }.joined()
return hashedString


}

/*func setConfig(config: CardWebSDKConfig) {
Expand Down
30 changes: 29 additions & 1 deletion PayButtonSDK/PayButtonSDK/PayButtonSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class PayButtonSettingsViewController: FormViewController {
form +++ Section("scope")
<<< AlertRow<String>("scope"){ row in
row.title = "Scope"
row.options = ["charge","authorize"]
row.options = ["charge","authorize","taptoken","googlepaytoken"]
row.value = (config! as NSDictionary).value(forKeyPath: "scope") as? String ?? "charge"
row.onChange { row in
self.update(dictionary: &self.config!, at: ["scope"], with: row.value ?? "charge")
Expand Down Expand Up @@ -187,6 +187,34 @@ class PayButtonSettingsViewController: FormViewController {
}*/


form +++ Section("acceptance")
<<< MultipleSelectorRow<String>("acceptance.supportedSchemes"){ row in
row.title = "supportedSchemes"
row.options = ["AMERICAN_EXPRESS","MADA","MASTERCARD","VISA","OMANNET","MEEZA"]
row.value = Set((config! as NSDictionary).value(forKeyPath: "acceptance.supportedSchemes") as? [String] ?? ["AMERICAN_EXPRESS","MADA","MASTERCARD","VISA","OMANNET","MEEZA"])
row.onChange { row in
self.update(dictionary: &self.config!, at: ["acceptance","supportedSchemes"], with: Array(row.value ?? ["AMERICAN_EXPRESS","MADA","MASTERCARD","VISA","OMANNET","MEEZA"]))
}
}

<<< MultipleSelectorRow<String>("acceptance.supportedFundSource"){ row in
row.title = "supportedFundSource"
row.options = ["CREDIT","DEBIT"]
row.value = Set((config! as NSDictionary).value(forKeyPath: "acceptance.supportedFundSource") as? [String] ?? ["DEBIT","CREDIT"])
row.onChange { row in
self.update(dictionary: &self.config!, at: ["acceptance","supportedFundSource"], with: Array(row.value ?? ["DEBIT","CREDIT"]))
}
}

<<< MultipleSelectorRow<String>("acceptance.supportedPaymentAuthentications"){ row in
row.title = "supportedPaymentAuthentications"
row.options = ["3DS"]
row.value = Set((config! as NSDictionary).value(forKeyPath: "acceptance.supportedPaymentAuthentications") as? [String] ?? ["3DS"])
row.onChange { row in
self.update(dictionary: &self.config!, at: ["acceptance","supportedPaymentAuthentications"], with: Array(row.value ?? ["3DS"]))
}
}

form +++ Section("interface")
<<< AlertRow<String>("interface.locale"){ row in
row.title = "locale"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal class RedirectionPayButton: PayButtonBaseView {
internal var webView: WKWebView = .init()
/// keeps a hold of the loaded web sdk configurations url
internal var currentlyLoadedConfigurations:URL?
// This means we are ok to start the authentication process
/// The view that will present full screen 3ds flow
internal var threeDsView:ThreeDSView?

//MARK: - Init methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ internal class BenefitPayButton: PayButtonBaseView {
*/
}

/// Used to open a url inside the Tap card web sdk.
/// Used to open a url inside the Tap button web sdk.
/// - Parameter url: The url needed to load.
internal func openUrl(url: URL?) {
// Store it for further usages
Expand All @@ -83,7 +83,7 @@ internal class BenefitPayButton: PayButtonBaseView {
webView.load(request)
}

/// used to setup the constraint of the Tap card sdk view
/// used to setup the constraint of the Tap button sdk view
private func setupWebView() {
// Creates needed configuration for the web view
let preferences = WKPreferences()
Expand Down Expand Up @@ -157,8 +157,8 @@ internal class BenefitPayButton: PayButtonBaseView {


/// Call it when you want to remove the benefitpay entry and get back to the merchant app
/// - Parameter shouldStopOnCancel: Whether or not, we should listen to the onCancel coming after this event or not.
/// - Parameter onDosmiss: a callback if needed to do some logic post closeing
/// - Parameter handleOnCancel: Whether or not, we should listen to the onCancel coming after this event or not.
/// - Parameter onDismiss: a callback if needed to do some logic post closeing
internal func removeBenefitPayPopupEntry(handleOnCancel:Bool = false, onDismiss:@escaping()->()) -> Bool {
guard let viewController:UIViewController = UIApplication.shared.topViewController(),
viewController.restorationIdentifier == "BenefitQRVC" else { return false }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// File.swift
//
//
// Created by Osama Rabie on 02/11/2023.
//

import Foundation
import WebKit

internal extension GooglePayButton {


/// Will create a view that contains a full screen web view to display within the google pay modal popup
func createGooglePayPopUpView() -> UIViewController {
// The container iew
let view:UIView = .init()
view.backgroundColor = .clear

//webView.isHidden = true
webView.removeFromSuperview()
view.addSubview(webView)

// Define the constrains of the web view to be full screen
let top = webView.topAnchor.constraint(equalTo: view.topAnchor)
let left = webView.leftAnchor.constraint(equalTo: view.leftAnchor)
let right = webView.rightAnchor.constraint(equalTo: view.rightAnchor)
let bottom = webView.bottomAnchor.constraint(equalTo: view.bottomAnchor)

// Activate the constraints
NSLayoutConstraint.activate([left, right, top, bottom])

self.webView.translatesAutoresizingMaskIntoConstraints = false


let ctr:UIViewController = .init()
ctr.view.backgroundColor = .clear
ctr.modalPresentationStyle = .overCurrentContext
ctr.view.addSubview(view)
ctr.restorationIdentifier = "GooglePayVC"
view.translatesAutoresizingMaskIntoConstraints = false

let vtop = view.topAnchor.constraint(equalTo: ctr.view.topAnchor)
let vleft = view.leftAnchor.constraint(equalTo: ctr.view.leftAnchor)
let vright = view.rightAnchor.constraint(equalTo: ctr.view.rightAnchor)
let vbottom = view.bottomAnchor.constraint(equalTo: ctr.view.bottomAnchor,constant: 60)

// Activate the constraints
NSLayoutConstraint.activate([left, right, top, bottom, vtop, vleft, vright, vbottom])

return ctr
}

}
Loading

0 comments on commit c88d75e

Please sign in to comment.