UNPKG

payvessel-checkout

Version:

A simple checkout integration for Payvessel.

110 lines (81 loc) โ€ข 3.03 kB
# Payvessel Checkout A lightweight JavaScript SDK for seamless integration of Payvessel's secure checkout flow into your web applications. ## โœจ Features - Simple, promise-based API for easy async integration - Easy integration with your existing frontend - Compatible with React, Next.js, and vanilla JavaScript projects --- ## ๐Ÿ“ฆ Installation Using npm: ```bash npm install payvessel-checkout ``` Using Yarn: ```bash yarn add payvessel-checkout ``` Or via CDN: ```html <script src="https://unpkg.com/payvessel-checkout@latest/dist/index.umd.js"></script> ``` --- ## ๐Ÿš€ Usage ### Import the package ```bash import { Checkout } from "payvessel-checkout"; ``` ### Initialize and launch checkout ```typescript const openCheckout = async () => { const init = Checkout({ api_key: "YOUR_API_KEY", }); await init.initializeCheckout({ customer_email: "customer@example.com", amount: "100", currency: "NGN", metadata: "any metadata", customer_name: "Customer Name", onError: (error) => console.error(error), onSuccess: (response) => console.log(response), onSuccessfulOrder: (e) => console.log(e), onClose: (e) => console.log(e), }); }; ``` ### Trigger from a button, a form submit event, etc #### React ```jsx <button className="inline-block bg-orange-500 text-white px-4 py-2.5 font-medium rounded" onClick={openCheckout} > Launch Checkout </button> ``` #### Vanila JavaScript ```html <button className="inline-block bg-orange-500 text-white px-4 py-2.5 font-medium rounded" onclick="openCheckout()" > Launch Checkout </button> ``` ### ๐Ÿงช Parameters #### Checkout(config) | Key | Type | Required | Description | |------------|--------|----------|---------------------| | api_key | string | โœ… | Your public API key | #### initializeCheckout(options) | Key | Type | Required | Description | |------------|--------|----------|---------------------| | customer_email | string | โœ… | Customer's email | | amount | string | โœ… | Amount to charg (e.g., "100") | | currency | string | โœ… | Currency code (e.g., "NGN") | | metadata | object \| string | โœ… | Any custom metadata (object/string) | | customer_name | string | โœ… | Full name of the customer | | onError | (orderDetails: ErrorResponse) => void | โŒ | Called when checkout fails. Receives an error object. | | onSuccess | (orderDetails: TransactionResponse) => void | โŒ | Called on successful order initialization. Receives order response data. | | onSuccessfulOrder | (orderDetails: OrderConfirmedResponse) => void | โŒ | Called after transaction verification succeeds. Receives verified order details. | | onClose | (orderReference: string) => void | โŒ | Called when the payment modal is closed. |