
Simple Stripe Client for basic create checkout session and webhook event.
Simplify Stripe integration.
- Support price (not product)
- Support one-time
payment and subscription.
- The backend creates a checkout session and returns a session ID and session URL.
- The backend listens for webhooks and paid payment/invoice and cancellation.
Webhook listening:
checkout.session.completed
invoice.paid
invoice.payment_failed
customer.subscription.deleted
Example
use simple_stripe::{SimpleEvent, Stripe};
#[tokio::main]
async fn main() {
let secret = "sk_xxx";
let webhook_key = "whsec_xxx";
let mut stripe = Stripe::init(secret, webhook_key);
stripe.add_payment_price(price_id1);
stripe.add_subscription_price(price_id2);
stripe.set_urls("https://success.url", "https://cacel.url");
let (session_id, session_url) = stripe.create_session(
your_uuid,
email_option,
customer_option,
price_id,
quantity
).await?;
let signature = headers.get("stripe-signature").unwrap().to_str().unwrap();
let event = stripe.simple_event(&request_body, &signature)
match event {
SimpleEvent::PaymentComplete(session_id, customer) => {
}
SimpleEvent::SubscriptionCreated(session, customer) => {
}
SimpleEvent::SubscriptionPaid(customer, _products) => {
}
SimpleEvent::SubscriptionDeleted(customer, _products) => {
}
SimpleEvent::None(_type) => (),
}
}
License
This project is licensed under either of
at your option.