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

feat(Connector): [ADEYN] DISPUTES Changes (#12868)

Nithin N53572f28c6e6
diff --git a/crates/common_enums/src/connector_enums.rs b/crates/common_enums/src/connector_enums.rs
index 236b86a65e..75d81cd082 100644
--- a/crates/common_enums/src/connector_enums.rs
+++ b/crates/common_enums/src/connector_enums.rs
@@ -294,7 +294,7 @@ impl Connector {
matches!(self, Self::Stripe | Self::Checkout | Self::Worldpayvantiv)
}
pub fn requires_defend_dispute(self) -> bool {
- matches!(self, Self::Checkout)
+ matches!(self, Self::Adyen | Self::Checkout)
}
pub fn is_separate_authentication_supported(self) -> bool {
match self {
diff --git a/crates/hyperswitch_connectors/src/connectors/adyen.rs b/crates/hyperswitch_connectors/src/connectors/adyen.rs
index 1dda6239f2..e82329b393 100644
--- a/crates/hyperswitch_connectors/src/connectors/adyen.rs
+++ b/crates/hyperswitch_connectors/src/connectors/adyen.rs
@@ -104,6 +104,13 @@ use crate::{
};
const ADYEN_API_VERSION: &str = "v68";
+const ADYEN_IMAGE_MAX_SIZE: i32 = 10_000_000;
+const ADYEN_PDF_MAX_SIZE: i32 = 2_000_000;
+const ADYEN_PDF_FORMAT: &str = "application/pdf";
+const ADYEN_SUPPORTED_DISPUTE_EVIDENCE_FILE_TYPES: [&str; 4] =
+ ["image/jpeg", "image/jpg", "image/tiff", ADYEN_PDF_FORMAT];
+const ADYEN_IMAGE_FILE_TYPES: [&str; 3] = ["image/jpeg", "image/jpg", "image/tiff"];
+
#[derive(Clone)]
pub struct Adyen {
amount_converter: &'static (dyn AmountConvertor<Output = MinorUnit> + Sync),
@@ -716,7 +723,6 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Ady
}),
},
};
-
Ok(RequestContent::Json(Box::new(connector_req)))
}
@@ -1197,7 +1203,6 @@ impl
_connectors: &Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
let connector_req = adyen::AdyenBalanceRequest::try_from(req)?;
-
Ok(RequestContent::Json(Box::new(connector_req)))
}
@@ -2314,6 +2319,7 @@ impl ConnectorIntegration<Accept, AcceptDisputeRequestData, AcceptDisputeRespons
.response
.parse_struct("AdyenDisputeResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+
RouterData::foreign_try_from((data, response))
.change_context(errors::ConnectorError::ResponseHandlingFailed)
}
@@ -2392,7 +2398,7 @@ impl ConnectorIntegration<Defend, DefendDisputeRequestData, DefendDisputeRespons
.response
.parse_struct("AdyenDisputeResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
- RouterData::foreign_try_from((data, response))
+ RouterData::foreign_try_from((data, res, response))
.change_context(errors::ConnectorError::ResponseHandlingFailed)
}
@@ -2497,28 +2503,24 @@ impl FileUpload for Adyen {
) -> CustomResult<(), errors::ConnectorError> {
match purpose {
FilePurpose::DisputeEvidence => {
- let supported_file_types =
- ["image/jpeg", "image/jpg", "image/png", "application/pdf"];
- if !supported_file_types.contains(&file_type.to_string().as_str()) {
+ let file_type_str = file_type.to_string();
+ if !ADYEN_SUPPORTED_DISPUTE_EVIDENCE_FILE_TYPES.contains(&file_type_str.as_str()) {
Err(errors::ConnectorError::FileValidationFailed {
- reason: "file_type does not match JPEG, JPG, PNG, or PDF format".to_owned(),
+ reason: "file_type does not match JPEG, JPG, TIFF, or PDF format"
+ .to_owned(),
})?
}
- //10 MB
- if (file_type.to_string().as_str() == "image/jpeg"
- || file_type.to_string().as_str() == "image/jpg"
- || file_type.to_string().as_str() == "image/png")
- && file_size > 10000000
+ if ADYEN_IMAGE_FILE_TYPES.contains(&file_type_str.as_str())
+ && file_size > ADYEN_IMAGE_MAX_SIZE
{
Err(errors::ConnectorError::FileValidationFailed {
reason: "file_size exceeded the max file size of 10MB for Image formats"
.to_owned(),
})?
}
- //2 MB
- if file_type.to_string().as_str() == "application/pdf" && file_size > 2000000 {
+ if file_type_str.as_str() == ADYEN_PDF_FORMAT && file_size > ADYEN_PDF_MAX_SIZE {
Err(errors::ConnectorError::FileValidationFailed {
- reason: "file_size exceeded the max file size of 2MB for PDF formats"
+ reason: "file_size exceeded the max file size of 2MB for PDF format"
.to_owned(),
})?
}
diff --git a/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs b/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs
index 393fdceb9f..aa5c0f9b7e 100644
--- a/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs
@@ -6,6 +6,7 @@ use api_models::{
enums,
payments::{self, PollConfig, QrCodeInformation, VoucherNextStepData},
};
+use base64::Engine;
use cards::{CardNumber, NetworkToken};
use common_enums::enums as storage_enums;
#[cfg(feature = "payouts")]
@@ -54,6 +55,7 @@ use hyperswitch_domain_models::{
use hyperswitch_interfaces::{
consts::{NO_ERROR_CODE, NO_ERROR_MESSAGE},
errors,
+ types::Response,
};
use hyperswitch_masking::{ExposeInterface, PeekInterface, Secret};
use serde::{Deserialize, Serialize};
@@ -5657,6 +5659,18 @@ pub enum WebhookEventCode {
PrearbitrationWon,
PrearbitrationLost,
RequestForInformation,
+ NotificationOfFraud,
+ InformationSupplied,
+ PrearbitrationOpen,
+ PrearbitrationAccepted,
+ PrearbitrationDeclined,
+ PrearbitrationIssuerWithdrawn,
+ SchemeArbitration,
+ SchemeArbitrationWon,
+ SchemeArbitrationLost,
+ DisputeDefensePeriodEnded,
+ IssuerResponseTimeframeExpired,
+ IssuerComments,
OfferClosed,
RecurringContract,
#[cfg(feature = "payouts")]
@@ -5710,6 +5724,16 @@ pub fn is_chargeback_event(event_code: &WebhookEventCode) -> bool {
| WebhookEventCode::PrearbitrationWon
| WebhookEventCode::PrearbitrationLost
| WebhookEventCode::RequestForInformation
+ | WebhookEventCode::InformationSupplied
+ | WebhookEventCode::PrearbitrationOpen
+ | WebhookEventCode::PrearbitrationAccepted
+ | WebhookEventCode::PrearbitrationDeclined
+ | WebhookEventCode::PrearbitrationIssuerWithdrawn
+ | WebhookEventCode::SchemeArbitration
+ | WebhookEventCode::SchemeArbitrationWon
+ | WebhookEventCode::SchemeArbitrationLost
+ | WebhookEventCode::DisputeDefensePeriodEnded
+ | WebhookEventCode::IssuerResponseTimeframeExpired
)
}
@@ -5768,25 +5792,39 @@ pub(crate) fn get_adyen_webhook_event(
WebhookEventCode::NotificationOfChargeback => {
api_models::webhooks::IncomingWebhookEvent::DisputeOpened
}
+ // NOTIFICATION_OF_FRAUD - Informational fraud alerts (Visa TC40/Mastercard SAFE)
+ // These are pre-dispute warnings that don't create a dispute record
+ WebhookEventCode::NotificationOfFraud => {
+ api_models::webhooks::IncomingWebhookEvent::EventNotSupported
+ }
WebhookEventCode::Chargeback => match dispute_status {
Some(DisputeStatus::Won) => api_models::webhooks::IncomingWebhookEvent::DisputeWon,
- Some(DisputeStatus::Lost) | None => {
- api_models::webhooks::IncomingWebhookEvent::DisputeLost
+ Some(DisputeStatus::Lost) => api_models::webhooks::IncomingWebhookEvent::DisputeLost,
+ Some(DisputeStatus::Accepted) => {
+ api_models::webhooks::IncomingWebhookEvent::DisputeAccepted
}
Some(_) => api_models::webhooks::IncomingWebhookEvent::DisputeOpened,
+ None => api_models::webhooks::IncomingWebhookEvent::DisputeLost,
},
WebhookEventCode::RequestForInformation => match dispute_status {
Some(DisputeStatus::Responded) => {
- api_models::webhooks::IncomingWebhookEvent::DisputeChallenged
+ api_models::webhooks::IncomingWebhookEvent::DisputeOpened
}
Some(DisputeStatus::Expired) => {
api_models::webhooks::IncomingWebhookEvent::DisputeExpired
}
Some(DisputeStatus::Unresponded) => {
- api_models::webhooks::IncomingWebhookEvent::EventNotSupported
+ api_models::webhooks::IncomingWebhookEvent::DisputeOpened
}
None | Some(_) => api_models::webhooks::IncomingWebhookEvent::DisputeOpened,
},
+ WebhookEventCode::InformationSupplied => match dispute_status {
+ Some(DisputeStatus::Responded) => {
+ api_models::webhooks::IncomingWebhookEvent::DisputeChallenged
+ }
+ Some(_) => api_models::webhooks::IncomingWebhookEvent::DisputeOpened,
+ None => api_models::webhooks::IncomingWebhookEvent::DisputeOpened,
+ },
WebhookEventCode::ChargebackReversed => match dispute_status {
Some(DisputeStatus::Pending) => {
api_models::webhooks::IncomingWebhookEvent::DisputeChallenged
@@ -5796,15 +5834,52 @@ pub(crate) fn get_adyen_webhook_event(
WebhookEventCode::SecondChargeback => {
api_models::webhooks::IncomingWebhookEvent::DisputeLost
}
- WebhookEventCode::PrearbitrationWon => match dispute_status {
- Some(DisputeStatus::Pending) => {
+ WebhookEventCode::PrearbitrationWon => {
+ api_models::webhooks::IncomingWebhookEvent::DisputeWon
+ }
+ WebhookEventCode::PrearbitrationLost => {
+ api_models::webhooks::IncomingWebhookEvent::DisputeLost
+ }
+ WebhookEventCode::PrearbitrationOpen => match dispute_status {
+ Some(DisputeStatus::Undefended) => {
api_models::webhooks::IncomingWebhookEvent::DisputeOpened
}
- _ => api_models::webhooks::IncomingWebhookEvent::DisputeWon,
+ _ => api_models::webhooks::IncomingWebhookEvent::DisputeOpened,
},
- WebhookEventCode::PrearbitrationLost => {
+ WebhookEventCode::PrearbitrationAccepted => {
+ api_models::webhooks::IncomingWebhookEvent::DisputeAccepted
+ }
+ WebhookEventCode::PrearbitrationDeclined => {
+ api_models::webhooks::IncomingWebhookEvent::DisputeChallenged
+ }
+ WebhookEventCode::PrearbitrationIssuerWithdrawn => {
+ api_models::webhooks::IncomingWebhookEvent::DisputeWon
+ }
+ WebhookEventCode::SchemeArbitration => {
+ api_models::webhooks::IncomingWebhookEvent::DisputeOpened
+ }
+ WebhookEventCode::SchemeArbitrationWon => {
+ api_models::webhooks::IncomingWebhookEvent::DisputeWon
+ }
+ WebhookEventCode::SchemeArbitrationLost => {
api_models::webhooks::IncomingWebhookEvent::DisputeLost
}
+ WebhookEventCode::DisputeDefensePeriodEnded => match dispute_status {
+ Some(DisputeStatus::Undefended) | Some(DisputeStatus::Lost) => {
+ api_models::webhooks::IncomingWebhookEvent::DisputeLost
+ }
+ Some(DisputeStatus::Accepted) => {
+ api_models::webhooks::IncomingWebhookEvent::DisputeAccepted
+ }
+ _ => api_models::webhooks::IncomingWebhookEvent::DisputeLost,
+ },
+ WebhookEventCode::IssuerResponseTimeframeExpired => {
+ api_models::webhooks::IncomingWebhookEvent::DisputeWon
+ }
+ // ISSUER_COMMENTS - Informational comments from issuer
+ WebhookEventCode::IssuerComments => {
+ api_models::webhooks::IncomingWebhookEvent::EventNotSupported
+ }
WebhookEventCode::Capture => {
if is_success_scenario(is_success) {
api_models::webhooks::IncomingWebhookEvent::PaymentIntentCaptureSuccess
@@ -5846,11 +5921,25 @@ pub(crate) fn get_adyen_webhook_event(
impl From<WebhookEventCode> for storage_enums::DisputeStage {
fn from(code: WebhookEventCode) -> Self {
match code {
- WebhookEventCode::NotificationOfChargeback
- | WebhookEventCode::RequestForInformation => Self::PreDispute,
- WebhookEventCode::SecondChargeback => Self::PreArbitration,
- WebhookEventCode::PrearbitrationWon => Self::PreArbitration,
- WebhookEventCode::PrearbitrationLost => Self::PreArbitration,
+ WebhookEventCode::RequestForInformation
+ | WebhookEventCode::NotificationOfChargeback
+ | WebhookEventCode::Chargeback
+ | WebhookEventCode::ChargebackReversed
+ | WebhookEventCode::InformationSupplied
+ | WebhookEventCode::DisputeDefensePeriodEnded
+ | WebhookEventCode::IssuerResponseTimeframeExpired => Self::Dispute,
+ // PreArbitration: Advanced dispute resolution phases
+ WebhookEventCode::SecondChargeback
+ | WebhookEventCode::PrearbitrationWon
+ | WebhookEventCode::PrearbitrationLost
+ | WebhookEventCode::PrearbitrationOpen
+ | WebhookEventCode::PrearbitrationAccepted
+ | WebhookEventCode::PrearbitrationDeclined
+ | WebhookEventCode::PrearbitrationIssuerWithdrawn
+ | WebhookEventCode::SchemeArbitration
+ | WebhookEventCode::SchemeArbitrationWon
+ | WebhookEventCode::SchemeArbitrationLost => Self::PreArbitration,
+ // Other events don't map to a specific dispute stage
_ => Self::Dispute,
}
}
@@ -5961,6 +6050,18 @@ impl From<AdyenNotificationRequestItemWH> for AdyenWebhookResponse {
| WebhookEventCode::SecondChargeback
| WebhookEventCode::PrearbitrationWon
| WebhookEventCode::PrearbitrationLost
+ | WebhookEventCode::NotificationOfFraud
+ | WebhookEventCode::InformationSupplied
+ | WebhookEventCode::PrearbitrationOpen
+ | WebhookEventCode::PrearbitrationAccepted
+ | WebhookEventCode::PrearbitrationDeclined
+ | WebhookEventCode::PrearbitrationIssuerWithdrawn
+ | WebhookEventCode::SchemeArbitration
+ | WebhookEventCode::SchemeArbitrationWon
+ | WebhookEventCode::SchemeArbitrationLost
+ | WebhookEventCode::DisputeDefensePeriodEnded
+ | WebhookEventCode::IssuerResponseTimeframeExpired
+ | WebhookEventCode::IssuerComments
| WebhookEventCode::Unknown => AdyenWebhookStatus::UnexpectedEvent,
},
amount: Some(Amount {
@@ -6543,11 +6644,17 @@ pub struct AdyenAcceptDisputeRequest {
#[derive(Default, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
-pub struct AdyenDisputeResponse {
+pub struct DisputeServiceResult {
pub error_message: Option<String>,
pub success: bool,
}
+#[derive(Default, Debug, Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct AdyenDisputeResponse {
+ pub dispute_service_result: DisputeServiceResult,
+}
+
impl TryFrom<&AcceptDisputeRouterData> for AdyenAcceptDisputeRequest {
type Error = Error;
fn try_from(item: &AcceptDisputeRouterData) -> Result<Self, Self::Error> {
@@ -6574,7 +6681,7 @@ impl TryFrom<&DefendDisputeRouterData> for AdyenDefendDisputeRequest {
Ok(Self {
dispute_psp_reference: item.request.connector_dispute_id.clone(),
merchant_account_code,
- defense_reason_code: "SupplyDefenseMaterial".into(),
+ defense_reason_code: "AdditionalInformation".into(),
})
}
}
@@ -6635,14 +6742,14 @@ fn get_defence_documents(item: SubmitEvidenceRequestData) -> Option<Vec<DefenseD
if let Some(shipping_documentation) = item.shipping_documentation {
defense_documents.push(DefenseDocuments {
content: get_content(shipping_documentation).into(),
- content_type: item.receipt_file_type,
+ content_type: item.shipping_documentation_file_type.clone(),
defense_document_type_code: "DefenseMaterial".into(),
})
}
if let Some(receipt) = item.receipt {
defense_documents.push(DefenseDocuments {
content: get_content(receipt).into(),
- content_type: item.shipping_documentation_file_type,
+ content_type: item.receipt_file_type.clone(),
defense_document_type_code: "DefenseMaterial".into(),
})
}
@@ -6712,7 +6819,7 @@ fn get_defence_documents(item: SubmitEvidenceRequestData) -> Option<Vec<DefenseD
}
fn get_content(item: Vec<u8>) -> String {
- String::from_utf8_lossy(&item).to_string()
+ base64::engine::general_purpose::STANDARD.encode(&item)
}
impl ForeignTryFrom<(&Self, AdyenDisputeResponse)> for AcceptDisputeRouterData {
@@ -6720,8 +6827,9 @@ impl ForeignTryFrom<(&Self, AdyenDisputeResponse)> for AcceptDisputeRouterData {
fn foreign_try_from(item: (&Self, AdyenDisputeResponse)) -> Result<Self, Self::Error> {
let (data, response) = item;
+ let dispute_result = response.dispute_service_result;
- if response.success {
+ if dispute_result.success {
Ok(AcceptDisputeRouterData {
response: Ok(AcceptDisputeResponse {
dispute_status: storage_enums::DisputeStatus::DisputeAccepted,
@@ -6732,20 +6840,16 @@ impl ForeignTryFrom<(&Self, AdyenDisputeResponse)> for AcceptDisputeRouterData {
} else {
Ok(AcceptDisputeRouterData {
response: Err(ErrorResponse {
- code: response
+ code: dispute_result
.error_message
.clone()
.unwrap_or_else(|| NO_ERROR_CODE.to_string()),
- message: response
+ message: dispute_result
.error_message
.clone()
.unwrap_or_else(|| NO_ERROR_MESSAGE.to_string()),
- reason: response.error_message,
- status_code: data.connector_http_status_code.ok_or(
- errors::ConnectorError::MissingRequiredField {
- field_name: "http code",
- },
- )?,
+ reason: dispute_result.error_message,
+ status_code: data.connector_http_status_code.unwrap_or_default(),
attempt_status: None,
connector_transaction_id: None,
connector_response_reference_id: None,
@@ -6764,7 +6868,8 @@ impl ForeignTryFrom<(&Self, AdyenDisputeResponse)> for SubmitEvidenceRouterData
type Error = errors::ConnectorError;
fn foreign_try_from(item: (&Self, AdyenDisputeResponse)) -> Result<Self, Self::Error> {
let (data, response) = item;
- if response.success {
+ let dispute_result = response.dispute_service_result;
+ if dispute_result.success {
Ok(SubmitEvidenceRouterData {
response: Ok(SubmitEvidenceResponse {
dispute_status: storage_enums::DisputeStatus::DisputeChallenged,
@@ -6775,20 +6880,16 @@ impl ForeignTryFrom<(&Self, AdyenDisputeResponse)> for SubmitEvidenceRouterData
} else {
Ok(SubmitEvidenceRouterData {
response: Err(ErrorResponse {
- code: response
+ code: dispute_result
.error_message
.clone()
.unwrap_or_else(|| NO_ERROR_CODE.to_string()),
- message: response
+ message: dispute_result
.error_message
.clone()
.unwrap_or_else(|| NO_ERROR_MESSAGE.to_string()),
- reason: response.error_message,
- status_code: data.connector_http_status_code.ok_or(
- errors::ConnectorError::MissingRequiredField {
- field_name: "http code",
- },
- )?,
+ reason: dispute_result.error_message,
+ status_code: data.connector_http_status_code.unwrap_or_default(),
attempt_status: None,
connector_transaction_id: None,
connector_response_reference_id: None,
@@ -6803,13 +6904,16 @@ impl ForeignTryFrom<(&Self, AdyenDisputeResponse)> for SubmitEvidenceRouterData
}
}
-impl ForeignTryFrom<(&Self, AdyenDisputeResponse)> for DefendDisputeRouterData {
+impl ForeignTryFrom<(&Self, Response, AdyenDisputeResponse)> for DefendDisputeRouterData {
type Error = errors::ConnectorError;
- fn foreign_try_from(item: (&Self, AdyenDisputeResponse)) -> Result<Self, Self::Error> {
- let (data, response) = item;
+ fn foreign_try_from(
+ item: (&Self, Response, AdyenDisputeResponse),
+ ) -> Result<Self, Self::Error> {
+ let (data, res, response) = item;
+ let dispute_result = response.dispute_service_result;
- if response.success {
+ if dispute_result.success {
Ok(DefendDisputeRouterData {
response: Ok(DefendDisputeResponse {
dispute_status: storage_enums::DisputeStatus::DisputeChallenged,
@@ -6820,20 +6924,16 @@ impl ForeignTryFrom<(&Self, AdyenDisputeResponse)> for DefendDisputeRouterData {
} else {
Ok(DefendDisputeRouterData {
response: Err(ErrorResponse {
- code: response
+ code: dispute_result
.error_message
.clone()
.unwrap_or_else(|| NO_ERROR_CODE.to_string()),
- message: response
+ message: dispute_result
.error_message
.clone()
.unwrap_or_else(|| NO_ERROR_MESSAGE.to_string()),
- reason: response.error_message,
- status_code: data.connector_http_status_code.ok_or(
- errors::ConnectorError::MissingRequiredField {
- field_name: "http code",
- },
- )?,
+ reason: dispute_result.error_message,
+ status_code: res.status_code,
attempt_status: None,
connector_transaction_id: None,
connector_response_reference_id: None,