0.0.1 • Published 1 month ago

@juspay/zephyr-sdk-web v0.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 month ago

Zephyr SDK Web

Zephyr SDK Web is a Javascript library which enables you to seamlessly integrate and use Breeze 1 Click Checkout in your Web app built using any kind of web technology.

Installation

Run following command in your node project to install the Zephyr SDK Web package:

npm install @juspay/zephyr-sdk-web

This will install the Zephyr SDK Web package in your project.

Note: You can use pnpm, yarn or any other package manager of your choice to install the package.

Usage

To start using the Zephyr SDK Web, you need to complete following steps:

Step 1: Initiate the Zephyr SDK Web

To initiate the Zephyr SDK Web, you need to call the initiate method of the SDK. This method takes an object as an argument which contains the following properties:

ParameterTypeMandatoryDescription
merchantIdStringYesThe merchant ID provided by Juspay.
shopUrlStringYesThe URL of the shop where the SDK will be used.
environmentStringYesThe environment in which the SDK should run. Possible values are beta and production.
shopPlatformStringYesThe platform on which the shop is built. Possible values are shopify, magento, woocommerce, custom
// Import the SDK to your project
import Zephyr from '@juspay/zephyr-sdk-web';

// Create the initiate payload

const initiatePayload = {
  merchantId: '<merchant-id-shared-by-breeze>',
  shopUrl: '<shop-url>',
  environment: 'production',
  shopPlatform: 'custom'
}

Zephyr.initiate(initiatePayload);

Step 2: Process your request through Zephyr SDK

To process your request through Zephyr SDK, you need to call the process method of the SDK. This method takes an object. Refer below sections to understand the object structure.

Process Payload

ParameterTypeMandatoryDescription
actionStringYesThe action to be performed by the SDK. Possible values are startCheckout
cartZephyrCartYesThe cart object which contains the cart details.
utmParamsObjectNoUTP Parameters associated with the user journey

ZephyrCart

ParameterTypeMandatoryDescription
initialPriceNumberYesThe initial price of the cart.
totalPriceNumberYesThe total price of the cart.
totalDiscountNumberYesThe total discount applied on the cart.
weightNumberNoThe total weight of the cart.
itemCountNumberYesThe total number of items in the cart.
currencyZephyrCurrencyYesThe currency of the cart.
itemsZephyrCartItem[]YesThe array of items in the cart.

ZephyrCurrency

Zephyr SDK Web supports the following currencies:

  • 'INR'
  • 'USD'
  • 'GBP'
  • 'AUD'
  • 'CAD'
  • 'SGD'
  • 'AED'
  • 'PKR'
  • 'BDT'

ZephyrCartItem

ParameterTypeMandatoryDescription
idStringYesThe ID of the item.
titleStringYesThe title of the item.
variantTitleStringNoThe variant title of the item.
variantIdStringNoThe variant ID of the item.
imageStringNoThe image URL of the item.
weightNumberNoThe weight of the item.
quantityNumberYesThe quantity of the item.
discountNumberYesThe discount applied on the item.
initialPriceNumberYesThe initial price of the item.
finalPriceNumberYesThe final price of the item.

Post you have initiated the SDK, you can call the process method to execute your query.

// Import your SDK
import Zephyr from '@juspay/zephyr-sdk-web';

// Creating process payload 
const processPayload = {
  action: 'startCheckout',
  cart: {
    initialPrice: 1000,
    totalPrice: 900,
    totalDiscount: 100,
    weight: 1000,
    itemCount: 2,
    currency: 'INR',
    items: [
      {
        id: '1',
        title: 'Item 1',
        variantTitle: 'Variant 1',
        variantId: '1',
        image: 'https://example.com/image1.jpg',
        weight: 500,
        quantity: 1,
        discount: 50,
        initialPrice: 500,
        finalPrice: 450
      },
      {
        id: '2',
        title: 'Item 2',
        variantTitle: 'Variant 2',
        variantId: '2',
        image: 'https://example.com/image2.jpg',
        weight: 500,
        quantity: 1,
        discount: 50,
        initialPrice: 500,
        finalPrice: 450
      }
    ]
  },
  utmParams: {
    utm_source: 'google',
    utm_medium: 'cpc',
    utm_campaign: 'summer-sale'
  }
}

Zephyr.process(processPayload);

Note: This SDK is in alpha stage. Expect new features & breaking changes in upcoming versions.