forked from arlyon/async-stripe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhook-axum.rs
35 lines (30 loc) · 973 Bytes
/
webhook-axum.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//! Web Hooks
//! =========
//!
//! Reference: <https://stripe.com/docs/webhooks/test>
//!
//! This example shows how to manage web hooks.
//! To trigger it, you can use the stripe cli.
//!
//! TLDR;
//! ```
//! stripe listen --forward-to localhost:4242/stripe_webhooks
//! stripe trigger checkout.session.completed
//! ```
use std::net::SocketAddr;
use axum::{routing::post, Json, Router};
use stripe::Event;
#[tokio::main]
async fn main() {
// build our application with a route
let app = Router::new().route("/stripe_webhooks", post(root));
// run our app with hyper
// `axum::Server` is a re-export of `hyper::Server`
let addr = SocketAddr::from(([127, 0, 0, 1], 4242));
println!("listening on {}", addr);
axum::Server::bind(&addr).serve(app.into_make_service()).await.unwrap();
}
// basic handler that parses stripe webhooks
async fn root(Json(event): Json<Event>) {
println!("received event '{}' ({}) ", event.type_, event.id);
}