mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 03:13:56 +08:00
feat(subscription): Add endpoint to get Subscription estimate (#9637)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Gaurav Rawat <104276743+GauravRawat369@users.noreply.github.com>
This commit is contained in:
@ -174,7 +174,9 @@ pub struct GetSubscriptionPlanPricesData {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct GetSubscriptionEstimateData;
|
||||
pub struct GetSubscriptionEstimateData {
|
||||
pub connector_meta_data: Option<pii::SecretSerdeValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct UasFlowData {
|
||||
|
||||
@ -36,7 +36,6 @@ pub enum SubscriptionStatus {
|
||||
Created,
|
||||
}
|
||||
|
||||
#[cfg(feature = "v1")]
|
||||
impl From<SubscriptionStatus> for api_models::subscription::SubscriptionStatus {
|
||||
fn from(status: SubscriptionStatus) -> Self {
|
||||
match status {
|
||||
@ -82,7 +81,6 @@ pub struct SubscriptionPlanPrices {
|
||||
pub trial_period_unit: Option<PeriodUnit>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "v1")]
|
||||
impl From<SubscriptionPlanPrices> for api_models::subscription::SubscriptionPlanPrices {
|
||||
fn from(item: SubscriptionPlanPrices) -> Self {
|
||||
Self {
|
||||
@ -106,7 +104,6 @@ pub enum PeriodUnit {
|
||||
Year,
|
||||
}
|
||||
|
||||
#[cfg(feature = "v1")]
|
||||
impl From<PeriodUnit> for api_models::subscription::PeriodUnit {
|
||||
fn from(unit: PeriodUnit) -> Self {
|
||||
match unit {
|
||||
@ -128,8 +125,28 @@ pub struct GetSubscriptionEstimateResponse {
|
||||
pub currency: Currency,
|
||||
pub next_billing_at: Option<PrimitiveDateTime>,
|
||||
pub line_items: Vec<SubscriptionLineItem>,
|
||||
pub customer_id: Option<id_type::CustomerId>,
|
||||
}
|
||||
|
||||
impl From<GetSubscriptionEstimateResponse>
|
||||
for api_models::subscription::EstimateSubscriptionResponse
|
||||
{
|
||||
fn from(value: GetSubscriptionEstimateResponse) -> Self {
|
||||
Self {
|
||||
amount: value.total,
|
||||
currency: value.currency,
|
||||
plan_id: None,
|
||||
item_price_id: None,
|
||||
coupon_code: None,
|
||||
customer_id: value.customer_id,
|
||||
line_items: value
|
||||
.line_items
|
||||
.into_iter()
|
||||
.map(api_models::subscription::SubscriptionLineItem::from)
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SubscriptionLineItem {
|
||||
pub item_id: String,
|
||||
@ -141,3 +158,16 @@ pub struct SubscriptionLineItem {
|
||||
pub quantity: i64,
|
||||
pub pricing_model: Option<String>,
|
||||
}
|
||||
|
||||
impl From<SubscriptionLineItem> for api_models::subscription::SubscriptionLineItem {
|
||||
fn from(value: SubscriptionLineItem) -> Self {
|
||||
Self {
|
||||
item_id: value.item_id,
|
||||
description: value.description,
|
||||
item_type: value.item_type,
|
||||
amount: value.amount,
|
||||
currency: value.currency,
|
||||
quantity: value.quantity,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user