rustauth-stripe 0.2.0

Stripe integration for RustAuth.
Documentation
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
use std::future::Future;
use std::sync::Arc;

use rustauth_core::api::ApiRequest;
use rustauth_core::context::AuthContext;
use rustauth_core::db::{Session, User};
use rustauth_core::env::logger::Logger;
use rustauth_core::error::RustAuthError;
use rustauth_core::plugin::PluginSchemaContribution;
use serde_json::json;

use crate::models::{StripeEvent, StripeSubscription, Subscription};
use crate::stripe_api::StripeClient;

#[non_exhaustive]
#[derive(Clone)]
pub struct StripeOptions {
    pub(crate) stripe_client: StripeClient,
    pub(crate) stripe_webhook_secret: String,
    pub(crate) create_customer_on_sign_up: bool,
    pub(crate) subscription: Option<SubscriptionOptions>,
    pub(crate) organization: Option<OrganizationStripeOptions>,
    pub(crate) on_event: Option<StripeEventHook>,
    pub(crate) on_customer_create: Option<CustomerCreateHook>,
    pub(crate) get_customer_create_params: Option<GetCustomerCreateParamsHook>,
    pub(crate) schema: Vec<PluginSchemaContribution>,
}

type StripeEventHook = Arc<
    dyn Fn(StripeEvent) -> crate::stripe_api::BoxFuture<'static, Result<(), RustAuthError>>
        + Send
        + Sync,
>;
type CustomerCreateHook = Arc<
    dyn Fn(
            CustomerCreateInput,
            CustomerCreateContext,
        ) -> crate::stripe_api::BoxFuture<'static, Result<(), RustAuthError>>
        + Send
        + Sync,
>;
type GetCustomerCreateParamsHook = Arc<
    dyn Fn(
            CustomerCreateParamsInput,
            CustomerCreateContext,
        )
            -> crate::stripe_api::BoxFuture<'static, Result<serde_json::Value, RustAuthError>>
        + Send
        + Sync,
>;

#[derive(Clone)]
pub struct CustomerCreateContext {
    pub base_url: Option<String>,
    pub request_path: Option<String>,
    pub logger: Logger,
}

impl std::fmt::Debug for CustomerCreateContext {
    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        formatter
            .debug_struct("CustomerCreateContext")
            .field("base_url", &self.base_url)
            .field("request_path", &self.request_path)
            .finish_non_exhaustive()
    }
}

impl CustomerCreateContext {
    pub fn from_auth_context(context: &AuthContext) -> Self {
        Self {
            base_url: Some(context.base_url.clone()),
            request_path: None,
            logger: context.logger.clone(),
        }
    }

    pub fn database_hook(request_path: Option<String>, logger: &Logger) -> Self {
        Self {
            base_url: None,
            request_path,
            logger: logger.clone(),
        }
    }
}

#[derive(Debug, Clone, PartialEq)]
pub struct CustomerCreateInput {
    pub stripe_customer: serde_json::Value,
    pub user: User,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CustomerCreateParamsInput {
    pub user: User,
}

impl StripeOptions {
    pub fn new(stripe_client: StripeClient, stripe_webhook_secret: impl Into<String>) -> Self {
        Self {
            stripe_client,
            stripe_webhook_secret: stripe_webhook_secret.into(),
            create_customer_on_sign_up: false,
            subscription: None,
            organization: None,
            on_event: None,
            on_customer_create: None,
            get_customer_create_params: None,
            schema: Vec::new(),
        }
    }

    /// Development only — do not use in production.
    ///
    /// Uses a no-op HTTP transport and the placeholder webhook secret `whsec_dev`.
    pub fn dev() -> Self {
        use std::sync::Arc;

        use crate::stripe_api::{
            StripeRequest, StripeResponse, StripeTransport, StripeTransportFuture,
        };

        struct DevStripeTransport;

        impl StripeTransport for DevStripeTransport {
            fn send<'a>(&'a self, _request: StripeRequest) -> StripeTransportFuture<'a> {
                Box::pin(async move {
                    Ok(StripeResponse {
                        status: 200,
                        body: serde_json::json!({}),
                    })
                })
            }
        }

        Self::new(
            StripeClient::with_transport("sk_test_dev", Arc::new(DevStripeTransport)),
            "whsec_dev",
        )
    }

    pub fn create_customer_on_sign_up(mut self, enabled: bool) -> Self {
        self.create_customer_on_sign_up = enabled;
        self
    }

    pub fn subscription(mut self, subscription: SubscriptionOptions) -> Self {
        self.subscription = Some(subscription);
        self
    }

    pub fn organization(mut self, organization: OrganizationStripeOptions) -> Self {
        self.organization = Some(organization);
        self
    }

    pub fn schema(mut self, contribution: PluginSchemaContribution) -> Self {
        self.schema.push(contribution);
        self
    }

    pub fn on_event<F, Fut>(mut self, hook: F) -> Self
    where
        F: Fn(StripeEvent) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = Result<(), RustAuthError>> + Send + 'static,
    {
        self.on_event = Some(Arc::new(move |event| Box::pin(hook(event))));
        self
    }

    pub fn on_customer_create<F, Fut>(mut self, hook: F) -> Self
    where
        F: Fn(CustomerCreateInput, CustomerCreateContext) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = Result<(), RustAuthError>> + Send + 'static,
    {
        self.on_customer_create = Some(Arc::new(move |input, ctx| Box::pin(hook(input, ctx))));
        self
    }

    pub fn get_customer_create_params<F, Fut>(mut self, hook: F) -> Self
    where
        F: Fn(CustomerCreateParamsInput, CustomerCreateContext) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = Result<serde_json::Value, RustAuthError>> + Send + 'static,
    {
        self.get_customer_create_params =
            Some(Arc::new(move |input, ctx| Box::pin(hook(input, ctx))));
        self
    }

    pub fn to_metadata(&self) -> serde_json::Value {
        json!({
            "subscription": self.subscription.as_ref().map(|subscription| json!({
                "enabled": subscription.enabled,
                "plans": subscription.plans.iter().map(|plan| plan.name.clone()).collect::<Vec<_>>()
            })),
            "organization": self.organization.as_ref().map(|organization| json!({
                "enabled": organization.enabled
            })),
            "createCustomerOnSignUp": self.create_customer_on_sign_up
        })
    }
}

#[non_exhaustive]
#[derive(Clone)]
pub struct SubscriptionOptions {
    pub(crate) enabled: bool,
    pub(crate) plans: Arc<Vec<StripePlan>>,
    pub(crate) get_plans: Option<GetPlansHook>,
    pub(crate) require_email_verification: bool,
    pub(crate) authorize_reference: Option<AuthorizeReferenceHook>,
    pub(crate) on_subscription_complete: Option<SubscriptionLifecycleHook>,
    pub(crate) on_subscription_created: Option<SubscriptionLifecycleHook>,
    pub(crate) on_subscription_update: Option<SubscriptionUpdateHook>,
    pub(crate) on_subscription_cancel: Option<SubscriptionLifecycleHook>,
    pub(crate) on_subscription_deleted: Option<SubscriptionLifecycleHook>,
    pub(crate) get_checkout_session_params: Option<GetCheckoutSessionParamsHook>,
}

type GetPlansHook = Arc<
    dyn Fn() -> crate::stripe_api::BoxFuture<'static, Result<Vec<StripePlan>, RustAuthError>>
        + Send
        + Sync,
>;

type AuthorizeReferenceHook = Arc<
    dyn Fn(
            AuthorizeReferenceInput,
            &AuthContext,
        ) -> crate::stripe_api::BoxFuture<'static, Result<bool, RustAuthError>>
        + Send
        + Sync,
>;

type SubscriptionLifecycleHook = Arc<
    dyn Fn(
            SubscriptionLifecycleInput,
        ) -> crate::stripe_api::BoxFuture<'static, Result<(), RustAuthError>>
        + Send
        + Sync,
>;

type SubscriptionUpdateHook = Arc<
    dyn Fn(
            SubscriptionUpdateInput,
        ) -> crate::stripe_api::BoxFuture<'static, Result<(), RustAuthError>>
        + Send
        + Sync,
>;
type GetCheckoutSessionParamsHook = Arc<
    dyn Fn(
            CheckoutSessionParamsInput,
            &ApiRequest,
            &AuthContext,
        )
            -> crate::stripe_api::BoxFuture<'static, Result<serde_json::Value, RustAuthError>>
        + Send
        + Sync,
>;

#[derive(Debug, Clone, PartialEq)]
pub struct SubscriptionLifecycleInput {
    pub event: StripeEvent,
    pub subscription: Subscription,
    pub stripe_subscription: Option<StripeSubscription>,
    pub plan: Option<StripePlan>,
    pub cancellation_details: Option<serde_json::Value>,
}

#[derive(Debug, Clone, PartialEq)]
pub struct SubscriptionUpdateInput {
    pub event: StripeEvent,
    pub subscription: Subscription,
}

#[derive(Debug, Clone, PartialEq)]
pub struct CheckoutSessionParamsInput {
    pub user: User,
    pub session: Session,
    pub plan: StripePlan,
    pub subscription: Subscription,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AuthorizeReferenceInput {
    pub user_id: String,
    pub user: User,
    pub session: Session,
    pub reference_id: String,
    pub action: AuthorizeReferenceAction,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AuthorizeReferenceAction {
    UpgradeSubscription,
    ListSubscription,
    CancelSubscription,
    RestoreSubscription,
    BillingPortal,
}

impl AuthorizeReferenceAction {
    pub fn as_str(self) -> &'static str {
        match self {
            Self::UpgradeSubscription => "upgrade-subscription",
            Self::ListSubscription => "list-subscription",
            Self::CancelSubscription => "cancel-subscription",
            Self::RestoreSubscription => "restore-subscription",
            Self::BillingPortal => "billing-portal",
        }
    }
}

impl SubscriptionOptions {
    pub fn enabled(plans: Vec<StripePlan>) -> Self {
        Self {
            enabled: true,
            plans: Arc::new(plans),
            get_plans: None,
            require_email_verification: false,
            authorize_reference: None,
            on_subscription_complete: None,
            on_subscription_created: None,
            on_subscription_update: None,
            on_subscription_cancel: None,
            on_subscription_deleted: None,
            get_checkout_session_params: None,
        }
    }

    pub fn enabled_dynamic<F, Fut>(provider: F) -> Self
    where
        F: Fn() -> Fut + Send + Sync + 'static,
        Fut: Future<Output = Result<Vec<StripePlan>, RustAuthError>> + Send + 'static,
    {
        Self {
            get_plans: Some(Arc::new(move || Box::pin(provider()))),
            ..Self::enabled(Vec::new())
        }
    }

    pub fn plans_provider<F, Fut>(mut self, provider: F) -> Self
    where
        F: Fn() -> Fut + Send + Sync + 'static,
        Fut: Future<Output = Result<Vec<StripePlan>, RustAuthError>> + Send + 'static,
    {
        self.get_plans = Some(Arc::new(move || Box::pin(provider())));
        self
    }

    pub async fn resolve_plans(&self) -> Result<Self, RustAuthError> {
        let Some(provider) = &self.get_plans else {
            return Ok(self.clone());
        };
        let plans = provider().await?;
        let mut resolved = self.clone();
        resolved.plans = Arc::new(plans);
        Ok(resolved)
    }

    pub fn require_email_verification(mut self, enabled: bool) -> Self {
        self.require_email_verification = enabled;
        self
    }

    pub fn authorize_reference<F, Fut>(mut self, hook: F) -> Self
    where
        F: Fn(AuthorizeReferenceInput, &AuthContext) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = Result<bool, RustAuthError>> + Send + 'static,
    {
        self.authorize_reference = Some(Arc::new(move |input, ctx| Box::pin(hook(input, ctx))));
        self
    }

    pub fn get_checkout_session_params<F, Fut>(mut self, hook: F) -> Self
    where
        F: Fn(CheckoutSessionParamsInput, &ApiRequest, &AuthContext) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = Result<serde_json::Value, RustAuthError>> + Send + 'static,
    {
        self.get_checkout_session_params = Some(Arc::new(move |input, request, ctx| {
            Box::pin(hook(input, request, ctx))
        }));
        self
    }

    pub fn on_subscription_complete<F, Fut>(mut self, hook: F) -> Self
    where
        F: Fn(SubscriptionLifecycleInput) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = Result<(), RustAuthError>> + Send + 'static,
    {
        self.on_subscription_complete = Some(Arc::new(move |input| Box::pin(hook(input))));
        self
    }

    pub fn on_subscription_created<F, Fut>(mut self, hook: F) -> Self
    where
        F: Fn(SubscriptionLifecycleInput) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = Result<(), RustAuthError>> + Send + 'static,
    {
        self.on_subscription_created = Some(Arc::new(move |input| Box::pin(hook(input))));
        self
    }

    pub fn on_subscription_update<F, Fut>(mut self, hook: F) -> Self
    where
        F: Fn(SubscriptionUpdateInput) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = Result<(), RustAuthError>> + Send + 'static,
    {
        self.on_subscription_update = Some(Arc::new(move |input| Box::pin(hook(input))));
        self
    }

    pub fn on_subscription_cancel<F, Fut>(mut self, hook: F) -> Self
    where
        F: Fn(SubscriptionLifecycleInput) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = Result<(), RustAuthError>> + Send + 'static,
    {
        self.on_subscription_cancel = Some(Arc::new(move |input| Box::pin(hook(input))));
        self
    }

    pub fn on_subscription_deleted<F, Fut>(mut self, hook: F) -> Self
    where
        F: Fn(SubscriptionLifecycleInput) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = Result<(), RustAuthError>> + Send + 'static,
    {
        self.on_subscription_deleted = Some(Arc::new(move |input| Box::pin(hook(input))));
        self
    }
}

#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
pub struct StripePlan {
    pub(crate) name: String,
    pub(crate) price_id: Option<String>,
    pub(crate) lookup_key: Option<String>,
    pub(crate) annual_discount_price_id: Option<String>,
    pub(crate) annual_discount_lookup_key: Option<String>,
    pub(crate) limits: Option<serde_json::Value>,
    pub(crate) group: Option<String>,
    pub(crate) seat_price_id: Option<String>,
    pub(crate) proration_behavior: Option<String>,
    pub(crate) line_items: Vec<serde_json::Value>,
    pub(crate) free_trial: Option<FreeTrialOptions>,
}

impl StripePlan {
    pub fn new(name: impl Into<String>) -> Self {
        Self {
            name: name.into(),
            price_id: None,
            lookup_key: None,
            annual_discount_price_id: None,
            annual_discount_lookup_key: None,
            limits: None,
            group: None,
            seat_price_id: None,
            proration_behavior: None,
            line_items: Vec::new(),
            free_trial: None,
        }
    }

    pub fn name(&self) -> &str {
        &self.name
    }

    pub fn price_id(mut self, price_id: impl Into<String>) -> Self {
        self.price_id = Some(price_id.into());
        self
    }

    pub fn lookup_key(mut self, lookup_key: impl Into<String>) -> Self {
        self.lookup_key = Some(lookup_key.into());
        self
    }

    pub fn annual_discount_price_id(mut self, price_id: impl Into<String>) -> Self {
        self.annual_discount_price_id = Some(price_id.into());
        self
    }

    pub fn annual_discount_lookup_key(mut self, lookup_key: impl Into<String>) -> Self {
        self.annual_discount_lookup_key = Some(lookup_key.into());
        self
    }

    pub fn seat_price_id(mut self, price_id: impl Into<String>) -> Self {
        self.seat_price_id = Some(price_id.into());
        self
    }

    pub fn limits(mut self, limits: serde_json::Value) -> Self {
        self.limits = Some(limits);
        self
    }

    pub fn group(mut self, group: impl Into<String>) -> Self {
        self.group = Some(group.into());
        self
    }

    pub fn line_item(mut self, line_item: serde_json::Value) -> Self {
        self.line_items.push(line_item);
        self
    }

    pub fn proration_behavior(mut self, proration_behavior: impl Into<String>) -> Self {
        self.proration_behavior = Some(proration_behavior.into());
        self
    }

    pub fn free_trial(mut self, free_trial: FreeTrialOptions) -> Self {
        self.free_trial = Some(free_trial);
        self
    }
}

#[non_exhaustive]
#[derive(Clone)]
pub struct FreeTrialOptions {
    pub(crate) days: i64,
    pub(crate) on_trial_start: Option<TrialStartHook>,
    pub(crate) on_trial_end: Option<TrialLifecycleHook>,
    pub(crate) on_trial_expired: Option<TrialLifecycleHook>,
}

type TrialStartHook = Arc<
    dyn Fn(Subscription) -> crate::stripe_api::BoxFuture<'static, Result<(), RustAuthError>>
        + Send
        + Sync,
>;
type TrialLifecycleHook = Arc<
    dyn Fn(
            Subscription,
            &AuthContext,
        ) -> crate::stripe_api::BoxFuture<'static, Result<(), RustAuthError>>
        + Send
        + Sync,
>;

impl std::fmt::Debug for FreeTrialOptions {
    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        formatter
            .debug_struct("FreeTrialOptions")
            .field("days", &self.days)
            .finish_non_exhaustive()
    }
}

impl PartialEq for FreeTrialOptions {
    fn eq(&self, other: &Self) -> bool {
        self.days == other.days
    }
}

impl Eq for FreeTrialOptions {}

impl FreeTrialOptions {
    pub fn new(days: i64) -> Self {
        Self {
            days,
            on_trial_start: None,
            on_trial_end: None,
            on_trial_expired: None,
        }
    }

    pub fn on_trial_start<F, Fut>(mut self, hook: F) -> Self
    where
        F: Fn(Subscription) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = Result<(), RustAuthError>> + Send + 'static,
    {
        self.on_trial_start = Some(Arc::new(move |subscription| Box::pin(hook(subscription))));
        self
    }

    pub fn on_trial_end<F, Fut>(mut self, hook: F) -> Self
    where
        F: Fn(Subscription, &AuthContext) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = Result<(), RustAuthError>> + Send + 'static,
    {
        self.on_trial_end = Some(Arc::new(move |subscription, ctx| {
            Box::pin(hook(subscription, ctx))
        }));
        self
    }

    pub fn on_trial_expired<F, Fut>(mut self, hook: F) -> Self
    where
        F: Fn(Subscription, &AuthContext) -> Fut + Send + Sync + 'static,
        Fut: Future<Output = Result<(), RustAuthError>> + Send + 'static,
    {
        self.on_trial_expired = Some(Arc::new(move |subscription, ctx| {
            Box::pin(hook(subscription, ctx))
        }));
        self
    }
}

#[non_exhaustive]
#[derive(Clone)]
pub struct OrganizationStripeOptions {
    pub(crate) enabled: bool,
    pub(crate) get_customer_create_params: Option<GetOrganizationCustomerCreateParamsHook>,
    pub(crate) on_customer_create: Option<OrganizationCustomerCreateHook>,
}

type GetOrganizationCustomerCreateParamsHook = Arc<
    dyn Fn(
            OrganizationCustomerCreateParamsInput,
            CustomerCreateContext,
        )
            -> crate::stripe_api::BoxFuture<'static, Result<serde_json::Value, RustAuthError>>
        + Send
        + Sync,
>;
type OrganizationCustomerCreateHook = Arc<
    dyn Fn(
            OrganizationCustomerCreateInput,
            CustomerCreateContext,
        ) -> crate::stripe_api::BoxFuture<'static, Result<(), RustAuthError>>
        + Send
        + Sync,
>;

#[derive(Debug, Clone, PartialEq)]
pub struct OrganizationCustomerCreateParamsInput {
    pub organization: serde_json::Value,
}

#[derive(Debug, Clone, PartialEq)]
pub struct OrganizationCustomerCreateInput {
    pub stripe_customer: serde_json::Value,
    pub organization: serde_json::Value,
}

impl OrganizationStripeOptions {
    pub fn enabled() -> Self {
        Self {
            enabled: true,
            get_customer_create_params: None,
            on_customer_create: None,
        }
    }

    pub fn get_customer_create_params<F, Fut>(mut self, hook: F) -> Self
    where
        F: Fn(OrganizationCustomerCreateParamsInput, CustomerCreateContext) -> Fut
            + Send
            + Sync
            + 'static,
        Fut: Future<Output = Result<serde_json::Value, RustAuthError>> + Send + 'static,
    {
        self.get_customer_create_params =
            Some(Arc::new(move |input, ctx| Box::pin(hook(input, ctx))));
        self
    }

    pub fn on_customer_create<F, Fut>(mut self, hook: F) -> Self
    where
        F: Fn(OrganizationCustomerCreateInput, CustomerCreateContext) -> Fut
            + Send
            + Sync
            + 'static,
        Fut: Future<Output = Result<(), RustAuthError>> + Send + 'static,
    {
        self.on_customer_create = Some(Arc::new(move |input, ctx| Box::pin(hook(input, ctx))));
        self
    }
}