mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 04:04:43 +08:00
docs(subscription): add open api specs (#9884)
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -1,10 +1,21 @@
|
||||
use common_enums::connector_enums::InvoiceStatus;
|
||||
use common_types::payments::CustomerAcceptance;
|
||||
use common_utils::{events::ApiEventMetric, types::MinorUnit};
|
||||
use common_utils::{
|
||||
events::ApiEventMetric,
|
||||
id_type::{
|
||||
CustomerId, InvoiceId, MerchantConnectorAccountId, MerchantId, PaymentId, ProfileId,
|
||||
SubscriptionId,
|
||||
},
|
||||
types::{MinorUnit, Url},
|
||||
};
|
||||
use masking::Secret;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
use crate::{
|
||||
enums as api_enums,
|
||||
enums::{
|
||||
AuthenticationType, CaptureMethod, Currency, FutureUsage, IntentStatus, PaymentExperience,
|
||||
PaymentMethod, PaymentMethodType, PaymentType,
|
||||
},
|
||||
mandates::RecurringDetails,
|
||||
payments::{Address, NextActionData, PaymentMethodDataRequest},
|
||||
};
|
||||
@ -28,7 +39,7 @@ pub struct CreateSubscriptionRequest {
|
||||
pub coupon_code: Option<String>,
|
||||
|
||||
/// customer ID associated with this subscription.
|
||||
pub customer_id: common_utils::id_type::CustomerId,
|
||||
pub customer_id: CustomerId,
|
||||
|
||||
/// payment details for the subscription.
|
||||
pub payment_details: CreateSubscriptionPaymentDetails,
|
||||
@ -46,7 +57,7 @@ pub struct CreateSubscriptionRequest {
|
||||
#[derive(Debug, Clone, serde::Serialize, ToSchema)]
|
||||
pub struct SubscriptionResponse {
|
||||
/// Unique identifier for the subscription.
|
||||
pub id: common_utils::id_type::SubscriptionId,
|
||||
pub id: SubscriptionId,
|
||||
|
||||
/// Merchant specific Unique identifier.
|
||||
pub merchant_reference_id: Option<String>,
|
||||
@ -61,19 +72,20 @@ pub struct SubscriptionResponse {
|
||||
pub item_price_id: Option<String>,
|
||||
|
||||
/// Associated profile ID.
|
||||
pub profile_id: common_utils::id_type::ProfileId,
|
||||
pub profile_id: ProfileId,
|
||||
|
||||
/// Optional client secret used for secure client-side interactions.
|
||||
#[schema(value_type = Option<String>)]
|
||||
/// This is a token which expires after 15 minutes, used from the client to authenticate and create sessions from the SDK
|
||||
pub client_secret: Option<Secret<String>>,
|
||||
|
||||
/// Merchant identifier owning this subscription.
|
||||
pub merchant_id: common_utils::id_type::MerchantId,
|
||||
pub merchant_id: MerchantId,
|
||||
|
||||
/// Optional coupon code applied to this subscription.
|
||||
pub coupon_code: Option<String>,
|
||||
|
||||
/// Optional customer ID associated with this subscription.
|
||||
pub customer_id: common_utils::id_type::CustomerId,
|
||||
pub customer_id: CustomerId,
|
||||
|
||||
/// Payment details for the invoice.
|
||||
pub payment: Option<PaymentResponseData>,
|
||||
@ -125,15 +137,15 @@ impl SubscriptionResponse {
|
||||
/// By default, `client_secret`, `coupon_code`, and `customer` fields are `None`.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
id: common_utils::id_type::SubscriptionId,
|
||||
id: SubscriptionId,
|
||||
merchant_reference_id: Option<String>,
|
||||
status: SubscriptionStatus,
|
||||
plan_id: Option<String>,
|
||||
item_price_id: Option<String>,
|
||||
profile_id: common_utils::id_type::ProfileId,
|
||||
merchant_id: common_utils::id_type::MerchantId,
|
||||
profile_id: ProfileId,
|
||||
merchant_id: MerchantId,
|
||||
client_secret: Option<Secret<String>>,
|
||||
customer_id: common_utils::id_type::CustomerId,
|
||||
customer_id: CustomerId,
|
||||
payment: Option<PaymentResponseData>,
|
||||
invoice: Option<Invoice>,
|
||||
) -> Self {
|
||||
@ -154,7 +166,7 @@ impl SubscriptionResponse {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
#[derive(Debug, Clone, serde::Serialize, ToSchema)]
|
||||
pub struct GetPlansResponse {
|
||||
pub plan_id: String,
|
||||
pub name: String,
|
||||
@ -162,19 +174,19 @@ pub struct GetPlansResponse {
|
||||
pub price_id: Vec<SubscriptionPlanPrices>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
#[derive(Debug, Clone, serde::Serialize, ToSchema)]
|
||||
pub struct SubscriptionPlanPrices {
|
||||
pub price_id: String,
|
||||
pub plan_id: Option<String>,
|
||||
pub amount: MinorUnit,
|
||||
pub currency: api_enums::Currency,
|
||||
pub currency: Currency,
|
||||
pub interval: PeriodUnit,
|
||||
pub interval_count: i64,
|
||||
pub trial_period: Option<i64>,
|
||||
pub trial_period_unit: Option<PeriodUnit>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
#[derive(Debug, Clone, serde::Serialize, ToSchema)]
|
||||
pub enum PeriodUnit {
|
||||
Day,
|
||||
Week,
|
||||
@ -182,7 +194,8 @@ pub enum PeriodUnit {
|
||||
Year,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||
/// For Client based calls, SDK will use the client_secret\nin order to call /payment_methods\nClient secret will be generated whenever a new\npayment method is created
|
||||
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
pub struct ClientSecret(String);
|
||||
|
||||
impl ClientSecret {
|
||||
@ -199,8 +212,10 @@ impl ClientSecret {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize, serde::Serialize, Debug)]
|
||||
#[derive(serde::Deserialize, serde::Serialize, Debug, ToSchema)]
|
||||
pub struct GetPlansQuery {
|
||||
#[schema(value_type = Option<String>)]
|
||||
/// This is a token which expires after 15 minutes, used from the client to authenticate and create sessions from the SDK
|
||||
pub client_secret: Option<ClientSecret>,
|
||||
pub limit: Option<u32>,
|
||||
pub offset: Option<u32>,
|
||||
@ -215,33 +230,37 @@ impl ApiEventMetric for GetPlansResponse {}
|
||||
pub struct ConfirmSubscriptionPaymentDetails {
|
||||
pub shipping: Option<Address>,
|
||||
pub billing: Option<Address>,
|
||||
pub payment_method: api_enums::PaymentMethod,
|
||||
pub payment_method_type: Option<api_enums::PaymentMethodType>,
|
||||
pub payment_method: PaymentMethod,
|
||||
pub payment_method_type: Option<PaymentMethodType>,
|
||||
pub payment_method_data: PaymentMethodDataRequest,
|
||||
pub customer_acceptance: Option<CustomerAcceptance>,
|
||||
pub payment_type: Option<api_enums::PaymentType>,
|
||||
pub payment_type: Option<PaymentType>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
pub struct CreateSubscriptionPaymentDetails {
|
||||
pub return_url: common_utils::types::Url,
|
||||
pub setup_future_usage: Option<api_enums::FutureUsage>,
|
||||
pub capture_method: Option<api_enums::CaptureMethod>,
|
||||
pub authentication_type: Option<api_enums::AuthenticationType>,
|
||||
pub payment_type: Option<api_enums::PaymentType>,
|
||||
/// The url to which user must be redirected to after completion of the purchase
|
||||
#[schema(value_type = String)]
|
||||
pub return_url: Url,
|
||||
pub setup_future_usage: Option<FutureUsage>,
|
||||
pub capture_method: Option<CaptureMethod>,
|
||||
pub authentication_type: Option<AuthenticationType>,
|
||||
pub payment_type: Option<PaymentType>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
pub struct PaymentDetails {
|
||||
pub payment_method: Option<api_enums::PaymentMethod>,
|
||||
pub payment_method_type: Option<api_enums::PaymentMethodType>,
|
||||
pub payment_method: Option<PaymentMethod>,
|
||||
pub payment_method_type: Option<PaymentMethodType>,
|
||||
pub payment_method_data: Option<PaymentMethodDataRequest>,
|
||||
pub setup_future_usage: Option<api_enums::FutureUsage>,
|
||||
pub setup_future_usage: Option<FutureUsage>,
|
||||
pub customer_acceptance: Option<CustomerAcceptance>,
|
||||
pub return_url: Option<common_utils::types::Url>,
|
||||
pub capture_method: Option<api_enums::CaptureMethod>,
|
||||
pub authentication_type: Option<api_enums::AuthenticationType>,
|
||||
pub payment_type: Option<api_enums::PaymentType>,
|
||||
/// The url to which user must be redirected to after completion of the purchase
|
||||
#[schema(value_type = Option<String>)]
|
||||
pub return_url: Option<Url>,
|
||||
pub capture_method: Option<CaptureMethod>,
|
||||
pub authentication_type: Option<AuthenticationType>,
|
||||
pub payment_type: Option<PaymentType>,
|
||||
}
|
||||
|
||||
// Creating new type for PaymentRequest API call as usage of api_models::PaymentsRequest will result in invalid payment request during serialization
|
||||
@ -249,84 +268,95 @@ pub struct PaymentDetails {
|
||||
#[derive(Debug, Clone, serde::Serialize, ToSchema)]
|
||||
pub struct CreatePaymentsRequestData {
|
||||
pub amount: MinorUnit,
|
||||
pub currency: api_enums::Currency,
|
||||
pub customer_id: Option<common_utils::id_type::CustomerId>,
|
||||
pub currency: Currency,
|
||||
pub customer_id: Option<CustomerId>,
|
||||
pub billing: Option<Address>,
|
||||
pub shipping: Option<Address>,
|
||||
pub profile_id: Option<common_utils::id_type::ProfileId>,
|
||||
pub setup_future_usage: Option<api_enums::FutureUsage>,
|
||||
pub return_url: Option<common_utils::types::Url>,
|
||||
pub capture_method: Option<api_enums::CaptureMethod>,
|
||||
pub authentication_type: Option<api_enums::AuthenticationType>,
|
||||
pub profile_id: Option<ProfileId>,
|
||||
pub setup_future_usage: Option<FutureUsage>,
|
||||
/// The url to which user must be redirected to after completion of the purchase
|
||||
#[schema(value_type = Option<String>)]
|
||||
pub return_url: Option<Url>,
|
||||
pub capture_method: Option<CaptureMethod>,
|
||||
pub authentication_type: Option<AuthenticationType>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, ToSchema)]
|
||||
pub struct ConfirmPaymentsRequestData {
|
||||
pub billing: Option<Address>,
|
||||
pub shipping: Option<Address>,
|
||||
pub profile_id: Option<common_utils::id_type::ProfileId>,
|
||||
pub payment_method: api_enums::PaymentMethod,
|
||||
pub payment_method_type: Option<api_enums::PaymentMethodType>,
|
||||
pub profile_id: Option<ProfileId>,
|
||||
pub payment_method: PaymentMethod,
|
||||
pub payment_method_type: Option<PaymentMethodType>,
|
||||
pub payment_method_data: PaymentMethodDataRequest,
|
||||
pub customer_acceptance: Option<CustomerAcceptance>,
|
||||
pub payment_type: Option<api_enums::PaymentType>,
|
||||
pub payment_type: Option<PaymentType>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, ToSchema)]
|
||||
pub struct CreateAndConfirmPaymentsRequestData {
|
||||
pub amount: MinorUnit,
|
||||
pub currency: api_enums::Currency,
|
||||
pub customer_id: Option<common_utils::id_type::CustomerId>,
|
||||
pub currency: Currency,
|
||||
pub customer_id: Option<CustomerId>,
|
||||
pub confirm: bool,
|
||||
pub billing: Option<Address>,
|
||||
pub shipping: Option<Address>,
|
||||
pub profile_id: Option<common_utils::id_type::ProfileId>,
|
||||
pub setup_future_usage: Option<api_enums::FutureUsage>,
|
||||
pub return_url: Option<common_utils::types::Url>,
|
||||
pub capture_method: Option<api_enums::CaptureMethod>,
|
||||
pub authentication_type: Option<api_enums::AuthenticationType>,
|
||||
pub payment_method: Option<api_enums::PaymentMethod>,
|
||||
pub payment_method_type: Option<api_enums::PaymentMethodType>,
|
||||
pub profile_id: Option<ProfileId>,
|
||||
pub setup_future_usage: Option<FutureUsage>,
|
||||
/// The url to which user must be redirected to after completion of the purchase
|
||||
#[schema(value_type = Option<String>)]
|
||||
pub return_url: Option<Url>,
|
||||
pub capture_method: Option<CaptureMethod>,
|
||||
pub authentication_type: Option<AuthenticationType>,
|
||||
pub payment_method: Option<PaymentMethod>,
|
||||
pub payment_method_type: Option<PaymentMethodType>,
|
||||
pub payment_method_data: Option<PaymentMethodDataRequest>,
|
||||
pub customer_acceptance: Option<CustomerAcceptance>,
|
||||
pub payment_type: Option<api_enums::PaymentType>,
|
||||
pub payment_type: Option<PaymentType>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
pub struct PaymentResponseData {
|
||||
pub payment_id: common_utils::id_type::PaymentId,
|
||||
pub status: api_enums::IntentStatus,
|
||||
pub payment_id: PaymentId,
|
||||
pub status: IntentStatus,
|
||||
pub amount: MinorUnit,
|
||||
pub currency: api_enums::Currency,
|
||||
pub profile_id: Option<common_utils::id_type::ProfileId>,
|
||||
pub currency: Currency,
|
||||
pub profile_id: Option<ProfileId>,
|
||||
pub connector: Option<String>,
|
||||
/// Identifier for Payment Method
|
||||
#[schema(value_type = Option<String>, example = "pm_01926c58bc6e77c09e809964e72af8c8")]
|
||||
pub payment_method_id: Option<Secret<String>>,
|
||||
pub return_url: Option<common_utils::types::Url>,
|
||||
/// The url to which user must be redirected to after completion of the purchase
|
||||
#[schema(value_type = Option<String>)]
|
||||
pub return_url: Option<Url>,
|
||||
pub next_action: Option<NextActionData>,
|
||||
pub payment_experience: Option<api_enums::PaymentExperience>,
|
||||
pub payment_experience: Option<PaymentExperience>,
|
||||
pub error_code: Option<String>,
|
||||
pub error_message: Option<String>,
|
||||
pub payment_method_type: Option<api_enums::PaymentMethodType>,
|
||||
pub payment_method_type: Option<PaymentMethodType>,
|
||||
#[schema(value_type = Option<String>)]
|
||||
/// This is a token which expires after 15 minutes, used from the client to authenticate and create sessions from the SDK
|
||||
pub client_secret: Option<Secret<String>>,
|
||||
pub billing: Option<Address>,
|
||||
pub shipping: Option<Address>,
|
||||
pub payment_type: Option<api_enums::PaymentType>,
|
||||
pub payment_type: Option<PaymentType>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
pub struct CreateMitPaymentRequestData {
|
||||
pub amount: MinorUnit,
|
||||
pub currency: api_enums::Currency,
|
||||
pub currency: Currency,
|
||||
pub confirm: bool,
|
||||
pub customer_id: Option<common_utils::id_type::CustomerId>,
|
||||
pub customer_id: Option<CustomerId>,
|
||||
pub recurring_details: Option<RecurringDetails>,
|
||||
pub off_session: Option<bool>,
|
||||
pub profile_id: Option<common_utils::id_type::ProfileId>,
|
||||
pub profile_id: Option<ProfileId>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
pub struct ConfirmSubscriptionRequest {
|
||||
/// Client secret for SDK based interaction.
|
||||
#[schema(value_type = Option<String>)]
|
||||
/// This is a token which expires after 15 minutes, used from the client to authenticate and create sessions from the SDK
|
||||
pub client_secret: Option<ClientSecret>,
|
||||
|
||||
/// Payment details for the invoice.
|
||||
@ -354,11 +384,11 @@ pub struct CreateAndConfirmSubscriptionRequest {
|
||||
/// Identifier for the associated item_price_id for the subscription.
|
||||
pub item_price_id: String,
|
||||
|
||||
/// Idenctifier for the coupon code for the subscription.
|
||||
/// Identifier for the coupon code for the subscription.
|
||||
pub coupon_code: Option<String>,
|
||||
|
||||
/// Identifier for customer.
|
||||
pub customer_id: common_utils::id_type::CustomerId,
|
||||
pub customer_id: CustomerId,
|
||||
|
||||
/// Billing address for the subscription.
|
||||
pub billing: Option<Address>,
|
||||
@ -388,7 +418,7 @@ impl ApiEventMetric for CreateAndConfirmSubscriptionRequest {}
|
||||
#[derive(Debug, Clone, serde::Serialize, ToSchema)]
|
||||
pub struct ConfirmSubscriptionResponse {
|
||||
/// Unique identifier for the subscription.
|
||||
pub id: common_utils::id_type::SubscriptionId,
|
||||
pub id: SubscriptionId,
|
||||
|
||||
/// Merchant specific Unique identifier.
|
||||
pub merchant_reference_id: Option<String>,
|
||||
@ -406,13 +436,13 @@ pub struct ConfirmSubscriptionResponse {
|
||||
pub coupon: Option<String>,
|
||||
|
||||
/// Associated profile ID.
|
||||
pub profile_id: common_utils::id_type::ProfileId,
|
||||
pub profile_id: ProfileId,
|
||||
|
||||
/// Payment details for the invoice.
|
||||
pub payment: Option<PaymentResponseData>,
|
||||
|
||||
/// Customer ID associated with this subscription.
|
||||
pub customer_id: Option<common_utils::id_type::CustomerId>,
|
||||
pub customer_id: Option<CustomerId>,
|
||||
|
||||
/// Invoice Details for the subscription.
|
||||
pub invoice: Option<Invoice>,
|
||||
@ -424,37 +454,38 @@ pub struct ConfirmSubscriptionResponse {
|
||||
#[derive(Debug, Clone, serde::Serialize, ToSchema)]
|
||||
pub struct Invoice {
|
||||
/// Unique identifier for the invoice.
|
||||
pub id: common_utils::id_type::InvoiceId,
|
||||
pub id: InvoiceId,
|
||||
|
||||
/// Unique identifier for the subscription.
|
||||
pub subscription_id: common_utils::id_type::SubscriptionId,
|
||||
pub subscription_id: SubscriptionId,
|
||||
|
||||
/// Identifier for the merchant.
|
||||
pub merchant_id: common_utils::id_type::MerchantId,
|
||||
pub merchant_id: MerchantId,
|
||||
|
||||
/// Identifier for the profile.
|
||||
pub profile_id: common_utils::id_type::ProfileId,
|
||||
pub profile_id: ProfileId,
|
||||
|
||||
/// Identifier for the merchant connector account.
|
||||
pub merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId,
|
||||
pub merchant_connector_id: MerchantConnectorAccountId,
|
||||
|
||||
/// Identifier for the Payment.
|
||||
pub payment_intent_id: Option<common_utils::id_type::PaymentId>,
|
||||
pub payment_intent_id: Option<PaymentId>,
|
||||
|
||||
/// Identifier for the Payment method.
|
||||
/// Identifier for Payment Method
|
||||
#[schema(value_type = Option<String>, example = "pm_01926c58bc6e77c09e809964e72af8c8")]
|
||||
pub payment_method_id: Option<String>,
|
||||
|
||||
/// Identifier for the Customer.
|
||||
pub customer_id: common_utils::id_type::CustomerId,
|
||||
pub customer_id: CustomerId,
|
||||
|
||||
/// Invoice amount.
|
||||
pub amount: MinorUnit,
|
||||
|
||||
/// Currency for the invoice payment.
|
||||
pub currency: api_enums::Currency,
|
||||
pub currency: Currency,
|
||||
|
||||
/// Status of the invoice.
|
||||
pub status: common_enums::connector_enums::InvoiceStatus,
|
||||
pub status: InvoiceStatus,
|
||||
}
|
||||
|
||||
impl ApiEventMetric for ConfirmSubscriptionResponse {}
|
||||
@ -477,7 +508,7 @@ pub struct EstimateSubscriptionQuery {
|
||||
/// Identifier for the associated item_price_id for the subscription.
|
||||
pub item_price_id: String,
|
||||
|
||||
/// Idenctifier for the coupon code for the subscription.
|
||||
/// Identifier for the coupon code for the subscription.
|
||||
pub coupon_code: Option<String>,
|
||||
}
|
||||
|
||||
@ -488,15 +519,15 @@ pub struct EstimateSubscriptionResponse {
|
||||
/// Estimated amount to be charged for the invoice.
|
||||
pub amount: MinorUnit,
|
||||
/// Currency for the amount.
|
||||
pub currency: api_enums::Currency,
|
||||
pub currency: Currency,
|
||||
/// Identifier for the associated plan_id.
|
||||
pub plan_id: Option<String>,
|
||||
/// Identifier for the associated item_price_id for the subscription.
|
||||
pub item_price_id: Option<String>,
|
||||
/// Idenctifier for the coupon code for the subscription.
|
||||
/// Identifier for the coupon code for the subscription.
|
||||
pub coupon_code: Option<String>,
|
||||
/// Identifier for customer.
|
||||
pub customer_id: Option<common_utils::id_type::CustomerId>,
|
||||
pub customer_id: Option<CustomerId>,
|
||||
pub line_items: Vec<SubscriptionLineItem>,
|
||||
}
|
||||
|
||||
@ -511,7 +542,7 @@ pub struct SubscriptionLineItem {
|
||||
/// Amount for the line item.
|
||||
pub amount: MinorUnit,
|
||||
/// Currency for the line item
|
||||
pub currency: common_enums::Currency,
|
||||
pub currency: Currency,
|
||||
/// Quantity of the line item.
|
||||
pub quantity: i64,
|
||||
}
|
||||
|
||||
@ -66,7 +66,8 @@ Never share your secret api keys. Keep them guarded and secure.
|
||||
(name = "payment link", description = "Create payment link"),
|
||||
(name = "Routing", description = "Create and manage routing configurations"),
|
||||
(name = "Event", description = "Manage events"),
|
||||
(name = "Authentication", description = "Create and manage authentication")
|
||||
(name = "Authentication", description = "Create and manage authentication"),
|
||||
(name = "Subscriptions", description = "Subscription management and billing endpoints")
|
||||
),
|
||||
// The paths will be displayed in the same order as they are registered here
|
||||
paths(
|
||||
@ -222,6 +223,15 @@ Never share your secret api keys. Keep them guarded and secure.
|
||||
|
||||
// Routes for platform account
|
||||
routes::platform::create_platform_account,
|
||||
|
||||
//Routes for subscriptions
|
||||
routes::subscriptions::create_and_confirm_subscription,
|
||||
routes::subscriptions::create_subscription,
|
||||
routes::subscriptions::confirm_subscription,
|
||||
routes::subscriptions::get_subscription,
|
||||
routes::subscriptions::update_subscription,
|
||||
routes::subscriptions::get_subscription_plans,
|
||||
routes::subscriptions::get_estimate,
|
||||
),
|
||||
components(schemas(
|
||||
common_utils::types::MinorUnit,
|
||||
@ -876,6 +886,31 @@ Never share your secret api keys. Keep them guarded and secure.
|
||||
api_models::open_router::PriorityLogicData,
|
||||
api_models::user::PlatformAccountCreateRequest,
|
||||
api_models::user::PlatformAccountCreateResponse,
|
||||
common_utils::id_type::CustomerId,
|
||||
common_utils::id_type::SubscriptionId,
|
||||
common_utils::id_type::MerchantId,
|
||||
common_utils::id_type::InvoiceId,
|
||||
common_utils::id_type::MerchantConnectorAccountId,
|
||||
api_models::enums::connector_enums::InvoiceStatus,
|
||||
api_models::subscription::ClientSecret,
|
||||
api_models::subscription::CreateAndConfirmSubscriptionRequest,
|
||||
api_models::subscription::CreateSubscriptionRequest,
|
||||
api_models::subscription::ConfirmSubscriptionRequest,
|
||||
api_models::subscription::UpdateSubscriptionRequest,
|
||||
api_models::subscription::SubscriptionResponse,
|
||||
api_models::subscription::GetPlansResponse,
|
||||
api_models::subscription::EstimateSubscriptionResponse,
|
||||
api_models::subscription::GetPlansQuery,
|
||||
api_models::subscription::EstimateSubscriptionQuery,
|
||||
api_models::subscription::ConfirmSubscriptionPaymentDetails,
|
||||
api_models::subscription::PaymentDetails,
|
||||
api_models::subscription::CreateSubscriptionPaymentDetails,
|
||||
api_models::subscription::SubscriptionLineItem,
|
||||
api_models::subscription::SubscriptionPlanPrices,
|
||||
api_models::subscription::PaymentResponseData,
|
||||
api_models::subscription::Invoice,
|
||||
api_models::subscription::SubscriptionStatus,
|
||||
api_models::subscription::PeriodUnit,
|
||||
)),
|
||||
modifiers(&SecurityAddon)
|
||||
)]
|
||||
|
||||
@ -23,6 +23,7 @@ pub mod refunds;
|
||||
pub mod relay;
|
||||
pub mod revenue_recovery;
|
||||
pub mod routing;
|
||||
pub mod subscriptions;
|
||||
pub mod three_ds_decision_rule;
|
||||
pub mod tokenization;
|
||||
pub mod webhook_events;
|
||||
|
||||
208
crates/openapi/src/routes/subscriptions.rs
Normal file
208
crates/openapi/src/routes/subscriptions.rs
Normal file
@ -0,0 +1,208 @@
|
||||
use serde_json::json;
|
||||
use utoipa;
|
||||
|
||||
/// Subscription - Create and Confirm
|
||||
///
|
||||
/// Creates and confirms a subscription in a single request.
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/subscriptions",
|
||||
request_body(
|
||||
content = CreateAndConfirmSubscriptionRequest,
|
||||
examples((
|
||||
"Create and confirm subscription" = (
|
||||
value = json!({
|
||||
"customer_id": "cust_123456789",
|
||||
"plan_id": "plan_monthly_basic",
|
||||
"payment_method_id": "pm_1234567890",
|
||||
"billing_details": {
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com"
|
||||
}
|
||||
})
|
||||
)
|
||||
))
|
||||
),
|
||||
responses(
|
||||
(status = 200, description = "Subscription created and confirmed successfully", body = SubscriptionResponse),
|
||||
(status = 400, description = "Invalid subscription data"),
|
||||
(status = 404, description = "Customer or plan not found")
|
||||
),
|
||||
params(
|
||||
("X-Profile-Id" = String, Header, description = "Profile ID for authentication")
|
||||
),
|
||||
tag = "Subscriptions",
|
||||
operation_id = "Create and Confirm Subscription",
|
||||
security(("api_key" = []))
|
||||
)]
|
||||
pub async fn create_and_confirm_subscription() {}
|
||||
|
||||
/// Subscription - Create
|
||||
///
|
||||
/// Creates a subscription that requires separate confirmation.
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/subscriptions/create",
|
||||
request_body(
|
||||
content = CreateSubscriptionRequest,
|
||||
examples((
|
||||
"Create subscription" = (
|
||||
value = json!({
|
||||
"customer_id": "cust_123456789",
|
||||
"plan_id": "plan_monthly_basic",
|
||||
"trial_days": 7,
|
||||
"metadata": {
|
||||
"source": "web_app"
|
||||
}
|
||||
})
|
||||
)
|
||||
))
|
||||
),
|
||||
responses(
|
||||
(status = 200, description = "Subscription created successfully", body = SubscriptionResponse),
|
||||
(status = 400, description = "Invalid subscription data"),
|
||||
(status = 404, description = "Customer or plan not found")
|
||||
),
|
||||
params(
|
||||
("X-Profile-Id" = String, Header, description = "Profile ID for authentication")
|
||||
),
|
||||
tag = "Subscriptions",
|
||||
operation_id = "Create Subscription",
|
||||
security(("api_key" = []))
|
||||
)]
|
||||
pub async fn create_subscription() {}
|
||||
|
||||
/// Subscription - Confirm
|
||||
///
|
||||
/// Confirms a previously created subscription.
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/subscriptions/{subscription_id}/confirm",
|
||||
params(
|
||||
("subscription_id" = String, Path, description = "The unique identifier for the subscription"),
|
||||
("X-Profile-Id" = String, Header, description = "Profile ID for authentication")
|
||||
),
|
||||
request_body(
|
||||
content = ConfirmSubscriptionRequest,
|
||||
examples((
|
||||
"Confirm subscription" = (
|
||||
value = json!({
|
||||
"payment_method_id": "pm_1234567890",
|
||||
"client_secret": "seti_1234567890_secret_abcdef",
|
||||
"return_url": "https://example.com/return"
|
||||
})
|
||||
)
|
||||
))
|
||||
),
|
||||
responses(
|
||||
(status = 200, description = "Subscription confirmed successfully", body = SubscriptionResponse),
|
||||
(status = 400, description = "Invalid confirmation data"),
|
||||
(status = 404, description = "Subscription not found"),
|
||||
(status = 409, description = "Subscription already confirmed")
|
||||
),
|
||||
tag = "Subscriptions",
|
||||
operation_id = "Confirm Subscription",
|
||||
security(("api_key" = []), ("client_secret" = []))
|
||||
)]
|
||||
pub async fn confirm_subscription() {}
|
||||
|
||||
/// Subscription - Retrieve
|
||||
///
|
||||
/// Retrieves subscription details by ID.
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/subscriptions/{subscription_id}",
|
||||
params(
|
||||
("subscription_id" = String, Path, description = "The unique identifier for the subscription"),
|
||||
("X-Profile-Id" = String, Header, description = "Profile ID for authentication")
|
||||
),
|
||||
responses(
|
||||
(status = 200, description = "Subscription retrieved successfully", body = SubscriptionResponse),
|
||||
(status = 404, description = "Subscription not found")
|
||||
),
|
||||
tag = "Subscriptions",
|
||||
operation_id = "Retrieve Subscription",
|
||||
security(("api_key" = []))
|
||||
)]
|
||||
pub async fn get_subscription() {}
|
||||
|
||||
/// Subscription - Update
|
||||
///
|
||||
/// Updates an existing subscription.
|
||||
#[utoipa::path(
|
||||
put,
|
||||
path = "/subscriptions/{subscription_id}/update",
|
||||
params(
|
||||
("subscription_id" = String, Path, description = "The unique identifier for the subscription"),
|
||||
("X-Profile-Id" = String, Header, description = "Profile ID for authentication")
|
||||
),
|
||||
request_body(
|
||||
content = UpdateSubscriptionRequest,
|
||||
examples((
|
||||
"Update subscription" = (
|
||||
value = json!({
|
||||
"plan_id": "plan_yearly_premium",
|
||||
"proration_behavior": "create_prorations",
|
||||
"metadata": {
|
||||
"updated_reason": "plan_upgrade"
|
||||
}
|
||||
})
|
||||
)
|
||||
))
|
||||
),
|
||||
responses(
|
||||
(status = 200, description = "Subscription updated successfully", body = SubscriptionResponse),
|
||||
(status = 400, description = "Invalid update data"),
|
||||
(status = 404, description = "Subscription not found")
|
||||
),
|
||||
tag = "Subscriptions",
|
||||
operation_id = "Update Subscription",
|
||||
security(("api_key" = []))
|
||||
)]
|
||||
pub async fn update_subscription() {}
|
||||
|
||||
/// Subscription - Get Plans
|
||||
///
|
||||
/// Retrieves available subscription plans.
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/subscriptions/plans",
|
||||
params(
|
||||
("X-Profile-Id" = String, Header, description = "Profile ID for authentication"),
|
||||
("limit" = Option<u32>, Query, description = "Number of plans to retrieve"),
|
||||
("offset" = Option<u32>, Query, description = "Number of plans to skip"),
|
||||
("product_id" = Option<String>, Query, description = "Filter by product ID")
|
||||
),
|
||||
responses(
|
||||
(status = 200, description = "Plans retrieved successfully", body = Vec<GetPlansResponse>),
|
||||
(status = 400, description = "Invalid query parameters")
|
||||
),
|
||||
tag = "Subscriptions",
|
||||
operation_id = "Get Subscription Plans",
|
||||
security(("api_key" = []), ("client_secret" = []))
|
||||
)]
|
||||
pub async fn get_subscription_plans() {}
|
||||
|
||||
/// Subscription - Get Estimate
|
||||
///
|
||||
/// Gets pricing estimate for a subscription.
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/subscriptions/estimate",
|
||||
params(
|
||||
("X-Profile-Id" = String, Header, description = "Profile ID for authentication"),
|
||||
("plan_id" = String, Query, description = "Plan ID for estimation"),
|
||||
("customer_id" = Option<String>, Query, description = "Customer ID for personalized pricing"),
|
||||
("coupon_id" = Option<String>, Query, description = "Coupon ID to apply discount"),
|
||||
("trial_days" = Option<u32>, Query, description = "Number of trial days")
|
||||
),
|
||||
responses(
|
||||
(status = 200, description = "Estimate retrieved successfully", body = EstimateSubscriptionResponse),
|
||||
(status = 400, description = "Invalid estimation parameters"),
|
||||
(status = 404, description = "Plan not found")
|
||||
),
|
||||
tag = "Subscriptions",
|
||||
operation_id = "Get Subscription Estimate",
|
||||
security(("api_key" = []))
|
||||
)]
|
||||
pub async fn get_estimate() {}
|
||||
Reference in New Issue
Block a user