Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/diesel_models/src/payment_attempt.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use common_utils::pii;
use diesel::{AsChangeset, Identifiable, Insertable, Queryable};
use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;
Expand Down Expand Up @@ -72,6 +73,7 @@ pub struct PaymentAttempt {
pub charge_id: Option<String>,
pub client_source: Option<String>,
pub client_version: Option<String>,
pub customer_acceptance: Option<pii::SecretSerdeValue>,
}

impl PaymentAttempt {
Expand Down Expand Up @@ -155,6 +157,7 @@ pub struct PaymentAttemptNew {
pub charge_id: Option<String>,
pub client_source: Option<String>,
pub client_version: Option<String>,
pub customer_acceptance: Option<pii::SecretSerdeValue>,
}

impl PaymentAttemptNew {
Expand Down Expand Up @@ -240,6 +243,7 @@ pub enum PaymentAttemptUpdate {
payment_method_billing_address_id: Option<String>,
client_source: Option<String>,
client_version: Option<String>,
customer_acceptance: Option<pii::SecretSerdeValue>,
},
VoidUpdate {
status: storage_enums::AttemptStatus,
Expand Down Expand Up @@ -410,6 +414,7 @@ pub struct PaymentAttemptUpdateInternal {
charge_id: Option<String>,
client_source: Option<String>,
client_version: Option<String>,
customer_acceptance: Option<pii::SecretSerdeValue>,
}

impl PaymentAttemptUpdateInternal {
Expand Down Expand Up @@ -478,6 +483,7 @@ impl PaymentAttemptUpdate {
charge_id,
client_source,
client_version,
customer_acceptance,
} = PaymentAttemptUpdateInternal::from(self).populate_derived_fields(&source);
PaymentAttempt {
amount: amount.unwrap_or(source.amount),
Expand Down Expand Up @@ -529,6 +535,7 @@ impl PaymentAttemptUpdate {
charge_id: charge_id.or(source.charge_id),
client_source: client_source.or(source.client_source),
client_version: client_version.or(source.client_version),
customer_acceptance: customer_acceptance.or(source.customer_acceptance),
..source
}
}
Expand Down Expand Up @@ -617,6 +624,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
payment_method_id,
client_source,
client_version,
customer_acceptance,
} => Self {
amount: Some(amount),
currency: Some(currency),
Expand Down Expand Up @@ -648,6 +656,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
capture_method,
client_source,
client_version,
customer_acceptance,
..Default::default()
},
PaymentAttemptUpdate::VoidUpdate {
Expand Down
1 change: 1 addition & 0 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ diesel::table! {
client_source -> Nullable<Varchar>,
#[max_length = 64]
client_version -> Nullable<Varchar>,
customer_acceptance -> Nullable<Jsonb>,
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/diesel_models/src/user/sample_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub struct PaymentAttemptBatchNew {
pub charge_id: Option<String>,
pub client_source: Option<String>,
pub client_version: Option<String>,
pub customer_acceptance: Option<common_utils::pii::SecretSerdeValue>,
}

#[allow(dead_code)]
Expand Down Expand Up @@ -139,6 +140,7 @@ impl PaymentAttemptBatchNew {
charge_id: self.charge_id,
client_source: self.client_source,
client_version: self.client_version,
customer_acceptance: self.customer_acceptance,
}
}
}
6 changes: 3 additions & 3 deletions crates/hyperswitch_domain_models/src/mandates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct MandateData {
pub mandate_type: Option<MandateDataType>,
}

#[derive(Default, Eq, PartialEq, Debug, Clone, serde::Deserialize)]
#[derive(Default, Eq, PartialEq, Debug, Clone, serde::Deserialize, serde::Serialize)]
pub struct CustomerAcceptance {
/// Type of acceptance provided by the
pub acceptance_type: AcceptanceType,
Expand All @@ -54,15 +54,15 @@ pub struct CustomerAcceptance {
pub online: Option<OnlineMandate>,
}

#[derive(Default, Debug, PartialEq, Eq, Clone, serde::Deserialize)]
#[derive(Default, Debug, PartialEq, Eq, Clone, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "lowercase")]
pub enum AcceptanceType {
Online,
#[default]
Offline,
}

#[derive(Default, Eq, PartialEq, Debug, Clone, serde::Deserialize)]
#[derive(Default, Eq, PartialEq, Debug, Clone, serde::Deserialize, serde::Serialize)]
pub struct OnlineMandate {
/// Ip address of the customer machine from which the mandate was created
#[serde(skip_deserializing)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use api_models::enums::Connector;
use common_enums as storage_enums;
use common_utils::{
errors::{CustomResult, ValidationError},
pii,
types::MinorUnit,
};
use error_stack::ResultExt;
Expand Down Expand Up @@ -175,6 +176,7 @@ pub struct PaymentAttempt {
pub charge_id: Option<String>,
pub client_source: Option<String>,
pub client_version: Option<String>,
pub customer_acceptance: Option<pii::SecretSerdeValue>,
}

impl PaymentAttempt {
Expand Down Expand Up @@ -264,6 +266,7 @@ pub struct PaymentAttemptNew {
pub charge_id: Option<String>,
pub client_source: Option<String>,
pub client_version: Option<String>,
pub customer_acceptance: Option<pii::SecretSerdeValue>,
}

impl PaymentAttemptNew {
Expand Down Expand Up @@ -346,6 +349,7 @@ pub enum PaymentAttemptUpdate {
payment_method_id: Option<String>,
client_source: Option<String>,
client_version: Option<String>,
customer_acceptance: Option<pii::SecretSerdeValue>,
},
RejectUpdate {
status: storage_enums::AttemptStatus,
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/core/payments/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3709,6 +3709,7 @@ impl AttemptType {
charge_id: None,
client_source: old_payment_attempt.client_source,
client_version: old_payment_attempt.client_version,
customer_acceptance: old_payment_attempt.customer_acceptance,
}
}

Expand Down
23 changes: 21 additions & 2 deletions crates/router/src/core/payments/operations/payment_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,15 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
.change_context(errors::ApiErrorResponse::InvalidDataValue {
field_name: "browser_info",
})?;
let customer_acceptance = request.customer_acceptance.clone().map(From::from);
let customer_acceptance = request.customer_acceptance.clone().or(payment_attempt
.customer_acceptance
.clone()
.map(|customer_acceptance| {
serde_json::from_value(customer_acceptance.expose())
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed while deserializing customer_acceptance")
})
.transpose()?);

let recurring_details = request.recurring_details.clone();

Expand All @@ -360,6 +368,16 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa

payment_attempt.capture_method = request.capture_method.or(payment_attempt.capture_method);

payment_attempt.customer_acceptance = request
.customer_acceptance
.clone()
.map(|customer_acceptance| customer_acceptance.encode_to_value())
.transpose()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed while encoding customer_acceptance to value")?
.map(masking::Secret::new)
.or(payment_attempt.customer_acceptance);

currency = payment_attempt.currency.get_required_value("currency")?;
amount = payment_attempt.get_total_amount().into();

Expand Down Expand Up @@ -616,7 +634,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
mandate_id: None,
mandate_connector,
setup_mandate,
customer_acceptance,
customer_acceptance: customer_acceptance.map(From::from),
token,
address: PaymentAddress::new(
shipping_address.as_ref().map(From::from),
Expand Down Expand Up @@ -1211,6 +1229,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
payment_method_id: m_payment_method_id,
client_source,
client_version,
customer_acceptance: payment_data.payment_attempt.customer_acceptance,
},
storage_scheme,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
&payment_method_info,
merchant_key_store,
profile_id,
&customer_acceptance,
)
.await?;

Expand Down Expand Up @@ -795,6 +796,7 @@ impl PaymentCreate {
payment_method_info: &Option<PaymentMethod>,
key_store: &domain::MerchantKeyStore,
profile_id: String,
customer_acceptance: &Option<payments::CustomerAcceptance>,
) -> RouterResult<(
storage::PaymentAttemptNew,
Option<api_models::payments::AdditionalPaymentData>,
Expand Down Expand Up @@ -965,6 +967,13 @@ impl PaymentCreate {
charge_id: None,
client_source: None,
client_version: None,
customer_acceptance: customer_acceptance
.clone()
.map(|customer_acceptance| customer_acceptance.encode_to_value())
.transpose()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to serialize customer_acceptance")?
.map(Secret::new),
},
additional_pm_data,
))
Expand Down
1 change: 1 addition & 0 deletions crates/storage_impl/src/mock_db/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ impl PaymentAttemptInterface for MockDb {
charge_id: payment_attempt.charge_id,
client_source: payment_attempt.client_source,
client_version: payment_attempt.client_version,
customer_acceptance: payment_attempt.customer_acceptance,
};
payment_attempts.push(payment_attempt.clone());
Ok(payment_attempt)
Expand Down
9 changes: 9 additions & 0 deletions crates/storage_impl/src/payments/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
charge_id: payment_attempt.charge_id.clone(),
client_source: payment_attempt.client_source.clone(),
client_version: payment_attempt.client_version.clone(),
customer_acceptance: payment_attempt.customer_acceptance.clone(),
};

let field = format!("pa_{}", created_attempt.attempt_id);
Expand Down Expand Up @@ -1202,6 +1203,7 @@ impl DataModelExt for PaymentAttempt {
charge_id: self.charge_id,
client_source: self.client_source,
client_version: self.client_version,
customer_acceptance: self.customer_acceptance,
}
}

Expand Down Expand Up @@ -1268,6 +1270,7 @@ impl DataModelExt for PaymentAttempt {
charge_id: storage_model.charge_id,
client_source: storage_model.client_source,
client_version: storage_model.client_version,
customer_acceptance: storage_model.customer_acceptance,
}
}
}
Expand Down Expand Up @@ -1339,6 +1342,7 @@ impl DataModelExt for PaymentAttemptNew {
charge_id: self.charge_id,
client_source: self.client_source,
client_version: self.client_version,
customer_acceptance: self.customer_acceptance,
}
}

Expand Down Expand Up @@ -1404,6 +1408,7 @@ impl DataModelExt for PaymentAttemptNew {
charge_id: storage_model.charge_id,
client_source: storage_model.client_source,
client_version: storage_model.client_version,
customer_acceptance: storage_model.customer_acceptance,
}
}
}
Expand Down Expand Up @@ -1528,6 +1533,7 @@ impl DataModelExt for PaymentAttemptUpdate {
payment_method_billing_address_id,
client_source,
client_version,
customer_acceptance,
} => DieselPaymentAttemptUpdate::ConfirmUpdate {
amount: amount.get_amount_as_i64(),
currency,
Expand Down Expand Up @@ -1560,6 +1566,7 @@ impl DataModelExt for PaymentAttemptUpdate {
payment_method_billing_address_id,
client_source,
client_version,
customer_acceptance,
},
Self::VoidUpdate {
status,
Expand Down Expand Up @@ -1863,6 +1870,7 @@ impl DataModelExt for PaymentAttemptUpdate {
payment_method_billing_address_id,
client_source,
client_version,
customer_acceptance,
} => Self::ConfirmUpdate {
amount: MinorUnit::new(amount),
currency,
Expand Down Expand Up @@ -1893,6 +1901,7 @@ impl DataModelExt for PaymentAttemptUpdate {
payment_method_billing_address_id,
client_source,
client_version,
customer_acceptance,
},
DieselPaymentAttemptUpdate::VoidUpdate {
status,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE payment_attempt DROP COLUMN IF EXISTS customer_acceptance;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Your SQL goes here
ALTER TABLE payment_attempt ADD COLUMN IF NOT EXISTS customer_acceptance JSONB DEFAULT NULL;