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

Merge request for some added features. #14

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 6 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```

Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.proteansoftware.capacitor.square;
package com.dolaned.capacitor.square;

import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -57,13 +57,23 @@ public Intent createChargeIntent(
Integer totalAmount,
CurrencyCode currencyCode,
ArrayList<ChargeRequest.TenderType> 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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.proteansoftware.capacitor.square;
package com.dolaned.capacitor.square;

import android.app.Activity;
import android.content.ActivityNotFoundException;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -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();
}
Expand Down
15 changes: 13 additions & 2 deletions ios/Plugin/CapacitorSquarePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
Loading