Skip to content

Commit 5a5400c

Browse files
feat(connector): [BOA/Cyb] Include merchant metadata in capture and void requests (#3308)
1 parent 4f9c04b commit 5a5400c

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,8 @@ pub struct OrderInformation {
988988
pub struct BankOfAmericaCaptureRequest {
989989
order_information: OrderInformation,
990990
client_reference_information: ClientReferenceInformation,
991+
#[serde(skip_serializing_if = "Option::is_none")]
992+
merchant_defined_information: Option<Vec<MerchantDefinedInformation>>,
991993
}
992994

993995
impl TryFrom<&BankOfAmericaRouterData<&types::PaymentsCaptureRouterData>>
@@ -997,6 +999,10 @@ impl TryFrom<&BankOfAmericaRouterData<&types::PaymentsCaptureRouterData>>
997999
fn try_from(
9981000
value: &BankOfAmericaRouterData<&types::PaymentsCaptureRouterData>,
9991001
) -> Result<Self, Self::Error> {
1002+
let merchant_defined_information =
1003+
value.router_data.request.metadata.clone().map(|metadata| {
1004+
Vec::<MerchantDefinedInformation>::foreign_from(metadata.peek().to_owned())
1005+
});
10001006
Ok(Self {
10011007
order_information: OrderInformation {
10021008
amount_details: Amount {
@@ -1007,6 +1013,7 @@ impl TryFrom<&BankOfAmericaRouterData<&types::PaymentsCaptureRouterData>>
10071013
client_reference_information: ClientReferenceInformation {
10081014
code: Some(value.router_data.connector_request_reference_id.clone()),
10091015
},
1016+
merchant_defined_information,
10101017
})
10111018
}
10121019
}
@@ -1016,6 +1023,9 @@ impl TryFrom<&BankOfAmericaRouterData<&types::PaymentsCaptureRouterData>>
10161023
pub struct BankOfAmericaVoidRequest {
10171024
client_reference_information: ClientReferenceInformation,
10181025
reversal_information: ReversalInformation,
1026+
#[serde(skip_serializing_if = "Option::is_none")]
1027+
merchant_defined_information: Option<Vec<MerchantDefinedInformation>>,
1028+
// The connector documentation does not mention the merchantDefinedInformation field for Void requests. But this has been still added because it works!
10191029
}
10201030

10211031
#[derive(Debug, Serialize)]
@@ -1032,6 +1042,10 @@ impl TryFrom<&BankOfAmericaRouterData<&types::PaymentsCancelRouterData>>
10321042
fn try_from(
10331043
value: &BankOfAmericaRouterData<&types::PaymentsCancelRouterData>,
10341044
) -> Result<Self, Self::Error> {
1045+
let merchant_defined_information =
1046+
value.router_data.request.metadata.clone().map(|metadata| {
1047+
Vec::<MerchantDefinedInformation>::foreign_from(metadata.peek().to_owned())
1048+
});
10351049
Ok(Self {
10361050
client_reference_information: ClientReferenceInformation {
10371051
code: Some(value.router_data.connector_request_reference_id.clone()),
@@ -1054,6 +1068,7 @@ impl TryFrom<&BankOfAmericaRouterData<&types::PaymentsCancelRouterData>>
10541068
field_name: "Cancellation Reason",
10551069
})?,
10561070
},
1071+
merchant_defined_information,
10571072
})
10581073
}
10591074
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,9 @@ impl TryFrom<&CybersourceRouterData<&types::PaymentsAuthorizeRouterData>>
837837
pub struct CybersourcePaymentsCaptureRequest {
838838
processing_information: ProcessingInformation,
839839
order_information: OrderInformationWithBill,
840+
client_reference_information: ClientReferenceInformation,
841+
#[serde(skip_serializing_if = "Option::is_none")]
842+
merchant_defined_information: Option<Vec<MerchantDefinedInformation>>,
840843
}
841844

842845
#[derive(Debug, Serialize)]
@@ -853,6 +856,10 @@ impl TryFrom<&CybersourceRouterData<&types::PaymentsCaptureRouterData>>
853856
fn try_from(
854857
item: &CybersourceRouterData<&types::PaymentsCaptureRouterData>,
855858
) -> Result<Self, Self::Error> {
859+
let merchant_defined_information =
860+
item.router_data.request.metadata.clone().map(|metadata| {
861+
Vec::<MerchantDefinedInformation>::foreign_from(metadata.peek().to_owned())
862+
});
856863
Ok(Self {
857864
processing_information: ProcessingInformation {
858865
capture_options: Some(CaptureOptions {
@@ -873,6 +880,10 @@ impl TryFrom<&CybersourceRouterData<&types::PaymentsCaptureRouterData>>
873880
},
874881
bill_to: None,
875882
},
883+
client_reference_information: ClientReferenceInformation {
884+
code: Some(item.router_data.connector_request_reference_id.clone()),
885+
},
886+
merchant_defined_information,
876887
})
877888
}
878889
}
@@ -918,6 +929,9 @@ impl TryFrom<&CybersourceRouterData<&types::PaymentsIncrementalAuthorizationRout
918929
pub struct CybersourceVoidRequest {
919930
client_reference_information: ClientReferenceInformation,
920931
reversal_information: ReversalInformation,
932+
#[serde(skip_serializing_if = "Option::is_none")]
933+
merchant_defined_information: Option<Vec<MerchantDefinedInformation>>,
934+
// The connector documentation does not mention the merchantDefinedInformation field for Void requests. But this has been still added because it works!
921935
}
922936

923937
#[derive(Debug, Serialize)]
@@ -932,6 +946,10 @@ impl TryFrom<&CybersourceRouterData<&types::PaymentsCancelRouterData>> for Cyber
932946
fn try_from(
933947
value: &CybersourceRouterData<&types::PaymentsCancelRouterData>,
934948
) -> Result<Self, Self::Error> {
949+
let merchant_defined_information =
950+
value.router_data.request.metadata.clone().map(|metadata| {
951+
Vec::<MerchantDefinedInformation>::foreign_from(metadata.peek().to_owned())
952+
});
935953
Ok(Self {
936954
client_reference_information: ClientReferenceInformation {
937955
code: Some(value.router_data.connector_request_reference_id.clone()),
@@ -954,6 +972,7 @@ impl TryFrom<&CybersourceRouterData<&types::PaymentsCancelRouterData>> for Cyber
954972
field_name: "Cancellation Reason",
955973
})?,
956974
},
975+
merchant_defined_information,
957976
})
958977
}
959978
}
@@ -1591,6 +1610,7 @@ impl<F>
15911610
#[serde(rename_all = "camelCase")]
15921611
pub struct CybersourceRefundRequest {
15931612
order_information: OrderInformation,
1613+
client_reference_information: ClientReferenceInformation,
15941614
}
15951615

15961616
impl<F> TryFrom<&CybersourceRouterData<&types::RefundsRouterData<F>>> for CybersourceRefundRequest {
@@ -1605,6 +1625,9 @@ impl<F> TryFrom<&CybersourceRouterData<&types::RefundsRouterData<F>>> for Cybers
16051625
currency: item.router_data.request.currency,
16061626
},
16071627
},
1628+
client_reference_information: ClientReferenceInformation {
1629+
code: Some(item.router_data.request.refund_id.clone()),
1630+
},
16081631
})
16091632
}
16101633
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsCaptureD
12231223
None => None,
12241224
},
12251225
browser_info,
1226+
metadata: payment_data.payment_intent.metadata,
12261227
})
12271228
}
12281229
}
@@ -1257,6 +1258,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsCancelDa
12571258
cancellation_reason: payment_data.payment_attempt.cancellation_reason,
12581259
connector_meta: payment_data.payment_attempt.connector_metadata,
12591260
browser_info,
1261+
metadata: payment_data.payment_intent.metadata,
12601262
})
12611263
}
12621264
}

crates/router/src/types.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ pub struct PaymentsCaptureData {
428428
pub multiple_capture_data: Option<MultipleCaptureRequestData>,
429429
pub connector_meta: Option<serde_json::Value>,
430430
pub browser_info: Option<BrowserInformation>,
431+
pub metadata: Option<pii::SecretSerdeValue>,
432+
// This metadata is used to store the metadata shared during the payment intent request.
431433
}
432434

433435
#[derive(Debug, Clone, Default)]
@@ -542,6 +544,8 @@ pub struct PaymentsCancelData {
542544
pub cancellation_reason: Option<String>,
543545
pub connector_meta: Option<serde_json::Value>,
544546
pub browser_info: Option<BrowserInformation>,
547+
pub metadata: Option<pii::SecretSerdeValue>,
548+
// This metadata is used to store the metadata shared during the payment intent request.
545549
}
546550

547551
#[derive(Debug, Default, Clone)]

0 commit comments

Comments
 (0)