-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from AssemblyPayments/spi-2.1
SPI 2.1 Samples
- Loading branch information
Showing
163 changed files
with
26,591 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -27,3 +27,4 @@ xcuserdata/ | |
*.ipa | ||
*.dSYM.zip | ||
*.dSYM | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
kebabpos/KebabPos.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
kebabpos/KebabPos.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
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,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
kebabpos/KebabPos.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
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,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
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,21 @@ | ||
// | ||
// AppDelegate.swift | ||
// KebabPos | ||
// | ||
// Created by Amir Kamali on 29/5/18. | ||
// Copyright © 2018 Assembly Payments. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
@UIApplicationMain | ||
class AppDelegate: UIResponder, UIApplicationDelegate { | ||
|
||
var window: UIWindow? | ||
|
||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | ||
KebabApp.current.initialize() | ||
return true | ||
} | ||
|
||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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,15 @@ | ||
// | ||
// AppEvents.swift | ||
// KebabPos | ||
// | ||
// Created by Amir Kamali on 28/5/18. | ||
// Copyright © 2018 Assembly Payments. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
enum AppEvent: String { | ||
case connectionStatusChanged | ||
case pairingFlowChanged | ||
case transactionFlowStateChanged | ||
} |
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,74 @@ | ||
// | ||
// SPIExtensions.swift | ||
// KebabPos | ||
// | ||
// Created by Amir Kamali on 6/6/18. | ||
// Copyright © 2018 Assembly Payments. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import SPIClient_iOS | ||
|
||
extension SPIMessageSuccessState { | ||
var name: String { | ||
switch self { | ||
case .failed: | ||
return "failed" | ||
case .success: | ||
return "success" | ||
case .unknown: | ||
return "unknown" | ||
} | ||
} | ||
} | ||
|
||
extension SPIStatus { | ||
var name: String { | ||
switch self { | ||
case .unpaired: | ||
return "Unpaired" | ||
case .pairedConnecting: | ||
return "Connecting" | ||
case .pairedConnected: | ||
return "Connected" | ||
} | ||
} | ||
} | ||
|
||
extension SPIFlow { | ||
var name: String { | ||
switch self { | ||
case .idle: | ||
return "Idle" | ||
case .pairing: | ||
return "Pairing" | ||
case .transaction: | ||
return "Transaction" | ||
} | ||
} | ||
} | ||
|
||
extension SPITransactionType { | ||
var name: String { | ||
switch self { | ||
case .getLastTransaction: | ||
return "Get Last Transaction" | ||
case .purchase: | ||
return "Purchase" | ||
case .refund: | ||
return "Refund" | ||
case .settle: | ||
return "Settle" | ||
case .cashoutOnly: | ||
return "Cashout Only" | ||
case .MOTO: | ||
return "MOTO" | ||
case .settleEnquiry: | ||
return "Settle Enquiry" | ||
case .preAuth: | ||
return "Pre Auth" | ||
case .accountVerify: | ||
return "Account Verify" | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
kebabpos/KebabPos/Logics/Extensions/UIViewController+Alert.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,65 @@ | ||
// | ||
// UIViewController+Alert.swift | ||
// KebabPos | ||
// | ||
// Created by Amir Kamali on 29/5/18. | ||
// Copyright © 2018 Assembly Payments. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
var remainingAlerts:[UIAlertController] = [] | ||
|
||
extension UIViewController { | ||
|
||
func showAlert(title: String, message: String) { | ||
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert) | ||
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) | ||
showAlert(alertController: alertController) | ||
} | ||
|
||
func showAlert(alertController: UIAlertController) { | ||
func displayNext(){ | ||
if remainingAlerts.count > 0 { | ||
let nextAlert = remainingAlerts.remove(at: 0) | ||
self.showAlert(alertController: nextAlert) | ||
} | ||
} | ||
|
||
func display() { | ||
DispatchQueue.main.async { | ||
self.present(alertController, animated: true) { | ||
displayNext() | ||
} | ||
} | ||
} | ||
|
||
if (presentedViewController == nil) { | ||
display() | ||
} else if let existingAlert = presentedViewController as? UIAlertController { | ||
if (!existingAlert.isBeingDismissed && !existingAlert.isBeingPresented){ | ||
existingAlert.dismiss(animated: false, completion: { | ||
display() | ||
}) | ||
} else { | ||
addToRemaining(alert: alertController) | ||
} | ||
return | ||
} | ||
} | ||
|
||
// In case multiple alerts needs to be shown in a sequence, we keep them in an array to display later | ||
private func addToRemaining(alert:UIAlertController){ | ||
if let existingAlert = presentedViewController as? UIAlertController , existingAlert.message == alert.message { | ||
return | ||
} | ||
else if remainingAlerts.isEmpty{ | ||
remainingAlerts.append(alert) | ||
} else if let lastAlert = remainingAlerts.last, lastAlert.message != alert.message { | ||
//if not duplicated messages | ||
remainingAlerts.append(alert) | ||
} | ||
} | ||
|
||
} |
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,37 @@ | ||
// | ||
// Date+String.swift | ||
// KebabPos | ||
// | ||
// Created by Amir Kamali on 6/6/18. | ||
// Copyright © 2018 Assembly Payments. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Date { | ||
|
||
func toString(includeTime: Bool = false) -> String { | ||
var format = "" | ||
if (includeTime) { | ||
format = "dd/MM/yyyy hh:mm a" | ||
} else { | ||
format = "dd/MM/yyyy" | ||
} | ||
return toString(format: format) | ||
} | ||
|
||
func toString(format: String) -> String { | ||
let dateFormatter = DateFormatter() | ||
dateFormatter.dateFormat = format | ||
return dateFormatter.string(from: self) | ||
} | ||
|
||
} | ||
|
||
extension Bool { | ||
|
||
func toString() -> String { | ||
return self ? "true" : "false" | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
kebabpos/KebabPos/Logics/KebabApp+SPIConnectionDelegate.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,61 @@ | ||
// | ||
// SPIConnectionDelegate.swift | ||
// KebabPos | ||
// | ||
// Created by Amir Kamali on 28/5/18. | ||
// Copyright © 2018 Assembly Payments. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import SPIClient_iOS | ||
|
||
extension KebabApp: SPIDelegate { | ||
|
||
/// Called when we received a Status Update i.e. Unpaired/PairedConnecting/PairedConnected | ||
func spi(_ spi: SPIClient, statusChanged state: SPIState) { | ||
NotificationCenter.default.post(name: NSNotification.Name(rawValue: AppEvent.connectionStatusChanged.rawValue), object: state) | ||
|
||
SPILogMsg("statusChanged \(state)") | ||
} | ||
|
||
// Called during the pairing process to let us know how it's going. | ||
// We just update our screen with the information, and provide relevant Actions to the user. | ||
func spi(_ spi: SPIClient, pairingFlowStateChanged state: SPIState) { | ||
SPILogMsg("pairingFlowStateChanged \(state)") | ||
|
||
NotificationCenter.default.post(name: NSNotification.Name(rawValue: AppEvent.pairingFlowChanged.rawValue), object: state) | ||
} | ||
|
||
func spi(_ spi: SPIClient!, secretsChanged secrets: SPISecrets?, state: SPIState!) { | ||
SPILogMsg("secrets \(state)") | ||
if let secrets = secrets { | ||
SPILogMsg("\n\n") | ||
SPILogMsg("# ----------- I GOT NEW SECRETS -----------") | ||
SPILogMsg("# ---------- PERSIST THEM SAFELY ----------") | ||
SPILogMsg("# \(secrets.encKey):\(secrets.hmacKey)") | ||
SPILogMsg("# -----------------------------------------") | ||
|
||
// In prod store them in the key chain | ||
settings.encriptionKey = secrets.encKey! | ||
settings.hmacKey = secrets.hmacKey! | ||
} else { | ||
SPILogMsg("\n\n") | ||
SPILogMsg("# ------ THE SECRETS HAVE BEEN VOIDED -----") | ||
SPILogMsg("# ---------- CONSIDER ME UNPAIRED ---------") | ||
SPILogMsg("# -----------------------------------------") | ||
|
||
settings.encriptionKey = "" | ||
settings.hmacKey = "" | ||
} | ||
} | ||
|
||
// Called during a transaction to let us know how it's going. | ||
// We just update our screen with the information, and provide relevant Actions to the user. | ||
func spi(_ spi: SPIClient, transactionFlowStateChanged state: SPIState) { | ||
SPILogMsg("transactionFlowStateChanged \(state)") | ||
|
||
// Let's show the user what options he has at this stage. | ||
NotificationCenter.default.post(name: NSNotification.Name(rawValue: AppEvent.transactionFlowStateChanged.rawValue), object: state) | ||
} | ||
|
||
} |
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,43 @@ | ||
// | ||
// KebabContext.swift | ||
// KebabPos | ||
// | ||
// Created by Amir Kamali on 28/5/18. | ||
// Copyright © 2018 Assembly Payments. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import SPIClient_iOS | ||
|
||
class KebabApp: NSObject { | ||
|
||
private static var _instance: KebabApp = KebabApp() | ||
|
||
var settings = SettingsProvider() | ||
var client = SPIClient() | ||
|
||
static var current: KebabApp { | ||
return _instance | ||
} | ||
|
||
func initialize() { | ||
guard let eftposAddress = settings.eftposAddress else { return } | ||
guard let eftposId = settings.posId else { return } | ||
|
||
if let encriptionKey = settings.encriptionKey, let hmacKey = settings.hmacKey { | ||
SPILogMsg("LOADED KEYS FROM USERDEFAULTS") | ||
SPILogMsg("KEYS \(encriptionKey):\(hmacKey)") | ||
client.setSecretEncKey(encriptionKey, hmacKey: hmacKey) | ||
} | ||
client.eftposAddress = eftposAddress | ||
client.posId = eftposId | ||
client.config.signatureFlowOnEftpos = settings.customerSignatureromEFTPos ?? false | ||
client.config.promptForCustomerCopyOnEftpos = settings.customerReceiptFromEFTPos ?? false | ||
client.delegate = self | ||
} | ||
|
||
func start() { | ||
client.start() | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
kebabpos/KebabPos/Logics/Protocols/NotificationListener.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,22 @@ | ||
// | ||
// NotificationListener.swift | ||
// KebabPos | ||
// | ||
// Created by Amir Kamali on 29/5/18. | ||
// Copyright © 2018 Assembly Payments. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
@objc | ||
protocol NotificationListener { | ||
@objc func onNotificationArrived(notification: NSNotification) | ||
} | ||
|
||
extension NotificationListener { | ||
func registerForEvents(appEvents: [AppEvent]) { | ||
for event in appEvents { | ||
NotificationCenter.default.addObserver(self, selector: #selector(onNotificationArrived), name: NSNotification.Name(rawValue: event.rawValue), object: nil) | ||
} | ||
} | ||
} |
Oops, something went wrong.