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): [BOA] Populate merchant_defined_information with metadata (#3208)

DEEPANSHU BANSAL18eca7e9fbe6
diff --git a/crates/router/src/connector/bankofamerica/transformers.rs b/crates/router/src/connector/bankofamerica/transformers.rs
index 477bbec735..def93ec5f8 100644
--- a/crates/router/src/connector/bankofamerica/transformers.rs
+++ b/crates/router/src/connector/bankofamerica/transformers.rs
@@ -1,8 +1,11 @@
+use std::collections::HashMap;
+
use api_models::payments;
use base64::Engine;
use common_utils::pii;
use masking::{PeekInterface, Secret};
use serde::{Deserialize, Serialize};
+use serde_json::Value;
use crate::{
connector::utils::{
@@ -83,6 +86,8 @@ pub struct BankOfAmericaPaymentsRequest {
payment_information: PaymentInformation,
order_information: OrderInformationWithBill,
client_reference_information: ClientReferenceInformation,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ merchant_defined_information: Option<Vec<MerchantDefinedInformation>>,
}
#[derive(Debug, Serialize)]
@@ -92,6 +97,13 @@ pub struct ProcessingInformation {
payment_solution: Option<String>,
}
+#[derive(Debug, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct MerchantDefinedInformation {
+ key: u8,
+ value: String,
+}
+
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CaptureOptions {
@@ -309,6 +321,23 @@ impl From<&BankOfAmericaRouterData<&types::PaymentsAuthorizeRouterData>>
}
}
+impl ForeignFrom<Value> for Vec<MerchantDefinedInformation> {
+ fn foreign_from(metadata: Value) -> Self {
+ let hashmap: HashMap<String, Value> =
+ serde_json::from_str(&metadata.to_string()).unwrap_or(HashMap::new());
+ let mut vector: Self = Self::new();
+ let mut iter = 1;
+ for (key, value) in hashmap {
+ vector.push(MerchantDefinedInformation {
+ key: iter,
+ value: format!("{key}={value}"),
+ });
+ iter += 1;
+ }
+ vector
+ }
+}
+
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ClientReferenceInformation {
@@ -331,13 +360,11 @@ impl
let email = item.router_data.request.get_email()?;
let bill_to = build_bill_to(item.router_data.get_billing()?, email)?;
let order_information = OrderInformationWithBill::from((item, bill_to));
-
let card_issuer = ccard.get_card_issuer();
let card_type = match card_issuer {
Ok(issuer) => Some(String::from(issuer)),
Err(_) => None,
};
-
let payment_information = PaymentInformation::Cards(CardPaymentInformation {
card: Card {
number: ccard.card_number,
@@ -347,15 +374,19 @@ impl
card_type,
},
});
-
let processing_information = ProcessingInformation::from((item, None));
let client_reference_information = ClientReferenceInformation::from(item);
+ let merchant_defined_information =
+ item.router_data.request.metadata.clone().map(|metadata| {
+ Vec::<MerchantDefinedInformation>::foreign_from(metadata.peek().to_owned())
+ });
Ok(Self {
processing_information,
payment_information,
order_information,
client_reference_information,
+ merchant_defined_information,
})
}
}
@@ -379,10 +410,8 @@ impl
let processing_information =
ProcessingInformation::from((item, Some(PaymentSolution::ApplePay)));
let client_reference_information = ClientReferenceInformation::from(item);
-
let expiration_month = apple_pay_data.get_expiry_month()?;
let expiration_year = apple_pay_data.get_four_digit_expiry_year()?;
-
let payment_information = PaymentInformation::ApplePay(ApplePayPaymentInformation {
tokenized_card: TokenizedCard {
number: apple_pay_data.application_primary_account_number,
@@ -392,12 +421,17 @@ impl
expiration_month,
},
});
+ let merchant_defined_information =
+ item.router_data.request.metadata.clone().map(|metadata| {
+ Vec::<MerchantDefinedInformation>::foreign_from(metadata.peek().to_owned())
+ });
Ok(Self {
processing_information,
payment_information,
order_information,
client_reference_information,
+ merchant_defined_information,
})
}
}
@@ -418,7 +452,6 @@ impl
let email = item.router_data.request.get_email()?;
let bill_to = build_bill_to(item.router_data.get_billing()?, email)?;
let order_information = OrderInformationWithBill::from((item, bill_to));
-
let payment_information = PaymentInformation::GooglePay(GooglePayPaymentInformation {
fluid_data: FluidData {
value: Secret::from(
@@ -426,16 +459,20 @@ impl
),
},
});
-
let processing_information =
ProcessingInformation::from((item, Some(PaymentSolution::GooglePay)));
let client_reference_information = ClientReferenceInformation::from(item);
+ let merchant_defined_information =
+ item.router_data.request.metadata.clone().map(|metadata| {
+ Vec::<MerchantDefinedInformation>::foreign_from(metadata.peek().to_owned())
+ });
Ok(Self {
processing_information,
payment_information,
order_information,
client_reference_information,
+ merchant_defined_information,
})
}
}
@@ -480,10 +517,17 @@ impl TryFrom<&BankOfAmericaRouterData<&types::PaymentsAuthorizeRouterData>>
},
},
);
+ let merchant_defined_information =
+ item.router_data.request.metadata.clone().map(|metadata| {
+ Vec::<MerchantDefinedInformation>::foreign_from(
+ metadata.peek().to_owned(),
+ )
+ });
Ok(Self {
processing_information,
payment_information,
order_information,
+ merchant_defined_information,
client_reference_information,
})
}
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index f0d8c9fd75..577480d311 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -1076,6 +1076,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
Some(RequestIncrementalAuthorization::True)
| Some(RequestIncrementalAuthorization::Default)
),
+ metadata: additional_data.payment_data.payment_intent.metadata,
})
}
}
diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs
index cc14fe36a0..50aba3de7b 100644
--- a/crates/router/src/types.rs
+++ b/crates/router/src/types.rs
@@ -407,6 +407,7 @@ pub struct PaymentsAuthorizeData {
pub surcharge_details: Option<types::SurchargeDetails>,
pub customer_id: Option<String>,
pub request_incremental_authorization: bool,
+ pub metadata: Option<pii::SecretSerdeValue>,
}
#[derive(Debug, Clone, Default)]
@@ -1245,6 +1246,7 @@ impl From<&SetupMandateRouterData> for PaymentsAuthorizeData {
customer_id: None,
surcharge_details: None,
request_incremental_authorization: data.request.request_incremental_authorization,
+ metadata: None,
}
}
}
diff --git a/crates/router/src/types/api/verify_connector.rs b/crates/router/src/types/api/verify_connector.rs
index 04a9d76632..c5fcce8b18 100644
--- a/crates/router/src/types/api/verify_connector.rs
+++ b/crates/router/src/types/api/verify_connector.rs
@@ -27,6 +27,7 @@ impl VerifyConnectorData {
amount: 1000,
confirm: true,
currency: storage_enums::Currency::USD,
+ metadata: None,
mandate_id: None,
webhook_url: None,
customer_id: None,
diff --git a/crates/router/tests/connectors/aci.rs b/crates/router/tests/connectors/aci.rs
index c46cca8e4d..35c9cbd952 100644
--- a/crates/router/tests/connectors/aci.rs
+++ b/crates/router/tests/connectors/aci.rs
@@ -70,6 +70,7 @@ fn construct_payment_router_data() -> types::PaymentsAuthorizeRouterData {
customer_id: None,
surcharge_details: None,
request_incremental_authorization: false,
+ metadata: None,
},
response: Err(types::ErrorResponse::default()),
payment_method_id: None,
diff --git a/crates/router/tests/connectors/adyen.rs b/crates/router/tests/connectors/adyen.rs
index 14177e6fb5..97dca3baa5 100644
--- a/crates/router/tests/connectors/adyen.rs
+++ b/crates/router/tests/connectors/adyen.rs
@@ -158,6 +158,7 @@ impl AdyenTest {
customer_id: None,
surcharge_details: None,
request_incremental_authorization: false,
+ metadata: None,
})
}
}
diff --git a/crates/router/tests/connectors/bitpay.rs b/crates/router/tests/connectors/bitpay.rs
index 3c9f08bf1b..8bac7c13c8 100644
--- a/crates/router/tests/connectors/bitpay.rs
+++ b/crates/router/tests/connectors/bitpay.rs
@@ -93,6 +93,7 @@ fn payment_method_details() -> Option<types::PaymentsAuthorizeData> {
customer_id: None,
surcharge_details: None,
request_incremental_authorization: false,
+ metadata: None,
})
}
diff --git a/crates/router/tests/connectors/cashtocode.rs b/crates/router/tests/connectors/cashtocode.rs
index a7c95936fb..68c4eb94bf 100644
--- a/crates/router/tests/connectors/cashtocode.rs
+++ b/crates/router/tests/connectors/cashtocode.rs
@@ -68,6 +68,7 @@ impl CashtocodeTest {
customer_id: Some("John Doe".to_owned()),
surcharge_details: None,
request_incremental_authorization: false,
+ metadata: None,
})
}
diff --git a/crates/router/tests/connectors/coinbase.rs b/crates/router/tests/connectors/coinbase.rs
index 2ddb5464d4..73ee93178c 100644
--- a/crates/router/tests/connectors/coinbase.rs
+++ b/crates/router/tests/connectors/coinbase.rs
@@ -95,6 +95,7 @@ fn payment_method_details() -> Option<types::PaymentsAuthorizeData> {
customer_id: None,
surcharge_details: None,
request_incremental_authorization: false,
+ metadata: None,
})
}
diff --git a/crates/router/tests/connectors/cryptopay.rs b/crates/router/tests/connectors/cryptopay.rs
index 11e556215c..5df8d80461 100644
--- a/crates/router/tests/connectors/cryptopay.rs
+++ b/crates/router/tests/connectors/cryptopay.rs
@@ -93,6 +93,7 @@ fn payment_method_details() -> Option<types::PaymentsAuthorizeData> {
customer_id: None,
surcharge_details: None,
request_incremental_authorization: false,
+ metadata: None,
})
}
diff --git a/crates/router/tests/connectors/opennode.rs b/crates/router/tests/connectors/opennode.rs
index 707192e01c..b140a7c051 100644
--- a/crates/router/tests/connectors/opennode.rs
+++ b/crates/router/tests/connectors/opennode.rs
@@ -94,6 +94,7 @@ fn payment_method_details() -> Option<types::PaymentsAuthorizeData> {
customer_id: None,
surcharge_details: None,
request_incremental_authorization: false,
+ metadata: None,
})
}
diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs
index 1c384b2e51..62fce84f1f 100644
--- a/crates/router/tests/connectors/utils.rs
+++ b/crates/router/tests/connectors/utils.rs
@@ -911,6 +911,7 @@ impl Default for PaymentAuthorizeType {
customer_id: None,
surcharge_details: None,
request_incremental_authorization: false,
+ metadata: None,
};
Self(data)
}
diff --git a/crates/router/tests/connectors/worldline.rs b/crates/router/tests/connectors/worldline.rs
index 6a92e0dc93..4f7a94780a 100644
--- a/crates/router/tests/connectors/worldline.rs
+++ b/crates/router/tests/connectors/worldline.rs
@@ -103,6 +103,7 @@ impl WorldlineTest {
customer_id: None,
surcharge_details: None,
request_incremental_authorization: false,
+ metadata: None,
})
}
}