From 3ed0e8b764d1f1bc7d249122dba39be7dfdcac8b Mon Sep 17 00:00:00 2001 From: AkshayaFoiger <131388445+AkshayaFoiger@users.noreply.github.com> Date: Thu, 2 May 2024 20:13:08 +0530 Subject: [PATCH] Refactor(Connectors): [BOA] enhance response objects (#4508) Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: SamraatBansal <55536657+SamraatBansal@users.noreply.github.com> --- .../connector/bankofamerica/transformers.rs | 409 ++++++++++++++++-- 1 file changed, 384 insertions(+), 25 deletions(-) diff --git a/crates/router/src/connector/bankofamerica/transformers.rs b/crates/router/src/connector/bankofamerica/transformers.rs index 3ea736486e..efece7f61f 100644 --- a/crates/router/src/connector/bankofamerica/transformers.rs +++ b/crates/router/src/connector/bankofamerica/transformers.rs @@ -378,11 +378,34 @@ impl let error_response = get_error_response_if_failure((&info_response, mandate_status, item.http_code)); - let connector_response = info_response - .processor_information - .as_ref() - .map(types::AdditionalPaymentMethodConnectorResponse::from) - .map(types::ConnectorResponseData::with_additional_payment_method_data); + let connector_response = match item.data.payment_method { + common_enums::PaymentMethod::Card => info_response + .processor_information + .as_ref() + .and_then(|processor_information| { + info_response + .consumer_authentication_information + .as_ref() + .map(|consumer_auth_information| { + types::AdditionalPaymentMethodConnectorResponse::from(( + processor_information, + consumer_auth_information, + )) + }) + }) + .map(types::ConnectorResponseData::with_additional_payment_method_data), + common_enums::PaymentMethod::CardRedirect + | common_enums::PaymentMethod::PayLater + | common_enums::PaymentMethod::Wallet + | common_enums::PaymentMethod::BankRedirect + | common_enums::PaymentMethod::BankTransfer + | common_enums::PaymentMethod::Crypto + | common_enums::PaymentMethod::BankDebit + | common_enums::PaymentMethod::Reward + | common_enums::PaymentMethod::Upi + | common_enums::PaymentMethod::Voucher + | common_enums::PaymentMethod::GiftCard => None, + }; Ok(Self { status: mandate_status, @@ -722,6 +745,44 @@ pub struct ClientReferenceInformation { pub struct ClientProcessorInformation { avs: Option, card_verification: Option, + processor: Option, + network_transaction_id: Option>, + approval_code: Option, + merchant_advice: Option, + response_code: Option, + ach_verification: Option, + system_trace_audit_number: Option, + event_status: Option, + retrieval_reference_number: Option, + consumer_authentication_response: Option, + response_details: Option, + transaction_id: Option>, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct MerchantAdvice { + code: Option, + code_raw: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct ConsumerAuthenticationResponse { + code: Option, + code_raw: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct AchVerification { + result_code_raw: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct ProcessorResponse { + name: Option, } #[derive(Debug, Clone, Deserialize, Serialize)] @@ -735,6 +796,39 @@ pub struct CardVerification { #[serde(rename_all = "camelCase")] pub struct ClientRiskInformation { rules: Option>, + profile: Option, + score: Option, + info_codes: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct InfoCodes { + address: Option>, + identity_change: Option>, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct Score { + factor_codes: Option>, + result: Option, + model_used: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(untagged)] +pub enum RiskResult { + StringVariant(String), + IntVariant(u64), +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct Profile { + early_decision: Option, + name: Option, + decision: Option, } #[derive(Debug, Clone, Deserialize, Serialize)] @@ -1254,26 +1348,36 @@ pub struct ClientAuthSetupInfoResponse { id: String, client_reference_information: ClientReferenceInformation, consumer_authentication_information: BankOfAmericaConsumerAuthInformationResponse, + processor_information: Option, + processing_information: Option, + payment_account_information: Option, + payment_information: Option, + payment_insights_information: Option, + risk_information: Option, + token_information: Option, + error_information: Option, + issuer_information: Option, + reconciliation_id: Option, } #[derive(Debug, Deserialize, Serialize)] #[serde(untagged)] pub enum BankOfAmericaAuthSetupResponse { - ClientAuthSetupInfo(ClientAuthSetupInfoResponse), + ClientAuthSetupInfo(Box), ErrorInformation(BankOfAmericaErrorInformationResponse), } #[derive(Debug, Deserialize, Serialize)] #[serde(untagged)] pub enum BankOfAmericaPaymentsResponse { - ClientReferenceInformation(BankOfAmericaClientReferenceResponse), + ClientReferenceInformation(Box), ErrorInformation(BankOfAmericaErrorInformationResponse), } #[derive(Debug, Deserialize, Serialize)] #[serde(untagged)] pub enum BankOfAmericaSetupMandatesResponse { - ClientReferenceInformation(BankOfAmericaClientReferenceResponse), + ClientReferenceInformation(Box), ErrorInformation(BankOfAmericaErrorInformationResponse), } @@ -1284,9 +1388,125 @@ pub struct BankOfAmericaClientReferenceResponse { status: BankofamericaPaymentStatus, client_reference_information: ClientReferenceInformation, processor_information: Option, + processing_information: Option, + payment_information: Option, + payment_insights_information: Option, risk_information: Option, token_information: Option, error_information: Option, + issuer_information: Option, + sender_information: Option, + payment_account_information: Option, + reconciliation_id: Option, + consumer_authentication_information: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct ConsumerAuthenticationInformation { + eci_raw: Option, + eci: Option, + acs_transaction_id: Option, + cavv: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct SenderInformation { + payment_information: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct PaymentInsightsInformation { + response_insights: Option, + rule_results: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct ResponseInsights { + category_code: Option, + category: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct RuleResults { + id: Option, + decision: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct PaymentInformationResponse { + tokenized_card: Option, + customer: Option, + card: Option, + scheme: Option, + bin: Option, + account_type: Option, + issuer: Option, + bin_country: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct CustomerResponseObject { + customer_id: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct PaymentAccountInformation { + card: Option, + features: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct PaymentAccountFeatureInformation { + health_card: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct PaymentAccountCardInformation { + #[serde(rename = "type")] + card_type: Option, + hashed_number: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct ProcessingInformationResponse { + payment_solution: Option, + commerce_indicator: Option, + commerce_indicator_label: Option, + authorization_options: Option, + ecommerce_indicator: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct AuthorizationOptions { + auth_type: Option, + initiator: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct Initiator { + merchant_initiated_transaction: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct MerchantInitiatedTransactionResponse { + agreement_id: Option, + previous_transaction_id: Option, + original_authorized_amount: Option, + reason: Option, } #[derive(Debug, Clone, Deserialize, Serialize)] @@ -1295,6 +1515,27 @@ pub struct BankOfAmericaTokenInformation { payment_instrument: Option, } +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct IssuerInformation { + country: Option, + discretionary_data: Option, + country_specific_discretionary_data: Option, + response_code: Option, + pin_request_indicator: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct CardResponseObject { + suffix: Option, + prefix: Option, + expiration_month: Option>, + expiration_year: Option>, + #[serde(rename = "type")] + card_type: Option, +} + #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct BankOfAmericaErrorInformationResponse { @@ -1862,11 +2103,35 @@ impl || is_setup_mandate_payment(&item.data.request), )); let response = get_payment_response((&info_response, status, item.http_code)); - let connector_response = info_response - .processor_information - .as_ref() - .map(types::AdditionalPaymentMethodConnectorResponse::from) - .map(types::ConnectorResponseData::with_additional_payment_method_data); + let connector_response = match item.data.payment_method { + common_enums::PaymentMethod::Card => info_response + .processor_information + .as_ref() + .and_then(|processor_information| { + info_response + .consumer_authentication_information + .as_ref() + .map(|consumer_auth_information| { + types::AdditionalPaymentMethodConnectorResponse::from(( + processor_information, + consumer_auth_information, + )) + }) + }) + .map(types::ConnectorResponseData::with_additional_payment_method_data), + common_enums::PaymentMethod::CardRedirect + | common_enums::PaymentMethod::PayLater + | common_enums::PaymentMethod::Wallet + | common_enums::PaymentMethod::BankRedirect + | common_enums::PaymentMethod::BankTransfer + | common_enums::PaymentMethod::Crypto + | common_enums::PaymentMethod::BankDebit + | common_enums::PaymentMethod::Reward + | common_enums::PaymentMethod::Upi + | common_enums::PaymentMethod::Voucher + | common_enums::PaymentMethod::GiftCard => None, + }; + Ok(Self { status, response, @@ -1911,11 +2176,34 @@ impl item.data.request.is_auto_capture()?, )); let response = get_payment_response((&info_response, status, item.http_code)); - let connector_response = info_response - .processor_information - .as_ref() - .map(types::AdditionalPaymentMethodConnectorResponse::from) - .map(types::ConnectorResponseData::with_additional_payment_method_data); + let connector_response = match item.data.payment_method { + common_enums::PaymentMethod::Card => info_response + .processor_information + .as_ref() + .and_then(|processor_information| { + info_response + .consumer_authentication_information + .as_ref() + .map(|consumer_auth_information| { + types::AdditionalPaymentMethodConnectorResponse::from(( + processor_information, + consumer_auth_information, + )) + }) + }) + .map(types::ConnectorResponseData::with_additional_payment_method_data), + common_enums::PaymentMethod::CardRedirect + | common_enums::PaymentMethod::PayLater + | common_enums::PaymentMethod::Wallet + | common_enums::PaymentMethod::BankRedirect + | common_enums::PaymentMethod::BankTransfer + | common_enums::PaymentMethod::Crypto + | common_enums::PaymentMethod::BankDebit + | common_enums::PaymentMethod::Reward + | common_enums::PaymentMethod::Upi + | common_enums::PaymentMethod::Voucher + | common_enums::PaymentMethod::GiftCard => None, + }; Ok(Self { status, @@ -1935,14 +2223,38 @@ impl } } -impl From<&ClientProcessorInformation> for types::AdditionalPaymentMethodConnectorResponse { - fn from(processor_information: &ClientProcessorInformation) -> Self { - let payment_checks = Some( - serde_json::json!({"avs_response": processor_information.avs, "card_verification": processor_information.card_verification}), - ); +impl + From<( + &ClientProcessorInformation, + &ConsumerAuthenticationInformation, + )> for types::AdditionalPaymentMethodConnectorResponse +{ + fn from( + item: ( + &ClientProcessorInformation, + &ConsumerAuthenticationInformation, + ), + ) -> Self { + let processor_information = item.0; + let consumer_authentication_information = item.1; + let payment_checks = Some(serde_json::json!({ + "avs_response": processor_information.avs, + "card_verification": processor_information.card_verification, + "approval_code": processor_information.approval_code, + "consumer_authentication_response": processor_information.consumer_authentication_response, + "cavv": consumer_authentication_information.cavv, + "eci": consumer_authentication_information.eci, + "eci_raw": consumer_authentication_information.eci_raw, + })); + + let authentication_data = Some(serde_json::json!({ + "retrieval_reference_number": processor_information.retrieval_reference_number, + "acs_transaction_id": consumer_authentication_information.acs_transaction_id, + "system_trace_audit_number": processor_information.system_trace_audit_number, + })); Self::Card { - authentication_data: None, + authentication_data, payment_checks, } } @@ -2025,7 +2337,7 @@ impl #[derive(Debug, Deserialize, Serialize)] #[serde(untagged)] pub enum BankOfAmericaTransactionResponse { - ApplicationInformation(BankOfAmericaApplicationInfoResponse), + ApplicationInformation(Box), ErrorInformation(BankOfAmericaErrorInformationResponse), } @@ -2035,7 +2347,22 @@ pub struct BankOfAmericaApplicationInfoResponse { id: String, application_information: ApplicationInformation, client_reference_information: Option, + processor_information: Option, + processing_information: Option, + payment_information: Option, + payment_insights_information: Option, error_information: Option, + fraud_marking_information: Option, + risk_information: Option, + token_information: Option, + reconciliation_id: Option, + consumer_authentication_information: Option, +} + +#[derive(Debug, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct FraudMarkingInformation { + reason: Option, } #[derive(Debug, Deserialize, Serialize)] @@ -2069,6 +2396,36 @@ impl app_response.application_information.status, item.data.request.is_auto_capture()?, )); + + let connector_response = match item.data.payment_method { + common_enums::PaymentMethod::Card => app_response + .processor_information + .as_ref() + .and_then(|processor_information| { + app_response + .consumer_authentication_information + .as_ref() + .map(|consumer_auth_information| { + types::AdditionalPaymentMethodConnectorResponse::from(( + processor_information, + consumer_auth_information, + )) + }) + }) + .map(types::ConnectorResponseData::with_additional_payment_method_data), + common_enums::PaymentMethod::CardRedirect + | common_enums::PaymentMethod::PayLater + | common_enums::PaymentMethod::Wallet + | common_enums::PaymentMethod::BankRedirect + | common_enums::PaymentMethod::BankTransfer + | common_enums::PaymentMethod::Crypto + | common_enums::PaymentMethod::BankDebit + | common_enums::PaymentMethod::Reward + | common_enums::PaymentMethod::Upi + | common_enums::PaymentMethod::Voucher + | common_enums::PaymentMethod::GiftCard => None, + }; + let risk_info: Option = None; if utils::is_payment_failure(status) { Ok(Self { @@ -2079,6 +2436,7 @@ impl app_response.id.clone(), ))), status: enums::AttemptStatus::Failure, + connector_response, ..item.data }) } else { @@ -2098,6 +2456,7 @@ impl .unwrap_or(Some(app_response.id)), incremental_authorization_allowed: None, }), + connector_response, ..item.data }) }