Skip to content

A Dart package to help use the Square Connect API

License

Notifications You must be signed in to change notification settings

Morel-Tech/square-connect-dart

Repository files navigation

Pub GitHub PRs Welcome

Dart Client for Square APIs

This package allows Dart developers to easily interact with Square APIs.

NOTE!

Due to the way Square authenticates it's API, DO NOT use this package in Flutter apps unless using the PKCE authentication flow.

Supported APIs

API Support Level
Payments ⏳ Partially Supported
Refunds ❌ Not Yet Supported
Disputes ❌ Not Yet Supported
Checkout ⏳ Partially Supported
Apple Pay ❌ Not Yet Supported
Cards ⏳ Partially Supported
Payouts ❌ Not Yet Supported
Terminal ❌ Not Yet Supported
Orders ✅ Fully Supported
Order Custom Attributes ❌ Not Yet Supported
Subscriptions ✅ Fully Supported
Catalog ⏳ Partially Supported
Inventory ❌ Not Yet Supported
Customers ✅ Fully Supported
Customer Custom Attributes ❌ Not Yet Supported
Customer Groups ❌ Not Yet Supported
Customer Segments ❌ Not Yet Supported
Loyalty ✅ Fully Supported
Gift Cards ✅ Fully Supported
Gift Card Activities ✅ Fully Supported
Bookings ❌ Not Yet Supported
Booking Custom Attributes ❌ Not Yet Supported
Merchants ✅ Fully Supported
Locations ✅ Fully Supported
Location Custom Attributes ❌ Not Yet Supported
Devices ❌ Not Yet Supported
Cash Drawers ❌ Not Yet Supported
Vendors ❌ Not Yet Supported
Team ⏳ Partially Supported
Labor ❌ Not Yet Supported
Bank Accounts ❌ Not Yet Supported
Sites ❌ Not Yet Supported
Snippets ❌ Not Yet Supported
OAuth ✅ Fully Supported
Mobile Authorization ❌ Not Yet Supported
Webhook Subscriptions ❌ Not Yet Supported

Usage

  1. Create Square API Client.
final client = SquareApiClient(
  accessToken: 'ACCESS_TOKEN', // Make SURE this is kept secret
  apiVersion: '2021-09-15', // Optional. If omitted latest api will be used.
);
  1. Call Square APIs.
final locations = await client.listLocations();

Errors

Instead of throwing errors caused by Square's API, methods return a list of errors returned by Square's API. To check if errors were thrown, you can call .hasErrors on the Response object, or simply check if the errors property is null.

Example

import 'package:square_connect/square_connect.dart';

async listCustomers() {
  String response = await CustomBackend.listCustomers();

  var responseObj = ListCustomersResponse.fromJson(json.decode(response));

  if (responseObj.hasErrors) {
    throw new Error(responseObj.errors)
  } else {
    return responseObj.customers;
  }
}

Pagination

If pagination is supported/needed, the response object will contain a cursor string returned by Square's API. To retrieve it, you can call response.cursor. If the field is null, then no cursor exists and there are no more items to be returned. If it was not null, you can pass it into another call of the specific method.

Contributions

If you have any feedback on how to improve the package for usability, or bugs to report, please do so at https://github.com/morel-tech/square-connect-dart/issues.

Using Mason

This package uses mason to generate new files. Run the appropriate command depending on what you want to generate, and be sure to append to the appropriate barrel file when prompted.

Shared Model

mason make shared_object

Functions Model

mason make function_object

Webhook Model

mason make webhook_event

Releases

No releases published

Languages