GoCommerce JS
This is a JS client library for GoCommerce API.
It handles orders and payments. Integrates with Stripe for payments and will support international pricing and VAT verification.
Usage
import GoCommerce from "gocommerce-js";
const commerce = new GoCommerce({
APIUrl: "https://commerce.netlify.com"
});
commerce.addToCart({
path: "/products/book-1/",
quantity: 2,
meta: {
photo: "/images/mugs/netlig-01.png"
}
}).then((lineItem) => console.log(lineItem));
console.log(commerce.getCart());
commerce.updateCart("netlify-mug-01", 3);
commerce.order({
email: "matt@netlify.com",
shipping_address: {
name: "Matt Biilmann",
company: "netlify",
address1: "610 22nd Street",
city: "San Francisco",
state: "CA",
country: "USA",
zip: "94107"
}
}).then(({cart, order}) => {
return commerce.payment({
"provider": "stripe",
"stripe_token": TOKEN_FROM_STRIPE_CC_FORM,
"amount": cart.total.cents,
"order_id": order.id,
})
}).then((transaction) => {
console.log("Order confirmed!")
});
commerce.clearCart();
You can change country (for VAT calculations) or currency at any time:
commerce.setCountry("USA");
commerce.setCurrency("USD");
You can use GoCommerce JS together with GoTrue to let users log in and claim view order history.
goTrue.login(email, password).then((user) => {
commerce.setUser(user);
commerce.order({
email: user.email,
shipping_address_id: "some-previously-generated-address"
});
commerce.orderHistory().then((orders) => {
console.log(orders);
});
});