Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

feat(router): add support for accepting an existing `payment_method_id` as the `payment_method_data` in `/payments` request (#4328)

Shankar Singh C92e19af275c6
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index f8aa463a44..647854cca6 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -52,7 +52,9 @@ use crate::{
self,
types::{self, AsyncLift},
},
- storage::{self, enums as storage_enums, ephemeral_key, CustomerUpdate::Update},
+ storage::{
+ self, enums as storage_enums, ephemeral_key, CardTokenData, CustomerUpdate::Update,
+ },
transformers::{ForeignFrom, ForeignTryFrom},
ErrorResponse, MandateReference, RouterData,
},
@@ -1853,6 +1855,25 @@ pub async fn make_pm_data<'a, F: Clone, R, Ctx: PaymentMethodRetrieve>(
}
}
+ if payment_data.token_data.is_none() {
+ if let Some(payment_method_info) = &payment_data.payment_method_info {
+ if payment_method_info.payment_method == storage_enums::PaymentMethod::Card {
+ payment_data.token_data =
+ Some(storage::PaymentTokenData::PermanentCard(CardTokenData {
+ payment_method_id: Some(payment_method_info.payment_method_id.clone()),
+ locker_id: payment_method_info
+ .locker_id
+ .clone()
+ .or(Some(payment_method_info.payment_method_id.clone())),
+ token: payment_method_info
+ .locker_id
+ .clone()
+ .unwrap_or(payment_method_info.payment_method_id.clone()),
+ }));
+ }
+ }
+ }
+
// TODO: Handle case where payment method and token both are present in request properly.
let (payment_method, pm_id) = match (request, payment_data.token_data.as_ref()) {
(_, Some(hyperswitch_token)) => {