fix(core): fixed type metadata to accept other udf fields as well (#321)

This commit is contained in:
Abhishek
2023-01-09 16:10:10 +05:30
committed by GitHub
parent 3fe60b5a48
commit 8cffdc96ca
8 changed files with 48 additions and 29 deletions

View File

@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
error-stack = "0.2.4"
frunk = "0.4.1"
frunk_core = "0.4.1"
serde = { version = "1.0.145", features = ["derive"] }

View File

@ -1,6 +1,6 @@
use std::num::NonZeroI64;
use common_utils::pii;
use common_utils::{errors, ext_traits::Encode, pii};
use masking::{PeekInterface, Secret};
use router_derive::Setter;
use time::PrimitiveDateTime;
@ -15,11 +15,6 @@ pub enum PaymentOp {
Confirm,
}
#[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone)]
pub struct Metadata {
pub order_details: OrderDetails,
}
#[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct PaymentsRequest {
@ -53,7 +48,7 @@ pub struct PaymentsRequest {
pub billing: Option<Address>,
pub statement_descriptor_name: Option<String>,
pub statement_descriptor_suffix: Option<String>,
pub metadata: Option<serde_json::Value>,
pub metadata: Option<Metadata>,
pub client_secret: Option<String>,
pub mandate_data: Option<MandateData>,
pub mandate_id: Option<String>,
@ -561,21 +556,25 @@ impl From<&VerifyRequest> for MandateValidationFields {
}
}
impl From<PaymentsRequest> for PaymentsResponse {
fn from(item: PaymentsRequest) -> Self {
impl TryFrom<PaymentsRequest> for PaymentsResponse {
type Error = error_stack::Report<errors::ParsingError>;
fn try_from(item: PaymentsRequest) -> Result<Self, Self::Error> {
let payment_id = match item.payment_id {
Some(PaymentIdType::PaymentIntentId(id)) => Some(id),
_ => None,
};
Self {
let metadata = item
.metadata
.map(|a| Encode::<Metadata>::encode_to_value(&a))
.transpose()?;
Ok(Self {
payment_id,
merchant_id: item.merchant_id,
setup_future_usage: item.setup_future_usage,
off_session: item.off_session,
shipping: item.shipping,
billing: item.billing,
metadata: item.metadata,
metadata,
capture_method: item.capture_method,
payment_method: item.payment_method,
capture_on: item.capture_on,
@ -592,7 +591,7 @@ impl From<PaymentsRequest> for PaymentsResponse {
statement_descriptor_suffix: item.statement_descriptor_suffix,
mandate_data: item.mandate_data,
..Default::default()
}
})
}
}
@ -759,12 +758,19 @@ pub enum SupportedWallets {
Gpay,
}
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, Clone)]
#[derive(Debug, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize, Clone)]
pub struct OrderDetails {
pub product_name: String,
pub quantity: u16,
}
#[derive(Default, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize, Clone)]
pub struct Metadata {
pub order_details: Option<OrderDetails>,
#[serde(flatten)]
pub data: serde_json::Value,
}
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
pub struct PaymentsSessionRequest {
pub payment_id: String,