shared/api/endpoints/
billing.rs

1use super::ApiEndpoint;
2use crate::domain::billing::{
3    AdminUpgradeSubscriptionPlanPath, AdminUpgradeSubscriptionPlanRequest,
4    CreateCustomerPortalLinkPath, CreateSetupIntentPath, CreateSetupIntentRequest,
5    SubscriptionCancellationStatusRequest, SubscriptionPauseRequest,
6    UpdateSubscriptionCancellationPath, UpdateSubscriptionPausedPath, UpgradeSubscriptionPlanPath,
7    UpgradeSubscriptionPlanRequest,
8};
9use crate::error::BillingError;
10use crate::{
11    api::Method,
12    domain::billing::{
13        CreateSubscriptionPath, CreateSubscriptionRequest, CreateSubscriptionResponse,
14    },
15};
16
17/// Create a subscription and store payment info if provided
18pub struct CreateSubscription;
19impl ApiEndpoint for CreateSubscription {
20    type Path = CreateSubscriptionPath;
21    type Req = CreateSubscriptionRequest;
22    type Res = Option<CreateSubscriptionResponse>;
23    type Err = BillingError;
24    const METHOD: Method = Method::Post;
25}
26
27/// Set the cancellation status of a subscription
28pub struct UpdateSubscriptionCancellation;
29impl ApiEndpoint for UpdateSubscriptionCancellation {
30    type Path = UpdateSubscriptionCancellationPath;
31    type Req = SubscriptionCancellationStatusRequest;
32    type Res = ();
33    type Err = BillingError;
34    const METHOD: Method = Method::Patch;
35}
36
37/// Set whether the subscription is paused or not
38pub struct UpdateSubscriptionPaused;
39impl ApiEndpoint for UpdateSubscriptionPaused {
40    type Path = UpdateSubscriptionPausedPath;
41    type Req = SubscriptionPauseRequest;
42    type Res = ();
43    type Err = BillingError;
44    const METHOD: Method = Method::Patch;
45}
46
47/// Set the cancellation status of a subscription
48pub struct UpgradeSubscriptionPlan;
49impl ApiEndpoint for UpgradeSubscriptionPlan {
50    type Path = UpgradeSubscriptionPlanPath;
51    type Req = UpgradeSubscriptionPlanRequest;
52    type Res = ();
53    type Err = BillingError;
54    const METHOD: Method = Method::Post;
55}
56
57/// Set the cancellation status of a subscription
58pub struct AdminUpgradeSubscriptionPlan;
59impl ApiEndpoint for AdminUpgradeSubscriptionPlan {
60    type Path = AdminUpgradeSubscriptionPlanPath;
61    type Req = AdminUpgradeSubscriptionPlanRequest;
62    type Res = ();
63    type Err = BillingError;
64    const METHOD: Method = Method::Post;
65}
66
67/// Create a setup intent so that a customer can add a payment method
68pub struct CreateSetupIntent;
69impl ApiEndpoint for CreateSetupIntent {
70    type Path = CreateSetupIntentPath;
71    type Req = CreateSetupIntentRequest;
72    type Res = String;
73    type Err = BillingError;
74    const METHOD: Method = Method::Post;
75}
76
77/// Generate a link for a customer to view their Stripe customer portal
78pub struct CreateCustomerPortalLink;
79impl ApiEndpoint for CreateCustomerPortalLink {
80    type Path = CreateCustomerPortalLinkPath;
81    type Req = ();
82    type Res = String;
83    type Err = BillingError;
84    const METHOD: Method = Method::Get;
85}