npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@janiscommerce/totem-checkout

v1.1.0

Published

Downloads

3

Readme

@janiscommerce/totem-checkout

Installation

npm install @janiscommerce/totem-checkout

API

Usage

const { Payment, Cart, Order } = require('@janiscommerce/totem-checkout');

const cartInstance = new Cart({ environment: 'tiendaqa' })

const orderInstance = new Order({ environment: 'tiendaqa', apiKey: 'API_KEY', apiToken: 'API_TOKEN' });

const paymentInstance = new Payment({ environment: 'tiendaqa', apiKey: 'API_KEY', apiToken: 'API_TOKEN', slaId: 'SLA_ID' });

Cart

Methods

addItems(items) ⇒ Promise

Function for add a new item or items to current order

| Param | Type | Description | | --- | --- | --- | | items | array/object | Object or Array with Object with id and quantity | | items.id | number | id of sku product. | | items.quantity | number | quantity items |

Example

const cart = await cartInstance.addItems({
	id: 45,
	quantity: 2
});

const cart = await cartInstance.addItems([{
	id: 45,
	quantity: 2
},{
	id: 45,
	quantity: 2
}]);

changeItemQuantity(items) ⇒ Promise

Function for change the quantity to item into the current orderForm

| Param | Type | Description | | --- | --- | --- | | items | array/object | Object or Array with Object with id and quantity | | items.id | number | id of sku product. | | items.quantity | number | quantity items |

Example

const cart = await cartInstance.changeItemsQuantity({
	id: 45,
	quantity: 2
});

const cart = await cartInstance.changeItemsQuantity([{
	id: 45,
	quantity: 5
},{
	id: 45,
	quantity: 8
}]);

removeItems(items) ⇒ Promise

Function for remove items

| Param | Type | Description | | --- | --- | --- | | items | array/object | Object or Array with Object with id and quantity | | items.id | number | id of sku product. |

Example

const cart = await cartInstance.removeItems({
		id: 44
});

const cart = await cartInstance.removeItems([{
	id: 45
},{
	id: 46
}]);

removeAllItems() ⇒ Promise

Function for remove all items Example

const cart = await CartInstance.removeAllItems();

simulate(items) ⇒ Promise

Function for simulate cart

| Param | Type | Description | | --- | --- | --- | | items | array/object | Object or Array with Object with id and quantity | | items.id | number | id of sku product. | | items.quantity | number | quantity items | | postalCode | number | PostalCoode for get availables slas |

Example

const cartSimulated = await cartInstance.simulate({
    id: 17,
    quantity: 2
}, 1000);

 const cartSimulated = await cartInstance.simulate([{
    id: 17,
    quantity: 2
}], 1000);

clearCart()

Function for clear cart cached in instance then call getOrder method Example

await cartInstance.getCart();
// into cartInstance.cart getCart method save cart created

cartInstance.clearCart();
// cartInstance.cart is null

Order

Methods

create(data) ⇒ Promise

Create new Order

| Param | Type | Description | | --- | --- | --- | | data | object | Object with data necesary for make order | | data.cart | object | Object Cart or Object Cart simulation | | data.slaId | string/ | logistic sla id | | data.paymentSystemId | number/string | id of payment system |

If order is created, the order response and passed data is cached in instance

Example

// Create order with payment promisory
await orderInstance.create({
	cart: orderSimulated,
	slaId: 'Normal',
	paymentSystemId: 201
});

// Create order with payment card
await orderInstance.create({
	cart: orderSimulated,
	slaId: 'Normal',
	paymentSystemId: 201,
	paymentFields: {
		holderName: 'Test TEST',
		cardNumber: '4700000000000000',
		validationCode: '',
		dueDate: "12/22",
		document: '',
		accountId: '',
		address: null,
		callbackUrl: ''
	}
});

sendTransactionPayments(data, transactionId) ⇒ Promise

Send to order created the paymentData

| Param | Type | Description | | --- | --- | --- | | data | object | Object with data necesary for make order | | data.cart | object | Object Cart or Object Cart simulation | | data.slaId | string/ | logistic sla id | | data.paymentSystemId | number/string | id of payment system | | transactionId | string | id of transaction |

if not pass data and transactionId, the function use data passed in method create, saved in instance

Example

// Send transaction custom
const data = {
	cart: orderSimulated,
	slaId: 'Normal',
	paymentSystemId: 201
};

await orderInstance.sendTransactionPayments(data, 'TRANSACTION_ID');

// send transaction with data and transaction id cached
await orderInstance.sendTransactionPayments();

authorizeTransaction(data) ⇒ Promise

Authorize Payment Methods order

| Param | Type | Description | | --- | --- | --- | | transactionId | string | id of transaction |

if not pass transactionId, the function use transactionId in cached order, saved in instance

Example

// authorizeTransaction custom
await orderInstance.authorizeTransaction('TRANSACTION_ID');

// authorizeTransaction with transactionId in order cached
await orderInstance.authorizeTransaction();

clearOrder()

Clear order created cached and data initial passed Example

await orderInstance.create({
	cart: orderSimulated,
	slaId: 'Normal',
	paymentSystemId: 201
});
// into orderInstance.order, create method save order created
// Into orderInstace.initialdata, create method save argument data passed

orderInstance.clearOrder();
// orderInstance.order is null
// orderInstance.initialData is null

Creating a Order

Example for simulate cart, and then create cart and send and authorize payment

const { Cart, Order } = require('totem-app-checkout');

const evironment = 'testqa';
const cart = new Cart({ environment });

const order = new Order({
	environment,
	apiKey: 'API_KEY',
	apiToken: 'API_TOKEN'
});

const items = [
	{ id: 8, quantity: 1 },
	{ id: 7, quantity: 1 }
];

const cartSimulated = await cart.simulate(items, 1000)


const data = await order.create({
	cart: orderSimulated,
	slaId: 'Normal',
	paymentSystemId: 201,
	paymentFields: {
		holderName: 'Test VTEX',
		cardNumber: '4704550000000005',
		validationCode: '',
		dueDate: "12/22",
		document: '',
		accountId: '',
		address: null,
		callbackUrl: ''
	}
});

const sendPaymentResponse = await order.sendTransactionPayments();

const authorizeResponse = await order.authorizeTransaction();

Payment

Methods

collect(value, paymentSystem, transactionId, cart, isCash, isContactless) ⇒ Promise

Function for add a new item or items to current order

| Param | Type | Description | Default | | --- | --- | --- | --- | | value | number | Value cart total | | | paymentSystem | string|number | id of payment | | | transactionId | string | id of transaction | | | cart | object | object cart simulated | | | isCash | boolean | is payment in cash or not | false | | isContactless | boolean | is payment with card contacless | false |

Creating a payment

  // payment with transaction id with card
  await paymentInstance.collect(18300, 2, 'TRANSACTION_ID');

  // payment with cart simlated with card
  await paymentInstance.collect(18300, 2, null, cartSimulatedObj);

  // payment with transaction id in cash
  await paymentInstance.collect(18300, 1, 'TRANSACTION_ID', null, true);

  // payment with cart simlated in cash
  await paymentInstance.collect(18300, 1, null, cartSimulatedObj, true);