Ecommerce

A collection of methods to manage products, SKUs, and process customer orders for one-time purchases.

products.list

Manually fetch ecommerce products from our backend. emits the PelcroEcommerceProductsLoaded DOM events when the response is returned successfully.

Example

window.Pelcro.ecommerce.products.list((error, response) => {
	if (error) {
  	return console.log("error", error.message);
  }
 
  const ecomProducts = response.data.products;
  console.log(ecomProducts);
});

products.read

Get the list of ecommerce products.

Example

window.Pelcro.ecommerce.products.read();

products.getByProductId

Get a specific ecommerce product by its id.

Example

const ecomProduct = window.Pelcro.ecommerce.products.getByProductId(123);

products.getBySkuId

Get a specific e-commerce SKU by its SKU id.

Example

const sku = window.Pelcro.ecommerce.products.getBySkuId(321);

order.create

Create an ecommerce order for the current user. emits the PelcroOrderCreated DOM events when the response is returned successfully.

Examples

Create an order with a new payment source token.

window.Pelcro.ecommerce.order.create(
  {
    items: [
      {
        "sku_id": 34,
        "quantity": 1
      }
    ],
    payment_gateway: "stripe",
    gateway_token: "stripe_1234322111",
    address_id: 123,
    campaign_key: "my_promotion",
  },
  (error, response) => {
    if (error) {
    	return console.log("error", error.message);
  	}
    
    const order = response.data.order;
    console.log(order);
  }
);

Create an order with a saved payment source id.

window.Pelcro.ecommerce.order.create(
  {
    items: [
      {
        "sku_id": 34,
        "quantity": 1
      }
    ],
    source_id: 123456,
    address_id: 123
  },
  (error, response) => {
    if (error) {
    	return console.log("error", error.message);
  	}
    
    const order = response.data.order;
    console.log(order);
  }
);

Parameters

Parameter

Type

Description

items

array

\

[{
        "sku_id": 34,
        "quantity": 1    
}]

source_id

number

Use a user saved payment method as the payment source. Instead of a new card token.

\

// list of user saved payment methods
window.Pelcro.user.read().sources;

payment_gateway

string
"stripe" \| "braintree"

gateway_token

string

address_id

number

coupon_code

string

campaign_key

string

The campaign associated to the order. If the key does not already exist, it will be created. The campaign key must be between 3 and 191 characters in length and include only letters, numbers, dashes and underscores without space.

order.createSummary

Gets a summary of an ecommerce order.
Including calculating taxes and price after applying coupon.

Example

window.Pelcro.ecommerce.order.createSummary(
  {
    items: [
      {
        "sku_id": 34,
        "quantity": 1
      }
    ],
    coupon_code: "50off"
  },
  (error, response) => {
    if (error) {
			return console.log("error", error.message);
  	}
    
    const summary = response.data;
    console.log(summary);    
  }
);

Parameters

Parameter

Type

items

array

\

[{
        "sku_id": 34,
        "quantity": 1    
}]

coupon_code

string