Skip to content

Commit

Permalink
fix(connector): fix for sending refund_amount in connectors refund re…
Browse files Browse the repository at this point in the history
…quest (#1278)

Co-authored-by: Narayan Bhat <[email protected]>
  • Loading branch information
ArjunKarthik and Narayanbhat166 authored Jun 15, 2023
1 parent 1e5d2a2 commit 016857f
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 82 deletions.
2 changes: 1 addition & 1 deletion crates/router/src/connector/bambora/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for BamboraRefundRequest {
type Error = error_stack::Report<errors::ParsingError>;
fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> {
Ok(Self {
amount: item.request.amount,
amount: item.request.refund_amount,
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/forte/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for ForteRefundRequest {
utils::to_connector_meta(item.request.connector_metadata.clone())?;
let auth_code = connector_auth_id.auth_id;
let authorization_amount =
utils::to_currency_base_unit_asf64(item.request.amount, item.request.currency)?;
utils::to_currency_base_unit_asf64(item.request.refund_amount, item.request.currency)?;
Ok(Self {
action: "reverse".to_string(),
authorization_amount,
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/mollie/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for MollieRefundRequest {
fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> {
let amount = Amount {
currency: item.request.currency,
value: utils::to_currency_base_unit(item.request.amount, item.request.currency)?,
value: utils::to_currency_base_unit(item.request.refund_amount, item.request.currency)?,
};
Ok(Self {
amount,
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/multisafepay/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for MultisafepayRefundRequest {
fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> {
Ok(Self {
currency: item.request.currency,
amount: item.request.amount,
amount: item.request.refund_amount,
description: item.description.clone(),
refund_order_id: Some(item.request.refund_id.clone()),
checkout_data: None,
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/nuvei/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ impl TryFrom<&types::RefundExecuteRouterData> for NuveiPaymentFlowRequest {
Self::try_from(NuveiPaymentRequestData {
client_request_id: item.attempt_id.clone(),
connector_auth_type: item.connector_auth_type.clone(),
amount: item.request.amount.to_string(),
amount: item.request.refund_amount.to_string(),
currency: item.request.currency,
related_transaction_id: Some(item.request.connector_transaction_id.clone()),
..Default::default()
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/opennode/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for OpennodeRefundRequest {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> {
Ok(Self {
amount: item.request.amount,
amount: item.request.refund_amount,
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/rapyd/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for RapydRefundRequest {
fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> {
Ok(Self {
payment: item.request.connector_transaction_id.to_string(),
amount: Some(item.request.amount),
amount: Some(item.request.refund_amount),
currency: Some(item.request.currency),
})
}
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/trustpay/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for TrustpayRefundRequest {
fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> {
let amount = format!(
"{:.2}",
utils::to_currency_base_unit(item.request.amount, item.request.currency)?
utils::to_currency_base_unit(item.request.refund_amount, item.request.currency)?
.parse::<f64>()
.into_report()
.change_context(errors::ConnectorError::RequestEncodingFailed)?
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/worldpay/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for WorldpayRefundRequest {
Ok(Self {
reference: item.request.connector_transaction_id.clone(),
value: PaymentValue {
amount: item.request.amount,
amount: item.request.refund_amount,
currency: item.request.currency.to_string(),
},
})
Expand Down
4 changes: 2 additions & 2 deletions crates/router/src/core/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub async fn construct_refund_router_data<'a, F>(

let status = payment_attempt.status;

let (amount, currency) = money;
let (payment_amount, currency) = money;

let payment_method_type = payment_attempt
.payment_method
Expand Down Expand Up @@ -87,7 +87,7 @@ pub async fn construct_refund_router_data<'a, F>(
connector_transaction_id: refund.connector_transaction_id.clone(),
refund_amount: refund.refund_amount,
currency,
amount,
payment_amount,
webhook_url,
connector_metadata: payment_attempt.connector_metadata.clone(),
reason: refund.refund_reason.clone(),
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ pub struct RefundsData {
pub connector_refund_id: Option<String>,
pub currency: storage_enums::Currency,
/// Amount for the payment against which this refund is issued
pub amount: i64,
pub payment_amount: i64,
pub reason: Option<String>,
pub webhook_url: Option<String>,
/// Amount to be refunded
Expand Down
2 changes: 1 addition & 1 deletion crates/router/tests/connectors/aci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn construct_refund_router_data<F>() -> types::RefundsRouterData<F> {
description: Some("This is a test".to_string()),
return_url: None,
request: types::RefundsData {
amount: 1000,
payment_amount: 1000,
currency: enums::Currency::USD,

refund_id: uuid::Uuid::new_v4().to_string(),
Expand Down
22 changes: 0 additions & 22 deletions crates/router/tests/connectors/forte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,28 +454,6 @@ async fn should_sync_refund() {
}

// Cards Negative scenerios
// Creates a payment with incorrect card number.
#[actix_web::test]
async fn should_fail_payment_for_incorrect_card_number() {
let response = CONNECTOR
.make_payment(
Some(types::PaymentsAuthorizeData {
payment_method_data: types::api::PaymentMethodData::Card(api::Card {
card_number: CardNumber::from_str("4111111111111100").unwrap(),
..utils::CCardType::default().0
}),
..utils::PaymentAuthorizeType::default().0
}),
get_default_payment_info(),
)
.await
.unwrap();
assert_eq!(
response.response.unwrap_err().message,
"INVALID CREDIT CARD NUMBER".to_string(),
);
}

// Creates a payment with incorrect CVC.
#[actix_web::test]
async fn should_fail_payment_for_incorrect_cvc() {
Expand Down
Loading

0 comments on commit 016857f

Please sign in to comment.