Skip to content

Commit

Permalink
router data modification
Browse files Browse the repository at this point in the history
  • Loading branch information
Sweta-Kumari-Sharma committed Dec 4, 2024
1 parent e4c3235 commit 1cc33c2
Show file tree
Hide file tree
Showing 20 changed files with 204 additions and 298 deletions.
70 changes: 8 additions & 62 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,8 @@ pub struct PaymentsRequest {
pub amount: Option<Amount>,

/// Total tax amount applicable to the order
#[schema(value_type = Option<i64>, example = 6540)]
pub order_tax_amount: Option<MinorUnit>,
#[schema(value_type = i64, example = 6540)]
pub order_tax_amount: MinorUnit,

/// The three letter ISO currency code in uppercase. Eg: 'USD' to charge US Dollars
#[schema(example = "USD", value_type = Option<Currency>)]
Expand Down Expand Up @@ -1151,6 +1151,9 @@ pub struct PaymentAttemptResponse {
/// The payment attempt amount. Amount for the payment in lowest denomination of the currency. (i.e) in cents for USD denomination, in paisa for INR denomination etc.,
#[schema(value_type = i64, example = 6540)]
pub amount: MinorUnit,
/// The payment attempt tax_amount.
#[schema(value_type = i64, example = 6540)]
pub order_tax_amount: Option<MinorUnit>,
/// The currency of the amount of the payment attempt
#[schema(value_type = Option<Currency>, example = "USD")]
pub currency: Option<enums::Currency>,
Expand Down Expand Up @@ -2414,7 +2417,6 @@ pub enum AdditionalPaymentData {
},
PayLater {
klarna_sdk: Option<KlarnaSdkPaymentMethod>,
klarna_checkout: Option<KlarnaCheckoutPaymentMethod>,
},
BankTransfer {
#[serde(flatten)]
Expand Down Expand Up @@ -3677,7 +3679,6 @@ pub struct VoucherResponse {
#[derive(Eq, PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct PaylaterResponse {
klarna_sdk: Option<KlarnaSdkPaymentMethodResponse>,
klarna_checkout: Option<KlarnaCheckoutPaymentMethodResponse>,
}

#[derive(Eq, PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, ToSchema)]
Expand All @@ -3701,13 +3702,6 @@ pub enum WalletResponseData {
pub struct KlarnaSdkPaymentMethodResponse {
pub payment_type: Option<String>,
}

#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]

pub struct KlarnaCheckoutPaymentMethodResponse {
pub payment_type: Option<String>,
}

#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, ToSchema, serde::Serialize)]
pub struct PaymentMethodDataResponseWithBilling {
// The struct is flattened in order to provide backwards compatibility
Expand Down Expand Up @@ -5169,17 +5163,6 @@ impl From<KlarnaSdkPaymentMethod> for PaylaterResponse {
klarna_sdk: Some(KlarnaSdkPaymentMethodResponse {
payment_type: klarna_sdk.payment_type,
}),
klarna_checkout: None,
}
}
}
impl From<KlarnaCheckoutPaymentMethod> for PaylaterResponse {
fn from(klarna_checkout: KlarnaCheckoutPaymentMethod) -> Self {
Self {
klarna_checkout: Some(KlarnaCheckoutPaymentMethodResponse {
payment_type: klarna_checkout.payment_type,
}),
klarna_sdk: None,
}
}
}
Expand All @@ -5188,16 +5171,9 @@ impl From<AdditionalPaymentData> for PaymentMethodDataResponse {
fn from(payment_method_data: AdditionalPaymentData) -> Self {
match payment_method_data {
AdditionalPaymentData::Card(card) => Self::Card(Box::new(CardResponse::from(*card))),
AdditionalPaymentData::PayLater {
klarna_sdk,
klarna_checkout,
} => match (klarna_sdk, klarna_checkout) {
(Some(sdk), _) => Self::PayLater(Box::new(PaylaterResponse::from(sdk))),
(_, Some(checkout)) => Self::PayLater(Box::new(PaylaterResponse::from(checkout))),
(None, None) => Self::PayLater(Box::new(PaylaterResponse {
klarna_sdk: None,
klarna_checkout: None,
})),
AdditionalPaymentData::PayLater { klarna_sdk } => match klarna_sdk {
Some(sdk) => Self::PayLater(Box::new(PaylaterResponse::from(sdk))),
None => Self::PayLater(Box::new(PaylaterResponse { klarna_sdk: None })),
},

AdditionalPaymentData::Wallet {
Expand Down Expand Up @@ -5359,36 +5335,6 @@ pub struct OrderDetailsWithAmount {

impl masking::SerializableSecret for OrderDetailsWithAmount {}

#[derive(Debug, Default, PartialEq, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
pub struct OrderDetails {
/// Name of the product that is being purchased
#[schema(max_length = 255, example = "shirt")]
pub product_name: String,
/// The quantity of the product to be purchased
#[schema(example = 1)]
pub quantity: u16,
/// tax rate applicable to the product
pub tax_rate: Option<f64>,
/// total tax amount applicable to the product
pub total_tax_amount: Option<MinorUnit>,
// Does the order include shipping
pub requires_shipping: Option<bool>,
/// The image URL of the product
pub product_img_link: Option<String>,
/// ID of the product that is being purchased
pub product_id: Option<String>,
/// Category of the product that is being purchased
pub category: Option<String>,
/// Sub category of the product that is being purchased
pub sub_category: Option<String>,
/// Brand of the product that is being purchased
pub brand: Option<String>,
/// Type of the product that is being purchased
pub product_type: Option<ProductType>,
/// The tax code for the product
pub product_tax_code: Option<String>,
}

#[derive(Default, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
pub struct RedirectResponse {
#[schema(value_type = Option<String>)]
Expand Down
2 changes: 1 addition & 1 deletion crates/diesel_models/src/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ pub struct PaymentAttemptNew {
pub attempt_id: String,
pub status: storage_enums::AttemptStatus,
pub amount: MinorUnit,
pub order_tax_amount: Option<MinorUnit>,
pub currency: Option<storage_enums::Currency>,
// pub auto_capture: Option<bool>,
pub save_to_locker: Option<bool>,
Expand Down Expand Up @@ -349,7 +350,6 @@ pub struct PaymentAttemptNew {
pub organization_id: id_type::OrganizationId,
pub card_network: Option<String>,
pub shipping_cost: Option<MinorUnit>,
pub order_tax_amount: Option<MinorUnit>,
pub connector_mandate_detail: Option<ConnectorMandateReferenceId>,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ pub struct PaymentAttempt {
pub status: storage_enums::AttemptStatus,
pub net_amount: NetAmount,
pub currency: Option<storage_enums::Currency>,
pub order_tax_amount: Option<MinorUnit>,
pub save_to_locker: Option<bool>,
pub connector: Option<String>,
pub error_message: Option<String>,
Expand Down Expand Up @@ -679,6 +680,7 @@ pub struct PaymentAttemptNew {
/// This field will always be derived before updating in the Database
pub net_amount: NetAmount,
pub currency: Option<storage_enums::Currency>,
pub order_tax_amount: Option<MinorUnit>,
// pub auto_capture: Option<bool>,
pub save_to_locker: Option<bool>,
pub connector: Option<String>,
Expand Down Expand Up @@ -1465,6 +1467,7 @@ impl behaviour::Conversion for PaymentAttempt {
storage_model.tax_amount,
),
currency: storage_model.currency,
order_tax_amount: storage_model.order_tax_amount,
save_to_locker: storage_model.save_to_locker,
connector: storage_model.connector,
error_message: storage_model.error_message,
Expand Down
6 changes: 0 additions & 6 deletions crates/hyperswitch_domain_models/src/router_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ pub enum AdditionalPaymentMethodConnectorResponse {
},
PayLater {
klarna_sdk: Option<KlarnaSdkResponse>,
klarna_checkout: Option<KlarnaCheckoutResponse>,
},
}

Expand All @@ -357,11 +356,6 @@ pub struct KlarnaSdkResponse {
pub payment_type: Option<String>,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct KlarnaCheckoutResponse {
pub payment_type: Option<String>,
}

#[derive(Clone, Debug, serde::Serialize)]
pub struct ErrorResponse {
pub code: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct PaymentsAuthorizeData {
/// get_total_surcharge_amount() // returns surcharge_amount + tax_on_surcharge_amount
/// ```
pub amount: i64,
pub order_tax_amount: Option<MinorUnit>,
pub email: Option<pii::Email>,
pub customer_name: Option<Secret<String>>,
pub currency: storage_enums::Currency,
Expand Down
2 changes: 0 additions & 2 deletions crates/openapi/src/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,9 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payments::CardResponse,
api_models::payments::PaylaterResponse,
api_models::payments::KlarnaSdkPaymentMethodResponse,
api_models::payments::KlarnaCheckoutPaymentMethodResponse,
api_models::payments::SwishQrData,
api_models::payments::AirwallexData,
api_models::payments::NoonData,
api_models::payments::OrderDetails,
api_models::payments::OrderDetailsWithAmount,
api_models::payments::NextActionType,
api_models::payments::WalletData,
Expand Down
2 changes: 0 additions & 2 deletions crates/openapi/src/openapi_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,9 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payments::CardResponse,
api_models::payments::PaylaterResponse,
api_models::payments::KlarnaSdkPaymentMethodResponse,
api_models::payments::KlarnaCheckoutPaymentMethodResponse,
api_models::payments::SwishQrData,
api_models::payments::AirwallexData,
api_models::payments::NoonData,
api_models::payments::OrderDetails,
api_models::payments::OrderDetailsWithAmount,
api_models::payments::NextActionType,
api_models::payments::WalletData,
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/klarna.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ impl
req.request.currency,
)?;
let connector_router_data = klarna::KlarnaRouterData::from((amount, req));
let connector_req = klarna::KlarnaAuthRequest::try_from(&connector_router_data)?;
let connector_req = klarna::KlarnaPaymentsRequest::try_from(&connector_router_data)?;
Ok(RequestContent::Json(Box::new(connector_req)))
}

Expand Down
Loading

0 comments on commit 1cc33c2

Please sign in to comment.