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

This commit is contained in:
Abhishek Marrivagu
2023-06-18 19:48:14 +05:30
committed by GitHub
parent 8d2057844e
commit 641995371d
12 changed files with 35 additions and 12 deletions

View File

@ -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>,

View File

@ -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()),

View File

@ -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);

View File

@ -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,
)

View File

@ -617,6 +617,7 @@ impl PaymentCreate {
business_label,
active_attempt_id,
order_details: order_details_outside_value,
udf: request.udf.clone(),
..storage::PaymentIntentNew::default()
})
}

View File

@ -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,
)

View File

@ -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()
}),
});

View File

@ -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)

View File

@ -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 {

View File

@ -477,6 +477,7 @@ diesel::table! {
#[max_length = 64]
business_label -> Varchar,
order_details -> Nullable<Array<Nullable<Jsonb>>>,
udf -> Nullable<Jsonb>,
}
}

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
ALTER TABLE payment_intent DROP COLUMN udf;

View File

@ -0,0 +1,2 @@
-- Your SQL goes here
ALTER TABLE payment_intent ADD COLUMN udf JSONB;