simple-stripe

Crates.iosimple-stripe
lib.rssimple-stripe
version0.1.0
created_at2025-07-31 04:25:38.821391+00
updated_at2025-07-31 04:25:38.821391+00
descriptionSimple Stripe for create checkout session and webhook event
homepage
repositoryhttps://github.com/sunhuachuang/simple-stripe
max_upload_size
id1774401
size72,495
Neo Sun (sunhuachuang)

documentation

README

crate doc

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?;

    // just open session url in front-end and pay

    // listen the webhook and parse the event
    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) => {
            // handle the payment session paid & cimpleted
        }
        SimpleEvent::SubscriptionCreated(session, customer) => {
            // handle the subscription session created
        }
        SimpleEvent::SubscriptionPaid(customer, _products) => {
            // handle the subscription paid
        }
        SimpleEvent::SubscriptionDeleted(customer, _products) => {
            // handle the subscription canceled
        }
        SimpleEvent::None(_type) => (),
    }
}

License

This project is licensed under either of

at your option.

Commit count: 0

cargo fmt