# gocommerce-js

> GoCommerce API client for JavaScript

Latest version **5.0.0** (published 2019-09-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install gocommerce-js
pnpm add gocommerce-js
yarn add gocommerce-js
bun add gocommerce-js
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.0.0 |
| Published | 2019-09-16 |
| First published | 2016-07-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 64.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 131 |
| Author | Mathias Biilmann Christensen |
| Maintainers | benaiah, biilmann, calavera, davidwells, erquhart, imorente, lunathecat, marcus.netlify, netlibot, raeesbhatti, shortdiv, sw-yx |
| Keywords | api, cli, commerce, netlify, static |

## Links

- npm: https://www.npmjs.com/package/gocommerce-js
- Repository: https://github.com/netlify/gocommerce-js
- Issues: https://github.com/netlify/gocommerce-js/issues
- npm.io page: https://npm.io/package/gocommerce-js

## Dependencies (1)

- [micro-api-client](https://npm.io/package/micro-api-client.md) ^2.0.0

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 5.0.0 (latest) — 2019-09-16
- 4.4.4-beta1 (next) — 2019-09-12
- 4.4.3 — 2019-09-10
- 4.4.2 — 2019-03-27
- 4.4.1 — 2018-12-14
- 4.4.0 — 2018-12-12
- 4.3.0 — 2018-12-10
- 4.2.0 — 2018-11-14
- 4.1.5 — 2018-06-13
- 4.1.4 — 2017-11-27
- 4.1.3 — 2017-11-18
- 4.1.2 — 2017-11-08
- 4.1.1 — 2017-10-09
- 4.1.0 — 2017-10-09
- 3.10.1 — 2017-10-09
- … 18 more at https://npm.io/package/gocommerce-js/versions

## README

# GoCommerce JS

This is a JS client library for [GoCommerce](https://github.com/netlify/gocommerce) API.

It handles orders and payments. Integrates with Stripe for payments and will support international pricing and VAT verification.

## Usage

```js
import GoCommerce from "gocommerce-js";

const commerce = new GoCommerce({
  APIUrl: "https://commerce.netlify.com"
});

commerce.addToCart({
	path: "/products/book-1/",
	quantity: 2,
	meta: {
    // You can add anything in metadata and use it in your checkout ui
		photo: "/images/mugs/netlig-01.png"
	}
}).then((lineItem) => console.log(lineItem));

console.log(commerce.getCart());
/*
{
  items: [{
  	title: "Netlify Mug",
  	sku: "netlify-mug-01",
  	description: "A mug with a netlify sticker!",
  	price: {amount: "49.00", "currency": "USD", cents: 4900},
    tax: {amount: "0.00", currency: "USD", cents: 0},
  	quantity: 2,
  	metadata: {
  		photo: "/images/mugs/netlig-01.png" // You can add anything in metadata
  	}
  }],
  subtotal: {amount: "98.00", "currency": "USD", cents: 9800},
  taxes: {amount: "0.00", "currency": "USD", cents: 0},
  total: {amount: "98.00", "currency": "USD", cents: 9800}
}
*/

commerce.updateCart("netlify-mug-01", 3); // Set to 0 to remove

commerce.order({
  email: "matt@netlify.com",
  shipping_address: {
    name: "Matt Biilmann",
    company: "netlify", // Optional
    address1: "610 22nd Street",
    city: "San Francisco",
    state: "CA",
    country: "USA",
    zip: "94107"
  }
  /* You can optionally specify billing_address as well */
}).then(({cart, order}) => {
  return commerce.payment({
    // Get a token from Stripes button or a custom integration
    "provider": "stripe",
    "stripe_token": TOKEN_FROM_STRIPE_CC_FORM,
    // The commerce API will verify that the amount and order ID match
    "amount": cart.total.cents,
    "order_id": order.id,
  })
}).then((transaction) => {
  console.log("Order confirmed!")
});

commerce.clearCart(); // Will be called automatically after a successful order
```

You can change country (for VAT calculations) or currency at any time:

```js
commerce.setCountry("USA");
commerce.setCurrency("USD");
```

You can use GoCommerce JS together with [GoTrue](https://github.com/netlify/gotrue) to let users log in and claim view order history.

```js
goTrue.login(email, password).then((user) => {
  commerce.setUser(user);

  commerce.order({
    email: user.email,
    shipping_address_id: "some-previously-generated-address"
    /* Normal order details */
  });

  commerce.orderHistory().then((orders) => {
    console.log(orders);
  });
});
```

---
_Source: https://npm.io/package/gocommerce-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
