Class SquareTerminal

java.lang.Object
com.codename1.payment.terminal.PaymentTerminal
com.codename1.payment.terminal.square.SquareTerminal

public class SquareTerminal extends PaymentTerminal

A Square Terminal, driven through Square's Terminal API.

Each sale creates a terminal checkout for the paired device and polls it until the customer has paid or it is canceled. It is plain HTTPS and JSON, so it works on every platform with no native SDK.

Credentials

Square's API takes an access token, which must not ship in an app a customer can install. On a till you control, use a token limited to the PAYMENTS_WRITE and PAYMENTS_READ permissions. Otherwise point setApiBase(String) at your own server, which adds the token and forwards the same paths to Square.

String accessToken = null; // null: your server adds the token
SquareTerminal terminal = new SquareTerminal("121CS145A5000029", accessToken);
terminal.collect(new TerminalPaymentRequest(1250, "USD").setReference("order-7"))
        .ready(result -> System.out.println(result));
What it does
  • Sales, with tipping on the device when the request asks for it.
  • Pre-authorizations (the checkout does not complete the payment), then capture(String, long, String) completes it -- at the authorized amount, which Square cannot lower on completion.
  • reverse(String) cancels a payment that is not completed yet.
  • refund(TerminalRefundRequest) refunds a payment by its ID; Square needs no card for it, and refunds no card that is not linked to one.
  • lookup(String) reads a payment by its ID.

Every request that moves money carries an idempotency key and is repeated with the same key when its answer is lost, so a retry can never charge twice. Starts against Square's sandbox; call setLive(boolean) for production.