npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

square-wrapi

v0.2.0

Published

Wrapper for Square Connect REST API

Downloads

9

Readme

Square Connect API Wrapper ▣

Client interface for accessing Square Connect API.

NPM version

Update

This is a breaking change.

Applications created after February 16, 2016 will not be able to use the merchant methods. Instead, use business methods. For older apps use version 0.1.0. More info.: https://docs.connect.squareup.com/articles/connect-api-changes-2016-02/

Usage

Create a client object to connect to Square Connect API endpoints.

var squareWrapi = require('square-wrapi');

var client = new squareWrapi('v1', API_ACCESS_TOKEN);

A note about LOCATION_ID:

Most endpoint paths include a location_id parameter that indicates which of a business's locations your application is acting on behalf of. You can get a business's location IDs with the business.locations() endpoint method.

There are two ways to use the API (use #1 or #2 - not both):

  1. For a specific location.

If you have the location id, create the client object with the location id.

var client = new squareWrapi('v1', API_ACCESS_TOKEN, LOCATION_ID);

square-wrapi will use this location id. on calls that require location id and you do not have to provide it on each call.

  1. For all locations.

Create the client object without location id.

var client = new squareWrapi('v1', API_ACCESS_TOKEN);

Provide location_id as the first parameter to all the calls that require location id.

Once you have the client object, you are ready to make API calls to Square.

Provide parameters and a callback.

API calls follow this syntax:

client.apigroup.action(param1, ..., queryString, callback);

  • param - (if required) url parameters - eg: For payments.retrieve the value for :payment_id. Provide location_id if you created the client without LOCATION_ID.
  • queryString - (as required) API endpoint parameters as key-value pairs.

Examples

List Payments

client.payments.list({
    "begin_time": "2015-12-01T00:00:00Z",
    "end_time": "2015-12-31T00:00:00Z"
  },
  function(err, data) {
    if (!err) {
      console.log(data);
    } 
  }
);

// Or with location_id
client.payments.list('JGHJ0343', {
    "begin_time": "2015-12-01T00:00:00Z",
    "end_time": "2015-12-31T00:00:00Z"
  },
  function(err, data) {
    if (!err) {
      console.log(data);
    } 
  }
);

Fetch Single Payment

client.payments.retrieve('Jq74mCczmFXk1tC10GB', function(err, data) {
  if (!err) {
    console.log(data);
  } 
});

Create a Refund

client.refunds.create({
    "payment_id": "Jq74mCczmFXk1tC10GB",
    "type": "PARTIAL",
    "reason": "Returned Goods",
    "refunded_money": {
      "amount": -500,
      "currency_code": "USD"
    },
    "request_idempotence_key": "1"
  }, 
  function(err, data) {
    if (!err) {
      console.log(data);
    } 
  }
);

Update an item

client.items.update("442d1344-6d2b-4238-83d0-0284dfd335d8", {
    "name": "Milkshake",
    "description": "It's better than yours",
    "visibility": "PRIVATE"
  },
  function(err, data) {
    if (!err) {
      console.log(data);
    } 
  }
);

Upload Item Image

client.items.uploadImage(
  {
    formData: {
      custom_file: {
        value:  fs.createReadStream('/path/to/MyImage.png.png'),
        options: {
          filename: 'MyImage.png',
          contentType: 'image/png'
        }
      }
    }
  }, 
  function(err, data) {
    if (!err) {
      console.log(data);
    } 
  }
);

Deletes an existing fee (tax).

client.fees.del(FEE_ID, function(err, data) {
  if (!err) {
    console.log(data);
  } 
});

// or with location_id
client.fees.del(LOCATION_ID, FEE_ID, function(err, data) {
  if (!err) {
    console.log(data);
  } 
});

Removes a fee assocation from an item.

client.fees.remove(ITEM_ID, FEE_ID, function(err, data) {
  if (!err) {
    console.log(data);
  } 
});

// or with location_id
client.fees.remove(LOCATION_ID, ITEM_ID, FEE_ID, function(err, data) {
  if (!err) {
    console.log(data);
  } 
});

API Functions

Business Management

Business & Locations

Employees

Roles

Timecards

Cash Drawer Shifts

Transaction Management

Payments

Settlements

Refunds

Orders

Merchant (Deprecated)

Bank Accounts

Item Management

Items

Variations

Inventory

Modifier Lists

Modifier Options

Categories

Discounts

Fees

Pages

Cells

License

MIT