Skip to content

Commit 18eca7e

Browse files
feat(connector): [BOA] Populate merchant_defined_information with metadata (#3208)
1 parent 561bb10 commit 18eca7e

File tree

13 files changed

+64
-7
lines changed

13 files changed

+64
-7
lines changed

crates/router/src/connector/bankofamerica/transformers.rs

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
use std::collections::HashMap;
2+
13
use api_models::payments;
24
use base64::Engine;
35
use common_utils::pii;
46
use masking::{PeekInterface, Secret};
57
use serde::{Deserialize, Serialize};
8+
use serde_json::Value;
69

710
use crate::{
811
connector::utils::{
@@ -83,6 +86,8 @@ pub struct BankOfAmericaPaymentsRequest {
8386
payment_information: PaymentInformation,
8487
order_information: OrderInformationWithBill,
8588
client_reference_information: ClientReferenceInformation,
89+
#[serde(skip_serializing_if = "Option::is_none")]
90+
merchant_defined_information: Option<Vec<MerchantDefinedInformation>>,
8691
}
8792

8893
#[derive(Debug, Serialize)]
@@ -92,6 +97,13 @@ pub struct ProcessingInformation {
9297
payment_solution: Option<String>,
9398
}
9499

100+
#[derive(Debug, Serialize)]
101+
#[serde(rename_all = "camelCase")]
102+
pub struct MerchantDefinedInformation {
103+
key: u8,
104+
value: String,
105+
}
106+
95107
#[derive(Debug, Serialize)]
96108
#[serde(rename_all = "camelCase")]
97109
pub struct CaptureOptions {
@@ -309,6 +321,23 @@ impl From<&BankOfAmericaRouterData<&types::PaymentsAuthorizeRouterData>>
309321
}
310322
}
311323

324+
impl ForeignFrom<Value> for Vec<MerchantDefinedInformation> {
325+
fn foreign_from(metadata: Value) -> Self {
326+
let hashmap: HashMap<String, Value> =
327+
serde_json::from_str(&metadata.to_string()).unwrap_or(HashMap::new());
328+
let mut vector: Self = Self::new();
329+
let mut iter = 1;
330+
for (key, value) in hashmap {
331+
vector.push(MerchantDefinedInformation {
332+
key: iter,
333+
value: format!("{key}={value}"),
334+
});
335+
iter += 1;
336+
}
337+
vector
338+
}
339+
}
340+
312341
#[derive(Clone, Debug, Deserialize, Serialize)]
313342
#[serde(rename_all = "camelCase")]
314343
pub struct ClientReferenceInformation {
@@ -331,13 +360,11 @@ impl
331360
let email = item.router_data.request.get_email()?;
332361
let bill_to = build_bill_to(item.router_data.get_billing()?, email)?;
333362
let order_information = OrderInformationWithBill::from((item, bill_to));
334-
335363
let card_issuer = ccard.get_card_issuer();
336364
let card_type = match card_issuer {
337365
Ok(issuer) => Some(String::from(issuer)),
338366
Err(_) => None,
339367
};
340-
341368
let payment_information = PaymentInformation::Cards(CardPaymentInformation {
342369
card: Card {
343370
number: ccard.card_number,
@@ -347,15 +374,19 @@ impl
347374
card_type,
348375
},
349376
});
350-
351377
let processing_information = ProcessingInformation::from((item, None));
352378
let client_reference_information = ClientReferenceInformation::from(item);
379+
let merchant_defined_information =
380+
item.router_data.request.metadata.clone().map(|metadata| {
381+
Vec::<MerchantDefinedInformation>::foreign_from(metadata.peek().to_owned())
382+
});
353383

354384
Ok(Self {
355385
processing_information,
356386
payment_information,
357387
order_information,
358388
client_reference_information,
389+
merchant_defined_information,
359390
})
360391
}
361392
}
@@ -379,10 +410,8 @@ impl
379410
let processing_information =
380411
ProcessingInformation::from((item, Some(PaymentSolution::ApplePay)));
381412
let client_reference_information = ClientReferenceInformation::from(item);
382-
383413
let expiration_month = apple_pay_data.get_expiry_month()?;
384414
let expiration_year = apple_pay_data.get_four_digit_expiry_year()?;
385-
386415
let payment_information = PaymentInformation::ApplePay(ApplePayPaymentInformation {
387416
tokenized_card: TokenizedCard {
388417
number: apple_pay_data.application_primary_account_number,
@@ -392,12 +421,17 @@ impl
392421
expiration_month,
393422
},
394423
});
424+
let merchant_defined_information =
425+
item.router_data.request.metadata.clone().map(|metadata| {
426+
Vec::<MerchantDefinedInformation>::foreign_from(metadata.peek().to_owned())
427+
});
395428

396429
Ok(Self {
397430
processing_information,
398431
payment_information,
399432
order_information,
400433
client_reference_information,
434+
merchant_defined_information,
401435
})
402436
}
403437
}
@@ -418,24 +452,27 @@ impl
418452
let email = item.router_data.request.get_email()?;
419453
let bill_to = build_bill_to(item.router_data.get_billing()?, email)?;
420454
let order_information = OrderInformationWithBill::from((item, bill_to));
421-
422455
let payment_information = PaymentInformation::GooglePay(GooglePayPaymentInformation {
423456
fluid_data: FluidData {
424457
value: Secret::from(
425458
consts::BASE64_ENGINE.encode(google_pay_data.tokenization_data.token),
426459
),
427460
},
428461
});
429-
430462
let processing_information =
431463
ProcessingInformation::from((item, Some(PaymentSolution::GooglePay)));
432464
let client_reference_information = ClientReferenceInformation::from(item);
465+
let merchant_defined_information =
466+
item.router_data.request.metadata.clone().map(|metadata| {
467+
Vec::<MerchantDefinedInformation>::foreign_from(metadata.peek().to_owned())
468+
});
433469

434470
Ok(Self {
435471
processing_information,
436472
payment_information,
437473
order_information,
438474
client_reference_information,
475+
merchant_defined_information,
439476
})
440477
}
441478
}
@@ -480,10 +517,17 @@ impl TryFrom<&BankOfAmericaRouterData<&types::PaymentsAuthorizeRouterData>>
480517
},
481518
},
482519
);
520+
let merchant_defined_information =
521+
item.router_data.request.metadata.clone().map(|metadata| {
522+
Vec::<MerchantDefinedInformation>::foreign_from(
523+
metadata.peek().to_owned(),
524+
)
525+
});
483526
Ok(Self {
484527
processing_information,
485528
payment_information,
486529
order_information,
530+
merchant_defined_information,
487531
client_reference_information,
488532
})
489533
}

crates/router/src/core/payments/transformers.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
10761076
Some(RequestIncrementalAuthorization::True)
10771077
| Some(RequestIncrementalAuthorization::Default)
10781078
),
1079+
metadata: additional_data.payment_data.payment_intent.metadata,
10791080
})
10801081
}
10811082
}

crates/router/src/types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ pub struct PaymentsAuthorizeData {
407407
pub surcharge_details: Option<types::SurchargeDetails>,
408408
pub customer_id: Option<String>,
409409
pub request_incremental_authorization: bool,
410+
pub metadata: Option<pii::SecretSerdeValue>,
410411
}
411412

412413
#[derive(Debug, Clone, Default)]
@@ -1245,6 +1246,7 @@ impl From<&SetupMandateRouterData> for PaymentsAuthorizeData {
12451246
customer_id: None,
12461247
surcharge_details: None,
12471248
request_incremental_authorization: data.request.request_incremental_authorization,
1249+
metadata: None,
12481250
}
12491251
}
12501252
}

crates/router/src/types/api/verify_connector.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ impl VerifyConnectorData {
2727
amount: 1000,
2828
confirm: true,
2929
currency: storage_enums::Currency::USD,
30+
metadata: None,
3031
mandate_id: None,
3132
webhook_url: None,
3233
customer_id: None,

crates/router/tests/connectors/aci.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ fn construct_payment_router_data() -> types::PaymentsAuthorizeRouterData {
7070
customer_id: None,
7171
surcharge_details: None,
7272
request_incremental_authorization: false,
73+
metadata: None,
7374
},
7475
response: Err(types::ErrorResponse::default()),
7576
payment_method_id: None,

crates/router/tests/connectors/adyen.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ impl AdyenTest {
158158
customer_id: None,
159159
surcharge_details: None,
160160
request_incremental_authorization: false,
161+
metadata: None,
161162
})
162163
}
163164
}

crates/router/tests/connectors/bitpay.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ fn payment_method_details() -> Option<types::PaymentsAuthorizeData> {
9393
customer_id: None,
9494
surcharge_details: None,
9595
request_incremental_authorization: false,
96+
metadata: None,
9697
})
9798
}
9899

crates/router/tests/connectors/cashtocode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ impl CashtocodeTest {
6868
customer_id: Some("John Doe".to_owned()),
6969
surcharge_details: None,
7070
request_incremental_authorization: false,
71+
metadata: None,
7172
})
7273
}
7374

crates/router/tests/connectors/coinbase.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ fn payment_method_details() -> Option<types::PaymentsAuthorizeData> {
9595
customer_id: None,
9696
surcharge_details: None,
9797
request_incremental_authorization: false,
98+
metadata: None,
9899
})
99100
}
100101

crates/router/tests/connectors/cryptopay.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ fn payment_method_details() -> Option<types::PaymentsAuthorizeData> {
9393
customer_id: None,
9494
surcharge_details: None,
9595
request_incremental_authorization: false,
96+
metadata: None,
9697
})
9798
}
9899

0 commit comments

Comments
 (0)