mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 21:07:58 +08:00
refactor(router): refactor amount in PaymentsCaptureData from Option<i64> to i64 (#821)
Co-authored-by: Arun Raj M <jarnura47@gmail.com>
This commit is contained in:
@ -995,10 +995,7 @@ impl TryFrom<&types::PaymentsCaptureRouterData> for AdyenCaptureRequest {
|
||||
reference: item.payment_id.to_string(),
|
||||
amount: Amount {
|
||||
currency: item.request.currency.to_string(),
|
||||
value: item
|
||||
.request
|
||||
.amount_to_capture
|
||||
.unwrap_or(item.request.amount),
|
||||
value: item.request.amount_to_capture,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@ -152,10 +152,10 @@ impl TryFrom<&types::PaymentsCaptureRouterData> for AirwallexPaymentsCaptureRequ
|
||||
fn try_from(item: &types::PaymentsCaptureRouterData) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
request_id: Uuid::new_v4().to_string(),
|
||||
amount: match item.request.amount_to_capture {
|
||||
Some(a) => Some(utils::to_currency_base_unit(a, item.request.currency)?),
|
||||
_ => None,
|
||||
},
|
||||
amount: Some(utils::to_currency_base_unit(
|
||||
item.request.amount_to_capture,
|
||||
item.request.currency,
|
||||
)?),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -295,7 +295,7 @@ impl TryFrom<&types::PaymentsCaptureRouterData> for BamboraPaymentsCaptureReques
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(item: &types::PaymentsCaptureRouterData) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
amount: item.request.amount_to_capture,
|
||||
amount: Some(item.request.amount_to_capture),
|
||||
payment_method: PaymentMethod::Card,
|
||||
})
|
||||
}
|
||||
|
||||
@ -91,10 +91,8 @@ impl TryFrom<&types::PaymentsCaptureRouterData> for BluesnapCaptureRequest {
|
||||
fn try_from(item: &types::PaymentsCaptureRouterData) -> Result<Self, Self::Error> {
|
||||
let card_transaction_type = BluesnapTxnType::Capture;
|
||||
let transaction_id = item.request.connector_transaction_id.to_string();
|
||||
let amount = utils::to_currency_base_unit_from_optional_amount(
|
||||
item.request.amount_to_capture,
|
||||
item.request.currency,
|
||||
)?;
|
||||
let amount =
|
||||
utils::to_currency_base_unit(item.request.amount_to_capture, item.request.currency)?;
|
||||
Ok(Self {
|
||||
card_transaction_type,
|
||||
transaction_id,
|
||||
|
||||
@ -331,7 +331,7 @@ impl TryFrom<&types::PaymentsCaptureRouterData> for PaymentCaptureRequest {
|
||||
let auth_type: CheckoutAuthType = connector_auth.try_into()?;
|
||||
let processing_channel_id = auth_type.processing_channel_id;
|
||||
Ok(Self {
|
||||
amount: item.request.amount_to_capture,
|
||||
amount: Some(item.request.amount_to_capture),
|
||||
capture_type: Some(CaptureType::Final),
|
||||
processing_channel_id,
|
||||
})
|
||||
@ -353,7 +353,7 @@ impl TryFrom<types::PaymentsCaptureResponseRouterData<PaymentCaptureResponse>>
|
||||
let (status, amount_captured) = if item.http_code == 202 {
|
||||
(
|
||||
enums::AttemptStatus::Charged,
|
||||
item.data.request.amount_to_capture,
|
||||
Some(item.data.request.amount_to_capture),
|
||||
)
|
||||
} else {
|
||||
(enums::AttemptStatus::Pending, None)
|
||||
|
||||
@ -174,11 +174,7 @@ impl TryFrom<&types::PaymentsCaptureRouterData> for CybersourcePaymentsRequest {
|
||||
},
|
||||
order_information: OrderInformationWithBill {
|
||||
amount_details: Amount {
|
||||
total_amount: value
|
||||
.request
|
||||
.amount_to_capture
|
||||
.map(|amount| amount.to_string())
|
||||
.ok_or_else(utils::missing_field_err("amount_to_capture"))?,
|
||||
total_amount: value.request.amount_to_capture.to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
|
||||
@ -179,13 +179,9 @@ pub struct DlocalPaymentsCaptureRequest {
|
||||
impl TryFrom<&types::PaymentsCaptureRouterData> for DlocalPaymentsCaptureRequest {
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(item: &types::PaymentsCaptureRouterData) -> Result<Self, Self::Error> {
|
||||
let amount_to_capture = match item.request.amount_to_capture {
|
||||
Some(val) => val,
|
||||
None => item.request.amount,
|
||||
};
|
||||
Ok(Self {
|
||||
authorization_id: item.request.connector_transaction_id.clone(),
|
||||
amount: amount_to_capture,
|
||||
amount: item.request.amount_to_capture,
|
||||
currency: item.request.currency.to_string(),
|
||||
order_id: item.payment_id.clone(),
|
||||
})
|
||||
|
||||
@ -388,10 +388,8 @@ impl TryFrom<&types::PaymentsCaptureRouterData> for FiservCaptureRequest {
|
||||
let session: SessionObject = metadata
|
||||
.parse_value("SessionObject")
|
||||
.change_context(errors::ConnectorError::RequestEncodingFailed)?;
|
||||
let amount = match item.request.amount_to_capture {
|
||||
Some(a) => utils::to_currency_base_unit(a, item.request.currency)?,
|
||||
_ => utils::to_currency_base_unit(item.request.amount, item.request.currency)?,
|
||||
};
|
||||
let amount =
|
||||
utils::to_currency_base_unit(item.request.amount_to_capture, item.request.currency)?;
|
||||
Ok(Self {
|
||||
amount: Amount {
|
||||
total: amount,
|
||||
|
||||
@ -121,10 +121,7 @@ impl TryFrom<&types::PaymentsCaptureRouterData> for requests::GlobalpayCaptureRe
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(value: &types::PaymentsCaptureRouterData) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
amount: value
|
||||
.request
|
||||
.amount_to_capture
|
||||
.map(|amount| amount.to_string()),
|
||||
amount: Some(value.request.amount_to_capture.to_string()),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -597,7 +597,7 @@ impl TryFrom<&types::PaymentsCaptureRouterData> for NuveiPaymentFlowRequest {
|
||||
merchant_id: merchant_id.clone(),
|
||||
merchant_site_id: merchant_site_id.clone(),
|
||||
client_request_id: client_request_id.clone(),
|
||||
amount: item.request.amount.clone().to_string(),
|
||||
amount: item.request.amount_to_capture.clone().to_string(),
|
||||
currency: item.request.currency.clone().to_string(),
|
||||
related_transaction_id: Some(item.request.connector_transaction_id.clone()),
|
||||
time_stamp: time_stamp.clone(),
|
||||
@ -605,7 +605,7 @@ impl TryFrom<&types::PaymentsCaptureRouterData> for NuveiPaymentFlowRequest {
|
||||
merchant_id,
|
||||
merchant_site_id,
|
||||
client_request_id,
|
||||
item.request.amount.to_string(),
|
||||
item.request.amount_to_capture.to_string(),
|
||||
item.request.currency.to_string(),
|
||||
item.request.connector_transaction_id.clone(),
|
||||
time_stamp,
|
||||
|
||||
@ -352,7 +352,7 @@ impl TryFrom<&types::PaymentsCaptureRouterData> for CaptureRequest {
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(item: &types::PaymentsCaptureRouterData) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
amount: item.request.amount_to_capture,
|
||||
amount: Some(item.request.amount_to_capture),
|
||||
receipt_email: None,
|
||||
statement_descriptor: None,
|
||||
})
|
||||
|
||||
@ -1180,7 +1180,7 @@ impl TryFrom<&types::PaymentsCaptureRouterData> for CaptureRequest {
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(item: &types::PaymentsCaptureRouterData) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
amount_to_capture: item.request.amount_to_capture,
|
||||
amount_to_capture: Some(item.request.amount_to_capture),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -533,14 +533,18 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<F>> for types::PaymentsCaptureData
|
||||
|
||||
fn try_from(additional_data: PaymentAdditionalData<F>) -> Result<Self, Self::Error> {
|
||||
let payment_data = additional_data.payment_data;
|
||||
let amount_to_capture: i64 = payment_data
|
||||
.payment_attempt
|
||||
.amount_to_capture
|
||||
.map_or(payment_data.amount.into(), |capture_amount| capture_amount);
|
||||
Ok(Self {
|
||||
amount_to_capture: payment_data.payment_attempt.amount_to_capture,
|
||||
amount_to_capture,
|
||||
currency: payment_data.currency,
|
||||
connector_transaction_id: payment_data
|
||||
.payment_attempt
|
||||
.connector_transaction_id
|
||||
.ok_or(errors::ApiErrorResponse::MerchantConnectorAccountNotFound)?,
|
||||
amount: payment_data.amount.into(),
|
||||
payment_amount: payment_data.amount.into(),
|
||||
connector_meta: payment_data.payment_attempt.connector_metadata,
|
||||
})
|
||||
}
|
||||
|
||||
@ -150,10 +150,10 @@ pub struct PaymentsAuthorizeData {
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct PaymentsCaptureData {
|
||||
pub amount_to_capture: Option<i64>,
|
||||
pub amount_to_capture: i64,
|
||||
pub currency: storage_enums::Currency,
|
||||
pub connector_transaction_id: String,
|
||||
pub amount: i64,
|
||||
pub payment_amount: i64,
|
||||
pub connector_meta: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
|
||||
@ -147,7 +147,7 @@ async fn should_partially_capture_authorized_payment() {
|
||||
enums::CaptureMethod::Manual,
|
||||
),
|
||||
Some(types::PaymentsCaptureData {
|
||||
amount_to_capture: Some(50),
|
||||
amount_to_capture: 50,
|
||||
..utils::PaymentCaptureType::default().0
|
||||
}),
|
||||
AdyenTest::get_payment_info(),
|
||||
|
||||
@ -98,7 +98,7 @@ async fn should_partially_capture_authorized_payment() {
|
||||
.authorize_and_capture_payment(
|
||||
payment_method_details(),
|
||||
Some(types::PaymentsCaptureData {
|
||||
amount_to_capture: Some(50),
|
||||
amount_to_capture: 50,
|
||||
..utils::PaymentCaptureType::default().0
|
||||
}),
|
||||
get_default_payment_info(),
|
||||
|
||||
@ -75,7 +75,7 @@ async fn should_partially_capture_authorized_payment() {
|
||||
.authorize_and_capture_payment(
|
||||
get_default_payment_authorize_data(),
|
||||
Some(types::PaymentsCaptureData {
|
||||
amount_to_capture: Some(50),
|
||||
amount_to_capture: 50,
|
||||
..utils::PaymentCaptureType::default().0
|
||||
}),
|
||||
None,
|
||||
|
||||
@ -67,7 +67,7 @@ async fn should_partially_capture_authorized_payment() {
|
||||
.authorize_and_capture_payment(
|
||||
None,
|
||||
Some(types::PaymentsCaptureData {
|
||||
amount_to_capture: Some(50),
|
||||
amount_to_capture: 50,
|
||||
..utils::PaymentCaptureType::default().0
|
||||
}),
|
||||
None,
|
||||
|
||||
@ -103,7 +103,7 @@ async fn should_partially_capture_already_authorized_payment() {
|
||||
.authorize_and_capture_payment(
|
||||
get_default_payment_authorize_data(),
|
||||
Some(types::PaymentsCaptureData {
|
||||
amount_to_capture: Some(50),
|
||||
amount_to_capture: 50,
|
||||
..utils::PaymentCaptureType::default().0
|
||||
}),
|
||||
get_default_payment_info(),
|
||||
|
||||
@ -63,7 +63,7 @@ async fn should_partially_capture_authorized_payment() {
|
||||
.authorize_and_capture_payment(
|
||||
None,
|
||||
Some(types::PaymentsCaptureData {
|
||||
amount_to_capture: Some(50),
|
||||
amount_to_capture: 50,
|
||||
..utils::PaymentCaptureType::default().0
|
||||
}),
|
||||
Some(get_payment_info()),
|
||||
|
||||
@ -92,7 +92,7 @@ async fn should_partially_capture_authorized_payment() {
|
||||
.authorize_and_capture_payment(
|
||||
payment_method_details(),
|
||||
Some(types::PaymentsCaptureData {
|
||||
amount_to_capture: Some(50),
|
||||
amount_to_capture: 50,
|
||||
..utils::PaymentCaptureType::default().0
|
||||
}),
|
||||
get_default_payment_info(),
|
||||
|
||||
@ -81,7 +81,7 @@ async fn should_capture_already_authorized_payment() {
|
||||
.authorize_and_capture_payment(
|
||||
None,
|
||||
Some(types::PaymentsCaptureData {
|
||||
amount_to_capture: Some(50),
|
||||
amount_to_capture: 50,
|
||||
..utils::PaymentCaptureType::default().0
|
||||
}),
|
||||
get_default_payment_info(),
|
||||
|
||||
@ -62,7 +62,7 @@ async fn should_partially_capture_authorized_payment() {
|
||||
.authorize_and_capture_payment(
|
||||
None,
|
||||
Some(types::PaymentsCaptureData {
|
||||
amount_to_capture: Some(50),
|
||||
amount_to_capture: 50,
|
||||
..utils::PaymentCaptureType::default().0
|
||||
}),
|
||||
None,
|
||||
|
||||
@ -76,7 +76,7 @@ async fn should_partially_capture_authorized_payment() {
|
||||
.authorize_and_capture_payment(
|
||||
get_payment_data(),
|
||||
Some(types::PaymentsCaptureData {
|
||||
amount_to_capture: Some(50),
|
||||
amount_to_capture: 50,
|
||||
..utils::PaymentCaptureType::default().0
|
||||
}),
|
||||
None,
|
||||
|
||||
@ -67,7 +67,7 @@ async fn should_partially_capture_authorized_payment() {
|
||||
.authorize_and_capture_payment(
|
||||
None,
|
||||
Some(types::PaymentsCaptureData {
|
||||
amount_to_capture: Some(50),
|
||||
amount_to_capture: 50,
|
||||
..utils::PaymentCaptureType::default().0
|
||||
}),
|
||||
None,
|
||||
|
||||
@ -75,7 +75,7 @@ async fn should_partially_capture_already_authorized_payment() {
|
||||
.authorize_and_capture_payment(
|
||||
get_payment_authorize_data(),
|
||||
Some(types::PaymentsCaptureData {
|
||||
amount_to_capture: Some(50),
|
||||
amount_to_capture: 50,
|
||||
..utils::PaymentCaptureType::default().0
|
||||
}),
|
||||
None,
|
||||
|
||||
@ -500,10 +500,10 @@ impl Default for PaymentAuthorizeType {
|
||||
impl Default for PaymentCaptureType {
|
||||
fn default() -> Self {
|
||||
Self(types::PaymentsCaptureData {
|
||||
amount_to_capture: Some(100),
|
||||
amount_to_capture: 100,
|
||||
currency: enums::Currency::USD,
|
||||
connector_transaction_id: "".to_string(),
|
||||
amount: 100,
|
||||
payment_amount: 100,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user