diff --git a/README.md b/README.md index 21a45ca..5da062f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A Cordova plugin to interface with the native Square Reader POS SDKs. # Install -`$ cordova plugin add @moltin/cordova-plugin-square-reader` +`$ cordova plugin add @f3/cordova-plugin-square-reader` `$ cordova platform ios prepare` @@ -22,11 +22,7 @@ Set up the Square Reader SDK ```ts window['squarereader'].setup(() => { - let params = { - "authCode": "" - }; - - window['squarereader'].authorizeReaderSDKIfNeeded(params, () => { + window['squarereader'].authorizeReaderSDKIfNeeded(() => { alert("Authorised!") }, (err) => { @@ -37,6 +33,8 @@ window['squarereader'].setup(() => { }); ``` +This will ask for location and microphone permission and then it will give QR code reader. User can use this to scan qr code on Square Reader SDK developer portal to authorize + Pair the reader POS system ```ts @@ -61,6 +59,16 @@ window['squarereader'].startCheckout(params, () => { }); ``` +## DeAuthorize + +```ts +window['squarereader'].deauthorize(() => { +alert("Success!") +}, (err) => { +alert(err); +}); +``` + ## Taking Contactless Payments In order to take contactless and card payments, you will need to ensure that you have completed your Square POS business set up on the Square dashboard. As soon as this is complete, the Square Reader system will automatically allow contactless and card payments. diff --git a/package.json b/package.json index f70033e..b2bbdb3 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { - "name": "@moltin/cordova-plugin-square-reader", - "version": "0.2.0", + "name": "@f3/cordova-plugin-square-reader", + "version": "0.2.4", "description": "Cordova Plugin to interface with the Square Reader SDK", "cordova": { - "id": "moltin-cordova-plugin-square-reader", + "id": "f3-cordova-plugin-square-reader", "platforms": [ "android", "ios" @@ -14,7 +14,7 @@ "cordova-android", "cordova-ios" ], - "author": "Craig Tweedy", + "author": "Habib Ali", "license": "MIT", "publishConfig": { "access": "public" diff --git a/plugin.xml b/plugin.xml index c727818..6b089a3 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,20 +1,20 @@ - - MoltinCordovaSquareReader + F3CordovaSquareReader - - + + - - + + @@ -46,7 +46,7 @@ - + - \ No newline at end of file + diff --git a/src/ios/MoltinCordovaSquareReader.swift b/src/ios/F3CordovaSquareReader.swift similarity index 83% rename from src/ios/MoltinCordovaSquareReader.swift rename to src/ios/F3CordovaSquareReader.swift index 4429d3a..2d66097 100644 --- a/src/ios/MoltinCordovaSquareReader.swift +++ b/src/ios/F3CordovaSquareReader.swift @@ -2,12 +2,13 @@ import SquareReaderSDK import CoreLocation import AVKit -@objc(MoltinCordovaSquareReader) class MoltinCordovaSquareReader : CDVPlugin, SQRDCheckoutControllerDelegate, SQRDReaderSettingsControllerDelegate, CLLocationManagerDelegate { +@objc(F3CordovaSquareReader) class F3CordovaSquareReader : CDVPlugin, SQRDCheckoutControllerDelegate, SQRDReaderSettingsControllerDelegate, CLLocationManagerDelegate { private lazy var locationManager = CLLocationManager() private var currentCommand: CDVInvokedUrlCommand? private var locationPermissionCallback: ((Bool) -> ())? + @objc(setup:) func setup(command: CDVInvokedUrlCommand) { @@ -42,7 +43,14 @@ import AVKit if locationSuccess { requestMicrophonePermission() { microphoneSuccess in if microphoneSuccess { - self.commandDelegate.send(CDVPluginResult(status: CDVCommandStatus_OK), callbackId: command.callbackId) + var message = "authorized" + if SQRDReaderSDK.shared.isAuthorized{ + message = "authorized" + } + else{ + message = "not authorized" + } + self.commandDelegate.send(CDVPluginResult(status: CDVCommandStatus_OK,messageAs:message), callbackId: command.callbackId) return } else { self.commandDelegate.send(CDVPluginResult(status: CDVCommandStatus_ERROR), callbackId: command.callbackId) @@ -63,10 +71,6 @@ import AVKit } } - func retrieveAuthorizationCode(command: CDVInvokedUrlCommand) -> String { - return "sq0acp-bFfIC3wV9xKx0cAc_8aoMbMmUtb_j2BNpL2WR55sS6Y" - } - @objc(authorizeReaderSDKIfNeeded:) func authorizeReaderSDKIfNeeded(command: CDVInvokedUrlCommand) { if SQRDReaderSDK.shared.isAuthorized { @@ -96,9 +100,9 @@ import AVKit func startCheckout(command: CDVInvokedUrlCommand) { guard let commandParams = command.arguments.first as? [String: Any], - let amount = commandParams["amount"] as? Int else { - self.commandDelegate.send(CDVPluginResult(status: CDVCommandStatus_ERROR, messageAs: "No parameters"), callbackId: command.callbackId) - return + let amount = commandParams["amount"] as? Int else { + self.commandDelegate.send(CDVPluginResult(status: CDVCommandStatus_ERROR, messageAs: "No parameters"), callbackId: command.callbackId) + return } // Create an amount of money in the currency of the authorized Square account @@ -126,6 +130,17 @@ import AVKit readerSettingsController.present(from: self.viewController) } + @objc(deauthorize:) + func deauthorize(command: CDVInvokedUrlCommand) { + SQRDReaderSDK.shared.deauthorize { (error) in + if (error == nil){ + self.commandDelegate.send(CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "Success"), callbackId: command.callbackId) + } + else{ + self.commandDelegate.send(CDVPluginResult(status: CDVCommandStatus_ERROR, messageAs: error?.localizedDescription), callbackId: command.callbackId) + } + } + } @objc(checkoutControllerDidCancel:) func checkoutControllerDidCancel( @@ -155,7 +170,7 @@ import AVKit guard let currentCommand = self.currentCommand else { return } - self.commandDelegate.send(CDVPluginResult(status: CDVCommandStatus_OK), callbackId: currentCommand.callbackId) + self.commandDelegate.send(CDVPluginResult(status: CDVCommandStatus_OK, messageAs:result.transactionID), callbackId: currentCommand.callbackId) self.currentCommand = nil } diff --git a/www/F3CordovaSquareReader.js b/www/F3CordovaSquareReader.js new file mode 100644 index 0000000..b7f4a7f --- /dev/null +++ b/www/F3CordovaSquareReader.js @@ -0,0 +1,29 @@ +function F3CordovaSquareReader() { +} + +F3CordovaSquareReader.prototype.setup = function (successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, "F3CordovaSquareReader", "setup", []); +}; + +F3CordovaSquareReader.prototype.authorizeReaderSDKIfNeeded = function (params,successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, "F3CordovaSquareReader", "authorizeReaderSDKIfNeeded", [params]); +}; + +F3CordovaSquareReader.prototype.startCheckout = function (params, successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, "F3CordovaSquareReader", "startCheckout", [params]); +}; + +F3CordovaSquareReader.prototype.pairCardReaders = function (successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, "F3CordovaSquareReader", "pairCardReaders", []); +}; + +F3CordovaSquareReader.prototype.deauthorize = function (successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, "F3CordovaSquareReader", "deauthorize", []); +}; + +F3CordovaSquareReader.install = function () { + window.squarereader = new F3CordovaSquareReader(); + return window.squarereader; +}; + +cordova.addConstructor(F3CordovaSquareReader.install); diff --git a/www/MoltinCordovaSquareReader.js b/www/MoltinCordovaSquareReader.js deleted file mode 100644 index 6f661fe..0000000 --- a/www/MoltinCordovaSquareReader.js +++ /dev/null @@ -1,25 +0,0 @@ -function MoltinCordovaSquareReader() { -} - -MoltinCordovaSquareReader.prototype.setup = function (successCallback, errorCallback) { - cordova.exec(successCallback, errorCallback, "MoltinCordovaSquareReader", "setup", []); -}; - -MoltinCordovaSquareReader.prototype.authorizeReaderSDKIfNeeded = function (params, successCallback, errorCallback) { - cordova.exec(successCallback, errorCallback, "MoltinCordovaSquareReader", "authorizeReaderSDKIfNeeded", [params]); -}; - -MoltinCordovaSquareReader.prototype.startCheckout = function (params, successCallback, errorCallback) { - cordova.exec(successCallback, errorCallback, "MoltinCordovaSquareReader", "startCheckout", [params]); -}; - -MoltinCordovaSquareReader.prototype.pairCardReaders = function (successCallback, errorCallback) { - cordova.exec(successCallback, errorCallback, "MoltinCordovaSquareReader", "pairCardReaders", []); -}; - -MoltinCordovaSquareReader.install = function () { - window.squarereader = new MoltinCordovaSquareReader(); - return window.squarereader; -}; - -cordova.addConstructor(MoltinCordovaSquareReader.install);