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