mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 04:04:43 +08:00
refactor: Add secret to metadata (#706)
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
use std::{convert::From, default::Default};
|
||||
|
||||
use api_models::payment_methods as api_types;
|
||||
use common_utils::date_time;
|
||||
use common_utils::{date_time, pii};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{logger, pii, types::api};
|
||||
use crate::{logger, types::api};
|
||||
|
||||
#[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct CreateCustomerRequest {
|
||||
@ -13,7 +13,7 @@ pub struct CreateCustomerRequest {
|
||||
pub name: Option<String>,
|
||||
pub phone: Option<masking::Secret<String>>,
|
||||
pub address: Option<masking::Secret<serde_json::Value>>,
|
||||
pub metadata: Option<serde_json::Value>,
|
||||
pub metadata: Option<pii::SecretSerdeValue>,
|
||||
pub description: Option<String>,
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ pub struct CustomerUpdateRequest {
|
||||
pub phone: Option<masking::Secret<String, masking::WithType>>,
|
||||
pub name: Option<String>,
|
||||
pub address: Option<masking::Secret<serde_json::Value>>,
|
||||
pub metadata: Option<serde_json::Value>,
|
||||
pub metadata: Option<pii::SecretSerdeValue>,
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, PartialEq, Eq)]
|
||||
@ -34,7 +34,7 @@ pub struct CreateCustomerResponse {
|
||||
pub created: u64,
|
||||
pub description: Option<String>,
|
||||
pub email: Option<masking::Secret<String, pii::Email>>,
|
||||
pub metadata: Option<serde_json::Value>,
|
||||
pub metadata: Option<pii::SecretSerdeValue>,
|
||||
pub name: Option<String>,
|
||||
pub phone: Option<masking::Secret<String, masking::WithType>>,
|
||||
}
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
use api_models::{payments, refunds};
|
||||
use common_utils::ext_traits::StringExt;
|
||||
use common_utils::{ext_traits::StringExt, pii as secret};
|
||||
use error_stack::ResultExt;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::{
|
||||
core::errors,
|
||||
@ -63,7 +62,7 @@ pub struct StripePaymentMethodData {
|
||||
pub billing_details: Option<StripeBillingDetails>,
|
||||
#[serde(flatten)]
|
||||
pub payment_method_details: Option<StripePaymentMethodDetails>, // enum
|
||||
pub metadata: Option<Value>,
|
||||
pub metadata: Option<secret::SecretSerdeValue>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Deserialize, Clone)]
|
||||
@ -277,7 +276,7 @@ pub struct StripePaymentIntentResponse {
|
||||
pub customer: Option<String>,
|
||||
pub refunds: Option<Vec<refunds::RefundResponse>>,
|
||||
pub mandate_id: Option<String>,
|
||||
pub metadata: Option<Value>,
|
||||
pub metadata: Option<secret::SecretSerdeValue>,
|
||||
pub charges: Charges,
|
||||
pub connector: Option<String>,
|
||||
pub description: Option<String>,
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
use std::{convert::From, default::Default};
|
||||
|
||||
use common_utils::pii;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::types::api::refunds;
|
||||
@ -13,7 +14,7 @@ pub struct StripeCreateRefundRequest {
|
||||
|
||||
#[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct StripeUpdateRefundRequest {
|
||||
pub metadata: Option<serde_json::Value>,
|
||||
pub metadata: Option<pii::SecretSerdeValue>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, PartialEq, Eq)]
|
||||
@ -24,7 +25,7 @@ pub struct StripeCreateRefundResponse {
|
||||
pub payment_intent: String,
|
||||
pub status: StripeRefundStatus,
|
||||
pub created: Option<i64>,
|
||||
pub metadata: serde_json::Value,
|
||||
pub metadata: pii::SecretSerdeValue,
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize, Eq, PartialEq)]
|
||||
@ -77,7 +78,9 @@ impl From<refunds::RefundResponse> for StripeCreateRefundResponse {
|
||||
payment_intent: res.payment_id,
|
||||
status: res.status.into(),
|
||||
created: res.created_at.map(|t| t.assume_utc().unix_timestamp()),
|
||||
metadata: res.metadata.unwrap_or_else(|| serde_json::json!({})),
|
||||
metadata: res
|
||||
.metadata
|
||||
.unwrap_or_else(|| masking::Secret::new(serde_json::json!({}))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use common_utils::pii;
|
||||
use common_utils::{ext_traits::ValueExt, pii};
|
||||
use error_stack::{report, IntoReport, ResultExt};
|
||||
use masking::Secret;
|
||||
use once_cell::sync::Lazy;
|
||||
@ -45,7 +45,7 @@ pub trait RouterData {
|
||||
fn get_billing_phone(&self) -> Result<&api::PhoneDetails, Error>;
|
||||
fn get_description(&self) -> Result<String, Error>;
|
||||
fn get_billing_address(&self) -> Result<&api::AddressDetails, Error>;
|
||||
fn get_connector_meta(&self) -> Result<serde_json::Value, Error>;
|
||||
fn get_connector_meta(&self) -> Result<pii::SecretSerdeValue, Error>;
|
||||
fn get_session_token(&self) -> Result<String, Error>;
|
||||
fn to_connector_meta<T>(&self) -> Result<T, Error>
|
||||
where
|
||||
@ -89,7 +89,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
|
||||
.and_then(|a| a.address.as_ref())
|
||||
.ok_or_else(missing_field_err("billing.address"))
|
||||
}
|
||||
fn get_connector_meta(&self) -> Result<serde_json::Value, Error> {
|
||||
fn get_connector_meta(&self) -> Result<pii::SecretSerdeValue, Error> {
|
||||
self.connector_meta_data
|
||||
.clone()
|
||||
.ok_or_else(missing_field_err("connector_meta_data"))
|
||||
@ -105,8 +105,8 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
|
||||
where
|
||||
T: serde::de::DeserializeOwned,
|
||||
{
|
||||
serde_json::from_value::<T>(self.get_connector_meta()?)
|
||||
.into_report()
|
||||
self.get_connector_meta()?
|
||||
.parse_value(std::any::type_name::<T>())
|
||||
.change_context(errors::ConnectorError::NoConnectorMetaData)
|
||||
}
|
||||
|
||||
|
||||
@ -502,7 +502,7 @@ impl PaymentCreate {
|
||||
billing_address_id,
|
||||
statement_descriptor_name: request.statement_descriptor_name.clone(),
|
||||
statement_descriptor_suffix: request.statement_descriptor_suffix.clone(),
|
||||
metadata,
|
||||
metadata: metadata.map(masking::Secret::new),
|
||||
..storage::PaymentIntentNew::default()
|
||||
})
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ pub mod transformers;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub use api_models::enums::Connector;
|
||||
use common_utils::pii::Email;
|
||||
use common_utils::{pii, pii::Email};
|
||||
use error_stack::{IntoReport, ResultExt};
|
||||
|
||||
use self::{api::payments, storage::enums as storage_enums};
|
||||
@ -92,7 +92,7 @@ pub struct RouterData<Flow, Request, Response> {
|
||||
pub router_return_url: Option<String>,
|
||||
pub address: PaymentAddress,
|
||||
pub auth_type: storage_enums::AuthenticationType,
|
||||
pub connector_meta_data: Option<serde_json::Value>,
|
||||
pub connector_meta_data: Option<pii::SecretSerdeValue>,
|
||||
pub amount_captured: Option<i64>,
|
||||
pub access_token: Option<AccessToken>,
|
||||
pub session_token: Option<String>,
|
||||
|
||||
Reference in New Issue
Block a user