Skip to content

Commit df49a6b

Browse files
dgeee13Debarati Ghatak
authored andcommitted
fix(connector): [ARCHIPEL] Change connector fields that are currently implemented as required in the code to optional (#8342)
Co-authored-by: Debarati Ghatak <[email protected]>
1 parent b159a1d commit df49a6b

File tree

1 file changed

+33
-25
lines changed

1 file changed

+33
-25
lines changed

crates/hyperswitch_connectors/src/connectors/archipel/transformers.rs

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -191,28 +191,30 @@ pub struct ArchipelCardHolder {
191191
billing_address: Option<ArchipelBillingAddress>,
192192
}
193193

194-
impl TryFrom<Option<ArchipelBillingAddress>> for ArchipelCardHolder {
195-
type Error = ();
196-
fn try_from(value: Option<ArchipelBillingAddress>) -> Result<Self, Self::Error> {
197-
Ok(Self {
194+
impl From<Option<ArchipelBillingAddress>> for ArchipelCardHolder {
195+
fn from(value: Option<ArchipelBillingAddress>) -> Self {
196+
Self {
198197
billing_address: value,
199-
})
198+
}
200199
}
201200
}
202201

203202
#[derive(Debug, Serialize, Eq, PartialEq)]
204203
#[serde(rename_all = "camelCase")]
205204
pub struct ArchipelBillingAddress {
206-
address: Secret<String>,
207-
postal_code: Secret<String>,
205+
address: Option<Secret<String>>,
206+
postal_code: Option<Secret<String>>,
208207
}
209208

210-
impl TryFrom<&AddressDetails> for ArchipelBillingAddress {
211-
type Error = error_stack::Report<errors::ConnectorError>;
212-
fn try_from(address_details: &AddressDetails) -> Result<Self, Self::Error> {
213-
Ok(Self {
214-
address: address_details.get_combined_address_line()?,
215-
postal_code: address_details.get_zip()?.clone(),
209+
pub trait ToArchipelBillingAddress {
210+
fn to_archipel_billing_address(&self) -> Option<ArchipelBillingAddress>;
211+
}
212+
213+
impl ToArchipelBillingAddress for AddressDetails {
214+
fn to_archipel_billing_address(&self) -> Option<ArchipelBillingAddress> {
215+
Some(ArchipelBillingAddress {
216+
address: self.get_combined_address_line().ok(),
217+
postal_code: self.get_optional_zip(),
216218
})
217219
}
218220
}
@@ -658,13 +660,15 @@ impl TryFrom<(MinorUnit, &PaymentsAuthorizeRouterData)> for ArchipelPaymentInfor
658660
initiator: transaction_initiator.clone(),
659661
};
660662

661-
let card_holder_name = router_data.get_billing()?.get_optional_full_name();
663+
let card_holder_name: Option<Secret<String>> = router_data
664+
.get_billing()
665+
.ok()
666+
.and_then(|billing| billing.get_optional_full_name());
662667
let cardholder = Some(ArchipelCardHolder {
663-
billing_address: Some(
664-
router_data
665-
.get_billing_address()
666-
.and_then(ArchipelBillingAddress::try_from)?,
667-
),
668+
billing_address: router_data
669+
.get_billing_address()
670+
.ok()
671+
.and_then(|address| address.to_archipel_billing_address()),
668672
});
669673

670674
let indicator_status = if is_subsequent_trx {
@@ -1027,14 +1031,18 @@ impl TryFrom<ArchipelRouterData<&SetupMandateRouterData>> for ArchipelCardAuthor
10271031
initiator: ArchipelPaymentInitiator::Customer,
10281032
};
10291033

1030-
let card_holder_name = item.router_data.get_billing()?.get_optional_full_name();
1034+
let card_holder_name = item
1035+
.router_data
1036+
.get_billing()
1037+
.ok()
1038+
.and_then(|billing| billing.get_optional_full_name());
10311039

10321040
let cardholder = Some(ArchipelCardHolder {
1033-
billing_address: Some(
1034-
item.router_data
1035-
.get_billing_address()
1036-
.and_then(ArchipelBillingAddress::try_from)?,
1037-
),
1041+
billing_address: item
1042+
.router_data
1043+
.get_billing_address()
1044+
.ok()
1045+
.and_then(|address| address.to_archipel_billing_address()),
10381046
});
10391047

10401048
let stored_on_file = true;

0 commit comments

Comments
 (0)