mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
feat(subscriptions): Add update subscriptions APIs with payments update call (#9778)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
use common_types::payments::CustomerAcceptance;
|
||||
use common_utils::{errors::ValidationError, events::ApiEventMetric, types::MinorUnit};
|
||||
use common_utils::{events::ApiEventMetric, types::MinorUnit};
|
||||
use masking::Secret;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
@ -24,6 +24,9 @@ pub struct CreateSubscriptionRequest {
|
||||
/// Merchant specific Unique identifier.
|
||||
pub merchant_reference_id: Option<String>,
|
||||
|
||||
/// Identifier for the associated item_price_id for the subscription.
|
||||
pub item_price_id: Option<String>,
|
||||
|
||||
/// Identifier for the subscription plan.
|
||||
pub plan_id: Option<String>,
|
||||
|
||||
@ -60,6 +63,9 @@ pub struct SubscriptionResponse {
|
||||
/// Identifier for the associated subscription plan.
|
||||
pub plan_id: Option<String>,
|
||||
|
||||
/// Identifier for the associated item_price_id for the subscription.
|
||||
pub item_price_id: Option<String>,
|
||||
|
||||
/// Associated profile ID.
|
||||
pub profile_id: common_utils::id_type::ProfileId,
|
||||
|
||||
@ -129,6 +135,7 @@ impl SubscriptionResponse {
|
||||
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,
|
||||
client_secret: Option<Secret<String>>,
|
||||
@ -141,6 +148,7 @@ impl SubscriptionResponse {
|
||||
merchant_reference_id,
|
||||
status,
|
||||
plan_id,
|
||||
item_price_id,
|
||||
profile_id,
|
||||
client_secret,
|
||||
merchant_id,
|
||||
@ -327,28 +335,11 @@ pub struct ConfirmSubscriptionRequest {
|
||||
/// Client secret for SDK based interaction.
|
||||
pub client_secret: Option<ClientSecret>,
|
||||
|
||||
/// 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.
|
||||
pub coupon_code: Option<String>,
|
||||
|
||||
/// Payment details for the invoice.
|
||||
pub payment_details: ConfirmSubscriptionPaymentDetails,
|
||||
}
|
||||
|
||||
impl ConfirmSubscriptionRequest {
|
||||
pub fn get_item_price_id(&self) -> Result<String, error_stack::Report<ValidationError>> {
|
||||
self.item_price_id.clone().ok_or(error_stack::report!(
|
||||
ValidationError::MissingRequiredField {
|
||||
field_name: "item_price_id".to_string()
|
||||
}
|
||||
))
|
||||
}
|
||||
|
||||
pub fn get_billing_address(&self) -> Option<Address> {
|
||||
self.payment_details
|
||||
.payment_method_data
|
||||
@ -421,7 +412,7 @@ pub struct ConfirmSubscriptionResponse {
|
||||
pub plan_id: Option<String>,
|
||||
|
||||
/// Identifier for the associated item_price_id for the subscription.
|
||||
pub price_id: Option<String>,
|
||||
pub item_price_id: Option<String>,
|
||||
|
||||
/// Optional coupon code applied to this subscription.
|
||||
pub coupon: Option<String>,
|
||||
@ -480,6 +471,20 @@ pub struct Invoice {
|
||||
|
||||
impl ApiEventMetric for ConfirmSubscriptionResponse {}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
pub struct UpdateSubscriptionRequest {
|
||||
/// Identifier for the associated plan_id.
|
||||
pub plan_id: String,
|
||||
/// Identifier for the associated item_price_id for the subscription.
|
||||
pub item_price_id: String,
|
||||
/// Amount to be charged for the invoice.
|
||||
pub amount: MinorUnit,
|
||||
/// Currency for the amount.
|
||||
pub currency: api_enums::Currency,
|
||||
}
|
||||
|
||||
impl ApiEventMetric for UpdateSubscriptionRequest {}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
pub struct EstimateSubscriptionQuery {
|
||||
/// Identifier for the associated subscription plan.
|
||||
|
||||
Reference in New Issue
Block a user