New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@snag/payments-sdk

Package Overview
Dependencies
Maintainers
4
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@snag/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.

  • 1.0.1-alpha.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created
Source

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-solutions/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.

FAQs

Package last updated on 11 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc