mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 11:06:50 +08:00
fix(connector): [Adyen] fix status mapping for Adyen authorize, capture, refund API (#1149)
This commit is contained in:
@ -152,7 +152,8 @@ impl ForeignFrom<(bool, AdyenStatus)> for storage_enums::AttemptStatus {
|
|||||||
AdyenStatus::AuthenticationNotRequired => Self::Pending,
|
AdyenStatus::AuthenticationNotRequired => Self::Pending,
|
||||||
AdyenStatus::Authorised => match is_manual_capture {
|
AdyenStatus::Authorised => match is_manual_capture {
|
||||||
true => Self::Authorized,
|
true => Self::Authorized,
|
||||||
false => Self::Charged,
|
// Final outcome of the payment can be confirmed only through webhooks
|
||||||
|
false => Self::Pending,
|
||||||
},
|
},
|
||||||
AdyenStatus::Cancelled => Self::Voided,
|
AdyenStatus::Cancelled => Self::Voided,
|
||||||
AdyenStatus::ChallengeShopper | AdyenStatus::RedirectShopper => {
|
AdyenStatus::ChallengeShopper | AdyenStatus::RedirectShopper => {
|
||||||
@ -1721,15 +1722,11 @@ impl TryFrom<types::PaymentsCaptureResponseRouterData<AdyenCaptureResponse>>
|
|||||||
fn try_from(
|
fn try_from(
|
||||||
item: types::PaymentsCaptureResponseRouterData<AdyenCaptureResponse>,
|
item: types::PaymentsCaptureResponseRouterData<AdyenCaptureResponse>,
|
||||||
) -> Result<Self, Self::Error> {
|
) -> Result<Self, Self::Error> {
|
||||||
let (status, amount_captured) = match item.response.status.as_str() {
|
|
||||||
"received" => (
|
|
||||||
storage_enums::AttemptStatus::Charged,
|
|
||||||
Some(item.response.amount.value),
|
|
||||||
),
|
|
||||||
_ => (storage_enums::AttemptStatus::Pending, None),
|
|
||||||
};
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
status,
|
// From the docs, the only value returned is "received", outcome of refund is available
|
||||||
|
// through refund notification webhook
|
||||||
|
// For more info: https://docs.adyen.com/online-payments/capture
|
||||||
|
status: storage_enums::AttemptStatus::Pending,
|
||||||
response: Ok(types::PaymentsResponseData::TransactionResponse {
|
response: Ok(types::PaymentsResponseData::TransactionResponse {
|
||||||
resource_id: types::ResponseId::ConnectorTransactionId(item.response.psp_reference),
|
resource_id: types::ResponseId::ConnectorTransactionId(item.response.psp_reference),
|
||||||
redirection_data: None,
|
redirection_data: None,
|
||||||
@ -1737,7 +1734,7 @@ impl TryFrom<types::PaymentsCaptureResponseRouterData<AdyenCaptureResponse>>
|
|||||||
connector_metadata: None,
|
connector_metadata: None,
|
||||||
network_txn_id: None,
|
network_txn_id: None,
|
||||||
}),
|
}),
|
||||||
amount_captured,
|
amount_captured: Some(item.response.amount.value),
|
||||||
..item.data
|
..item.data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1801,16 +1798,13 @@ impl<F> TryFrom<types::RefundsResponseRouterData<F, AdyenRefundResponse>>
|
|||||||
fn try_from(
|
fn try_from(
|
||||||
item: types::RefundsResponseRouterData<F, AdyenRefundResponse>,
|
item: types::RefundsResponseRouterData<F, AdyenRefundResponse>,
|
||||||
) -> Result<Self, Self::Error> {
|
) -> Result<Self, Self::Error> {
|
||||||
let refund_status = match item.response.status.as_str() {
|
|
||||||
// From the docs, the only value returned is "received", outcome of refund is available
|
|
||||||
// through refund notification webhook
|
|
||||||
"received" => storage_enums::RefundStatus::Success,
|
|
||||||
_ => storage_enums::RefundStatus::Pending,
|
|
||||||
};
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
response: Ok(types::RefundsResponseData {
|
response: Ok(types::RefundsResponseData {
|
||||||
connector_refund_id: item.response.reference,
|
connector_refund_id: item.response.reference,
|
||||||
refund_status,
|
// From the docs, the only value returned is "received", outcome of refund is available
|
||||||
|
// through refund notification webhook
|
||||||
|
// For more info: https://docs.adyen.com/online-payments/refund
|
||||||
|
refund_status: storage_enums::RefundStatus::Pending,
|
||||||
}),
|
}),
|
||||||
..item.data
|
..item.data
|
||||||
})
|
})
|
||||||
|
|||||||
@ -133,7 +133,7 @@ async fn should_capture_authorized_payment() {
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.expect("Capture payment response");
|
.expect("Capture payment response");
|
||||||
assert_eq!(response.status, enums::AttemptStatus::Charged);
|
assert_eq!(response.status, enums::AttemptStatus::Pending);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Partially captures a payment using the manual capture flow (Non 3DS).
|
// Partially captures a payment using the manual capture flow (Non 3DS).
|
||||||
@ -156,7 +156,7 @@ async fn should_partially_capture_authorized_payment() {
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.expect("Capture payment response");
|
.expect("Capture payment response");
|
||||||
assert_eq!(response.status, enums::AttemptStatus::Charged);
|
assert_eq!(response.status, enums::AttemptStatus::Pending);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Voids a payment using the manual capture flow (Non 3DS).
|
// Voids a payment using the manual capture flow (Non 3DS).
|
||||||
@ -207,7 +207,7 @@ async fn should_refund_manually_captured_payment() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
response.response.unwrap().refund_status,
|
response.response.unwrap().refund_status,
|
||||||
enums::RefundStatus::Success,
|
enums::RefundStatus::Pending,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +235,7 @@ async fn should_partially_refund_manually_captured_payment() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
response.response.unwrap().refund_status,
|
response.response.unwrap().refund_status,
|
||||||
enums::RefundStatus::Success,
|
enums::RefundStatus::Pending,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,7 +255,7 @@ async fn should_make_payment() {
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(authorize_response.status, enums::AttemptStatus::Charged);
|
assert_eq!(authorize_response.status, enums::AttemptStatus::Pending);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refunds a payment using the automatic capture flow (Non 3DS).
|
// Refunds a payment using the automatic capture flow (Non 3DS).
|
||||||
@ -281,7 +281,7 @@ async fn should_refund_auto_captured_payment() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
response.response.unwrap().refund_status,
|
response.response.unwrap().refund_status,
|
||||||
enums::RefundStatus::Success,
|
enums::RefundStatus::Pending,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,15 +308,17 @@ async fn should_partially_refund_succeeded_payment() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
refund_response.response.unwrap().refund_status,
|
refund_response.response.unwrap().refund_status,
|
||||||
enums::RefundStatus::Success,
|
enums::RefundStatus::Pending,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates multiple refunds against a payment using the automatic capture flow (Non 3DS).
|
// Creates multiple refunds against a payment using the automatic capture flow (Non 3DS).
|
||||||
#[actix_web::test]
|
#[actix_web::test]
|
||||||
async fn should_refund_succeeded_payment_multiple_times() {
|
async fn should_refund_succeeded_payment_multiple_times() {
|
||||||
CONNECTOR
|
let payment_info = AdyenTest::get_payment_info();
|
||||||
.make_payment_and_multiple_refund(
|
//make a successful payment
|
||||||
|
let response = CONNECTOR
|
||||||
|
.make_payment(
|
||||||
AdyenTest::get_payment_authorize_data(
|
AdyenTest::get_payment_authorize_data(
|
||||||
"2222400070000005",
|
"2222400070000005",
|
||||||
"03",
|
"03",
|
||||||
@ -324,14 +326,31 @@ async fn should_refund_succeeded_payment_multiple_times() {
|
|||||||
"737",
|
"737",
|
||||||
enums::CaptureMethod::Automatic,
|
enums::CaptureMethod::Automatic,
|
||||||
),
|
),
|
||||||
Some(types::RefundsData {
|
payment_info.clone(),
|
||||||
refund_amount: 100,
|
|
||||||
reason: Some("CUSTOMER REQUEST".to_string()),
|
|
||||||
..utils::PaymentRefundType::default().0
|
|
||||||
}),
|
|
||||||
AdyenTest::get_payment_info(),
|
|
||||||
)
|
)
|
||||||
.await;
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
//try refund for previous payment
|
||||||
|
let transaction_id = utils::get_connector_transaction_id(response.response).unwrap();
|
||||||
|
for _x in 0..2 {
|
||||||
|
let refund_response = CONNECTOR
|
||||||
|
.refund_payment(
|
||||||
|
transaction_id.clone(),
|
||||||
|
Some(types::RefundsData {
|
||||||
|
refund_amount: 100,
|
||||||
|
reason: Some("CUSTOMER REQUEST".to_string()),
|
||||||
|
..utils::PaymentRefundType::default().0
|
||||||
|
}),
|
||||||
|
payment_info.clone(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
refund_response.response.unwrap().refund_status,
|
||||||
|
enums::RefundStatus::Pending,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cards Negative scenerios
|
// Cards Negative scenerios
|
||||||
|
|||||||
Reference in New Issue
Block a user