1.0.1-alpha.0 • Published 8 months ago

@snag/payments-sdk v1.0.1-alpha.0

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

Snag Solutions Payments SDK

This readme provides instructions on how to install and use the Payment SDK to facilitate online payments and retrieve session details based on session IDs.

Installation

To get started, follow these steps to install the Payment SDK:

  1. Install Node.js and npm:

    Ensure you have Node.js and npm (Node Package Manager) installed on your system. You can download and install them from the official Node.js website: Node.js Downloads

  2. Install the Payment SDK:

    Use npm to install the Payment SDK package:

    npm install @snag/payments-sdk --save

Usage

Once you've installed the Payment SDK, you can use it to perform payment checkouts and retrieve session details based on session IDs.

Payment Checkout

To initiate a payment checkout, use the await new PaymentSDK().checkout() method. Provide the necessary information for the payment, such as the name, description, amount, currency, and more. Here's an example:

const PaymentSDK = require('payment-sdk');
const sdkApiKey = 'sdk-api-key';

(async () => {
  try {
    await new PaymentSDK(sdkApiKey).checkout({
      name: 'Sample Item',
      description: 'A sample item description',
      images: ['https://example.com/item-image.jpg'],
      amount: 1999, // Amount in cents (e.g., $19.99)
      currency: 'usd',
      shippingRate: 'shipping_rate_id',
      successUrl: 'https://example.com/success',
      cancelUrl: 'https://example.com/cancel',
      tokenId: 1,
    });
  } catch (error) {
    console.error('Error initiating payment checkout:', error);
  }
})();

The sessionId will be included as a query parameter (session_id) in the successUrl and cancelUrl, making it accessible on those pages for further processing.

Retrieve Session Details

To retrieve session details based on a session ID, use the await new PaymentSDK().sessionDetails(sessionId) method. Replace sessionId with the actual session ID you want to retrieve details for. Here's an example:

const PaymentSDK = require('payment-sdk');
const sdkApiKey = 'sdk-api-key';

(async () => {
  try {
    const sessionId = 'your-session-id'; // Replace with the actual session ID
    const sessionDetails = await new PaymentSDK(sdkApiKey).sessionDetails(
      sessionId,
    );

    console.log('Session Details:', sessionDetails);
  } catch (error) {
    console.error('Error retrieving session details:', error);
  }
})();

Make sure to replace 'your-session-id' with the actual session ID you want to retrieve details for.

1.0.1-alpha.3

8 months ago

1.0.1-alpha.2

8 months ago

1.0.1-alpha.1

8 months ago

1.0.1-alpha.0

8 months ago