Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

fix(connector): [Adyen] fix status mapping for Adyen authorize, capture, refund API (#1149)

Arjun Karthik2932a5f0ff5a
diff --git a/crates/router/src/connector/adyen/transformers.rs b/crates/router/src/connector/adyen/transformers.rs
index 57dfe7f3fc..259c3559ba 100644
--- a/crates/router/src/connector/adyen/transformers.rs
+++ b/crates/router/src/connector/adyen/transformers.rs
@@ -152,7 +152,8 @@ impl ForeignFrom<(bool, AdyenStatus)> for storage_enums::AttemptStatus {
AdyenStatus::AuthenticationNotRequired => Self::Pending,
AdyenStatus::Authorised => match is_manual_capture {
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::ChallengeShopper | AdyenStatus::RedirectShopper => {
@@ -1721,15 +1722,11 @@ impl TryFrom<types::PaymentsCaptureResponseRouterData<AdyenCaptureResponse>>
fn try_from(
item: types::PaymentsCaptureResponseRouterData<AdyenCaptureResponse>,
) -> 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 {
- 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 {
resource_id: types::ResponseId::ConnectorTransactionId(item.response.psp_reference),
redirection_data: None,
@@ -1737,7 +1734,7 @@ impl TryFrom<types::PaymentsCaptureResponseRouterData<AdyenCaptureResponse>>
connector_metadata: None,
network_txn_id: None,
}),
- amount_captured,
+ amount_captured: Some(item.response.amount.value),
..item.data
})
}
@@ -1801,16 +1798,13 @@ impl<F> TryFrom<types::RefundsResponseRouterData<F, AdyenRefundResponse>>
fn try_from(
item: types::RefundsResponseRouterData<F, AdyenRefundResponse>,
) -> 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 {
response: Ok(types::RefundsResponseData {
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
})
diff --git a/crates/router/tests/connectors/adyen.rs b/crates/router/tests/connectors/adyen.rs
index 80f3c17890..ab37c8ff49 100644
--- a/crates/router/tests/connectors/adyen.rs
+++ b/crates/router/tests/connectors/adyen.rs
@@ -133,7 +133,7 @@ async fn should_capture_authorized_payment() {
)
.await
.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).
@@ -156,7 +156,7 @@ async fn should_partially_capture_authorized_payment() {
)
.await
.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).
@@ -207,7 +207,7 @@ async fn should_refund_manually_captured_payment() {
.unwrap();
assert_eq!(
response.response.unwrap().refund_status,
- enums::RefundStatus::Success,
+ enums::RefundStatus::Pending,
);
}
@@ -235,7 +235,7 @@ async fn should_partially_refund_manually_captured_payment() {
.unwrap();
assert_eq!(
response.response.unwrap().refund_status,
- enums::RefundStatus::Success,
+ enums::RefundStatus::Pending,
);
}
@@ -255,7 +255,7 @@ async fn should_make_payment() {
)
.await
.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).
@@ -281,7 +281,7 @@ async fn should_refund_auto_captured_payment() {
.unwrap();
assert_eq!(
response.response.unwrap().refund_status,
- enums::RefundStatus::Success,
+ enums::RefundStatus::Pending,
);
}
@@ -308,15 +308,17 @@ async fn should_partially_refund_succeeded_payment() {
.unwrap();
assert_eq!(
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).
#[actix_web::test]
async fn should_refund_succeeded_payment_multiple_times() {
- CONNECTOR
- .make_payment_and_multiple_refund(
+ let payment_info = AdyenTest::get_payment_info();
+ //make a successful payment
+ let response = CONNECTOR
+ .make_payment(
AdyenTest::get_payment_authorize_data(
"2222400070000005",
"03",
@@ -324,14 +326,31 @@ async fn should_refund_succeeded_payment_multiple_times() {
"737",
enums::CaptureMethod::Automatic,
),
- Some(types::RefundsData {
- refund_amount: 100,
- reason: Some("CUSTOMER REQUEST".to_string()),
- ..utils::PaymentRefundType::default().0
- }),
- AdyenTest::get_payment_info(),
+ payment_info.clone(),
)
- .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