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

refactor(payments): add udf field and remove refactor metadata (#1466)

Abhishek Marrivagu641995371db4
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index 455da286ae..5363f396f0 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -1,4 +1,4 @@
-use std::{collections::HashMap, num::NonZeroI64};
+use std::num::NonZeroI64;
use cards::CardNumber;
use common_utils::{
@@ -281,6 +281,10 @@ pub struct PaymentsRequest {
/// If enabled payment can be retried from the client side until the payment is successful or payment expires or the attempts(configured by the merchant) for payment are exhausted.
#[serde(default)]
pub manual_retry: bool,
+
+ /// Any user defined fields can be passed here.
+ #[schema(value_type = Option<Object>, example = r#"{ "udf1": "some-value", "udf2": "some-value" }"#)]
+ pub udf: Option<pii::SecretSerdeValue>,
}
#[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone, Copy, PartialEq, Eq)]
@@ -1377,6 +1381,10 @@ pub struct PaymentsResponse {
/// ephemeral_key for the customer_id mentioned
pub ephemeral_key: Option<EphemeralKeyCreateResponse>,
+
+ /// Any user defined fields can be passed here.
+ #[schema(value_type = Option<Object>, example = r#"{ "udf1": "some-value", "udf2": "some-value" }"#)]
+ pub udf: Option<pii::SecretSerdeValue>,
}
#[derive(Clone, Debug, serde::Deserialize, ToSchema)]
@@ -1636,12 +1644,7 @@ pub struct OrderDetails {
pub struct Metadata {
/// Information about the product and quantity for specific connectors. (e.g. Klarna)
pub order_details: Option<OrderDetails>,
- /// Information used for routing
- pub routing_parameters: Option<HashMap<String, String>>,
- /// Any other metadata that is to be provided
- #[schema(value_type = Object, example = r#"{ "city": "NY", "unit": "245" }"#)]
- #[serde(flatten)]
- pub data: pii::SecretSerdeValue,
+
/// Information about the order category that merchant wants to specify at connector level. (e.g. In Noon Payments it can take values like "pay", "food", or any other custom string set by the merchant in Noon's Dashboard)
pub order_category: Option<String>,
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 89f7333f43..b2ab1b74c1 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -357,9 +357,7 @@ impl PaymentRedirectFlow for PaymentRedirectCompleteAuthorize {
payment_id: Some(req.resource_id.clone()),
merchant_id: req.merchant_id.clone(),
metadata: Some(Metadata {
- routing_parameters: None,
order_details: None,
- data: masking::Secret::new("{}".into()),
redirect_response: Some(api_models::payments::RedirectResponse {
param: req.param.map(Secret::new),
json_payload: Some(req.json_payload.unwrap_or(serde_json::json!({})).into()),
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index badb8d948b..6d6017f6f8 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -1790,6 +1790,7 @@ mod tests {
business_country: storage_enums::CountryAlpha2::AG,
business_label: "no".to_string(),
order_details: None,
+ udf: None,
};
let req_cs = Some("1".to_string());
let merchant_fulfillment_time = Some(900);
@@ -1830,6 +1831,7 @@ mod tests {
business_country: storage_enums::CountryAlpha2::AG,
business_label: "no".to_string(),
order_details: None,
+ udf: None,
};
let req_cs = Some("1".to_string());
let merchant_fulfillment_time = Some(10);
@@ -1870,6 +1872,7 @@ mod tests {
business_country: storage_enums::CountryAlpha2::AG,
business_label: "no".to_string(),
order_details: None,
+ udf: None,
};
let req_cs = Some("1".to_string());
let merchant_fulfillment_time = Some(10);
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index 00951faee3..0c8fd679f2 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -198,6 +198,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
.as_ref()
.map(|a| a.to_string())
.or(payment_intent.return_url);
+ payment_intent.udf = request.udf.clone().or(payment_intent.udf);
payment_attempt.business_sub_label = request
.business_sub_label
@@ -414,7 +415,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
let business_country = Some(payment_data.payment_intent.business_country);
let order_details = payment_data.payment_intent.order_details.clone();
let metadata = payment_data.payment_intent.metadata.clone();
-
+ let udf = payment_data.payment_intent.udf.clone();
payment_data.payment_intent = db
.update_payment_intent(
payment_data.payment_intent,
@@ -431,6 +432,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
business_label,
order_details,
metadata,
+ udf,
},
storage_scheme,
)
diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs
index b4b75cd815..ef89d7151b 100644
--- a/crates/router/src/core/payments/operations/payment_create.rs
+++ b/crates/router/src/core/payments/operations/payment_create.rs
@@ -617,6 +617,7 @@ impl PaymentCreate {
business_label,
active_attempt_id,
order_details: order_details_outside_value,
+ udf: request.udf.clone(),
..storage::PaymentIntentNew::default()
})
}
diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs
index 15ef40f34e..b7f06ad76f 100644
--- a/crates/router/src/core/payments/operations/payment_update.rs
+++ b/crates/router/src/core/payments/operations/payment_update.rs
@@ -151,7 +151,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
payment_intent.shipping_address_id = shipping_address.clone().map(|x| x.address_id);
payment_intent.billing_address_id = billing_address.clone().map(|x| x.address_id);
payment_intent.return_url = request.return_url.as_ref().map(|a| a.to_string());
-
+ payment_intent.udf = request.udf.clone().or(payment_intent.udf);
payment_intent.business_country = request
.business_country
.unwrap_or(payment_intent.business_country);
@@ -474,7 +474,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
let business_country = Some(payment_data.payment_intent.business_country);
let order_details = payment_data.payment_intent.order_details.clone();
let metadata = payment_data.payment_intent.metadata.clone();
-
+ let udf = payment_data.payment_intent.udf.clone();
payment_data.payment_intent = db
.update_payment_intent(
payment_data.payment_intent,
@@ -491,6 +491,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
business_label,
order_details,
metadata,
+ udf,
},
storage_scheme,
)
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 5ded67b261..f65b5d8ba0 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -451,6 +451,7 @@ where
.and_then(|metadata| metadata.allowed_payment_method_types),
)
.set_ephemeral_key(ephemeral_key_option.map(ForeignFrom::foreign_from))
+ .set_udf(payment_intent.udf)
.to_owned(),
)
}
@@ -494,6 +495,7 @@ where
payment_token: payment_attempt.payment_token,
metadata: payment_intent.metadata,
order_details: payment_intent.order_details,
+ udf: payment_intent.udf,
..Default::default()
}),
});
diff --git a/crates/router/src/db/payment_intent.rs b/crates/router/src/db/payment_intent.rs
index 35d22def71..b526c8d138 100644
--- a/crates/router/src/db/payment_intent.rs
+++ b/crates/router/src/db/payment_intent.rs
@@ -96,6 +96,7 @@ mod storage {
business_label: new.business_label.clone(),
active_attempt_id: new.active_attempt_id.to_owned(),
order_details: new.order_details.clone(),
+ udf: new.udf.clone(),
};
match self
@@ -355,6 +356,7 @@ impl PaymentIntentInterface for MockDb {
business_label: new.business_label,
active_attempt_id: new.active_attempt_id.to_owned(),
order_details: new.order_details,
+ udf: new.udf,
};
payment_intents.push(payment_intent.clone());
Ok(payment_intent)
diff --git a/crates/storage_models/src/payment_intent.rs b/crates/storage_models/src/payment_intent.rs
index b49c10d355..89d29738ec 100644
--- a/crates/storage_models/src/payment_intent.rs
+++ b/crates/storage_models/src/payment_intent.rs
@@ -38,6 +38,7 @@ pub struct PaymentIntent {
pub business_label: String,
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
+ pub udf: Option<pii::SecretSerdeValue>,
}
#[derive(
@@ -82,6 +83,7 @@ pub struct PaymentIntentNew {
pub business_label: String,
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
+ pub udf: Option<pii::SecretSerdeValue>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -122,6 +124,7 @@ pub enum PaymentIntentUpdate {
business_label: Option<String>,
order_details: Option<Vec<pii::SecretSerdeValue>>,
metadata: Option<pii::SecretSerdeValue>,
+ udf: Option<pii::SecretSerdeValue>,
},
PaymentAttemptUpdate {
active_attempt_id: String,
@@ -154,6 +157,7 @@ pub struct PaymentIntentUpdateInternal {
pub business_label: Option<String>,
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
+ pub udf: Option<pii::SecretSerdeValue>,
}
impl PaymentIntentUpdate {
@@ -203,6 +207,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
business_label,
order_details,
metadata,
+ udf,
} => Self {
amount: Some(amount),
currency: Some(currency),
@@ -218,6 +223,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
business_label,
order_details,
metadata,
+ udf,
..Default::default()
},
PaymentIntentUpdate::MetadataUpdate { metadata } => Self {
diff --git a/crates/storage_models/src/schema.rs b/crates/storage_models/src/schema.rs
index 4e77a0b7f7..91005970f4 100644
--- a/crates/storage_models/src/schema.rs
+++ b/crates/storage_models/src/schema.rs
@@ -477,6 +477,7 @@ diesel::table! {
#[max_length = 64]
business_label -> Varchar,
order_details -> Nullable<Array<Nullable<Jsonb>>>,
+ udf -> Nullable<Jsonb>,
}
}
diff --git a/migrations/2023-06-18-042123_add_udf_column_in_payments/down.sql b/migrations/2023-06-18-042123_add_udf_column_in_payments/down.sql
new file mode 100644
index 0000000000..8711baa3ec
--- /dev/null
+++ b/migrations/2023-06-18-042123_add_udf_column_in_payments/down.sql
@@ -0,0 +1,2 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE payment_intent DROP COLUMN udf;
diff --git a/migrations/2023-06-18-042123_add_udf_column_in_payments/up.sql b/migrations/2023-06-18-042123_add_udf_column_in_payments/up.sql
new file mode 100644
index 0000000000..f9fb4ef967
--- /dev/null
+++ b/migrations/2023-06-18-042123_add_udf_column_in_payments/up.sql
@@ -0,0 +1,2 @@
+-- Your SQL goes here
+ALTER TABLE payment_intent ADD COLUMN udf JSONB;