mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 11:24:45 +08:00
refactor: move merchant_key_store table to accounts schema (#7746)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -4,6 +4,7 @@ use diesel::{
|
||||
backend::Backend,
|
||||
deserialize,
|
||||
deserialize::FromSql,
|
||||
serialize::ToSql,
|
||||
sql_types::{Json, Jsonb},
|
||||
AsExpression, Queryable,
|
||||
};
|
||||
@ -28,6 +29,69 @@ pub struct PaymentMethodsEnabled {
|
||||
pub payment_method_subtypes: Option<Vec<RequestPaymentMethodTypes>>,
|
||||
}
|
||||
|
||||
// Custom FromSql implmentation to handle deserialization of v1 data format
|
||||
impl FromSql<Json, diesel::pg::Pg> for PaymentMethodsEnabled {
|
||||
fn from_sql(bytes: <diesel::pg::Pg as Backend>::RawValue<'_>) -> deserialize::Result<Self> {
|
||||
let helper: PaymentMethodsEnabledHelper = serde_json::from_slice(bytes.as_bytes())
|
||||
.map_err(|e| Box::new(diesel::result::Error::DeserializationError(Box::new(e))))?;
|
||||
Ok(helper.into())
|
||||
}
|
||||
}
|
||||
|
||||
// In this ToSql implementation, we are directly serializing the PaymentMethodsEnabled struct to JSON
|
||||
impl ToSql<Json, diesel::pg::Pg> for PaymentMethodsEnabled {
|
||||
fn to_sql<'b>(
|
||||
&'b self,
|
||||
out: &mut diesel::serialize::Output<'b, '_, diesel::pg::Pg>,
|
||||
) -> diesel::serialize::Result {
|
||||
let value = serde_json::to_value(self)?;
|
||||
// the function `reborrow` only works in case of `Pg` backend. But, in case of other backends
|
||||
// please refer to the diesel migration blog:
|
||||
// https://github.com/Diesel-rs/Diesel/blob/master/guide_drafts/migration_guide.md#changed-tosql-implementations
|
||||
<serde_json::Value as ToSql<Json, diesel::pg::Pg>>::to_sql(&value, &mut out.reborrow())
|
||||
}
|
||||
}
|
||||
|
||||
// Intermediate type to handle deserialization of v1 data format of PaymentMethodsEnabled
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum PaymentMethodsEnabledHelper {
|
||||
V2 {
|
||||
payment_method_type: common_enums::PaymentMethod,
|
||||
payment_method_subtypes: Option<Vec<RequestPaymentMethodTypes>>,
|
||||
},
|
||||
V1 {
|
||||
payment_method: common_enums::PaymentMethod,
|
||||
payment_method_types: Option<Vec<RequestPaymentMethodTypesV1>>,
|
||||
},
|
||||
}
|
||||
|
||||
impl From<PaymentMethodsEnabledHelper> for PaymentMethodsEnabled {
|
||||
fn from(helper: PaymentMethodsEnabledHelper) -> Self {
|
||||
match helper {
|
||||
PaymentMethodsEnabledHelper::V2 {
|
||||
payment_method_type,
|
||||
payment_method_subtypes,
|
||||
} => Self {
|
||||
payment_method_type,
|
||||
payment_method_subtypes,
|
||||
},
|
||||
PaymentMethodsEnabledHelper::V1 {
|
||||
payment_method,
|
||||
payment_method_types,
|
||||
} => Self {
|
||||
payment_method_type: payment_method,
|
||||
payment_method_subtypes: payment_method_types.map(|subtypes| {
|
||||
subtypes
|
||||
.into_iter()
|
||||
.map(RequestPaymentMethodTypes::from)
|
||||
.collect()
|
||||
}),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PaymentMethodsEnabled {
|
||||
/// Get payment_method_type
|
||||
#[cfg(feature = "v2")]
|
||||
@ -92,6 +156,35 @@ pub struct RequestPaymentMethodTypes {
|
||||
pub installment_payment_enabled: bool,
|
||||
}
|
||||
|
||||
impl From<RequestPaymentMethodTypesV1> for RequestPaymentMethodTypes {
|
||||
fn from(value: RequestPaymentMethodTypesV1) -> Self {
|
||||
Self {
|
||||
payment_method_subtype: value.payment_method_type,
|
||||
payment_experience: value.payment_experience,
|
||||
card_networks: value.card_networks,
|
||||
accepted_currencies: value.accepted_currencies,
|
||||
accepted_countries: value.accepted_countries,
|
||||
minimum_amount: value.minimum_amount,
|
||||
maximum_amount: value.maximum_amount,
|
||||
recurring_enabled: value.recurring_enabled,
|
||||
installment_payment_enabled: value.installment_payment_enabled,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
struct RequestPaymentMethodTypesV1 {
|
||||
pub payment_method_type: common_enums::PaymentMethodType,
|
||||
pub payment_experience: Option<common_enums::PaymentExperience>,
|
||||
pub card_networks: Option<Vec<common_enums::CardNetwork>>,
|
||||
pub accepted_currencies: Option<AcceptedCurrencies>,
|
||||
pub accepted_countries: Option<AcceptedCountries>,
|
||||
pub minimum_amount: Option<common_utils::types::MinorUnit>,
|
||||
pub maximum_amount: Option<common_utils::types::MinorUnit>,
|
||||
pub recurring_enabled: bool,
|
||||
pub installment_payment_enabled: bool,
|
||||
}
|
||||
|
||||
impl RequestPaymentMethodTypes {
|
||||
///Get payment_method_subtype
|
||||
pub fn get_payment_method_type(&self) -> Option<common_enums::PaymentMethodType> {
|
||||
@ -153,8 +246,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
common_utils::impl_to_sql_from_sql_json!(PaymentMethodsEnabled);
|
||||
|
||||
/// The network tokenization configuration for creating the payment method session
|
||||
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema)]
|
||||
pub struct NetworkTokenization {
|
||||
|
||||
@ -128,4 +128,46 @@ mod bool_wrappers {
|
||||
bool::from_sql(value).map(Self)
|
||||
}
|
||||
}
|
||||
|
||||
/// Bool that represents if Cvv should be collected during payment or not. Default is true
|
||||
#[derive(
|
||||
Clone, Copy, Debug, Eq, PartialEq, diesel::expression::AsExpression, Serialize, Deserialize,
|
||||
)]
|
||||
#[diesel(sql_type = diesel::sql_types::Bool)]
|
||||
pub struct ShouldCollectCvvDuringPayment(bool);
|
||||
impl Deref for ShouldCollectCvvDuringPayment {
|
||||
type Target = bool;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
impl<DB> diesel::serialize::ToSql<diesel::sql_types::Bool, DB> for ShouldCollectCvvDuringPayment
|
||||
where
|
||||
DB: diesel::backend::Backend,
|
||||
bool: diesel::serialize::ToSql<diesel::sql_types::Bool, DB>,
|
||||
{
|
||||
fn to_sql<'b>(
|
||||
&'b self,
|
||||
out: &mut diesel::serialize::Output<'b, '_, DB>,
|
||||
) -> diesel::serialize::Result {
|
||||
self.0.to_sql(out)
|
||||
}
|
||||
}
|
||||
impl<DB> diesel::deserialize::FromSql<diesel::sql_types::Bool, DB> for ShouldCollectCvvDuringPayment
|
||||
where
|
||||
DB: diesel::backend::Backend,
|
||||
bool: diesel::deserialize::FromSql<diesel::sql_types::Bool, DB>,
|
||||
{
|
||||
fn from_sql(value: DB::RawValue<'_>) -> diesel::deserialize::Result<Self> {
|
||||
bool::from_sql(value).map(Self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ShouldCollectCvvDuringPayment {
|
||||
/// Default for `ShouldCollectCvvDuringPayment` is `true`
|
||||
fn default() -> Self {
|
||||
Self(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user