feat(core): update card_details for an existing mandate (#3452)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Amisha Prabhat
2024-01-30 12:35:42 +05:30
committed by GitHub
parent c9d41e2169
commit 02074dfc23
22 changed files with 451 additions and 72 deletions

View File

@ -2,7 +2,7 @@ use api_models::enums::{AuthenticationType, Connector, PaymentMethod, PaymentMet
use common_utils::{errors::CustomResult, fallback_reverse_lookup_not_found};
use data_models::{
errors,
mandates::{MandateAmountData, MandateDataType},
mandates::{MandateAmountData, MandateDataType, MandateDetails, MandateTypeDetails},
payments::{
payment_attempt::{
PaymentAttempt, PaymentAttemptInterface, PaymentAttemptNew, PaymentAttemptUpdate,
@ -14,6 +14,7 @@ use data_models::{
use diesel_models::{
enums::{
MandateAmountData as DieselMandateAmountData, MandateDataType as DieselMandateType,
MandateDetails as DieselMandateDetails, MandateTypeDetails as DieselMandateTypeOrDetails,
MerchantStorageScheme,
},
kv,
@ -999,6 +1000,50 @@ impl DataModelExt for MandateAmountData {
}
}
}
impl DataModelExt for MandateDetails {
type StorageModel = DieselMandateDetails;
fn to_storage_model(self) -> Self::StorageModel {
DieselMandateDetails {
update_mandate_id: self.update_mandate_id,
mandate_type: self
.mandate_type
.map(|mand_type| mand_type.to_storage_model()),
}
}
fn from_storage_model(storage_model: Self::StorageModel) -> Self {
Self {
update_mandate_id: storage_model.update_mandate_id,
mandate_type: storage_model
.mandate_type
.map(MandateDataType::from_storage_model),
}
}
}
impl DataModelExt for MandateTypeDetails {
type StorageModel = DieselMandateTypeOrDetails;
fn to_storage_model(self) -> Self::StorageModel {
match self {
Self::MandateType(mandate_type) => {
DieselMandateTypeOrDetails::MandateType(mandate_type.to_storage_model())
}
Self::MandateDetails(mandate_details) => {
DieselMandateTypeOrDetails::MandateDetails(mandate_details.to_storage_model())
}
}
}
fn from_storage_model(storage_model: Self::StorageModel) -> Self {
match storage_model {
DieselMandateTypeOrDetails::MandateType(data) => {
Self::MandateType(MandateDataType::from_storage_model(data))
}
DieselMandateTypeOrDetails::MandateDetails(data) => {
Self::MandateDetails(MandateDetails::from_storage_model(data))
}
}
}
}
impl DataModelExt for MandateDataType {
type StorageModel = DieselMandateType;
@ -1123,7 +1168,7 @@ impl DataModelExt for PaymentAttempt {
preprocessing_step_id: storage_model.preprocessing_step_id,
mandate_details: storage_model
.mandate_details
.map(MandateDataType::from_storage_model),
.map(MandateTypeDetails::from_storage_model),
error_reason: storage_model.error_reason,
multiple_capture_count: storage_model.multiple_capture_count,
connector_response_reference_id: storage_model.connector_response_reference_id,
@ -1231,7 +1276,7 @@ impl DataModelExt for PaymentAttemptNew {
preprocessing_step_id: storage_model.preprocessing_step_id,
mandate_details: storage_model
.mandate_details
.map(MandateDataType::from_storage_model),
.map(MandateTypeDetails::from_storage_model),
error_reason: storage_model.error_reason,
connector_response_reference_id: storage_model.connector_response_reference_id,
multiple_capture_count: storage_model.multiple_capture_count,