Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

feat(payments_update): update payment_method_billing in payment update (#4614)

Narayan Bhat26929956172e
diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs
index 65481d93be..d4d2ddaef0 100644
--- a/crates/diesel_models/src/payment_attempt.rs
+++ b/crates/diesel_models/src/payment_attempt.rs
@@ -188,6 +188,7 @@ pub enum PaymentAttemptUpdate {
surcharge_amount: Option<i64>,
tax_amount: Option<i64>,
fingerprint_id: Option<String>,
+ payment_method_billing_address_id: Option<String>,
updated_by: String,
},
UpdateTrackers {
@@ -526,6 +527,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
tax_amount,
fingerprint_id,
updated_by,
+ payment_method_billing_address_id,
} => Self {
amount: Some(amount),
currency: Some(currency),
@@ -544,6 +546,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
surcharge_amount,
tax_amount,
fingerprint_id,
+ payment_method_billing_address_id,
updated_by,
..Default::default()
},
diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
index 7e406ca24d..d6565a6be6 100644
--- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
+++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
@@ -282,6 +282,7 @@ pub enum PaymentAttemptUpdate {
surcharge_amount: Option<i64>,
tax_amount: Option<i64>,
fingerprint_id: Option<String>,
+ payment_method_billing_address_id: Option<String>,
updated_by: String,
},
UpdateTrackers {
diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs
index c7479672c7..ff0b3a9f15 100644
--- a/crates/router/src/core/payments/operations/payment_update.rs
+++ b/crates/router/src/core/payments/operations/payment_update.rs
@@ -97,11 +97,6 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
helpers::authenticate_client_secret(request.client_secret.as_ref(), &payment_intent)?;
- payment_intent = db
- .find_payment_intent_by_payment_id_merchant_id(&payment_id, merchant_id, storage_scheme)
- .await
- .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
-
payment_intent.order_details = request
.get_order_details_as_value()
.change_context(errors::ApiErrorResponse::InternalServerError)
@@ -236,6 +231,9 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
payment_intent.shipping_address_id = shipping_address.clone().map(|x| x.address_id);
payment_intent.billing_address_id = billing_address.clone().map(|x| x.address_id);
+ payment_attempt.payment_method_billing_address_id = payment_method_billing
+ .as_ref()
+ .map(|payment_method_billing| payment_method_billing.address_id.clone());
payment_intent.allowed_payment_method_types = request
.get_allowed_payment_method_types_as_value()
@@ -348,16 +346,20 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
(Box::new(self), amount)
};
- payment_intent.status = match request.payment_method_data.as_ref() {
- Some(_) => {
- if request.confirm.unwrap_or(false) {
- payment_intent.status
- } else {
- storage_enums::IntentStatus::RequiresConfirmation
- }
+ payment_intent.status = if request
+ .payment_method_data
+ .as_ref()
+ .is_some_and(|payment_method_data| payment_method_data.payment_method_data.is_some())
+ {
+ if request.confirm.unwrap_or(false) {
+ payment_intent.status
+ } else {
+ storage_enums::IntentStatus::RequiresConfirmation
}
- None => storage_enums::IntentStatus::RequiresPaymentMethod,
+ } else {
+ storage_enums::IntentStatus::RequiresPaymentMethod
};
+
payment_intent.request_external_three_ds_authentication = request
.request_external_three_ds_authentication
.or(payment_intent.request_external_three_ds_authentication);
@@ -622,6 +624,10 @@ impl<F: Clone, Ctx: PaymentMethodRetrieve>
let payment_experience = payment_data.payment_attempt.payment_experience;
let amount_to_capture = payment_data.payment_attempt.amount_to_capture;
let capture_method = payment_data.payment_attempt.capture_method;
+ let payment_method_billing_address_id = payment_data
+ .payment_attempt
+ .payment_method_billing_address_id
+ .clone();
let surcharge_amount = payment_data
.surcharge_details
@@ -651,6 +657,7 @@ impl<F: Clone, Ctx: PaymentMethodRetrieve>
surcharge_amount,
tax_amount,
fingerprint_id: None,
+ payment_method_billing_address_id,
updated_by: storage_scheme.to_string(),
},
storage_scheme,
diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs
index 4308e463b0..d090f646da 100644
--- a/crates/storage_impl/src/payments/payment_attempt.rs
+++ b/crates/storage_impl/src/payments/payment_attempt.rs
@@ -1377,6 +1377,7 @@ impl DataModelExt for PaymentAttemptUpdate {
surcharge_amount,
tax_amount,
fingerprint_id,
+ payment_method_billing_address_id,
updated_by,
} => DieselPaymentAttemptUpdate::Update {
amount,
@@ -1394,6 +1395,7 @@ impl DataModelExt for PaymentAttemptUpdate {
surcharge_amount,
tax_amount,
fingerprint_id,
+ payment_method_billing_address_id,
updated_by,
},
Self::UpdateTrackers {
@@ -1697,6 +1699,7 @@ impl DataModelExt for PaymentAttemptUpdate {
tax_amount,
fingerprint_id,
updated_by,
+ payment_method_billing_address_id,
} => Self::Update {
amount,
currency,
@@ -1713,6 +1716,7 @@ impl DataModelExt for PaymentAttemptUpdate {
surcharge_amount,
tax_amount,
fingerprint_id,
+ payment_method_billing_address_id,
updated_by,
},
DieselPaymentAttemptUpdate::UpdateTrackers {