1.0.11 โข Published 3 years ago
@dulysse1/better-stripe v1.0.11
๐ฑ Better Stripe ๐ฑ
Stripe connector with instance selector
![]()
Prerequisites
Environment variable:
STRIPE_API_SECRET="sk_stripe"
Architecture ๐
/better-stripe
--/@types
--/index.d.ts: Type definition of the module
--/lib
--/hook.js : Stripe hooks initialized here
--/setup.js : private methods and set up
--/stripe.js : file called to initialize stripe instanceHow to use ? ๐ค
With commonJS
const { Stripe } = require("@dulysse1/better-stripe");With ES6 and more
import { Stripe } from "@dulysse1/better-stripe";Documentation ๐ง
Choose instance:
Default instance ๐ฅ
const { Stripe } = require("@dulysse1/better-stripe");
Stripe.main; // use Stripe secret key in .env file (STRIPE_API_SECRET)Dynamic instance โก๏ธ
const { Stripe } = require("@dulysse1/better-stripe");
Stripe.store("sk_stripe"); // use specific Stripe secret key !Methods:
Get Stripe initialized ๐
const { Stripe } = require("@dulysse1/better-stripe");
const stripe = Stripe.main.getInstance();
console.log(stripe);> Stripe [object, Object]Upload Image to Stripe ๐
const { Stripe } = require("@dulysse1/better-stripe");
const fs = require("fs");
const fileBuffer = fs.readFileSync("./file.png");
const { url } = await Stripe.store("sk_stripe").uploadImage(
fileBuffer,
"demo.png"
);
console.log(url);> "https://url.of.stripe.image.demo.png"List Stripe customers ๐งโ๐ป
const { Stripe } = require("@dulysse1/better-stripe");
const { data } = await Stripe.main.listCustomers();
console.log(data);> [ ... ]Create a new Stripe customer ๐งโ๐ป
const { Stripe } = require("@dulysse1/better-stripe");
const { id } = await Stripe.main.createCustomer({
name: "customer_name",
email: "customer_email",
description: "customer_description",
address: "customer_address",
});
console.log(id);> "cus_MuMfCIj5KbYc6P"List Stripe products ๐ฅ
const { Stripe } = require("@dulysse1/better-stripe");
const { data } = await Stripe.store("sk_stripe").listProduct();
console.log(data);> [ ... ]Create a new Stripe product ๐ฅ
const { Stripe } = require("@dulysse1/better-stripe");
const { id } = await Stripe.main.createProduct({
name: "product_name",
description: "product_description",
images: ["stripe_file_url"],
default_price_data: {
currency: "EUR",
unit_amount_decimal: 1000, // 10 โฌ
},
});
console.log(id);> "prod_MuMepkWVBITkxl"Create a new Stripe session checkout ๐งพ
const { Stripe } = require("@dulysse1/better-stripe");
const { url } = await Stripe.store("sk_stripe").createCheckout(
[
{
quantity: 1,
price: "price_id",
},
],
"http://localhost:1337/callback/success",
"http://localhost:1337/callback/error"
);
console.log(url);> "https://stripe.com/checkout/session/dzedjeojferifozeji4dz5de4zed46"Get balance of Stripe ๐ธ
const { Stripe } = require("@dulysse1/better-stripe");
const balance = await Stripe.main.getBalance();
console.log(balance);> {
object: 'balance',
available: [Array],
livemode: false,
pending: [Array]
}...and more ! โ๏ธ
Information
Author: Ulysse Dupont @Ulysse
Contact: ulysse@euranov.com