Skip to content

Commit

Permalink
refactor(compatibility): map connector to routing in payments request…
Browse files Browse the repository at this point in the history
… for backward compatibility (#1339)

Co-authored-by: Tinu Hareesswar <[email protected]>
  • Loading branch information
Abhicodes-crypto and tinu-hareesswar authored Jun 2, 2023
1 parent 23458bc commit 166688a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions crates/router/src/compatibility/stripe/payment_intents/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl From<Shipping> for payments::Address {
pub struct StripePaymentIntentRequest {
pub id: Option<String>,
pub amount: Option<i64>, //amount in cents, hence passed as integer
pub connector: Option<Vec<api_enums::Connector>>,
pub connector: Option<Vec<api_enums::RoutableConnectors>>,
pub currency: Option<String>,
#[serde(rename = "amount_to_capture")]
pub amount_capturable: Option<i64>,
Expand Down Expand Up @@ -169,10 +169,22 @@ impl TryFrom<StripePaymentIntentRequest> 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(crate::types::api::RoutingAlgorithm::Single)
.map(|r| {
serde_json::to_value(r)
.into_report()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("converting to routing failed")
})
.transpose()?;
let request = Ok(Self {
payment_id: item.id.map(payments::PaymentIdType::PaymentIntentId),
amount: item.amount.map(|amount| amount.into()),
connector: item.connector,
currency: item
.currency
.as_ref()
Expand Down Expand Up @@ -215,6 +227,7 @@ impl TryFrom<StripePaymentIntentRequest> for payments::PaymentsRequest {
setup_future_usage: item.setup_future_usage,
mandate_id: item.mandate_id,
off_session: item.off_session,
routing,
..Self::default()
});
request
Expand Down

0 comments on commit 166688a

Please sign in to comment.