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>
This commit is contained in:
AkshayaFoiger
2024-05-02 20:13:08 +05:30
committed by GitHub
parent 67794da36e
commit 3ed0e8b764

View File

@ -378,11 +378,34 @@ impl<F, T>
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<Avs>,
card_verification: Option<CardVerification>,
processor: Option<ProcessorResponse>,
network_transaction_id: Option<Secret<String>>,
approval_code: Option<String>,
merchant_advice: Option<MerchantAdvice>,
response_code: Option<String>,
ach_verification: Option<AchVerification>,
system_trace_audit_number: Option<String>,
event_status: Option<String>,
retrieval_reference_number: Option<String>,
consumer_authentication_response: Option<ConsumerAuthenticationResponse>,
response_details: Option<String>,
transaction_id: Option<Secret<String>>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct MerchantAdvice {
code: Option<String>,
code_raw: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ConsumerAuthenticationResponse {
code: Option<String>,
code_raw: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AchVerification {
result_code_raw: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ProcessorResponse {
name: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
@ -735,6 +796,39 @@ pub struct CardVerification {
#[serde(rename_all = "camelCase")]
pub struct ClientRiskInformation {
rules: Option<Vec<ClientRiskInformationRules>>,
profile: Option<Profile>,
score: Option<Score>,
info_codes: Option<InfoCodes>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct InfoCodes {
address: Option<Vec<String>>,
identity_change: Option<Vec<String>>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Score {
factor_codes: Option<Vec<String>>,
result: Option<RiskResult>,
model_used: Option<String>,
}
#[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<String>,
name: Option<String>,
decision: Option<String>,
}
#[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<ClientProcessorInformation>,
processing_information: Option<ProcessingInformationResponse>,
payment_account_information: Option<PaymentAccountInformation>,
payment_information: Option<PaymentInformationResponse>,
payment_insights_information: Option<PaymentInsightsInformation>,
risk_information: Option<ClientRiskInformation>,
token_information: Option<BankOfAmericaTokenInformation>,
error_information: Option<BankOfAmericaErrorInformation>,
issuer_information: Option<IssuerInformation>,
reconciliation_id: Option<String>,
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(untagged)]
pub enum BankOfAmericaAuthSetupResponse {
ClientAuthSetupInfo(ClientAuthSetupInfoResponse),
ClientAuthSetupInfo(Box<ClientAuthSetupInfoResponse>),
ErrorInformation(BankOfAmericaErrorInformationResponse),
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(untagged)]
pub enum BankOfAmericaPaymentsResponse {
ClientReferenceInformation(BankOfAmericaClientReferenceResponse),
ClientReferenceInformation(Box<BankOfAmericaClientReferenceResponse>),
ErrorInformation(BankOfAmericaErrorInformationResponse),
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(untagged)]
pub enum BankOfAmericaSetupMandatesResponse {
ClientReferenceInformation(BankOfAmericaClientReferenceResponse),
ClientReferenceInformation(Box<BankOfAmericaClientReferenceResponse>),
ErrorInformation(BankOfAmericaErrorInformationResponse),
}
@ -1284,9 +1388,125 @@ pub struct BankOfAmericaClientReferenceResponse {
status: BankofamericaPaymentStatus,
client_reference_information: ClientReferenceInformation,
processor_information: Option<ClientProcessorInformation>,
processing_information: Option<ProcessingInformationResponse>,
payment_information: Option<PaymentInformationResponse>,
payment_insights_information: Option<PaymentInsightsInformation>,
risk_information: Option<ClientRiskInformation>,
token_information: Option<BankOfAmericaTokenInformation>,
error_information: Option<BankOfAmericaErrorInformation>,
issuer_information: Option<IssuerInformation>,
sender_information: Option<SenderInformation>,
payment_account_information: Option<PaymentAccountInformation>,
reconciliation_id: Option<String>,
consumer_authentication_information: Option<ConsumerAuthenticationInformation>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ConsumerAuthenticationInformation {
eci_raw: Option<String>,
eci: Option<String>,
acs_transaction_id: Option<String>,
cavv: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SenderInformation {
payment_information: Option<PaymentInformationResponse>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PaymentInsightsInformation {
response_insights: Option<ResponseInsights>,
rule_results: Option<RuleResults>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ResponseInsights {
category_code: Option<String>,
category: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RuleResults {
id: Option<String>,
decision: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PaymentInformationResponse {
tokenized_card: Option<CardResponseObject>,
customer: Option<CustomerResponseObject>,
card: Option<CardResponseObject>,
scheme: Option<String>,
bin: Option<String>,
account_type: Option<String>,
issuer: Option<String>,
bin_country: Option<api_enums::CountryAlpha2>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CustomerResponseObject {
customer_id: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PaymentAccountInformation {
card: Option<PaymentAccountCardInformation>,
features: Option<PaymentAccountFeatureInformation>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PaymentAccountFeatureInformation {
health_card: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PaymentAccountCardInformation {
#[serde(rename = "type")]
card_type: Option<String>,
hashed_number: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ProcessingInformationResponse {
payment_solution: Option<String>,
commerce_indicator: Option<String>,
commerce_indicator_label: Option<String>,
authorization_options: Option<AuthorizationOptions>,
ecommerce_indicator: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AuthorizationOptions {
auth_type: Option<String>,
initiator: Option<Initiator>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Initiator {
merchant_initiated_transaction: Option<MerchantInitiatedTransactionResponse>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct MerchantInitiatedTransactionResponse {
agreement_id: Option<String>,
previous_transaction_id: Option<String>,
original_authorized_amount: Option<String>,
reason: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
@ -1295,6 +1515,27 @@ pub struct BankOfAmericaTokenInformation {
payment_instrument: Option<BankOfAmericaPaymentInstrument>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct IssuerInformation {
country: Option<api_enums::CountryAlpha2>,
discretionary_data: Option<String>,
country_specific_discretionary_data: Option<String>,
response_code: Option<String>,
pin_request_indicator: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CardResponseObject {
suffix: Option<String>,
prefix: Option<String>,
expiration_month: Option<Secret<String>>,
expiration_year: Option<Secret<String>>,
#[serde(rename = "type")]
card_type: Option<String>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct BankOfAmericaErrorInformationResponse {
@ -1862,11 +2103,35 @@ impl<F>
|| 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<F>
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<F>
}
}
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<F>
#[derive(Debug, Deserialize, Serialize)]
#[serde(untagged)]
pub enum BankOfAmericaTransactionResponse {
ApplicationInformation(BankOfAmericaApplicationInfoResponse),
ApplicationInformation(Box<BankOfAmericaApplicationInfoResponse>),
ErrorInformation(BankOfAmericaErrorInformationResponse),
}
@ -2035,7 +2347,22 @@ pub struct BankOfAmericaApplicationInfoResponse {
id: String,
application_information: ApplicationInformation,
client_reference_information: Option<ClientReferenceInformation>,
processor_information: Option<ClientProcessorInformation>,
processing_information: Option<ProcessingInformationResponse>,
payment_information: Option<PaymentInformationResponse>,
payment_insights_information: Option<PaymentInsightsInformation>,
error_information: Option<BankOfAmericaErrorInformation>,
fraud_marking_information: Option<FraudMarkingInformation>,
risk_information: Option<ClientRiskInformation>,
token_information: Option<BankOfAmericaTokenInformation>,
reconciliation_id: Option<String>,
consumer_authentication_information: Option<ConsumerAuthenticationInformation>,
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct FraudMarkingInformation {
reason: Option<String>,
}
#[derive(Debug, Deserialize, Serialize)]
@ -2069,6 +2396,36 @@ impl<F>
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<ClientRiskInformation> = None;
if utils::is_payment_failure(status) {
Ok(Self {
@ -2079,6 +2436,7 @@ impl<F>
app_response.id.clone(),
))),
status: enums::AttemptStatus::Failure,
connector_response,
..item.data
})
} else {
@ -2098,6 +2456,7 @@ impl<F>
.unwrap_or(Some(app_response.id)),
incremental_authorization_allowed: None,
}),
connector_response,
..item.data
})
}