Stripe
A secure client library for Stripe's API
Install
npm install @appstitch/stripeappstitch_stripe: ^1.0.0Install Peer Dependencies
npm install @appstitch/core
npm install @appstitch/typesappstitch_core: ^2.0.0Usage
Apart from a few exceptions, this library mirror Stripe's API. You can use Stripe's Docs for reference.
import { createSubscription } from "@appstitch/stripe";
// OR
import * as stripeClient from "@appstitch/stripe";import 'package:appstitch_stripe/stripe.dart'Create a customer
import * as stripe from "@appstitch/stripe";
const createCustomer = () => {
stripe.createCustomer({
email: "[email protected]"
})
.then((res) => {
if (res.object === "customer") {
// success
}
})
}import 'package:appstitch_stripe/stripe.dart';
import 'package:appstitch_stripe/types.dart';
createCustomer() async {
final customerOpts = CreateCustomerOpts(email: "[email protected]");
final customer = await stripe.createCustomer(customerOpts);
if (customer.object == "customer") {
// success
}
}
Create a subscription
import * as stripe from "@appstitch/stripe";
const createSubscription = () => {
stripe.createSubsciption({
customer : "cus_ABC123456",
items:[{price : "price_XYZ123456"}],
})
.then(result => {
if(result.object === "subscription")
{
// Success
}
})
}import 'package:appstitch_stripe/stripe.dart'
import 'package:appstitch_stripe/types.dart';
createSubscription() async {
final subscriptionOpts = CreateSubscriptionOpts(
customer: "cus_ABC123456",
items: [SubscriptionItemOpts(price: "price_XYZ123456")],
);
final subscription = await stripe.createCustomer(subscriptionOpts);
if (subscription.object == "subscription") {
// success
}
}Create a Payment Intent
import * as stripe from "@appstitch/stripe";
const createPaymentIntent = () => {
stripeClient.createPaymentIntent({
customer: "cus_abc123"
amount : 2500, // $25.00
currency:"usd",
confirm:true
receipt_email: "[email protected]"
})
.then(result => {
if(result.object === "payment_intent")
{
// Success
}
})
}
import 'package:appstitch_stripe/stripe.dart'
import 'package:appstitch_stripe/types.dart';
createPaymentIntent() async {
final paymentIntentOpts = CreatePaymentIntentOpts(
customer: "cus_abc123",
amount: 2500, // $25.00
currency: "usd",
confirm: true,
receiptEmail: "[email protected]");
final paymentIntent = await stripe.createPaymentIntent(paymentIntentOpts);
if (paymentIntent.object == "payment_intent") {
// success
}
}Stripe Connect Options
All requests can be made on behalf of another Stripe Account. Here's how you do it
import * as stripe from "@appstitch/stripe";
const createPaymentIntent = () => {
stripe.createPaymentIntent({
customer: "cus_abc123"
amount : 2500,
currency:"usd",
confirm:true
receipt_email: "[email protected]"
// Stripe Account ID
stripeAccount : "act_xyz890"
})
.then(result => {
if(result.object === "payment_intent")
{
// Success
}
})
}import 'package:appstitch_stripe/types.dart';
createCustomer() async {
final customerOpts = CreateCustomerOpts(email: "[email protected]");
// Stripe Account ID
customerOpts.stripeAccount = "act_abc123";
final customer = await stripe.createCustomer(customerOpts);
if (customer.object == "customer") {
// success
}
}Exceptions
For Retrieve, Delete and Update requests, Stripe Api look something similar to this
// Update a customer
customers.update(id, {
...options
})After consideration, we went for chose to go for this approach instead. Notice the invoice id is passed with the update options
// Update a customer
updateInvoice({
id,
...options
})Reference Stripe's Docs
Last updated
Was this helpful?