Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ pub enum DeutschebankVopMatchStatus {
Nmtc,
}

impl DeutschebankVopMatchStatus {
pub fn code(self) -> &'static str {
match self {
Self::Mtch => "MTCH",
Self::Cmtc => "CMTC",
Self::Noap => "NOAP",
Self::Nmtc => "NMTC",
}
}
}

impl From<DeutschebankVopMatchStatus> for PayoutStatus {
fn from(value: DeutschebankVopMatchStatus) -> Self {
match value {
Expand Down Expand Up @@ -170,6 +181,24 @@ pub struct DeutschebankVopResponse {
skip_serializing_if = "Option::is_none"
)]
pub additional_info: Option<String>,
#[serde(
rename = "matchedName",
default,
skip_serializing_if = "Option::is_none"
)]
pub matched_name: Option<String>,
#[serde(
rename = "noapDescription",
default,
skip_serializing_if = "Option::is_none"
)]
pub noap_description: Option<String>,
#[serde(
rename = "isNoapRetryable",
default,
skip_serializing_if = "Option::is_none"
)]
pub is_noap_retryable: Option<bool>,
Comment thread
heykulthe marked this conversation as resolved.
Outdated
}

impl<T: PaymentMethodDataTypes + Debug + Send + Sync + 'static + Serialize>
Expand Down Expand Up @@ -267,14 +296,52 @@ pub fn build_eligibility_response(
DeutschebankVopMatchStatus::Mtch | DeutschebankVopMatchStatus::Cmtc
);

let connector_payout_id = is_eligible.then_some(vop_id);
// Surface the refusal to the merchant. Only the conclusive no-match verdicts
// carry an error; `MTCH` and `CMTC` are successes and stay clean. `CMTC` is a
// near-match that DB still permits, so its advisory text is reported through
// `connector_metadata` rather than as an error.
let (error_code, error_message) = if is_eligible {
(None, None)
} else {
(
Some(match_status.code().to_string()),
vop_body.additional_info.clone(),
)
};

// On a successful verdict the outcome is not an error, so it travels as
// metadata instead: the verdict itself plus DB's explanation. A refusal
// already carries both in `error_code` / `error_message`, so it gets none.
let connector_metadata = is_eligible.then(|| {
let mut metadata = serde_json::Map::new();
metadata.insert(
"vop_status".to_string(),
serde_json::Value::String(match_status.code().to_string()),
);
if let Some(info) = vop_body.additional_info.clone() {
metadata.insert(
"additional_info".to_string(),
serde_json::Value::String(info),
);
}
serde_json::Value::Object(metadata)
});

// Only an eligible payee yields a payout id to act on; the VoP reference is
// reported separately so a refusal is still traceable, and so it survives the
// transfer overwriting `connector_payout_id`.
let connector_payout_id = is_eligible.then(|| vop_id.clone());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you confirm, that this will be the payout reference id for the transaction?


Ok(PayoutEligibilityResponse {
merchant_payout_id: None,
payout_status,
connector_payout_id,
payout_eligible: Some(is_eligible),
status_code: http_code,
error_code,
error_message,
connector_metadata,
eligibility_reference_id: Some(vop_id),
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,4 +417,8 @@ pub struct PayoutEligibilityResponse {
pub connector_payout_id: Option<String>,
pub payout_eligible: Option<bool>,
pub status_code: u16,
pub error_code: Option<String>,
pub error_message: Option<String>,
Comment on lines +420 to +421

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we putting error code and message here, shouldn't this be accompanied with error response?

pub connector_metadata: Option<serde_json::Value>,
pub eligibility_reference_id: Option<String>,
}
30 changes: 29 additions & 1 deletion crates/types-traits/domain_types/src/payouts/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2262,13 +2262,39 @@ pub fn generate_payout_eligibility_response(
let payout_status = grpc_api_types::payouts::payout_enums::PayoutStatus::foreign_from(
response.payout_status,
) as i32;
// A connector-declared refusal (e.g. Deutsche Bank VoP NMTC/NOAP) is a
// successful call with a negative verdict, so the reason travels in
// `error` alongside the terminal status rather than as a transport error.
let error =
response
.error_code
.clone()
.map(|code| grpc_api_types::payouts::ErrorInfo {
unified_details: None,
connector_details: Some(grpc_api_types::payouts::ConnectorErrorDetails {
code: Some(code),
message: response.error_message.clone(),
reason: response.error_message.clone(),
connector_transaction_id: response.connector_payout_id.clone(),
status: None,
}),
issuer_details: None,
});

let connector_metadata = response
.connector_metadata
.as_ref()
.map(|value| hyperswitch_masking::Secret::new(value.to_string()));

Ok(grpc_api_types::payouts::PayoutMethodEligibilityResponse {
merchant_payout_id: response.merchant_payout_id,
payout_status: Some(payout_status),
connector_payout_id: response.connector_payout_id,
payout_eligible: response.payout_eligible,
error: None,
error,
status_code: u32::from(response.status_code),
connector_metadata,
eligibility_reference_id: response.eligibility_reference_id,
})
}
Err(err) => Ok(grpc_api_types::payouts::PayoutMethodEligibilityResponse {
Expand All @@ -2281,6 +2307,8 @@ pub fn generate_payout_eligibility_response(
// eligibility is *unknown* — not that the payee is ineligible. `Some(false)`
// is reserved for the connector-declared NOAP/NMTC path.
payout_eligible: None,
connector_metadata: None,
eligibility_reference_id: None,
error: Some(grpc_api_types::payouts::ErrorInfo {
unified_details: None,
connector_details: Some(grpc_api_types::payouts::ConnectorErrorDetails {
Expand Down
7 changes: 7 additions & 0 deletions crates/types-traits/grpc-api-types/proto/payouts.proto
Original file line number Diff line number Diff line change
Expand Up @@ -575,5 +575,12 @@ message PayoutMethodEligibilityResponse {
uint32 status_code = 5;
// Whether the payout is eligible
optional bool payout_eligible = 6;
// Connector-specific details as a JSON object, surfaced to the merchant
optional SecretString connector_metadata = 7;
// Connector's reference for the eligibility check itself, independent of
// `connector_payout_id` (which is only set when the payee is eligible, and is
// later replaced by the transfer's id). Set for every verdict — including
// refusals — so the check remains traceable for reconciliation.
optional string eligibility_reference_id = 8;
}

1 change: 1 addition & 0 deletions sdk/javascript/src/payments/_generated_grpc_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ const _SECRET_STRING_FIELDS: Record<string, readonly string[]> = {
PayoutServiceCreateRecipientRequest: ["accessToken"],
PayoutServiceEnrollDisburseAccountRequest: ["accessToken"],
PayoutMethodEligibilityRequest: ["connectorFeatureData", "accessToken"],
PayoutMethodEligibilityResponse: ["connectorMetadata"],
SurchargeServiceCalculateRequest: ["postalCode"],
};

Expand Down
Loading