mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 12:06:56 +08:00
refactor(mandate): allow merchant to pass the mandate details and customer acceptance separately (#1188)
This commit is contained in:
@ -16,6 +16,9 @@ pub mod diesel_exports {
|
||||
}
|
||||
|
||||
pub use common_enums::*;
|
||||
use common_utils::pii;
|
||||
use diesel::serialize::{Output, ToSql};
|
||||
use time::PrimitiveDateTime;
|
||||
|
||||
#[derive(
|
||||
Clone,
|
||||
@ -574,6 +577,54 @@ pub enum MandateType {
|
||||
MultiUse,
|
||||
}
|
||||
|
||||
use diesel::{
|
||||
backend::Backend,
|
||||
deserialize::{FromSql, FromSqlRow},
|
||||
expression::AsExpression,
|
||||
sql_types::Jsonb,
|
||||
};
|
||||
#[derive(
|
||||
serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq, FromSqlRow, AsExpression,
|
||||
)]
|
||||
#[diesel(sql_type = Jsonb)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum MandateDataType {
|
||||
SingleUse(MandateAmountData),
|
||||
MultiUse(Option<MandateAmountData>),
|
||||
}
|
||||
|
||||
impl<DB: Backend> FromSql<Jsonb, DB> for MandateDataType
|
||||
where
|
||||
serde_json::Value: FromSql<Jsonb, DB>,
|
||||
{
|
||||
fn from_sql(bytes: diesel::backend::RawValue<'_, DB>) -> diesel::deserialize::Result<Self> {
|
||||
let value = <serde_json::Value as FromSql<Jsonb, DB>>::from_sql(bytes)?;
|
||||
Ok(serde_json::from_value(value)?)
|
||||
}
|
||||
}
|
||||
impl ToSql<Jsonb, diesel::pg::Pg> for MandateDataType
|
||||
where
|
||||
serde_json::Value: ToSql<Jsonb, diesel::pg::Pg>,
|
||||
{
|
||||
fn to_sql<'b>(&'b self, out: &mut 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<Jsonb, diesel::pg::Pg>>::to_sql(&value, &mut out.reborrow())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
|
||||
pub struct MandateAmountData {
|
||||
pub amount: i64,
|
||||
pub currency: Currency,
|
||||
pub start_date: Option<PrimitiveDateTime>,
|
||||
pub end_date: Option<PrimitiveDateTime>,
|
||||
pub metadata: Option<pii::SecretSerdeValue>,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Clone,
|
||||
Copy,
|
||||
|
||||
@ -46,6 +46,8 @@ pub struct PaymentAttempt {
|
||||
pub payment_method_data: Option<serde_json::Value>,
|
||||
pub business_sub_label: Option<String>,
|
||||
pub straight_through_algorithm: Option<serde_json::Value>,
|
||||
// providing a location to store mandate details intermediately for transaction
|
||||
pub mandate_details: Option<storage_enums::MandateDataType>,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
@ -91,6 +93,7 @@ pub struct PaymentAttemptNew {
|
||||
pub payment_method_data: Option<serde_json::Value>,
|
||||
pub business_sub_label: Option<String>,
|
||||
pub straight_through_algorithm: Option<serde_json::Value>,
|
||||
pub mandate_details: Option<storage_enums::MandateDataType>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
|
||||
@ -321,6 +321,7 @@ diesel::table! {
|
||||
payment_method_data -> Nullable<Jsonb>,
|
||||
business_sub_label -> Nullable<Varchar>,
|
||||
straight_through_algorithm -> Nullable<Jsonb>,
|
||||
mandate_details -> Nullable<Jsonb>,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user