diff --git a/ProteansoftwareCapacitorSquare.podspec b/DolanedCapacitorSquare.podspec similarity index 92% rename from ProteansoftwareCapacitorSquare.podspec rename to DolanedCapacitorSquare.podspec index 3645396..2bf2f2e 100644 --- a/ProteansoftwareCapacitorSquare.podspec +++ b/DolanedCapacitorSquare.podspec @@ -3,7 +3,7 @@ require 'json' package = JSON.parse(File.read(File.join(__dir__, 'package.json'))) Pod::Spec.new do |s| - s.name = 'ProteansoftwareCapacitorSquare' + s.name = 'DolanedCapacitorSquare' s.version = package['version'] s.summary = package['description'] s.license = package['license'] diff --git a/LICENSE b/LICENSE index 14a5b46..5f771a0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Protean Software +Copyright (c) 2023 Dolaned Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 597af1a..ad3a310 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,16 @@ -# @proteansoftware/capacitor-square +# @dolaned/capacitor-square Integrate with Square Payments SDK | Package Version | Capacitor Version | |-----------------|-------------------| -| 4.X | 4.X | -| 3.X | 3.X | +| 1.X | 5.X | ## Install -Version 4.X is compatible with Capacitor 4.X +Version 1.X is compatible with Capacitor 5.X ```bash -npm install @proteansoftware/capacitor-square@V4 -npx cap sync -``` - -Version 3.X is compatible with Capacitor 3.X -```bash -npm install @proteansoftware/capacitor-square@V3 +npm install @dolaned/capacitor-square npx cap sync ``` @@ -28,7 +21,7 @@ App Initalisation - app.component.ts (Angular example) ```ts import { App } from "@capacitor/app"; import { Platform } from "@ionic/angular"; -import { CapacitorSquare } from "@proteansoftware/capacitor-square"; +import { CapacitorSquare } from "@dolaned/capacitor-square"; export class AppComponent { constructor(private platform: Platform) { @@ -57,7 +50,7 @@ export class AppComponent { Payment flow ```ts -import { CapacitorSquare } from "@proteansoftware/capacitor-square"; +import { CapacitorSquare } from "@dolaned/capacitor-square"; // // Initalise the square plugin diff --git a/android/build.gradle b/android/build.gradle index 9347e9b..f64abc4 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -18,7 +18,7 @@ buildscript { apply plugin: 'com.android.library' android { - namespace "com.proteansoftware.capacitor.square" + namespace "com.dolaned.capacitor.square" compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 33 defaultConfig { minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22 diff --git a/android/src/main/java/com/proteansoftware/capacitor/square/CapacitorSquare.java b/android/src/main/java/com/dolaned/capacitor/square/CapacitorSquare.java similarity index 89% rename from android/src/main/java/com/proteansoftware/capacitor/square/CapacitorSquare.java rename to android/src/main/java/com/dolaned/capacitor/square/CapacitorSquare.java index d53466a..f3d6925 100644 --- a/android/src/main/java/com/proteansoftware/capacitor/square/CapacitorSquare.java +++ b/android/src/main/java/com/dolaned/capacitor/square/CapacitorSquare.java @@ -1,4 +1,4 @@ -package com.proteansoftware.capacitor.square; +package com.dolaned.capacitor.square; import android.content.Context; import android.content.Intent; @@ -57,13 +57,23 @@ public Intent createChargeIntent( Integer totalAmount, CurrencyCode currencyCode, ArrayList restrictPaymentMethods, - @Nullable Integer autoReturnTimeout) { + @Nullable Integer autoReturnTimeout, + @Nullable String locationId, + @Nullable String note) { ChargeRequest.Builder request = new ChargeRequest.Builder(totalAmount, currencyCode); if (!restrictPaymentMethods.isEmpty()) { request.restrictTendersTo(restrictPaymentMethods); } + if(locationId != null) { + request.enforceBusinessLocation(locationId); + } + + if(note != null) { + request.note(note); + } + if (autoReturnTimeout != null) { request.autoReturn(autoReturnTimeout, autoReturnTimeout.equals(PosApi.AUTO_RETURN_NO_TIMEOUT) ? null : TimeUnit.MILLISECONDS); } diff --git a/android/src/main/java/com/proteansoftware/capacitor/square/CapacitorSquarePlugin.java b/android/src/main/java/com/dolaned/capacitor/square/CapacitorSquarePlugin.java similarity index 84% rename from android/src/main/java/com/proteansoftware/capacitor/square/CapacitorSquarePlugin.java rename to android/src/main/java/com/dolaned/capacitor/square/CapacitorSquarePlugin.java index 3966d18..182b4b1 100644 --- a/android/src/main/java/com/proteansoftware/capacitor/square/CapacitorSquarePlugin.java +++ b/android/src/main/java/com/dolaned/capacitor/square/CapacitorSquarePlugin.java @@ -1,4 +1,4 @@ -package com.proteansoftware.capacitor.square; +package com.dolaned.capacitor.square; import android.app.Activity; import android.content.ActivityNotFoundException; @@ -68,6 +68,12 @@ public void startTransaction(PluginCall call) { return; } + String note = call.getString("note"); + if (note != null && note.length() >= 500) { + call.reject("Note is too long."); + return; + } + CurrencyCode currencyCode = implementation.parseCurrencyCode(currencyCodeString); if (currencyCode == null) { call.reject("currencyCode '" + currencyCodeString + "' is invalid"); @@ -111,12 +117,16 @@ public void startTransaction(PluginCall call) { return; } + String locationId = call.getString("locationId"); + try { Intent intent = implementation.createChargeIntent( totalAmount, currencyCode, restrictPaymentMethods, - autoReturnTimeout); + autoReturnTimeout, + locationId, + note); startActivityForResult(call, intent, "chargeRequest"); } catch (ActivityNotFoundException e) { implementation.openPointOfSalePlayStoreListing(); @@ -133,7 +143,9 @@ protected void chargeRequest(PluginCall call, ActivityResult result) { JSObject errorObject = new JSObject(); try { if (call == null) { - errorObject.put("error", "could not retrieve saved call"); + errorObject.put("status", "error"); + errorObject.put("error_code", "NO_SAVED_CALL"); + errorObject.put("errorDebugDescription", "could not retrieve saved call"); notifyListeners("transactionFailed", errorObject); return; } @@ -144,7 +156,7 @@ protected void chargeRequest(PluginCall call, ActivityResult result) { Intent data = result.getData(); ChargeRequest.Success success = implementation.parseChargeSuccess(data); JSObject resultData = new JSObject(); - resultData.put("message", "Success"); + resultData.put("status", "ok"); resultData.put("clientTransactionId", success.clientTransactionId); resultData.put("serverTransactionId", success.serverTransactionId); notifyListeners("transactionComplete", resultData); @@ -153,13 +165,16 @@ protected void chargeRequest(PluginCall call, ActivityResult result) { // Handle expected errors Intent data = result.getData(); ChargeRequest.Error error = implementation.parseChargeError(data); - String errorMessage = "Error" + error.code + "\nclientTransactionId" + error.debugDescription; - errorObject.put("error", errorMessage); + errorObject.put("status", "error"); + errorObject.put("error_code", error.code); + errorObject.put("errorDebugDescription", error.debugDescription); notifyListeners("transactionFailed", errorObject); call.resolve(); } } catch (Exception e) { - errorObject.put("error", e.getMessage()); + errorObject.put("status", "error"); + errorObject.put("error_code", "EXCEPTION_ERROR"); + errorObject.put("errorDebugDescription", e.getMessage()); notifyListeners("transactionFailed", errorObject); call.resolve(); } diff --git a/ios/Plugin/CapacitorSquarePlugin.swift b/ios/Plugin/CapacitorSquarePlugin.swift index 3dd1f1c..af0af03 100644 --- a/ios/Plugin/CapacitorSquarePlugin.swift +++ b/ios/Plugin/CapacitorSquarePlugin.swift @@ -44,6 +44,17 @@ public class CapacitorSquarePlugin: CAPPlugin { return; } + //add optional location id + let locationId = call.getString("locationId") ?? nil; + + // handle a note + let note = call.getString("note") ?? ""; + if(note.count >= 500) { + call.reject("Note is too long"); + return; + } + + let yourCallbackURL = URL(string: callbackUrl)! // Specify the amount of money to charge. @@ -86,8 +97,8 @@ public class CapacitorSquarePlugin: CAPPlugin { request = try SCCAPIRequest(callbackURL: yourCallbackURL, amount: amount, userInfoString: nil, - locationID: nil, - notes: nil, + locationID: locationId, + notes: note, customerID: nil, supportedTenderTypes: supportedTenderTypes, clearsDefaultFees: false, diff --git a/package.json b/package.json index 9a8822a..50f826f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "@proteansoftware/capacitor-square", - "version": "5.0.0", - "description": "Integrate with Square Payments SDK", + "name": "@dolaned/capacitor-square", + "version": "1.1.0", + "description": "Integrate with Square Payments SDK for capacitor", "main": "dist/plugin.cjs.js", "module": "dist/esm/index.js", "types": "dist/esm/index.d.ts", @@ -11,16 +11,19 @@ "android/build.gradle", "dist/", "ios/Plugin/", - "ProteansoftwareCapacitorSquare.podspec" + "DolanedCapacitorSquare.podspec" ], - "author": "Ashley Medway", + "contributors": [ + "Ashley Medway (https://github.com/AshleyMedway)" + ], + "author": "Dylan Aird", "license": "MIT", "repository": { "type": "git", - "url": "git+https://github.com/ProteanSoftware/capacitor-square.git" + "url": "git+https://github.com/dolaned/capacitor-square.git" }, "bugs": { - "url": "https://github.com/ProteanSoftware/capacitor-square/issues" + "url": "https://github.com/dolaned/capacitor-square/issues" }, "keywords": [ "capacitor", @@ -74,5 +77,203 @@ "android": { "src": "android" } + }, + "homepage": "https://github.com/dolaned/capacitor-square#readme", + "dependencies": { + "acorn": "^7.4.1", + "acorn-jsx": "^5.3.2", + "ajv": "^6.12.6", + "ansi-colors": "^4.1.1", + "ansi-regex": "^5.0.1", + "ansi-styles": "^4.3.0", + "argparse": "^1.0.10", + "array-includes": "^3.1.3", + "array-union": "^2.1.0", + "array.prototype.flat": "^1.2.4", + "astral-regex": "^2.0.0", + "at-least-node": "^1.0.0", + "balanced-match": "^1.0.2", + "brace-expansion": "^1.1.11", + "braces": "^3.0.2", + "call-bind": "^1.0.2", + "callsites": "^3.1.0", + "chalk": "^4.1.1", + "chevrotain": "^6.5.0", + "color-convert": "^2.0.1", + "color-name": "^1.1.4", + "colorette": "^1.2.2", + "concat-map": "^0.0.1", + "cosmiconfig": "^6.0.0", + "cross-spawn": "^7.0.3", + "debug": "^4.3.2", + "deep-is": "^0.1.3", + "define-properties": "^1.1.3", + "dir-glob": "^3.0.1", + "doctrine": "^3.0.0", + "emoji-regex": "^6.1.1", + "enquirer": "^2.3.6", + "error-ex": "^1.3.2", + "es-abstract": "^1.18.3", + "es-to-primitive": "^1.2.1", + "escape-string-regexp": "^4.0.0", + "eslint-config-prettier": "^6.15.0", + "eslint-import-resolver-node": "^0.3.4", + "eslint-module-utils": "^2.6.1", + "eslint-plugin-import": "^2.23.4", + "eslint-scope": "^5.1.1", + "eslint-utils": "^3.0.0", + "eslint-visitor-keys": "^2.1.0", + "espree": "^7.3.1", + "esprima": "^4.0.1", + "esquery": "^1.4.0", + "esrecurse": "^4.3.0", + "estraverse": "^4.3.0", + "esutils": "^2.0.3", + "fast-deep-equal": "^3.1.3", + "fast-glob": "^3.2.7", + "fast-json-stable-stringify": "^2.1.0", + "fast-levenshtein": "^2.0.6", + "fastq": "^1.11.1", + "file-entry-cache": "^6.0.1", + "fill-range": "^7.0.1", + "find-up": "^2.1.0", + "flat-cache": "^3.0.4", + "flatted": "^3.2.1", + "fs-extra": "^9.1.0", + "fs.realpath": "^1.0.0", + "function-bind": "^1.1.1", + "functional-red-black-tree": "^1.0.1", + "get-intrinsic": "^1.1.1", + "get-stdin": "^6.0.0", + "github-slugger": "^1.3.0", + "glob": "^7.1.7", + "glob-parent": "^5.1.2", + "globals": "^13.10.0", + "globby": "^11.0.4", + "graceful-fs": "^4.2.6", + "has": "^1.0.3", + "has-bigints": "^1.0.1", + "has-flag": "^4.0.0", + "has-symbols": "^1.0.2", + "hosted-git-info": "^2.8.9", + "ignore": "^4.0.6", + "import-fresh": "^3.3.0", + "imurmurhash": "^0.1.4", + "inflight": "^1.0.6", + "inherits": "^2.0.4", + "is-arrayish": "^0.2.1", + "is-bigint": "^1.0.2", + "is-boolean-object": "^1.1.1", + "is-callable": "^1.2.3", + "is-core-module": "^2.5.0", + "is-date-object": "^1.0.4", + "is-extglob": "^2.1.1", + "is-fullwidth-code-point": "^3.0.0", + "is-glob": "^4.0.1", + "is-negative-zero": "^2.0.1", + "is-number": "^7.0.0", + "is-number-object": "^1.0.5", + "is-regex": "^1.1.3", + "is-string": "^1.0.6", + "is-symbol": "^1.0.4", + "isexe": "^2.0.0", + "java-parser": "^1.0.2", + "js-tokens": "^4.0.0", + "js-yaml": "^3.14.1", + "json-parse-better-errors": "^1.0.2", + "json-parse-even-better-errors": "^2.3.1", + "json-schema-traverse": "^0.4.1", + "json-stable-stringify-without-jsonify": "^1.0.1", + "json5": "^2.2.0", + "jsonfile": "^6.1.0", + "levn": "^0.4.1", + "lines-and-columns": "^1.1.6", + "load-json-file": "^4.0.0", + "locate-path": "^2.0.0", + "lodash": "^4.17.21", + "lodash.clonedeep": "^4.5.0", + "lodash.merge": "^4.6.2", + "lodash.truncate": "^4.4.2", + "lru-cache": "^6.0.0", + "merge2": "^1.4.1", + "micromatch": "^4.0.4", + "minimatch": "^3.0.4", + "minimist": "^1.2.6", + "ms": "^2.1.2", + "natural-compare": "^1.4.0", + "normalize-package-data": "^2.5.0", + "object-inspect": "^1.11.0", + "object-keys": "^1.1.1", + "object.assign": "^4.1.2", + "object.values": "^1.1.4", + "once": "^1.4.0", + "optionator": "^0.9.1", + "p-limit": "^1.3.0", + "p-locate": "^2.0.0", + "p-try": "^1.0.0", + "parent-module": "^1.0.1", + "parse-json": "^4.0.0", + "path-exists": "^3.0.0", + "path-is-absolute": "^1.0.1", + "path-key": "^3.1.1", + "path-parse": "^1.0.7", + "path-type": "^4.0.0", + "picomatch": "^2.3.0", + "pify": "^3.0.0", + "pkg-dir": "^2.0.0", + "pkg-up": "^2.0.0", + "prelude-ls": "^1.2.1", + "progress": "^2.0.3", + "punycode": "^2.1.1", + "queue-microtask": "^1.2.3", + "read-pkg": "^3.0.0", + "read-pkg-up": "^3.0.0", + "regexp-to-ast": "^0.4.0", + "regexpp": "^3.2.0", + "require-from-string": "^2.0.2", + "resolve": "^1.20.0", + "resolve-from": "^4.0.0", + "reusify": "^1.0.4", + "run-parallel": "^1.2.0", + "semver": "^7.3.5", + "shebang-command": "^2.0.0", + "shebang-regex": "^3.0.0", + "signal-exit": "^3.0.3", + "slash": "^3.0.0", + "slice-ansi": "^4.0.0", + "spdx-correct": "^3.1.1", + "spdx-exceptions": "^2.3.0", + "spdx-expression-parse": "^3.0.1", + "spdx-license-ids": "^3.0.9", + "sprintf-js": "^1.0.3", + "string-width": "^4.2.2", + "string.prototype.trimend": "^1.0.4", + "string.prototype.trimstart": "^1.0.4", + "strip-ansi": "^6.0.0", + "strip-bom": "^3.0.0", + "strip-json-comments": "^3.1.1", + "supports-color": "^7.2.0", + "table": "^6.7.1", + "text-table": "^0.2.0", + "to-regex-range": "^5.0.1", + "tree-kill": "^1.2.2", + "tsconfig-paths": "^3.10.1", + "tslib": "^2.3.0", + "tsutils": "^3.21.0", + "type-check": "^0.4.0", + "type-fest": "^0.20.2", + "unbox-primitive": "^1.0.1", + "universalify": "^2.0.0", + "untildify": "^4.0.0", + "uri-js": "^4.4.1", + "v8-compile-cache": "^2.3.0", + "validate-npm-package-license": "^3.0.4", + "which": "^2.0.2", + "which-boxed-primitive": "^1.0.2", + "word-wrap": "^1.2.3", + "wrap-ansi": "^7.0.0", + "wrappy": "^1.0.2", + "yallist": "^4.0.0", + "yaml": "^1.10.2" } }