Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is this package up to date, and would you like to collab on making it work for android? #9

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand All @@ -22,11 +22,7 @@ Set up the Square Reader SDK

```ts
window['squarereader'].setup(() => {
let params = {
"authCode": "<YOUR AUTH CODE>"
};

window['squarereader'].authorizeReaderSDKIfNeeded(params, () => {
window['squarereader'].authorizeReaderSDKIfNeeded(() => {
alert("Authorised!")
},
(err) => {
Expand All @@ -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
Expand All @@ -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.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -14,7 +14,7 @@
"cordova-android",
"cordova-ios"
],
"author": "Craig Tweedy",
"author": "Habib Ali",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand Down
16 changes: 8 additions & 8 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?xml version='1.0' encoding='utf-8'?>
<plugin id="moltin-cordova-plugin-square-reader" version="0.0.1"
<plugin id="f3-cordova-plugin-square-reader" version="0.0.5"
xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android">

<name>MoltinCordovaSquareReader</name>
<name>F3CordovaSquareReader</name>

<dependency id="cordova-plugin-add-swift-support" version="1.7.2"/>

<js-module name="MoltinCordovaSquareReader" src="www/MoltinCordovaSquareReader.js">
<clobbers target="MoltinCordovaSquareReader" />
<js-module name="F3CordovaSquareReader" src="www/F3CordovaSquareReader.js">
<clobbers target="F3CordovaSquareReader" />
</js-module>

<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="MoltinCordovaSquareReader">
<param name="ios-package" value="MoltinCordovaSquareReader" />
<feature name="F3CordovaSquareReader">
<param name="ios-package" value="F3CordovaSquareReader" />
</feature>
</config-file>

Expand Down Expand Up @@ -46,7 +46,7 @@
</array>
</config-file>

<source-file src="src/ios/MoltinCordovaSquareReader.swift" />
<source-file src="src/ios/F3CordovaSquareReader.swift" />
</platform>

</plugin>
</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
}

Expand Down
29 changes: 29 additions & 0 deletions www/F3CordovaSquareReader.js
Original file line number Diff line number Diff line change
@@ -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);
25 changes: 0 additions & 25 deletions www/MoltinCordovaSquareReader.js

This file was deleted.