mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 11:06:50 +08:00
refactor(payments): add udf field and remove refactor metadata (#1466)
This commit is contained in:
committed by
GitHub
parent
8d2057844e
commit
641995371d
@ -1,4 +1,4 @@
|
|||||||
use std::{collections::HashMap, num::NonZeroI64};
|
use std::num::NonZeroI64;
|
||||||
|
|
||||||
use cards::CardNumber;
|
use cards::CardNumber;
|
||||||
use common_utils::{
|
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.
|
/// 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)]
|
#[serde(default)]
|
||||||
pub manual_retry: bool,
|
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)]
|
#[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
|
/// ephemeral_key for the customer_id mentioned
|
||||||
pub ephemeral_key: Option<EphemeralKeyCreateResponse>,
|
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)]
|
#[derive(Clone, Debug, serde::Deserialize, ToSchema)]
|
||||||
@ -1636,12 +1644,7 @@ pub struct OrderDetails {
|
|||||||
pub struct Metadata {
|
pub struct Metadata {
|
||||||
/// Information about the product and quantity for specific connectors. (e.g. Klarna)
|
/// Information about the product and quantity for specific connectors. (e.g. Klarna)
|
||||||
pub order_details: Option<OrderDetails>,
|
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)
|
/// 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>,
|
pub order_category: Option<String>,
|
||||||
|
|
||||||
|
|||||||
@ -357,9 +357,7 @@ impl PaymentRedirectFlow for PaymentRedirectCompleteAuthorize {
|
|||||||
payment_id: Some(req.resource_id.clone()),
|
payment_id: Some(req.resource_id.clone()),
|
||||||
merchant_id: req.merchant_id.clone(),
|
merchant_id: req.merchant_id.clone(),
|
||||||
metadata: Some(Metadata {
|
metadata: Some(Metadata {
|
||||||
routing_parameters: None,
|
|
||||||
order_details: None,
|
order_details: None,
|
||||||
data: masking::Secret::new("{}".into()),
|
|
||||||
redirect_response: Some(api_models::payments::RedirectResponse {
|
redirect_response: Some(api_models::payments::RedirectResponse {
|
||||||
param: req.param.map(Secret::new),
|
param: req.param.map(Secret::new),
|
||||||
json_payload: Some(req.json_payload.unwrap_or(serde_json::json!({})).into()),
|
json_payload: Some(req.json_payload.unwrap_or(serde_json::json!({})).into()),
|
||||||
|
|||||||
@ -1790,6 +1790,7 @@ mod tests {
|
|||||||
business_country: storage_enums::CountryAlpha2::AG,
|
business_country: storage_enums::CountryAlpha2::AG,
|
||||||
business_label: "no".to_string(),
|
business_label: "no".to_string(),
|
||||||
order_details: None,
|
order_details: None,
|
||||||
|
udf: None,
|
||||||
};
|
};
|
||||||
let req_cs = Some("1".to_string());
|
let req_cs = Some("1".to_string());
|
||||||
let merchant_fulfillment_time = Some(900);
|
let merchant_fulfillment_time = Some(900);
|
||||||
@ -1830,6 +1831,7 @@ mod tests {
|
|||||||
business_country: storage_enums::CountryAlpha2::AG,
|
business_country: storage_enums::CountryAlpha2::AG,
|
||||||
business_label: "no".to_string(),
|
business_label: "no".to_string(),
|
||||||
order_details: None,
|
order_details: None,
|
||||||
|
udf: None,
|
||||||
};
|
};
|
||||||
let req_cs = Some("1".to_string());
|
let req_cs = Some("1".to_string());
|
||||||
let merchant_fulfillment_time = Some(10);
|
let merchant_fulfillment_time = Some(10);
|
||||||
@ -1870,6 +1872,7 @@ mod tests {
|
|||||||
business_country: storage_enums::CountryAlpha2::AG,
|
business_country: storage_enums::CountryAlpha2::AG,
|
||||||
business_label: "no".to_string(),
|
business_label: "no".to_string(),
|
||||||
order_details: None,
|
order_details: None,
|
||||||
|
udf: None,
|
||||||
};
|
};
|
||||||
let req_cs = Some("1".to_string());
|
let req_cs = Some("1".to_string());
|
||||||
let merchant_fulfillment_time = Some(10);
|
let merchant_fulfillment_time = Some(10);
|
||||||
|
|||||||
@ -198,6 +198,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
|
|||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|a| a.to_string())
|
.map(|a| a.to_string())
|
||||||
.or(payment_intent.return_url);
|
.or(payment_intent.return_url);
|
||||||
|
payment_intent.udf = request.udf.clone().or(payment_intent.udf);
|
||||||
|
|
||||||
payment_attempt.business_sub_label = request
|
payment_attempt.business_sub_label = request
|
||||||
.business_sub_label
|
.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 business_country = Some(payment_data.payment_intent.business_country);
|
||||||
let order_details = payment_data.payment_intent.order_details.clone();
|
let order_details = payment_data.payment_intent.order_details.clone();
|
||||||
let metadata = payment_data.payment_intent.metadata.clone();
|
let metadata = payment_data.payment_intent.metadata.clone();
|
||||||
|
let udf = payment_data.payment_intent.udf.clone();
|
||||||
payment_data.payment_intent = db
|
payment_data.payment_intent = db
|
||||||
.update_payment_intent(
|
.update_payment_intent(
|
||||||
payment_data.payment_intent,
|
payment_data.payment_intent,
|
||||||
@ -431,6 +432,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
|
|||||||
business_label,
|
business_label,
|
||||||
order_details,
|
order_details,
|
||||||
metadata,
|
metadata,
|
||||||
|
udf,
|
||||||
},
|
},
|
||||||
storage_scheme,
|
storage_scheme,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -617,6 +617,7 @@ impl PaymentCreate {
|
|||||||
business_label,
|
business_label,
|
||||||
active_attempt_id,
|
active_attempt_id,
|
||||||
order_details: order_details_outside_value,
|
order_details: order_details_outside_value,
|
||||||
|
udf: request.udf.clone(),
|
||||||
..storage::PaymentIntentNew::default()
|
..storage::PaymentIntentNew::default()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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.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.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.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
|
payment_intent.business_country = request
|
||||||
.business_country
|
.business_country
|
||||||
.unwrap_or(payment_intent.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 business_country = Some(payment_data.payment_intent.business_country);
|
||||||
let order_details = payment_data.payment_intent.order_details.clone();
|
let order_details = payment_data.payment_intent.order_details.clone();
|
||||||
let metadata = payment_data.payment_intent.metadata.clone();
|
let metadata = payment_data.payment_intent.metadata.clone();
|
||||||
|
let udf = payment_data.payment_intent.udf.clone();
|
||||||
payment_data.payment_intent = db
|
payment_data.payment_intent = db
|
||||||
.update_payment_intent(
|
.update_payment_intent(
|
||||||
payment_data.payment_intent,
|
payment_data.payment_intent,
|
||||||
@ -491,6 +491,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
|
|||||||
business_label,
|
business_label,
|
||||||
order_details,
|
order_details,
|
||||||
metadata,
|
metadata,
|
||||||
|
udf,
|
||||||
},
|
},
|
||||||
storage_scheme,
|
storage_scheme,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -451,6 +451,7 @@ where
|
|||||||
.and_then(|metadata| metadata.allowed_payment_method_types),
|
.and_then(|metadata| metadata.allowed_payment_method_types),
|
||||||
)
|
)
|
||||||
.set_ephemeral_key(ephemeral_key_option.map(ForeignFrom::foreign_from))
|
.set_ephemeral_key(ephemeral_key_option.map(ForeignFrom::foreign_from))
|
||||||
|
.set_udf(payment_intent.udf)
|
||||||
.to_owned(),
|
.to_owned(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -494,6 +495,7 @@ where
|
|||||||
payment_token: payment_attempt.payment_token,
|
payment_token: payment_attempt.payment_token,
|
||||||
metadata: payment_intent.metadata,
|
metadata: payment_intent.metadata,
|
||||||
order_details: payment_intent.order_details,
|
order_details: payment_intent.order_details,
|
||||||
|
udf: payment_intent.udf,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@ -96,6 +96,7 @@ mod storage {
|
|||||||
business_label: new.business_label.clone(),
|
business_label: new.business_label.clone(),
|
||||||
active_attempt_id: new.active_attempt_id.to_owned(),
|
active_attempt_id: new.active_attempt_id.to_owned(),
|
||||||
order_details: new.order_details.clone(),
|
order_details: new.order_details.clone(),
|
||||||
|
udf: new.udf.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
match self
|
match self
|
||||||
@ -355,6 +356,7 @@ impl PaymentIntentInterface for MockDb {
|
|||||||
business_label: new.business_label,
|
business_label: new.business_label,
|
||||||
active_attempt_id: new.active_attempt_id.to_owned(),
|
active_attempt_id: new.active_attempt_id.to_owned(),
|
||||||
order_details: new.order_details,
|
order_details: new.order_details,
|
||||||
|
udf: new.udf,
|
||||||
};
|
};
|
||||||
payment_intents.push(payment_intent.clone());
|
payment_intents.push(payment_intent.clone());
|
||||||
Ok(payment_intent)
|
Ok(payment_intent)
|
||||||
|
|||||||
@ -38,6 +38,7 @@ pub struct PaymentIntent {
|
|||||||
pub business_label: String,
|
pub business_label: String,
|
||||||
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
|
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
|
||||||
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
|
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
|
||||||
|
pub udf: Option<pii::SecretSerdeValue>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
@ -82,6 +83,7 @@ pub struct PaymentIntentNew {
|
|||||||
pub business_label: String,
|
pub business_label: String,
|
||||||
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
|
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
|
||||||
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
|
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
|
||||||
|
pub udf: Option<pii::SecretSerdeValue>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
@ -122,6 +124,7 @@ pub enum PaymentIntentUpdate {
|
|||||||
business_label: Option<String>,
|
business_label: Option<String>,
|
||||||
order_details: Option<Vec<pii::SecretSerdeValue>>,
|
order_details: Option<Vec<pii::SecretSerdeValue>>,
|
||||||
metadata: Option<pii::SecretSerdeValue>,
|
metadata: Option<pii::SecretSerdeValue>,
|
||||||
|
udf: Option<pii::SecretSerdeValue>,
|
||||||
},
|
},
|
||||||
PaymentAttemptUpdate {
|
PaymentAttemptUpdate {
|
||||||
active_attempt_id: String,
|
active_attempt_id: String,
|
||||||
@ -154,6 +157,7 @@ pub struct PaymentIntentUpdateInternal {
|
|||||||
pub business_label: Option<String>,
|
pub business_label: Option<String>,
|
||||||
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
|
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
|
||||||
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
|
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
|
||||||
|
pub udf: Option<pii::SecretSerdeValue>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PaymentIntentUpdate {
|
impl PaymentIntentUpdate {
|
||||||
@ -203,6 +207,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
|
|||||||
business_label,
|
business_label,
|
||||||
order_details,
|
order_details,
|
||||||
metadata,
|
metadata,
|
||||||
|
udf,
|
||||||
} => Self {
|
} => Self {
|
||||||
amount: Some(amount),
|
amount: Some(amount),
|
||||||
currency: Some(currency),
|
currency: Some(currency),
|
||||||
@ -218,6 +223,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
|
|||||||
business_label,
|
business_label,
|
||||||
order_details,
|
order_details,
|
||||||
metadata,
|
metadata,
|
||||||
|
udf,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
PaymentIntentUpdate::MetadataUpdate { metadata } => Self {
|
PaymentIntentUpdate::MetadataUpdate { metadata } => Self {
|
||||||
|
|||||||
@ -477,6 +477,7 @@ diesel::table! {
|
|||||||
#[max_length = 64]
|
#[max_length = 64]
|
||||||
business_label -> Varchar,
|
business_label -> Varchar,
|
||||||
order_details -> Nullable<Array<Nullable<Jsonb>>>,
|
order_details -> Nullable<Array<Nullable<Jsonb>>>,
|
||||||
|
udf -> Nullable<Jsonb>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,2 @@
|
|||||||
|
-- This file should undo anything in `up.sql`
|
||||||
|
ALTER TABLE payment_intent DROP COLUMN udf;
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
-- Your SQL goes here
|
||||||
|
ALTER TABLE payment_intent ADD COLUMN udf JSONB;
|
||||||
Reference in New Issue
Block a user