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:
Arjun Karthik
2023-04-06 15:31:25 +05:30
committed by GitHub
parent de29eb68b6
commit b8bcba4e6c
27 changed files with 41 additions and 55 deletions

View File

@ -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,
},
})
}

View File

@ -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,
)?),
})
}
}

View File

@ -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,
})
}

View File

@ -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,

View File

@ -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)

View File

@ -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()

View File

@ -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(),
})

View File

@ -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,

View File

@ -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()),
})
}
}

View File

@ -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,

View File

@ -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,
})

View File

@ -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),
})
}
}