Skip to content

Commit 2932a5f

Browse files
authored
fix(connector): [Adyen] fix status mapping for Adyen authorize, capture, refund API (#1149)
1 parent a5756aa commit 2932a5f

File tree

2 files changed

+46
-33
lines changed

2 files changed

+46
-33
lines changed

crates/router/src/connector/adyen/transformers.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ impl ForeignFrom<(bool, AdyenStatus)> for storage_enums::AttemptStatus {
152152
AdyenStatus::AuthenticationNotRequired => Self::Pending,
153153
AdyenStatus::Authorised => match is_manual_capture {
154154
true => Self::Authorized,
155-
false => Self::Charged,
155+
// Final outcome of the payment can be confirmed only through webhooks
156+
false => Self::Pending,
156157
},
157158
AdyenStatus::Cancelled => Self::Voided,
158159
AdyenStatus::ChallengeShopper | AdyenStatus::RedirectShopper => {
@@ -1721,23 +1722,19 @@ impl TryFrom<types::PaymentsCaptureResponseRouterData<AdyenCaptureResponse>>
17211722
fn try_from(
17221723
item: types::PaymentsCaptureResponseRouterData<AdyenCaptureResponse>,
17231724
) -> Result<Self, Self::Error> {
1724-
let (status, amount_captured) = match item.response.status.as_str() {
1725-
"received" => (
1726-
storage_enums::AttemptStatus::Charged,
1727-
Some(item.response.amount.value),
1728-
),
1729-
_ => (storage_enums::AttemptStatus::Pending, None),
1730-
};
17311725
Ok(Self {
1732-
status,
1726+
// From the docs, the only value returned is "received", outcome of refund is available
1727+
// through refund notification webhook
1728+
// For more info: https://docs.adyen.com/online-payments/capture
1729+
status: storage_enums::AttemptStatus::Pending,
17331730
response: Ok(types::PaymentsResponseData::TransactionResponse {
17341731
resource_id: types::ResponseId::ConnectorTransactionId(item.response.psp_reference),
17351732
redirection_data: None,
17361733
mandate_reference: None,
17371734
connector_metadata: None,
17381735
network_txn_id: None,
17391736
}),
1740-
amount_captured,
1737+
amount_captured: Some(item.response.amount.value),
17411738
..item.data
17421739
})
17431740
}
@@ -1801,16 +1798,13 @@ impl<F> TryFrom<types::RefundsResponseRouterData<F, AdyenRefundResponse>>
18011798
fn try_from(
18021799
item: types::RefundsResponseRouterData<F, AdyenRefundResponse>,
18031800
) -> Result<Self, Self::Error> {
1804-
let refund_status = match item.response.status.as_str() {
1805-
// From the docs, the only value returned is "received", outcome of refund is available
1806-
// through refund notification webhook
1807-
"received" => storage_enums::RefundStatus::Success,
1808-
_ => storage_enums::RefundStatus::Pending,
1809-
};
18101801
Ok(Self {
18111802
response: Ok(types::RefundsResponseData {
18121803
connector_refund_id: item.response.reference,
1813-
refund_status,
1804+
// From the docs, the only value returned is "received", outcome of refund is available
1805+
// through refund notification webhook
1806+
// For more info: https://docs.adyen.com/online-payments/refund
1807+
refund_status: storage_enums::RefundStatus::Pending,
18141808
}),
18151809
..item.data
18161810
})

crates/router/tests/connectors/adyen.rs

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ async fn should_capture_authorized_payment() {
133133
)
134134
.await
135135
.expect("Capture payment response");
136-
assert_eq!(response.status, enums::AttemptStatus::Charged);
136+
assert_eq!(response.status, enums::AttemptStatus::Pending);
137137
}
138138

139139
// Partially captures a payment using the manual capture flow (Non 3DS).
@@ -156,7 +156,7 @@ async fn should_partially_capture_authorized_payment() {
156156
)
157157
.await
158158
.expect("Capture payment response");
159-
assert_eq!(response.status, enums::AttemptStatus::Charged);
159+
assert_eq!(response.status, enums::AttemptStatus::Pending);
160160
}
161161

162162
// Voids a payment using the manual capture flow (Non 3DS).
@@ -207,7 +207,7 @@ async fn should_refund_manually_captured_payment() {
207207
.unwrap();
208208
assert_eq!(
209209
response.response.unwrap().refund_status,
210-
enums::RefundStatus::Success,
210+
enums::RefundStatus::Pending,
211211
);
212212
}
213213

@@ -235,7 +235,7 @@ async fn should_partially_refund_manually_captured_payment() {
235235
.unwrap();
236236
assert_eq!(
237237
response.response.unwrap().refund_status,
238-
enums::RefundStatus::Success,
238+
enums::RefundStatus::Pending,
239239
);
240240
}
241241

@@ -255,7 +255,7 @@ async fn should_make_payment() {
255255
)
256256
.await
257257
.unwrap();
258-
assert_eq!(authorize_response.status, enums::AttemptStatus::Charged);
258+
assert_eq!(authorize_response.status, enums::AttemptStatus::Pending);
259259
}
260260

261261
// Refunds a payment using the automatic capture flow (Non 3DS).
@@ -281,7 +281,7 @@ async fn should_refund_auto_captured_payment() {
281281
.unwrap();
282282
assert_eq!(
283283
response.response.unwrap().refund_status,
284-
enums::RefundStatus::Success,
284+
enums::RefundStatus::Pending,
285285
);
286286
}
287287

@@ -308,30 +308,49 @@ async fn should_partially_refund_succeeded_payment() {
308308
.unwrap();
309309
assert_eq!(
310310
refund_response.response.unwrap().refund_status,
311-
enums::RefundStatus::Success,
311+
enums::RefundStatus::Pending,
312312
);
313313
}
314314

315315
// Creates multiple refunds against a payment using the automatic capture flow (Non 3DS).
316316
#[actix_web::test]
317317
async fn should_refund_succeeded_payment_multiple_times() {
318-
CONNECTOR
319-
.make_payment_and_multiple_refund(
318+
let payment_info = AdyenTest::get_payment_info();
319+
//make a successful payment
320+
let response = CONNECTOR
321+
.make_payment(
320322
AdyenTest::get_payment_authorize_data(
321323
"2222400070000005",
322324
"03",
323325
"2030",
324326
"737",
325327
enums::CaptureMethod::Automatic,
326328
),
327-
Some(types::RefundsData {
328-
refund_amount: 100,
329-
reason: Some("CUSTOMER REQUEST".to_string()),
330-
..utils::PaymentRefundType::default().0
331-
}),
332-
AdyenTest::get_payment_info(),
329+
payment_info.clone(),
333330
)
334-
.await;
331+
.await
332+
.unwrap();
333+
334+
//try refund for previous payment
335+
let transaction_id = utils::get_connector_transaction_id(response.response).unwrap();
336+
for _x in 0..2 {
337+
let refund_response = CONNECTOR
338+
.refund_payment(
339+
transaction_id.clone(),
340+
Some(types::RefundsData {
341+
refund_amount: 100,
342+
reason: Some("CUSTOMER REQUEST".to_string()),
343+
..utils::PaymentRefundType::default().0
344+
}),
345+
payment_info.clone(),
346+
)
347+
.await
348+
.unwrap();
349+
assert_eq!(
350+
refund_response.response.unwrap().refund_status,
351+
enums::RefundStatus::Pending,
352+
);
353+
}
335354
}
336355

337356
// Cards Negative scenerios

0 commit comments

Comments
 (0)