4.1.1 • Published 2 years ago

@proteansoftware/capacitor-square v4.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

@proteansoftware/capacitor-square

Integrate with Square Payments SDK

Install

npm install @proteansoftware/capacitor-square
npx cap sync

Usage

App Initalisation - app.component.ts (Angular example)

import { App } from "@capacitor/app";
import { Platform } from "@ionic/angular";
import { CapacitorSquare } from "@proteansoftware/capacitor-square";

export class AppComponent {
  constructor(private platform: Platform) {
    this.initializeApp();
  }
  
  private void initializeApp() {
    this.platform.ready().then(() => {
      App.addListener("appUrlOpen", (data: URLOpenListenerEvent) => {
        console.log("appUrlOpen: " + data.url);

        if (data.url.toLowerCase().startsWith("app-url-scheme://callback-url")) {
          CapacitorSquare.handleIosResponse({
            url: data.url
          }).then(() => {
            console.log("handle ios callback - successful");
          }).catch(e => {
            console.error("handle ios callback - error - " + e);
          });
        }
      });
    });
  }
}

Payment flow

import { CapacitorSquare } from "@proteansoftware/capacitor-square";

//
// Initalise the square plugin
CapacitorSquare.initApp({
  applicationId: "Some square app id"
}).then(() => {
  console.log("Square payment ready");
}).catch(error => {
  console.error(error);
});

// Listen for sucessful payments
CapacitorSquare.addListener("transactionComplete", callback => {
  console.log("clientTransactionId:" + callback.clientTransactionId);
  console.log("serverTransactionId:" + callback.serverTransactionId);
});

// Listen for failed payments
CapacitorSquare.addListener("transactionFailed", callback => {
  console.error(callback.error);
});

// Initiate a transaction
CapacitorSquare.startTransaction({
  totalAmount: 100, // amount in pennies/cents
  currencyCode: "GBP", // ISO currency code, must be support by square
  allowedPaymentMethods: ["CARD"], // Sqaure TendType: https://developer.squareup.com/docs/api/point-of-sale/android/com/squareup/sdk/pos/ChargeRequest.TenderType.html
  autoReturnTimeout: 4000, // Android only - The timeout to set in milliseconds, or AutoReturn.NoTimeout. If you specify a timeout, it must be between 3200 milliseconds and 10000 milliseconds.
  skipsReceipt: false, // iOS only - No documentation available from Square
  callbackUrl: "app-url-scheme://callback-url" // see iOS setup
}).then(() => {
  console.log("transaction started");
}).catch(error => {
  console.error(error);
});

Note: autoReturnTimeout is only available on Android

Follow these setup steps from square to enable call back to your app: Square Documentation.

API

initApp(...)

initApp(options: { applicationId: string; }) => any
ParamType
options{ applicationId: string; }

Returns: any


startTransaction(...)

startTransaction(options: { totalAmount: number; currencyCode: string; allowedPaymentMethods?: string[] | null; autoReturnTimeout?: number | AutoReturn.NoTimeout | null; skipsReceipt?: boolean | null; callbackUrl?: string | null; }) => any
ParamType
options{ totalAmount: number; currencyCode: string; allowedPaymentMethods?: {} | null; autoReturnTimeout?: number | null; skipsReceipt?: boolean | null; callbackUrl?: string | null; }

Returns: any


handleIosResponse(...)

handleIosResponse(options: { url: string; }) => any
ParamType
options{ url: string; }

Returns: any


addListener(...)

addListener(eventName: 'transactionComplete', listenerFunc: TransactionCompletedListener) => Promise<PluginListenerHandle> & PluginListenerHandle
ParamType
eventName"transactionComplete"
listenerFunc(callback: { clientTransactionId: string; serverTransactionId: string; }) => void

Returns: any


addListener(...)

addListener(eventName: 'transactionFailed', listenerFunc: TransactionFailedListener) => Promise<PluginListenerHandle> & PluginListenerHandle
ParamType
eventName"transactionFailed"
listenerFunc(callback: { error: any; }) => void

Returns: any


Interfaces

PluginListenerHandle

PropType
remove() => any

Enums

AutoReturn

MembersValueDescription
NoTimeout0No timeout
Min3200Minimum timeout value (3200 milliseconds)
Max10000Maximum timeout value (10000 milliseconds)
5.0.0

2 years ago

3.4.0

3 years ago

3.4.2

3 years ago

3.4.1

3 years ago

4.0.1

3 years ago

4.0.0

3 years ago

4.1.0

3 years ago

4.1.2

3 years ago

4.1.1

3 years ago

3.2.8

3 years ago

3.2.7

3 years ago

3.3.1

3 years ago

3.3.0

3 years ago

3.3.2

3 years ago

3.2.6

4 years ago

3.2.5

4 years ago

3.2.2

4 years ago

3.2.1

4 years ago

3.2.0

4 years ago

3.2.4

4 years ago

3.2.3

4 years ago

3.1.5

4 years ago

3.1.4

4 years ago

3.1.3

4 years ago

3.1.2

4 years ago

3.1.1

4 years ago

3.1.0

4 years ago

3.0.1

4 years ago

3.0.0

5 years ago

2.0.0

5 years ago

0.0.1-alpha.29

5 years ago

0.0.1-alpha.30

5 years ago

0.0.1-alpha.31

5 years ago

0.0.1-alpha.27

5 years ago

0.0.1-alpha.28

5 years ago

0.0.1-alpha.26

5 years ago

0.0.1-alpha.25

5 years ago

0.0.1-alpha.24

5 years ago

0.0.1-alpha.23

5 years ago

0.0.1-alpha.22

5 years ago

0.0.1-alpha.21

5 years ago

0.0.1-alpha.20

5 years ago

0.0.1-alpha.19

5 years ago

0.0.1-alpha.18

5 years ago

0.0.1-alpha.17

5 years ago

0.0.1-alpha.16

5 years ago

0.0.1-alpha.15

5 years ago

0.0.1-alpha.14

5 years ago

0.0.1-alpha.13

5 years ago

0.0.1-alpha.12

5 years ago

0.0.1-alpha.11

5 years ago

0.0.1-alpha.10

5 years ago

0.0.1-alpha.9

5 years ago

0.0.1-alpha.8

5 years ago

0.0.1-alpha.7

5 years ago

0.0.1-alpha.6

5 years ago

0.0.1-alpha.5

5 years ago

0.0.1-alpha.4

5 years ago

0.0.1-alpha.3

5 years ago

0.0.1-alpha.2

5 years ago

0.0.1-alpha.1

5 years ago