JavaScript SDK for Hanzo
Hanzo.js is a client and server-side library for Hanzo. It is a complete Ecommerce SDK for JavaScript.
With it you can:
- Launch static sites to test new ideas or reach additional markets.
- Gather detailed analytics about your users and their behavior.
- Acquire, on-board and keep users.
- Collect payments and create subscriptions for products, software or services.
- Manage orders, shipping and fulfillment for products.
- Run referral programs and other incentive-based programs for your business.
$ npm install hanzo.js
You can embed Hanzo.js in your application or web page or on the server with Node. Getting started is easy: you just need an API key from Hanzo and a snippet of JavaScript to get going.
Include hanzo.js
in your website or bundle it with your
JavaScript application using your favorite build tool. All account and commerce
related APIs are available in the browser making it possible to launch an
ecommerce site without building, maintaining or securing any backend services.
<script src="https://cdn.rawgit.com/hanzoai/hanzo.js/v2.2.8/hanzo.min.js"></script>
<script>
var api = new Hanzo.Api({key: yourPublishedKey});
</script>
Make sure you use your published key and not your secret key!
You can use either a published or secret key with the Node client. A secret key is required for full use of the Hanzo API.
Hanzo = require('hanzo.js');
var api = new Hanzo({key: yourSecretKey});
Promises are returned by every asynchronous method when a callback is not provided. Error-first callbacks are optional to every asynchronous method and may be used interchangeably with the Promise-based API.
Full Promise A+ compliant promises are returned by every API method call.
var promise = api.account.create({});
promise
.then(success)
.catch(failure)
Node.js-style error first callbacks can also be supplied.
api.account.create({}, function(err, user) {
// ...etc
});
Create a new Hanzo API Client. Has a high level API which returns objects directly.
opts
Options, optionalkey
Key to use during requests.endpoint
Defaults to'https://api.hanzo.io'
Lower-level client which Api
builds on. You can direct requests to Hanzo
using blueprints.
opts
Options, optionalkey
Key to use during requests.endpoint
Defaults to'https://api.hanzo.io'
Make a request using blueprint
. Returns a promise which eventually returns a
response object or rejects with an Error
.
A blueprint
is a description of an API method including URL, method, etc. You
can re-use the default blueprints pretty easily to make your own requests directly.
client.request(api.account.create, {email: '', ...})
.then(function(res) {
console.log(res.data)
console.log(res.status)
})
.catch(function(err) {
console.log(err.stack)
})
blueprint
Description of API endpoint.data
Data to send to Hanzo.key
Key to use during requests.
We only expose a subset of API methods to the Browser. Only the API calls which are possible with a publishable token or user token are available.
Account API encompasses our authentication, login, and user creation APIs.
This method creates a new user. It has more strict validation than the standard
user
API and will send welcome emails if configured.
user
, required.firstName
string, required.lastName
string, required.email
string, required.password
string, required.passwordConfirm
string, required.
callback
, optional.
This method enable's a user account after creation using token provided in email.
token
string, required. This is the token that comes in when a user clicks the confirm email in their inbox.callback
, optional
- boolean
This method returns account information for currently logged in user.
callback
, optional
This method checks to see if a exists, as per the identifier.
identifier
string, required. Can be a user's email, username, or unique id.callback
, optional
- boolean
This method logs in a user and sets a user token on the client for subsequent calls.
user
, required.email
string, required.password
string, required.
callback
, optional.
This method destroys the current user session.
callback
, optional.
- null
This method starts the account reset process (such as if a user has forgotten their password)
reset
, required, contains the following key:email
, string, required
callback
, optional
- null
This method completes the account reset process by confirming it with the ID garnished from the user's email.
tokenId
string, requiredcallback
, optional
- null
This method updates a user with new information. All fields in the user
object are optional,
but the ones given will overwrite whatever was there before.
user
, required.firstName
string, optionallastName
string, optionalphone
string, optionalbillingAddress
string, optionalshippingAddress
string, optionalemail
string, optional
callback
, optional.
Checkout encompasses the actual purchase of things from your website, and has support for both one and two step payment styles.
This is the one-step payment process, which will attempt to both authorize and capture the payment at the same time.
opts
required, containing the following keys:callback
, optional.
order
, order information.
This is the first half of the two-step payment process, and will authorize the payment for later capture.
opts
required, containing the following keys:callback
, optional.
order
, order information.
This is the first half of the two-step payment process, and will capture a payment that has been authorized prior.
opts
required, containing the following keys:callback
, optional.
order
, order information.
This initiates a PayPal payment.
opts
required, containing the following keys:callback
, optional.
order
, order information.PayKey
is added to the order to allow for appropriate redirection to PayPal's site.
This describes a bundle of products that are bunched together for a specific sale.
This gets the information of a collection with the supplied ID.
id
string, requiredcallback
, optional
collection
, the collection information.
This lists all the collections available on your store.
callback
, optional
collection[]
, an array of available collections.
This is an entity that allows for special offers to be posted through your online store.
This gets the information of a coupon with the supplied ID.
id
string, requiredcallback
, optional
coupon
, coupon information.
This lists all the coupons available on your store.
callback
, optional
coupon[]
, an array of available coupons.
This is an entity that represents the things that are on offer at your site.
This gets the information of a product with the supplied ID.
id
string, requiredcallback
, optional
product
, product information.
This lists all the products available on your store.
callback
, optional
product[]
, an array of available products.
This is an entity that represents a variation of a product that is available on your site.
This gets the information of a variant with the supplied ID.
id
string, requiredcallback
, optional
variant
, variant information.
This lists all the variants available on your store.
callback
, optional
variant[]
, an array of available variants.
You have pretty much complete access to Hanzo from your own server with a secret key. Never share your secret key. All usages explained below are specifically for a Node.js server.
Account API encompasses our authentication, login, and user creation APIs.
This method creates a new user. It has more strict validation than the standard
user
API and will send welcome emails if configured.
user
, required.firstName
string, required.lastName
string, required.email
string, required.password
string, required.passwordConfirm
string, required.
callback
, optional.
This method returns account information for currently logged in user.
callback
, optional
This method logs in a user and sets a user token on the client for making calls on their behalf.
user
, required.email
string, required.password
string, required.
callback
, optional.
This method destroys the current user session.
callback
, optional.
- null
This method checks to see if a exists, as per the identifier.
identifier
string, required. Can be a user's email, username, or unique id.callback
, optional
- boolean
This method starts the account reset process (such as if a user has forgotten their password)
opts
, required, contains the following key:email
, string, required
callback
, optional
- null
This method completes the account reset process by confirming it with the ID garnished from the user's email.
tokenId
string, requiredcallback
, optional
- null
This method updates a user with new information. All fields in the user
object are optional,
but the ones given will overwrite whatever was there before.
user
, required.firstName
string, optionallastName
string, optionalphone
string, optionalbillingAddress
string, optionalshippingAddress
string, optionalemail
string, optional
callback
, optional.
Checkout encompasses the actual purchase of things from your website, and has support for both one and two step payment styles.
This is the one-step payment process, which will attempt to both authorize and capture the payment at the same time.
opts
required, containing the following keys:callback
, optional.
order
, order information.
This is the first half of the two-step payment process, and will authorize the payment for later capture.
opts
required, containing the following keys:callback
, optional.
order
, order information.
This is the first half of the two-step payment process, and will capture a payment that has been authorized prior.
opts
required, containing the following keys:callback
, optional.
order
, order information.
This initiates a PayPal payment.
opts
required, containing the following keys:callback
, optional.
order
, order information.PayKey
is added to the order to allow for appropriate redirection to PayPal's site.
This entity represents a bundle of products that are available on your shop.
This gets the information of a collection with the supplied ID.
id
string, requiredcallback
, optional
collection
, collection information.
This lists all the collections available on your store.
callback
, optional
collection[]
, an array of available collections.
This creates a new collection.
collection
, collection information, requiredcallback
, optional
collection
, the newly created collection, with unique identifier information added.
This updates a collection with new information. All fields aside from the unique identifier are optional, and if present, will overwrite what is on the server.
collection
, collection information, requires: -id
string, the unique identifier for the collection to be changedcallback
, optional
collection
, the newly modified collection, with unique identifier information added.
This deletes a collection from your account.
id
string, requiredcallback
, optional
- boolean
This represents a confirmed request for products.
This gets the information of a order with the supplied ID.
id
string, requiredcallback
, optional
order
, order information.
This lists all the orders available on your store.
callback
, optional
order[]
, an array of available orders.
This creates a new order.
order
, order information, requiredcallback
, optional
order
, the newly created order, with unique identifier information added.
This updates a order with new information. All fields aside from the unique identifier are optional, and if present, will overwrite what is on the server.
order
, order information, requires: -id
string, the unique identifier for the order to be changedcallback
, optional
order
, the newly modified order, with unique identifier information added.
This deletes a order from your account.
id
string, requiredcallback
, optional
- boolean
This represents a transaction to give you money.
This gets the information of a payment with the supplied ID.
id
string, requiredcallback
, optional
payment
, payment information.
This lists all the payments available on your store.
callback
, optional
payment[]
, an array of available payments.
This creates a new payment.
payment
, payment information, requiredcallback
, optional
payment
, the newly created payment, with unique identifier information added.
This updates a payment with new information. All fields aside from the unique identifier are optional, and if present, will overwrite what is on the server.
payment
, payment information, requires: -id
string, the unique identifier for the payment to be changedcallback
, optional
payment
, the newly modified payment, with unique identifier information added.
This deletes a payment from your account.
id
string, requiredcallback
, optional
- boolean
This represents a thing that is available on your shop.
This gets the information of a product with the supplied ID.
id
string, requiredcallback
, optional
product
, product information.
This lists all the products available on your store.
callback
, optional
product[]
, an array of available products.
This creates a new product.
product
, product information, requiredcallback
, optional
product
, the newly created product, with unique identifier information added.
This updates a product with new information. All fields aside from the unique identifier are optional, and if present, will overwrite what is on the server.
product
, product information, requires: -id
string, the unique identifier for the product to be changedcallback
, optional
product
, the newly modified product, with unique identifier information added.
This deletes a product from your account.
id
string, requiredcallback
, optional
- boolean
This represents an identifying instance of an order that happened due to the intervention of a user on your site.
This gets the information of a referral with the supplied ID.
id
string, requiredcallback
, optional
referral
, referral information.
This lists all the referrals available on your store.
callback
, optional
referral[]
, an array of available referrals.
This creates a new referral.
referral
, referral information, requiredcallback
, optional
referral
, the newly created referral, with unique identifier information added.
This updates a referral with new information. All fields aside from the unique identifier are optional, and if present, will overwrite what is on the server.
referral
, referral information, requires: -id
string, the unique identifier for the referral to be changedcallback
, optional
referral
, the newly modified referral, with unique identifier information added.
This deletes a referral from your account.
id
string, requiredcallback
, optional
- boolean
This represents a user that has induced an order to happen.
This gets the information of a referral with the supplied ID.
id
string, requiredcallback
, optional
referral
, referral information.
This lists all the referrals available on your store.
callback
, optional
referral[]
, an array of available referrals.
This creates a new referral.
referral
, referral information, requiredcallback
, optional
referral
, the newly created referral, with unique identifier information added.
This updates a referral with new information. All fields aside from the unique identifier are optional, and if present, will overwrite what is on the server.
referral
, referral information, requires: -id
string, the unique identifier for the referral to be changedcallback
, optional
referral
, the newly modified referral, with unique identifier information added.
This deletes a referral from your account.
id
string, requiredcallback
, optional
- boolean
This represents a user that is subscribed to a mailing list.
This gets the information of a subscriber with the supplied ID.
id
string, requiredcallback
, optional
subscriber
, subscriber information.
This lists all the subscribers available on your store.
callback
, optional
subscriber[]
, an array of available subscribers.
This creates a new subscriber.
subscriber
, subscriber information, requiredcallback
, optional
subscriber
, the newly created subscriber, with unique identifier information added.
This updates a subscriber with new information. All fields aside from the unique identifier are optional, and if present, will overwrite what is on the server.
subscriber
, subscriber information, requires: -id
string, the unique identifier for the subscriber to be changedcallback
, optional
subscriber
, the newly modified subscriber, with unique identifier information added.
This deletes a subscriber from your account.
id
string, requiredcallback
, optional
- boolean
This represents an internal action to settle up a user's account - think of it as store credit to Payment's real money.
This gets the information of a transaction with the supplied ID.
id
string, requiredcallback
, optional
transaction
, transaction information.
This lists all the transactions available on your store.
callback
, optional
transaction[]
, an array of available transactions.
This creates a new transaction.
transaction
, transaction information, requiredcallback
, optional
transaction
, the newly created transaction, with unique identifier information added.
This updates a transaction with new information. All fields aside from the unique identifier are optional, and if present, will overwrite what is on the server.
transaction
, transaction information, requires: -id
string, the unique identifier for the transaction to be changedcallback
, optional
transaction
, the newly modified transaction, with unique identifier information added.
This deletes a transaction from your account.
id
string, requiredcallback
, optional
- boolean
This is a customer on your site.
This gets the information of a user with the supplied ID.
id
string, requiredcallback
, optional
user
, user information.
This lists all the users available on your store.
callback
, optional
user[]
, an array of available users.
This creates a new user.
user
, user information, requiredcallback
, optional
user
, the newly created user, with unique identifier information added.
This updates a user with new information. All fields aside from the unique identifier are optional, and if present, will overwrite what is on the server.
user
, user information, requires: -id
string, the unique identifier for the user to be changedcallback
, optional
user
, the newly modified user, with unique identifier information added.
This deletes a user from your account.
id
string, requiredcallback
, optional
- boolean
This is an entity that represents a variation of a product that is available on your site.
This gets the information of a variant with the supplied ID.
id
string, requiredcallback
, optional
variant
, variant information.
This lists all the variants available on your store.
callback
, optional
variant[]
, an array of available variants.
This creates a new variant.
variant
, variant information, requiredcallback
, optional
variant
, the newly created variant, with unique identifier information added.
This updates a variant with new information. All fields aside from the unique identifier are optional, and if present, will overwrite what is on the server.
variant
, variant information, requires: -id
string, the unique identifier for the variant to be changedcallback
, optional
variant
, the newly modified variant, with unique identifier information added.
This deletes a variant from your account.
id
string, requiredcallback
, optional
- boolean