Skip to content
This repository was archived by the owner on Sep 8, 2021. It is now read-only.

Commit 0af96c5

Browse files
committed
Change name according to Netlify Commerce guidelines.
Signed-off-by: David Calavera <david.calavera@gmail.com>
1 parent e6e110a commit 0af96c5

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

README.md

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
# Gocommerce JS Client
1+
# Netlify Commerce JS
22

3-
This is a JS library for the [Gocommerce](https://github.com/netlify/gocommerce) API.
3+
This is a JS client library for [Netlify Commerce](https://github.com/netlify/netlify-commerce) API.
44

55
It lets you signup and authenticate users and is a building block for constructing
66
the UI for signups, password recovery, login and logout.
77

88
## Usage
99

1010
```js
11-
import Gocommerce from `gocommerce-js`;
11+
import NetlifyCommerce from `netlify-commerce-js`;
1212

13-
const gocommerce = new Gocommerce({
14-
APIUrl: "https://gocommerce.netlify.com"
13+
const commerce = new NetlifyCommerce({
14+
APIUrl: "https://commerce.netlify.com"
1515
});
1616

17-
gocommerce.addToCart({
17+
commerce.addToCart({
1818
path: '/producs/book-1/',
1919
quantity: 2,
2020
meta: {
@@ -23,7 +23,7 @@ gocommerce.addToCart({
2323
}
2424
}).then((lineItem) => console.log(lineItem));
2525

26-
console.log(gocommerce.getCart());
26+
console.log(commerce.getCart());
2727
/*
2828
{
2929
items: [{
@@ -43,9 +43,9 @@ console.log(gocommerce.getCart());
4343
}
4444
*/
4545

46-
gocommerce.updateCard("netlify-mug-01", 3); // Set to 0 to remove
46+
commerce.updateCard("netlify-mug-01", 3); // Set to 0 to remove
4747

48-
gocommerce.order({
48+
commerce.order({
4949
email: "matt@netlify.com",
5050
shipping_address: {
5151
first_name: "Matt",
@@ -59,40 +59,40 @@ gocommerce.order({
5959
}
6060
/* You can optionally specify billing_address as well */
6161
}).then(({cart, order}) => {
62-
return gocommerce.payment({
62+
return commerce.payment({
6363
// Get a token from Stripes button or a custom integration
6464
"stripe_token": TOKEN_FROM_STRIPE_CC_FORM,
65-
// The gocommerce API will verify that the amount and order ID match
65+
// The commerce API will verify that the amount and order ID match
6666
"amount": cart.total.cents,
6767
"order_id": order.id,
6868
})
6969
}).then((transaction) => {
7070
console.log("Order confirmed!")
7171
});
7272

73-
gocommerce.clearCart(); // Will be called automatically after a successful order
73+
commerce.clearCart(); // Will be called automatically after a successful order
7474
```
7575

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

7878
```
79-
gocommerce.setCountry("USA");
80-
gocommerce.setCurrency("USD");
79+
commerce.setCountry("USA");
80+
commerce.setCurrency("USD");
8181
```
8282

83-
You can use `gocommerce` together with [authlify](https://github.com/netlify/authlify) to let users log in and claim view order history.
83+
You can use Netlify Commerce JS together with [authlify](https://github.com/netlify/authlify) to let users log in and claim view order history.
8484

8585
```js
8686
authlify.login(email, password).then((user) => {
87-
gocommerce.setUser(user);
87+
commerce.setUser(user);
8888

89-
gocommerce.order({
89+
commerce.order({
9090
email: user.email,
9191
shipping_address_id: "some-previously-generated-address"
9292
/* Normal order details */
9393
});
9494

95-
gocommerce.orderHistory().then((orders) => {
95+
commerce.orderHistory().then((orders) => {
9696
console.log(orders);
9797
});
9898
});

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"name": "gocommerce-js",
2+
"name": "netlify-commerce-js",
33
"version": "1.1.1",
4-
"description": "Gocommerce API client for JavaScript",
4+
"description": "Netlify Commerce API client for JavaScript",
55
"main": "lib/index.js",
66
"scripts": {
77
"compile": "babel --presets es2015 --plugins syntax-object-rest-spread,transform-object-rest-spread -d lib/ src/",
88
"prepublish": "npm run compile",
9-
"babelify": "browserify src/index.js -t [ babelify --presets [ es2015 ] --plugins syntax-object-rest-spread,transform-object-rest-spread ] | uglifyjs > browser/gocommerce.js"
9+
"babelify": "browserify src/index.js -t [ babelify --presets [ es2015 ] --plugins syntax-object-rest-spread,transform-object-rest-spread ] | uglifyjs > browser/commerce.js"
1010
},
1111
"author": "Mathias Biilmann Christensen",
1212
"license": "MIT",

src/index.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import API from "./api";
22

33
const HTTPRegexp = /^http:\/\//;
4-
const cartKey = "gocommerce.shopping-cart";
4+
const cartKey = "netlify.commerce.shopping-cart";
55
const vatnumbers = {};
66

77
function checkRole(user, role) {
@@ -43,19 +43,19 @@ function centsToAmount(cents) {
4343
return `${(Math.round(cents) / 100).toFixed(2)}`;
4444
}
4545

46-
export default class Gocommerce {
46+
export default class NetlifyCommerce {
4747
constructor(options) {
4848
if (!options.APIUrl) {
49-
throw("You must specify an APIUrl of your Gocommerce instance");
49+
throw("You must specify an APIUrl of your Netlify Commerce instance");
5050
}
5151
if (options.APIUrl.match(HTTPRegexp)) {
52-
console.log('Warning:\n\nDO NOT USE HTTP IN PRODUCTION FOR GOCOMMERCE EVER!\GOCOMMERCE REQUIRES HTTPS to work securely.')
52+
console.log('Warning:\n\nDO NOT USE HTTP IN PRODUCTION FOR NETLIFY COMMERCE EVER!\NETLIFY COMMERCE REQUIRES HTTPS to work securely.')
5353
}
5454

5555
this.api = new API(options.APIUrl);
5656
this.currency = options.currency || "USD";
5757
this.billing_country = options.country;
58-
this.settings_path = "/gocommerce/settings.json";
58+
this.settings_path = "/netlify-commerce/settings.json";
5959
this.settings_refresh_period = options.settingsRefreshPeriod || (10 * 60 * 1000);
6060
this.loadCart();
6161
}
@@ -73,7 +73,7 @@ export default class Gocommerce {
7373
return response.text().then((html) => {
7474
const doc = document.implementation.createHTMLDocument("product");
7575
doc.documentElement.innerHTML = html;
76-
const product = JSON.parse(doc.getElementById("gocommerce-product").innerHTML);
76+
const product = JSON.parse(doc.getElementById("netlify-commerce-product").innerHTML);
7777
const {sku, title, prices, description, type, vat} = product;
7878
if (sku && title && prices) {
7979
if (this.line_items[sku]) {
@@ -292,5 +292,5 @@ export default class Gocommerce {
292292
}
293293

294294
if (typeof window !== "undefined") {
295-
window.Gocommerce = Gocommerce
295+
window.NetlifyCommerce = NetlifyCommerce
296296
}

0 commit comments

Comments
 (0)