mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 11:24:45 +08:00
feat(subscriptions): Add client secret auth support in subscriptions APIs (#9713)
Co-authored-by: Prajjwal kumar <write2prajjwal@gmail.com> Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Prajjwal Kumar <prajjwal.kumar@juspay.in> Co-authored-by: Jagan <jaganelavarasan@gmail.com>
This commit is contained in:
@ -74,6 +74,12 @@ pub struct SubscriptionResponse {
|
||||
|
||||
/// Optional customer ID associated with this subscription.
|
||||
pub customer_id: common_utils::id_type::CustomerId,
|
||||
|
||||
/// Payment details for the invoice.
|
||||
pub payment: Option<PaymentResponseData>,
|
||||
|
||||
/// Invoice Details for the subscription.
|
||||
pub invoice: Option<Invoice>,
|
||||
}
|
||||
|
||||
/// Possible states of a subscription lifecycle.
|
||||
@ -127,6 +133,8 @@ impl SubscriptionResponse {
|
||||
merchant_id: common_utils::id_type::MerchantId,
|
||||
client_secret: Option<Secret<String>>,
|
||||
customer_id: common_utils::id_type::CustomerId,
|
||||
payment: Option<PaymentResponseData>,
|
||||
invoice: Option<Invoice>,
|
||||
) -> Self {
|
||||
Self {
|
||||
id,
|
||||
@ -138,6 +146,8 @@ impl SubscriptionResponse {
|
||||
merchant_id,
|
||||
coupon_code: None,
|
||||
customer_id,
|
||||
payment,
|
||||
invoice,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -181,6 +191,10 @@ impl ClientSecret {
|
||||
pub fn as_str(&self) -> &str {
|
||||
&self.0
|
||||
}
|
||||
|
||||
pub fn as_string(&self) -> &String {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize, serde::Serialize, Debug)]
|
||||
@ -197,6 +211,7 @@ impl ApiEventMetric for GetPlansResponse {}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
pub struct ConfirmSubscriptionPaymentDetails {
|
||||
pub shipping: Option<Address>,
|
||||
pub payment_method: api_enums::PaymentMethod,
|
||||
pub payment_method_type: Option<api_enums::PaymentMethodType>,
|
||||
pub payment_method_data: PaymentMethodDataRequest,
|
||||
@ -278,7 +293,7 @@ pub struct PaymentResponseData {
|
||||
pub error_code: Option<String>,
|
||||
pub error_message: Option<String>,
|
||||
pub payment_method_type: Option<api_enums::PaymentMethodType>,
|
||||
pub client_secret: Option<String>,
|
||||
pub client_secret: Option<Secret<String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
@ -294,7 +309,7 @@ pub struct CreateMitPaymentRequestData {
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
pub struct ConfirmSubscriptionRequest {
|
||||
/// Client secret for SDK based interaction.
|
||||
pub client_secret: Option<String>,
|
||||
pub client_secret: Option<ClientSecret>,
|
||||
|
||||
/// Identifier for the associated plan_id.
|
||||
pub plan_id: Option<String>,
|
||||
@ -305,15 +320,6 @@ pub struct ConfirmSubscriptionRequest {
|
||||
/// Idenctifier for the coupon code for the subscription.
|
||||
pub coupon_code: Option<String>,
|
||||
|
||||
/// Identifier for customer.
|
||||
pub customer_id: common_utils::id_type::CustomerId,
|
||||
|
||||
/// Billing address for the subscription.
|
||||
pub billing: Option<Address>,
|
||||
|
||||
/// Shipping address for the subscription.
|
||||
pub shipping: Option<Address>,
|
||||
|
||||
/// Payment details for the invoice.
|
||||
pub payment_details: ConfirmSubscriptionPaymentDetails,
|
||||
}
|
||||
@ -328,11 +334,15 @@ impl ConfirmSubscriptionRequest {
|
||||
}
|
||||
|
||||
pub fn get_billing_address(&self) -> Result<Address, error_stack::Report<ValidationError>> {
|
||||
self.billing.clone().ok_or(error_stack::report!(
|
||||
ValidationError::MissingRequiredField {
|
||||
field_name: "billing".to_string()
|
||||
}
|
||||
))
|
||||
self.payment_details
|
||||
.payment_method_data
|
||||
.billing
|
||||
.clone()
|
||||
.ok_or(error_stack::report!(
|
||||
ValidationError::MissingRequiredField {
|
||||
field_name: "billing".to_string()
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user