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

@verysell-group/verypay-sdk

v0.4.37

Published

> Powerful tool for integrating VeryPay payment functionality into your applications

Downloads

52

Readme

VeryPay SDK Development Integration Guide

Powerful tool for integrating VeryPay payment functionality into your applications

build status code coverage npm version bundle size npm downloads apache license

The default JS SDK code snippet blocks page rendering:

<script src="https://www.verypay.ch/sdk/js?client-id=test"></script>
<script>
  verypay.renderButton({
	  selector: "body", // replace body to your element
	  clientId: "CLIENT_ID", // .e.g: VeryPay
	  env: "TARGET_ENV", // test, uat, demo, production
	  merchantId: "MERCHANT_ID",// .e.g: b2e56b86-c599-4432-8c81-bf5f15fcd267
	  initialData: paymentData,
	  onPaymentCompleted(transaction) {
	    // Callback when payment is completed
	  },
	  // ... other options and callbacks
	});
</script>

The VeryPay SDK is a powerful tool for integrating VeryPay payment functionality into your applications.

This guide will walk you through the steps to integrate the VeryPay SDK into your project, and provide examples of how to use the renderButton function to enable payments.

Table of Contents

  • Installation
  • Usage
    • JavaScript
    • HTML
  • Options
    • Detail for initialData object param
  • Callbacks
  • Example
    • React Code snippet
    • HTML Example
  • License

Installation

You can install the VeryPay SDK via packages:

# npm
npm install @verysell-group/verypay-sdk
# yarn
yarn add @verysell-group/verypay-sdk
# pnpm
pnpm add @verysell-group/verypay-sdk

Usage

JavaScript

To use the VeryPay SDK in a JavaScript application, you can import it as follows:

import { renderButton } from "@verysell-group/verypay-sdk";

// Initialize the VeryPay button
renderButton({
  selector: "#verypay-button",
  clientId: "CLIENT_ID", // .e.g: VeryPay
  env: "TARGET_ENV", // test, uat, demo, production
  merchantId: "MERCHANT_ID", // .e.g: b2e56b86-c599-4432-8c81-bf5f15fcd267
  initialData: paymentData,
  onPaymentCompleted(transaction) {
    // Callback when payment is completed
  },
  // ... other options and callbacks
});

HTML

If you prefer to include the VeryPay SDK in your HTML file, you can use the following script tag:

<script src="https://verypay-demo.verypay.ch/sdk/verypay-checkout.js"></script>

You can then use the global verypay object to render the button:

verypay.renderButton({
  selector: "#verypay-button",
  clientId: "CLIENT_ID", // .e.g: VeryPay
  env: "TARGET_ENV", // test, uat, demo, production
  merchantId: "MERCHANT_ID", // .e.g: b2e56b86-c599-4432-8c81-bf5f15fcd267
  initialData: paymentData,
  onPaymentCompleted(transaction) {
    // Callback when payment is completed
  },
  // ... other options and callbacks
});

Options

Here are the available options when calling renderButton:

  • selector (string): The CSS selector for the element where the VeryPay button should be rendered.
  • clientId (string): Your VeryPay client ID.
  • baseURL (string): The base URL for VeryPay API requests.
  • merchantId (string): Your merchant ID.
  • initialData (object): Initial payment data.
  • onPaymentCompleted (function): Callback function when payment is completed.
  • onPaymentFailed (function): Callback function when payment fails.
  • onAddressesSelected (function): Callback function when addresses are selected.
  • onAuthenticationSuccess (function): Callback function when authentication is successful.
  • onShippingSelected (function): Callback function when shipping is selected.

Detail for initialData object param

type InitialData = {
    clientCartId: string;
    orderDetails: {
        items: {
            id: string;
            quantity: number;
            name: string;
            sku: string;
            price: number;
            amount: number;
        }[];
        tax: number;
        shippingFee: number;
        totalPrice: number;
        currency: string;
    };
    defaultShippingOption: string;
    shippingOptions: {
        id: string;
        amount: number;
        name: string;
    }[]
}
  • clientCartId (string): A unique identifier for the client's cart. This identifier helps link the cart to the client's session or profile.
  • orderDetails (object): An object containing information about the client's order.
    • items (array of objects): An array of items in the client's order. Each item object includes the following properties:
      • id (string): A unique identifier for the item.
      • quantity (number): The quantity of this item in the order.
      • name (string): The name or description of the item.
      • sku (string): The Stock Keeping Unit (SKU) identifier for the item.
      • price (number): The individual price of one unit of this item.
      • amount (number): The total amount for this item (quantity multiplied by price).
    • tax (number): The total tax amount for the order.
    • shippingFee (number): The shipping fee for the order.
    • totalPrice (number): The total price of the order, including the subtotal, tax, and shipping fees.
    • currency (string): The currency in which the prices are specified, e.g., "USD" for US Dollars.
  • defaultShippingOption (string): The identifier for the default or selected shipping option for the order. This should match one of the id values in the shippingOptions array.
  • shippingOptions (array of objects): An array of available shipping options for the order. Each shipping option object includes the following properties:
    • id (string): A unique identifier for the shipping option.
    • amount (number): The cost of this shipping option.
    • name (string): The name or description of the shipping option.

These parameters collectively provide detailed information about the client's shopping cart and order, allowing the VeryPay SDK to calculate the total amount, including tax and shipping fees, for the order.

Callbacks

Callbacks are functions that you can define to handle various events during the payment process. These are passed as options when calling renderButton. See the Options section for details on which callbacks are available.

Example

Here is an example of how to use renderButton:

renderButton({
  selector: "#verypay-button",
  clientId: "CLIENT_ID", // .e.g: VeryPay
  env: "TARGET_ENV", // test, uat, demo, production
  merchantId: "MERCHANT_ID", // .e.g: b2e56b86-c599-4432-8c81-bf5f15fcd267
  initialData: paymentData,
  onPaymentCompleted(transaction) {
    // Callback when payment is completed
  },
  onPaymentFailed() {
    // Callback when payment failed
  },
  onAddressesSelected(addresses) {
    // Handle selected addresses
  },
  onAuthenticationSuccess() {
    // Handle when login successfull
  },
  onShippingSelected(shippingOptionId) {
    // Handle selected shipping option
    // ...
  },
});

React Code snippet example

import { useEffect } from "react";
import { renderButton } from "@verysell-group/verypay-sdk";

export const PaymentButton = () => {
  useEffect(() => {
    renderButton({
      selector: "#verypay-buttons",
      clientId: "CLIENT_ID", // .e.g: VeryPay
      env: "TARGET_ENV", // test, uat, demo, production
      merchantId: "MERCHANT_ID", // .e.g: b2e56b86-c599-4432-8c81-bf5f15fcd267
      // ...pass the callback function here
    });
  }, []);

  return <div id="verypay-button" />;
};

HTML Example

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>VeryPay SDK - HTML Example</title>
  <script src="https://verypay-demo.verypay.ch/sdk/verypay-checkout.js"></script>
</head>
<body>
  <div id="verypay-buttons"></div>

  <script type="module">
    verypay.renderButton({
      selector: "#verypay-buttons",
		  clientId: "CLIENT_ID", // .e.g: VeryPay
		  env: "TARGET_ENV", // test, uat, demo, production
		  merchantId: "MERCHANT_ID",// .e.g: b2e56b86-c599-4432-8c81-bf5f15fcd267
      // ...pass the callback function here
    });
  </script>
</body>
</html>

Using a CDN

The verypay-sdk script is also available on the unpkg CDN. Here's an example:

<!doctype html>
<html lang="en">
  <head>
    <script src="https://unpkg.com/@verysell-group/verypay-sdk@latest/dist/verypay-sdk.iife.js"></script>
  </head>
  <body>
    <div id="verypay-buttons"></div>
    <script>
      verypay.renderButton({
	      selector: "#verypay-buttons",
			  clientId: "CLIENT_ID", // .e.g: VeryPay
			  env: "TARGET_ENV", // test, uat, demo, production
			  merchantId: "MERCHANT_ID",// .e.g: b2e56b86-c599-4432-8c81-bf5f15fcd267
	      // ...pass the callback function here
	    });
    </script>
  </body>
</html>

TypeScript Support

This package includes TypeScript type definitions for the Verypay JS SDK. This includes types for the window.verypay namespace. We support projects using TypeScript versions >= 3.8.

Releasing

Run npm run release to publish a new release. The version number is determined by the git commits which follow conventional commits spec.

License

Verysell Group - VeryPay