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

stripe-multi-payments

v1.2.8

Published

ANode.js module for processing payments via Strapi integration

Downloads

24

Readme

stripe-multi-payments

A Node.js module for simplified payment processing via the Stripe integration in a multi-user environment for transfer to connect accounts with calculation.

Introduction

stripe-multi-payments streamlines the process of handling payments through the Stripe API in a multi-user application. This package provides a flexible and convenient interface for developers to seamlessly integrate payment processing functionality into their Next.js/Node js projects.

Features

  • Multi-User Support: Easily process payments on behalf of individual users in a multi-user system.
  • Flexible Configuration: Configure the package using environment variables and your Stripe account settings.
  • Automatic Stripe Charges: Automatically calculate and deduct Stripe charges from the payment amount.

Installation

  1. Install the package using npm:

    npm install stripe-multi-payments
    Set Up Your Stripe Account

If you don't have a Stripe account, follow these steps to create one:

  1. Sign up for a Stripe account
  2. After signing up, obtain your Stripe secret key from the Stripe Dashboard.
  3. Create a .env file in the root of your project and add your Stripe secret key:
  4. Create stripe connect accounts and configure your account for trsanfer seprate charges and obtained connect ids

Usage with Next.js API

Here's an example of using the module in a Next.js API route:

// Add Account IDs to .env File

NEXT_PUBLIC_STRIPE_SECRET_KEY=sk_test_your_actual_stripe_secret_key
NEXT_PUBLIC_STRIPE_CONNECT_ADMIN_ACCOUNT_ID=acct\***\*\*\*\*\*\*\***oB
NEXT_PUBLIC_STRIPE_CONNECT_VENDOR_ACCOUNT_ID=acct\***\*\*\*\*\*\*\***iV

// pages/api/checkout.js

//Import the Module
import stripeMultiPayments from "stripe-multi-payments";

const secretKey = process.env.NEXT_PUBLIC_STRIPE_SECRET_KEY;
export default async function handler(req, res) {
  if (req.method === "POST") {
    try {
      const cartItems = req.body.cartItem;
      const transformedItems = cartItems.map((item) => ({
        price_data: {
          currency: "usd",
          product_data: {
            name: item.name,
            images: [req.headers.origin + item.image],
          },
          unit_amount: item.price * 100,
        },
        quantity: item.quantity,
      }));
      let successUrl = `${req.headers.origin}/success`;
      let cancelUrl = `${req.headers.origin}/cancel`;
      let paymentMode = "payment";
      const paymentResult = await stripeMultiPayments.processPayment(
        secretKey,
        transformedItems,
        successUrl,
        cancelUrl,
        paymentMode
      );
      res.json({ success: true, result: paymentResult });
    } catch (error) {
      console.error("Error processing payment:", error);
      res
        .status(500)
        .json({ success: false, message: "Internal server error" });
    }
  } else {
    res.setHeader("Allow", "POST");
    res.status(405).end("Method Not Allowed");
  }
}

// page/api/webhook

const stripeMultiPayments = require("stripe-multi-payments");
import { buffer } from "micro";

const secretKey = 'your*stripe_secret_key';
const webhookSecret = 'your_webhook_secret';
let transferGroups = {
         "adminAccountId": process.env.NEXT_PUBLIC_STRIPE_CONNECT_ADMIN_ACCOUNT_ID,
         "vendorAccountId": process.env.NEXT_PUBLIC_STRIPE_CONNECT_VENDOR_ACCOUNT_ID,
         "vendorPayPercentange": 90 // Percentage of the amount to be paid to the vendor
     }
export default async (req, res) => {
 if (req.method === "POST") {
     const sig = req.headers["stripe-signature"];
     const body = await buffer(req);
     try {
         await stripeMultiPayments.handleWebhookAndTransfers(
             secretKey,
             webhookSecret,
             body,
             sig,
             transferGroups
         );
     } catch (error) {
         return res.status(400).send(`Webhook error: ${error.message}`);
     }
 } else {
     res.setHeader("Allow", ["POST", "GET"]);
     res.status(405).end("Method Not Allowed");
 }
};

export const config = {
 api: {
     bodyParser: false,
     externalResolver: true,
 },
};

Make sure to replace placeholders like 'your_stripe_secret_key', 'your_webhook_secret', and others with your actual values.

Feel free to customize the code based on your project's needs and structure.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.