mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 19:42:27 +08:00
feat(payment_request): add field amount to OrderDetails and make order_details a Vec in payments_create request (#964)
This commit is contained in:
@ -1424,12 +1424,14 @@ pub struct OrderDetails {
|
|||||||
/// The quantity of the product to be purchased
|
/// The quantity of the product to be purchased
|
||||||
#[schema(example = 1)]
|
#[schema(example = 1)]
|
||||||
pub quantity: u16,
|
pub quantity: u16,
|
||||||
|
/// the amount per quantity of product
|
||||||
|
pub amount: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
|
#[derive(Default, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
|
||||||
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<Vec<OrderDetails>>,
|
||||||
/// Any other metadata that is to be provided
|
/// Any other metadata that is to be provided
|
||||||
#[schema(value_type = Object, example = r#"{ "city": "NY", "unit": "245" }"#)]
|
#[schema(value_type = Object, example = r#"{ "city": "NY", "unit": "245" }"#)]
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
|
|||||||
@ -883,18 +883,31 @@ fn get_address_info(address: Option<&api_models::payments::Address>) -> Option<A
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_line_items(item: &types::PaymentsAuthorizeRouterData) -> Vec<LineItem> {
|
fn get_line_items(item: &types::PaymentsAuthorizeRouterData) -> Vec<LineItem> {
|
||||||
let order_details = item.request.order_details.as_ref();
|
let order_details = item.request.order_details.clone();
|
||||||
let line_item = LineItem {
|
match order_details {
|
||||||
amount_including_tax: Some(item.request.amount),
|
Some(od) => od
|
||||||
amount_excluding_tax: Some(item.request.amount),
|
.iter()
|
||||||
description: order_details.map(|details| details.product_name.clone()),
|
.map(|data| LineItem {
|
||||||
// We support only one product details in payment request as of now, therefore hard coded the id.
|
amount_including_tax: Some(item.request.amount),
|
||||||
// If we begin to support multiple product details in future then this logic should be made to create ID dynamically
|
amount_excluding_tax: Some(item.request.amount),
|
||||||
id: Some(String::from("Items #1")),
|
description: Some(data.product_name.clone()),
|
||||||
tax_amount: None,
|
id: Some(String::from("Items #1")),
|
||||||
quantity: Some(order_details.map_or(1, |details| details.quantity)),
|
tax_amount: None,
|
||||||
};
|
quantity: Some(data.quantity),
|
||||||
vec![line_item]
|
})
|
||||||
|
.collect(),
|
||||||
|
None => {
|
||||||
|
let line_item = LineItem {
|
||||||
|
amount_including_tax: Some(item.request.amount),
|
||||||
|
amount_excluding_tax: Some(item.request.amount),
|
||||||
|
description: None,
|
||||||
|
id: Some(String::from("Items #1")),
|
||||||
|
tax_amount: None,
|
||||||
|
quantity: Some(1),
|
||||||
|
};
|
||||||
|
vec![line_item]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_telephone_number(item: &types::PaymentsAuthorizeRouterData) -> Option<Secret<String>> {
|
fn get_telephone_number(item: &types::PaymentsAuthorizeRouterData) -> Option<Secret<String>> {
|
||||||
|
|||||||
@ -48,12 +48,15 @@ impl TryFrom<&types::PaymentsSessionRouterData> for KlarnaSessionRequest {
|
|||||||
purchase_currency: request.currency,
|
purchase_currency: request.currency,
|
||||||
order_amount: request.amount,
|
order_amount: request.amount,
|
||||||
locale: "en-US".to_string(),
|
locale: "en-US".to_string(),
|
||||||
order_lines: vec![OrderLines {
|
order_lines: order_details
|
||||||
name: order_details.product_name,
|
.iter()
|
||||||
quantity: order_details.quantity,
|
.map(|data| OrderLines {
|
||||||
unit_price: request.amount,
|
name: data.product_name.clone(),
|
||||||
total_amount: request.amount,
|
quantity: data.quantity,
|
||||||
}],
|
unit_price: data.amount,
|
||||||
|
total_amount: i64::from(data.quantity) * (data.amount),
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
}),
|
}),
|
||||||
None => Err(report!(errors::ConnectorError::MissingRequiredField {
|
None => Err(report!(errors::ConnectorError::MissingRequiredField {
|
||||||
field_name: "product_name",
|
field_name: "product_name",
|
||||||
@ -93,12 +96,15 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for KlarnaPaymentsRequest {
|
|||||||
purchase_country: "US".to_string(),
|
purchase_country: "US".to_string(),
|
||||||
purchase_currency: request.currency,
|
purchase_currency: request.currency,
|
||||||
order_amount: request.amount,
|
order_amount: request.amount,
|
||||||
order_lines: vec![OrderLines {
|
order_lines: order_details
|
||||||
name: order_details.product_name,
|
.iter()
|
||||||
quantity: order_details.quantity,
|
.map(|data| OrderLines {
|
||||||
unit_price: request.amount,
|
name: data.product_name.clone(),
|
||||||
total_amount: request.amount,
|
quantity: data.quantity,
|
||||||
}],
|
unit_price: data.amount,
|
||||||
|
total_amount: i64::from(data.quantity) * (data.amount),
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
}),
|
}),
|
||||||
None => Err(report!(errors::ConnectorError::MissingRequiredField {
|
None => Err(report!(errors::ConnectorError::MissingRequiredField {
|
||||||
field_name: "product_name"
|
field_name: "product_name"
|
||||||
|
|||||||
@ -163,7 +163,7 @@ pub trait PaymentsAuthorizeRequestData {
|
|||||||
fn is_auto_capture(&self) -> Result<bool, Error>;
|
fn is_auto_capture(&self) -> Result<bool, Error>;
|
||||||
fn get_email(&self) -> Result<Email, Error>;
|
fn get_email(&self) -> Result<Email, Error>;
|
||||||
fn get_browser_info(&self) -> Result<types::BrowserInformation, Error>;
|
fn get_browser_info(&self) -> Result<types::BrowserInformation, Error>;
|
||||||
fn get_order_details(&self) -> Result<OrderDetails, Error>;
|
fn get_order_details(&self) -> Result<Vec<OrderDetails>, Error>;
|
||||||
fn get_card(&self) -> Result<api::Card, Error>;
|
fn get_card(&self) -> Result<api::Card, Error>;
|
||||||
fn get_return_url(&self) -> Result<String, Error>;
|
fn get_return_url(&self) -> Result<String, Error>;
|
||||||
fn connector_mandate_id(&self) -> Option<String>;
|
fn connector_mandate_id(&self) -> Option<String>;
|
||||||
@ -189,7 +189,7 @@ impl PaymentsAuthorizeRequestData for types::PaymentsAuthorizeData {
|
|||||||
.clone()
|
.clone()
|
||||||
.ok_or_else(missing_field_err("browser_info"))
|
.ok_or_else(missing_field_err("browser_info"))
|
||||||
}
|
}
|
||||||
fn get_order_details(&self) -> Result<OrderDetails, Error> {
|
fn get_order_details(&self) -> Result<Vec<OrderDetails>, Error> {
|
||||||
self.order_details
|
self.order_details
|
||||||
.clone()
|
.clone()
|
||||||
.ok_or_else(missing_field_err("order_details"))
|
.ok_or_else(missing_field_err("order_details"))
|
||||||
|
|||||||
@ -204,12 +204,15 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for ZenPaymentsRequest {
|
|||||||
ip,
|
ip,
|
||||||
},
|
},
|
||||||
custom_ipn_url: item.request.get_webhook_url()?,
|
custom_ipn_url: item.request.get_webhook_url()?,
|
||||||
items: vec![ZenItemObject {
|
items: order_details
|
||||||
name: order_details.product_name,
|
.iter()
|
||||||
price: order_amount.clone(),
|
.map(|data| ZenItemObject {
|
||||||
quantity: 1,
|
name: data.product_name.clone(),
|
||||||
line_amount_total: order_amount,
|
quantity: data.quantity,
|
||||||
}],
|
price: data.amount.to_string(),
|
||||||
|
line_amount_total: order_amount.clone(),
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1429,6 +1429,7 @@ mod tests {
|
|||||||
active_attempt_id: "nopes".to_string(),
|
active_attempt_id: "nopes".to_string(),
|
||||||
business_country: storage_enums::CountryAlpha2::AG,
|
business_country: storage_enums::CountryAlpha2::AG,
|
||||||
business_label: "no".to_string(),
|
business_label: "no".to_string(),
|
||||||
|
meta_data: 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);
|
||||||
@ -1468,6 +1469,7 @@ mod tests {
|
|||||||
active_attempt_id: "nopes".to_string(),
|
active_attempt_id: "nopes".to_string(),
|
||||||
business_country: storage_enums::CountryAlpha2::AG,
|
business_country: storage_enums::CountryAlpha2::AG,
|
||||||
business_label: "no".to_string(),
|
business_label: "no".to_string(),
|
||||||
|
meta_data: 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);
|
||||||
@ -1507,6 +1509,7 @@ mod tests {
|
|||||||
active_attempt_id: "nopes".to_string(),
|
active_attempt_id: "nopes".to_string(),
|
||||||
business_country: storage_enums::CountryAlpha2::AG,
|
business_country: storage_enums::CountryAlpha2::AG,
|
||||||
business_label: "no".to_string(),
|
business_label: "no".to_string(),
|
||||||
|
meta_data: 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);
|
||||||
|
|||||||
@ -196,16 +196,20 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsSessionRequest> for
|
|||||||
F: 'b + Send,
|
F: 'b + Send,
|
||||||
{
|
{
|
||||||
let metadata = payment_data.payment_intent.metadata.clone();
|
let metadata = payment_data.payment_intent.metadata.clone();
|
||||||
payment_data.payment_intent = match metadata {
|
let meta_data = payment_data.payment_intent.meta_data.clone();
|
||||||
Some(metadata) => db
|
payment_data.payment_intent = match (metadata, meta_data) {
|
||||||
|
(Some(metadata), Some(meta_data)) => db
|
||||||
.update_payment_intent(
|
.update_payment_intent(
|
||||||
payment_data.payment_intent,
|
payment_data.payment_intent,
|
||||||
storage::PaymentIntentUpdate::MetadataUpdate { metadata },
|
storage::PaymentIntentUpdate::MetadataUpdate {
|
||||||
|
metadata,
|
||||||
|
meta_data,
|
||||||
|
},
|
||||||
storage_scheme,
|
storage_scheme,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?,
|
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?,
|
||||||
None => payment_data.payment_intent,
|
_ => payment_data.payment_intent,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((Box::new(self), payment_data))
|
Ok((Box::new(self), payment_data))
|
||||||
|
|||||||
@ -513,14 +513,14 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
|
|||||||
|
|
||||||
let parsed_metadata: Option<api_models::payments::Metadata> = payment_data
|
let parsed_metadata: Option<api_models::payments::Metadata> = payment_data
|
||||||
.payment_intent
|
.payment_intent
|
||||||
.metadata
|
.meta_data
|
||||||
.map(|metadata_value| {
|
.map(|metadata_value| {
|
||||||
metadata_value
|
metadata_value
|
||||||
.parse_value("metadata")
|
.parse_value("meta_data")
|
||||||
.change_context(errors::ApiErrorResponse::InvalidDataValue {
|
.change_context(errors::ApiErrorResponse::InvalidDataValue {
|
||||||
field_name: "metadata",
|
field_name: "meta_data",
|
||||||
})
|
})
|
||||||
.attach_printable("unable to parse metadata")
|
.attach_printable("unable to parse meta_data")
|
||||||
})
|
})
|
||||||
.transpose()
|
.transpose()
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
@ -683,14 +683,14 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsSessionD
|
|||||||
let payment_data = additional_data.payment_data;
|
let payment_data = additional_data.payment_data;
|
||||||
let parsed_metadata: Option<api_models::payments::Metadata> = payment_data
|
let parsed_metadata: Option<api_models::payments::Metadata> = payment_data
|
||||||
.payment_intent
|
.payment_intent
|
||||||
.metadata
|
.meta_data
|
||||||
.map(|metadata_value| {
|
.map(|metadata_value| {
|
||||||
metadata_value
|
metadata_value
|
||||||
.parse_value("metadata")
|
.parse_value("meta_data")
|
||||||
.change_context(errors::ApiErrorResponse::InvalidDataValue {
|
.change_context(errors::ApiErrorResponse::InvalidDataValue {
|
||||||
field_name: "metadata",
|
field_name: "meta_data",
|
||||||
})
|
})
|
||||||
.attach_printable("unable to parse metadata")
|
.attach_printable("unable to parse meta_data")
|
||||||
})
|
})
|
||||||
.transpose()
|
.transpose()
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|||||||
@ -95,6 +95,7 @@ mod storage {
|
|||||||
business_country: new.business_country,
|
business_country: new.business_country,
|
||||||
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(),
|
||||||
|
meta_data: new.meta_data.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
match self
|
match self
|
||||||
@ -353,6 +354,7 @@ impl PaymentIntentInterface for MockDb {
|
|||||||
business_country: new.business_country,
|
business_country: new.business_country,
|
||||||
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(),
|
||||||
|
meta_data: new.meta_data,
|
||||||
};
|
};
|
||||||
payment_intents.push(payment_intent.clone());
|
payment_intents.push(payment_intent.clone());
|
||||||
Ok(payment_intent)
|
Ok(payment_intent)
|
||||||
|
|||||||
@ -215,7 +215,7 @@ pub struct PaymentsAuthorizeData {
|
|||||||
pub off_session: Option<bool>,
|
pub off_session: Option<bool>,
|
||||||
pub setup_mandate_details: Option<payments::MandateData>,
|
pub setup_mandate_details: Option<payments::MandateData>,
|
||||||
pub browser_info: Option<BrowserInformation>,
|
pub browser_info: Option<BrowserInformation>,
|
||||||
pub order_details: Option<api_models::payments::OrderDetails>,
|
pub order_details: Option<Vec<api_models::payments::OrderDetails>>,
|
||||||
pub session_token: Option<String>,
|
pub session_token: Option<String>,
|
||||||
pub enrolled_for_3ds: bool,
|
pub enrolled_for_3ds: bool,
|
||||||
pub related_transaction_id: Option<String>,
|
pub related_transaction_id: Option<String>,
|
||||||
@ -297,7 +297,7 @@ pub struct PaymentsSessionData {
|
|||||||
pub amount: i64,
|
pub amount: i64,
|
||||||
pub currency: storage_enums::Currency,
|
pub currency: storage_enums::Currency,
|
||||||
pub country: Option<api::enums::CountryAlpha2>,
|
pub country: Option<api::enums::CountryAlpha2>,
|
||||||
pub order_details: Option<api_models::payments::OrderDetails>,
|
pub order_details: Option<Vec<api_models::payments::OrderDetails>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|||||||
@ -306,10 +306,11 @@ async fn should_fail_payment_for_incorrect_card_number() {
|
|||||||
card_number: CardNumber::from_str("1234567891011").unwrap(),
|
card_number: CardNumber::from_str("1234567891011").unwrap(),
|
||||||
..utils::CCardType::default().0
|
..utils::CCardType::default().0
|
||||||
}),
|
}),
|
||||||
order_details: Some(OrderDetails {
|
order_details: Some(vec![OrderDetails {
|
||||||
product_name: "test".to_string(),
|
product_name: "test".to_string(),
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
}),
|
amount: 1000,
|
||||||
|
}]),
|
||||||
email: Some(Email::from_str("test@gmail.com").unwrap()),
|
email: Some(Email::from_str("test@gmail.com").unwrap()),
|
||||||
webhook_url: Some("https://1635-116-74-253-164.ngrok-free.app".to_string()),
|
webhook_url: Some("https://1635-116-74-253-164.ngrok-free.app".to_string()),
|
||||||
..utils::PaymentAuthorizeType::default().0
|
..utils::PaymentAuthorizeType::default().0
|
||||||
@ -340,10 +341,11 @@ async fn should_fail_payment_for_incorrect_cvc() {
|
|||||||
card_cvc: Secret::new("12345".to_string()),
|
card_cvc: Secret::new("12345".to_string()),
|
||||||
..utils::CCardType::default().0
|
..utils::CCardType::default().0
|
||||||
}),
|
}),
|
||||||
order_details: Some(OrderDetails {
|
order_details: Some(vec![OrderDetails {
|
||||||
product_name: "test".to_string(),
|
product_name: "test".to_string(),
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
}),
|
amount: 1000,
|
||||||
|
}]),
|
||||||
email: Some(Email::from_str("test@gmail.com").unwrap()),
|
email: Some(Email::from_str("test@gmail.com").unwrap()),
|
||||||
webhook_url: Some("https://1635-116-74-253-164.ngrok-free.app".to_string()),
|
webhook_url: Some("https://1635-116-74-253-164.ngrok-free.app".to_string()),
|
||||||
..utils::PaymentAuthorizeType::default().0
|
..utils::PaymentAuthorizeType::default().0
|
||||||
@ -374,10 +376,11 @@ async fn should_fail_payment_for_invalid_exp_month() {
|
|||||||
card_exp_month: Secret::new("20".to_string()),
|
card_exp_month: Secret::new("20".to_string()),
|
||||||
..utils::CCardType::default().0
|
..utils::CCardType::default().0
|
||||||
}),
|
}),
|
||||||
order_details: Some(OrderDetails {
|
order_details: Some(vec![OrderDetails {
|
||||||
product_name: "test".to_string(),
|
product_name: "test".to_string(),
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
}),
|
amount: 1000,
|
||||||
|
}]),
|
||||||
email: Some(Email::from_str("test@gmail.com").unwrap()),
|
email: Some(Email::from_str("test@gmail.com").unwrap()),
|
||||||
webhook_url: Some("https://1635-116-74-253-164.ngrok-free.app".to_string()),
|
webhook_url: Some("https://1635-116-74-253-164.ngrok-free.app".to_string()),
|
||||||
..utils::PaymentAuthorizeType::default().0
|
..utils::PaymentAuthorizeType::default().0
|
||||||
@ -408,10 +411,11 @@ async fn should_fail_payment_for_incorrect_expiry_year() {
|
|||||||
card_exp_year: Secret::new("2000".to_string()),
|
card_exp_year: Secret::new("2000".to_string()),
|
||||||
..utils::CCardType::default().0
|
..utils::CCardType::default().0
|
||||||
}),
|
}),
|
||||||
order_details: Some(OrderDetails {
|
order_details: Some(vec![OrderDetails {
|
||||||
product_name: "test".to_string(),
|
product_name: "test".to_string(),
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
}),
|
amount: 1000,
|
||||||
|
}]),
|
||||||
email: Some(Email::from_str("test@gmail.com").unwrap()),
|
email: Some(Email::from_str("test@gmail.com").unwrap()),
|
||||||
webhook_url: Some("https://1635-116-74-253-164.ngrok-free.app".to_string()),
|
webhook_url: Some("https://1635-116-74-253-164.ngrok-free.app".to_string()),
|
||||||
..utils::PaymentAuthorizeType::default().0
|
..utils::PaymentAuthorizeType::default().0
|
||||||
|
|||||||
@ -36,6 +36,7 @@ pub struct PaymentIntent {
|
|||||||
pub active_attempt_id: String,
|
pub active_attempt_id: String,
|
||||||
pub business_country: storage_enums::CountryAlpha2,
|
pub business_country: storage_enums::CountryAlpha2,
|
||||||
pub business_label: String,
|
pub business_label: String,
|
||||||
|
pub meta_data: Option<pii::SecretSerdeValue>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
@ -78,6 +79,7 @@ pub struct PaymentIntentNew {
|
|||||||
pub active_attempt_id: String,
|
pub active_attempt_id: String,
|
||||||
pub business_country: storage_enums::CountryAlpha2,
|
pub business_country: storage_enums::CountryAlpha2,
|
||||||
pub business_label: String,
|
pub business_label: String,
|
||||||
|
pub meta_data: Option<pii::SecretSerdeValue>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
@ -89,6 +91,7 @@ pub enum PaymentIntentUpdate {
|
|||||||
},
|
},
|
||||||
MetadataUpdate {
|
MetadataUpdate {
|
||||||
metadata: pii::SecretSerdeValue,
|
metadata: pii::SecretSerdeValue,
|
||||||
|
meta_data: pii::SecretSerdeValue,
|
||||||
},
|
},
|
||||||
ReturnUrlUpdate {
|
ReturnUrlUpdate {
|
||||||
return_url: Option<String>,
|
return_url: Option<String>,
|
||||||
@ -142,6 +145,7 @@ pub struct PaymentIntentUpdateInternal {
|
|||||||
pub active_attempt_id: Option<String>,
|
pub active_attempt_id: Option<String>,
|
||||||
pub business_country: Option<storage_enums::CountryAlpha2>,
|
pub business_country: Option<storage_enums::CountryAlpha2>,
|
||||||
pub business_label: Option<String>,
|
pub business_label: Option<String>,
|
||||||
|
pub meta_data: Option<pii::SecretSerdeValue>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PaymentIntentUpdate {
|
impl PaymentIntentUpdate {
|
||||||
@ -169,6 +173,7 @@ impl PaymentIntentUpdate {
|
|||||||
.shipping_address_id
|
.shipping_address_id
|
||||||
.or(source.shipping_address_id),
|
.or(source.shipping_address_id),
|
||||||
modified_at: common_utils::date_time::now(),
|
modified_at: common_utils::date_time::now(),
|
||||||
|
meta_data: internal_update.meta_data.or(source.meta_data),
|
||||||
..source
|
..source
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,8 +208,12 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
|
|||||||
business_label,
|
business_label,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
PaymentIntentUpdate::MetadataUpdate { metadata } => Self {
|
PaymentIntentUpdate::MetadataUpdate {
|
||||||
|
metadata,
|
||||||
|
meta_data,
|
||||||
|
} => Self {
|
||||||
metadata: Some(metadata),
|
metadata: Some(metadata),
|
||||||
|
meta_data: Some(meta_data),
|
||||||
modified_at: Some(common_utils::date_time::now()),
|
modified_at: Some(common_utils::date_time::now()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
|||||||
@ -353,6 +353,7 @@ diesel::table! {
|
|||||||
active_attempt_id -> Varchar,
|
active_attempt_id -> Varchar,
|
||||||
business_country -> CountryAlpha2,
|
business_country -> CountryAlpha2,
|
||||||
business_label -> Varchar,
|
business_label -> Varchar,
|
||||||
|
meta_data -> Nullable<Jsonb>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
1
migrations/2023-05-12-103127_payment_intent.sql/down.sql
Normal file
1
migrations/2023-05-12-103127_payment_intent.sql/down.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE payment_intent DROP COLUMN meta_data;
|
||||||
7
migrations/2023-05-12-103127_payment_intent.sql/up.sql
Normal file
7
migrations/2023-05-12-103127_payment_intent.sql/up.sql
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
ALTER TABLE payment_intent ADD COLUMN meta_data jsonb;
|
||||||
|
|
||||||
|
UPDATE payment_intent SET meta_data = metadata;
|
||||||
|
|
||||||
|
UPDATE payment_intent SET meta_data = jsonb_set(meta_data, '{order_details}', to_jsonb(ARRAY(select metadata -> 'order_details')), true);
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user