Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 51 additions & 7 deletions crates/router/src/connector/bankofamerica/transformers.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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)]
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -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,
})
}
}
Expand All @@ -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,
Expand All @@ -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,
})
}
}
Expand All @@ -418,24 +452,27 @@ 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(
consts::BASE64_ENGINE.encode(google_pay_data.tokenization_data.token),
),
},
});

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,
})
}
}
Expand Down Expand Up @@ -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,
})
}
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/core/payments/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/types/api/verify_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions crates/router/tests/connectors/aci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions crates/router/tests/connectors/adyen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ impl AdyenTest {
customer_id: None,
surcharge_details: None,
request_incremental_authorization: false,
metadata: None,
})
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/router/tests/connectors/bitpay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ fn payment_method_details() -> Option<types::PaymentsAuthorizeData> {
customer_id: None,
surcharge_details: None,
request_incremental_authorization: false,
metadata: None,
})
}

Expand Down
1 change: 1 addition & 0 deletions crates/router/tests/connectors/cashtocode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl CashtocodeTest {
customer_id: Some("John Doe".to_owned()),
surcharge_details: None,
request_incremental_authorization: false,
metadata: None,
})
}

Expand Down
1 change: 1 addition & 0 deletions crates/router/tests/connectors/coinbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ fn payment_method_details() -> Option<types::PaymentsAuthorizeData> {
customer_id: None,
surcharge_details: None,
request_incremental_authorization: false,
metadata: None,
})
}

Expand Down
1 change: 1 addition & 0 deletions crates/router/tests/connectors/cryptopay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ fn payment_method_details() -> Option<types::PaymentsAuthorizeData> {
customer_id: None,
surcharge_details: None,
request_incremental_authorization: false,
metadata: None,
})
}

Expand Down
1 change: 1 addition & 0 deletions crates/router/tests/connectors/opennode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ fn payment_method_details() -> Option<types::PaymentsAuthorizeData> {
customer_id: None,
surcharge_details: None,
request_incremental_authorization: false,
metadata: None,
})
}

Expand Down
1 change: 1 addition & 0 deletions crates/router/tests/connectors/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ impl Default for PaymentAuthorizeType {
customer_id: None,
surcharge_details: None,
request_incremental_authorization: false,
metadata: None,
};
Self(data)
}
Expand Down
1 change: 1 addition & 0 deletions crates/router/tests/connectors/worldline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl WorldlineTest {
customer_id: None,
surcharge_details: None,
request_incremental_authorization: false,
metadata: None,
})
}
}
Expand Down