1.0.11 โ€ข Published 2 years ago

@dulysse1/better-stripe v1.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

๐Ÿ”ฑ Better Stripe ๐Ÿ”ฑ

Stripe connector with instance selector

https://upload.wikimedia.org/wikipedia/commons/thumb/b/ba/Stripe_Logo%2C_revised_2016.svg/2560px-Stripe_Logo%2C_revised_2016.svg.png

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 instance

How 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

Help me to improve better-stripe !

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago