# Stripe

We created a Stripe crate in order to regroup all the associated functions. For example, the handling of the customers, or of the webhooks.

# Webhook handler system

In order for our app to work, we've created a webhook handler system. For the moment, we've added the logic only for the customer creation event, but we'll add more in the future. You can also add the events that you're interested in by adding the event to the match in the handle_webhook function in webhooks.rs.

# Stripe Customers

As this object is one of the principal Stripe objects when coming to code, we've added a customer management. It is very simple, as it only updates the database user which matches with the email we find in the event.

# Crate content

# Structs

#[derive(Debug, Clone, Deserialize)]
pub struct StripeCreateCustomerPayload {
  pub email: String,
  pub name: String,
  pub metadata: HashMap<String, String>,
}

# Methods

pub fn init_client(secret_key: String) -> Client
pub async fn webhook_handler(req: HttpRequest, payload: web::Bytes, state: Data<AppState>) -> HttpResponse
pub async fn handle_webhook(req: HttpRequest, payload: web::Bytes, state: Data<AppState>) -> Result<(), WebhookError>
fn get_header_value<'b>(req: &'b HttpRequest, key: &'b str) -> Option<&'b str>
pub async fn create_customer(state: Data<AppState>, customer_payload: Json<StripeCreateCustomerPayload>) -> Result<HttpResponse, RustSaaSError>
pub fn handle_account_updated(account: stripe::Account) -> Result<(), WebhookError>
pub async fn handle_customer_created(customer: Customer, pool: &PgPool) -> Result<(), RustSaaSError>