feat(compatibility): add straight through routing and udf mapping in setup intent (#1536)

Co-authored-by: Sahkal Poddar <sahkal.poddar@juspay.in>
This commit is contained in:
Sahkal Poddar
2023-07-03 18:18:54 +05:30
committed by GitHub
parent 6dd61b62ef
commit 1e87f3d673

View File

@ -125,6 +125,7 @@ impl From<Shipping> for payments::Address {
pub struct StripeSetupIntentRequest {
pub confirm: Option<bool>,
pub customer: Option<String>,
pub connector: Option<Vec<api_enums::RoutableConnectors>>,
pub description: Option<String>,
pub currency: Option<String>,
pub payment_method_data: Option<StripePaymentMethodData>,
@ -165,6 +166,18 @@ impl TryFrom<StripeSetupIntentRequest> for payments::PaymentsRequest {
}
None => (None, None),
};
let routable_connector: Option<api_enums::RoutableConnectors> =
item.connector.and_then(|v| v.into_iter().next());
let routing = routable_connector
.map(api_types::RoutingAlgorithm::Single)
.map(|r| {
serde_json::to_value(r)
.into_report()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("converting to routing failed")
})
.transpose()?;
let ip_address = item
.receipt_ipaddress
.map(|ip| std::net::IpAddr::from_str(ip.as_str()))
@ -228,6 +241,7 @@ impl TryFrom<StripeSetupIntentRequest> for payments::PaymentsRequest {
setup_future_usage: item.setup_future_usage,
merchant_connector_details: item.merchant_connector_details,
authentication_type,
routing,
mandate_data: mandate_options,
browser_info: Some(
serde_json::to_value(crate::types::BrowserInformation {
@ -360,6 +374,7 @@ pub struct StripeSetupIntentResponse {
pub object: String,
pub status: StripeSetupStatus,
pub client_secret: Option<masking::Secret<String>>,
pub metadata: Option<secret::SecretSerdeValue>,
#[serde(with = "common_utils::custom_serde::iso8601::option")]
pub created: Option<time::PrimitiveDateTime>,
pub customer: Option<String>,
@ -403,6 +418,7 @@ impl From<payments::PaymentsResponse> for StripeSetupIntentResponse {
charges: payment_intent::Charges::new(),
created: resp.created,
customer: resp.customer_id,
metadata: resp.udf,
id: resp.payment_id,
refunds: resp
.refunds