Skip to content

A simple and elegant shopping cart supporting both Stripe and Paypal checkouts.

License

Notifications You must be signed in to change notification settings

joncody/stripal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 

Repository files navigation

stripal

A simple, elegant shopping cart supporting both Stripe and Paypal checkouts. Currently supports USD as a currency.

API

Table Of Contents

stripal

The only global variable and entry point.

Methods

each(fn)

Iterate through each Item passing it to the function argument.

Parameters
Name Type Description
fn Function The function to run on each Item.

get(id) -> {Item}

Gets a saved Item.

Parameters
Name Type Description
id Number The unique identifier of the Item.

length() -> {Number}

Gets the amount of saved Items.


quantity() -> {Number}

Gets the accumulated sum of all Item quantities.


find(properties) -> {Array}

Gets the items that match the rules defined in the passed argument.

Parameters
Name Type Description
properties Object The rules to match - keys and values map to Item. Values may be preceded by operators: "<=", ">=", "!=", "<", ">". Values can be a RegExp or any other type.

items() -> {Object}

Gets the cart as an object - keys are Item ids and values are the corresponding Item.


save()

Updates the current cart values in the indexedDB database.


loaded() -> {Boolean}

Indicates the cart loading status.


empty()

Removes all Items from the cart.


stripeKey(key) -> {String}

Gets or sets the Stripe API key.

Parameters
Name Type Description
key String (optional) The API key.

paypalKey(key) -> {String}

Gets or sets the Paypal API key.

Parameters
Name Type Description
key String (optional) The API key.

currency(currency) -> {String}

Gets or sets the cart currency.

Parameters
Name Type Description
currency String (optional) The currency code.

tax(tax) -> {Number}

Gets or sets the tax rate percentage.

Parameters
Name Type Description
tax Number (optional, default: 7.75) The tax rate.

discountflat(discountflat) -> {Number}

Gets or sets a flat discount amount.

Parameters
Name Type Description
discountflat Number (optional) The discount amount.

subtotal() -> {Number}

Gets the total cart price without tax.


total() -> {Number}

Gets the total cart price with tax.


newItem(opts) -> {Item}

Creates a new Item.

Parameters
Name Type Description
opts Object (optional) The properties to assign to the Item.

load(dbname)

Opens an indexedDB database and loads any values to the cart.

Parameters
Name Type Description
dbname String The name of the database.

checkout(type, opts) -> {GObject}

Starts the checkout process.

Parameters
Name Type Description
type String The checkout method - "stripe" or "paypal".
opts Object (optional) The method specific checkout options.

Events

Name Parameters Description
load Fired after the Stripal database is loaded.
item-cart Item Fired when an item has been added to the cart.
item-remove Item Fired when an item has been removed from the cart.
item-update Item, Key, Value (optional) Fired when an item is updated always passing the key and, if the attribute was not deleted, the value.
paypal-checkout-start Payment Options Object Fired when a PayPal checkout process has started.
paypal-checkout-end Payment Data Object
stripe-checkout-start Fired when a Stripe checkout process starts.
stripe-checkout-end Token, Args Fired when a Stripe checkout process ends.

Item

A stripal item.

Properties

Name Type Description
stripal_item Boolean Indicator of a stripal item.
id Number The unique identifier.

Methods

save()

Saves the Item to the cart.


quiet(quiet) -> {Boolean}

Gets or sets the option to emit events.

Parameters
Name Type Description
quiet Boolean (optional) Determines event emission.

name(name) -> {String}

Gets or sets the item name.

Parameters
Name Type Description
name String (optional) The item name.

currency(currency) -> {Number}

Gets or sets the currency for the item.

Parameters
Name Type Description
currency String (optional, default: "USD") The currency code.

price(price) -> {Number}

Gets or sets the price of the item.

Parameters
Name Type Description
price Number (optional) The price of the item.

minimum(minimum) -> {Number}

Gets or sets the minimum quantity which must be purchased.

Parameters
Name Type Description
minimum Number (optional, default: 1) The minimum quantity.

quantity(quantity) -> {Number}

Gets or sets the quantity.

Parameters
Name Type Description
quantity Number (optional, default: 1) The quantity.

step(step) -> {Number}

Gets or sets the step when calling increment() and decrement()

Parameters
Name Type Description
step Number (optional, default: 1) The quantity to increase and decrease by.

add(add) -> {Number}

Gets or sets the additional amount to add to the price of each item considering the quantity.

Parameters
Name Type Description
add Number (optional) The amount to add.

addflat(addflat) -> {Number}

Gets or sets a flat, additional amount to add to the price of each item not considering quantity.

Parameters
Name Type Description
addflat Number (optional) The flat amount to add.

discount(discount) -> {Number}

Gets or sets the additional amount to subtract from the price of each item considering the quantity.

Parameters
Name Type Description
discount Number (optional) The amount to subtract.

discountflat(discountflat) -> {Number}

Gets or sets a flat amount to subtract from the price of each item not considering quantity.

Parameters
Name Type Description
discountflat Number (optional) The flat amount to subtract.

increment(inc) -> {Number}

Increases the quantity by the passed value or by the step and returns the quantity.

Parameters
Name Type Description
inc Number (optional) The amount to increase the quantity by.

decrement(dec) -> {Number}

Decreases the quantity by the passed value or by the step and returns the quantity.

Parameters
Name Type Description
dec Number (optional) The amount to decrease the quantity by.

total() -> {Number}

Gets the total price.


cart()

Adds the item to the cart.


remove()

Removes the item from the cart.


set(key, value)

Sets or updates an attribute on the item.

Parameters
Name Type Description
key String The attribute name.
value Any The value.

get(key) -> {Any}

Gets the value of an attribute on the item.

Parameters
Name Type Description
key String The attribute name.

del(key)

Removes an attribute from the item.

Parameters
Name Type Description
key String The attribute name.

object(added) -> {Object}

Essentially "unwraps" the item and returns its current state as an object.

Parameters
Name Type Description
added Boolean If true then the returned object will exclude default item properties

Events

Name Parameters Description
cart Item Fired when the item is added to the cart.
remove Item Fired when the item is removed from the cart.
update Item, Key, Value (optional) Fired when an item is updated always passing the key and, if the attribute was not deleted, the value.

About

A simple and elegant shopping cart supporting both Stripe and Paypal checkouts.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published