mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 11:06:50 +08:00
fix: customer id is not mandatory during confirm (#1317)
This commit is contained in:
@ -151,10 +151,7 @@ pub async fn get_address_for_payment_request(
|
||||
}
|
||||
None => {
|
||||
// generate a new address here
|
||||
let customer_id = customer_id
|
||||
.as_deref()
|
||||
.get_required_value("customer_id")
|
||||
.change_context(errors::ApiErrorResponse::CustomerNotFound)?;
|
||||
let customer_id = customer_id.as_deref().get_required_value("customer_id")?;
|
||||
|
||||
let address_details = address.address.clone().unwrap_or_default();
|
||||
Some(
|
||||
@ -395,11 +392,12 @@ pub fn validate_request_amount_and_amount_to_capture(
|
||||
|
||||
pub fn validate_mandate(
|
||||
req: impl Into<api::MandateValidationFields>,
|
||||
is_confirm_operation: bool,
|
||||
) -> RouterResult<Option<api::MandateTxnType>> {
|
||||
let req: api::MandateValidationFields = req.into();
|
||||
match req.is_mandate() {
|
||||
Some(api::MandateTxnType::NewMandateTxn) => {
|
||||
validate_new_mandate_request(req)?;
|
||||
validate_new_mandate_request(req, is_confirm_operation)?;
|
||||
Ok(Some(api::MandateTxnType::NewMandateTxn))
|
||||
}
|
||||
Some(api::MandateTxnType::RecurringMandateTxn) => {
|
||||
@ -410,8 +408,18 @@ pub fn validate_mandate(
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_new_mandate_request(req: api::MandateValidationFields) -> RouterResult<()> {
|
||||
let _ = req.customer_id.as_ref().get_required_value("customer_id")?;
|
||||
fn validate_new_mandate_request(
|
||||
req: api::MandateValidationFields,
|
||||
is_confirm_operation: bool,
|
||||
) -> RouterResult<()> {
|
||||
// We need not check for customer_id in the confirm request if it is already passed
|
||||
//in create request
|
||||
|
||||
fp_utils::when(!is_confirm_operation && req.customer_id.is_none(), || {
|
||||
Err(report!(errors::ApiErrorResponse::PreconditionFailed {
|
||||
message: "`customer_id` is mandatory for mandates".into()
|
||||
}))
|
||||
})?;
|
||||
|
||||
let mandate_data = req
|
||||
.mandate_data
|
||||
@ -776,10 +784,15 @@ pub async fn create_customer_if_not_exist<'a, F: Clone, R>(
|
||||
let req = req
|
||||
.get_required_value("customer")
|
||||
.change_context(errors::StorageError::ValueNotFound("customer".to_owned()))?;
|
||||
let optional_customer = match req.customer_id.as_ref() {
|
||||
|
||||
let customer_id = req
|
||||
.customer_id
|
||||
.or(payment_data.payment_intent.customer_id.clone());
|
||||
|
||||
let optional_customer = match customer_id {
|
||||
Some(customer_id) => {
|
||||
let customer_data = db
|
||||
.find_customer_optional_by_customer_id_merchant_id(customer_id, merchant_id)
|
||||
.find_customer_optional_by_customer_id_merchant_id(&customer_id, merchant_id)
|
||||
.await?;
|
||||
Some(match customer_data {
|
||||
Some(c) => Ok(c),
|
||||
|
||||
@ -9,7 +9,7 @@ use super::{BoxedOperation, Domain, GetTracker, Operation, UpdateTracker, Valida
|
||||
use crate::{
|
||||
core::{
|
||||
errors::{self, CustomResult, RouterResult, StorageErrorExt},
|
||||
payments::{helpers, operations, CustomerDetails, PaymentAddress, PaymentData},
|
||||
payments::{self, helpers, operations, CustomerDetails, PaymentAddress, PaymentData},
|
||||
utils as core_utils,
|
||||
},
|
||||
db::StorageInterface,
|
||||
@ -331,7 +331,8 @@ impl<F: Send + Clone> ValidateRequest<F, api::PaymentsRequest> for CompleteAutho
|
||||
|
||||
helpers::validate_payment_method_fields_present(request)?;
|
||||
|
||||
let mandate_type = helpers::validate_mandate(request)?;
|
||||
let mandate_type =
|
||||
helpers::validate_mandate(request, payments::is_operation_confirm(self))?;
|
||||
let payment_id = core_utils::get_or_generate_id("payment_id", &given_payment_id, "pay")?;
|
||||
|
||||
Ok((
|
||||
|
||||
@ -10,7 +10,7 @@ use super::{BoxedOperation, Domain, GetTracker, Operation, UpdateTracker, Valida
|
||||
use crate::{
|
||||
core::{
|
||||
errors::{self, CustomResult, RouterResult, StorageErrorExt},
|
||||
payments::{helpers, operations, CustomerDetails, PaymentAddress, PaymentData},
|
||||
payments::{self, helpers, operations, CustomerDetails, PaymentAddress, PaymentData},
|
||||
utils as core_utils,
|
||||
},
|
||||
db::StorageInterface,
|
||||
@ -467,7 +467,8 @@ impl<F: Send + Clone> ValidateRequest<F, api::PaymentsRequest> for PaymentConfir
|
||||
|
||||
helpers::validate_payment_method_fields_present(request)?;
|
||||
|
||||
let mandate_type = helpers::validate_mandate(request)?;
|
||||
let mandate_type =
|
||||
helpers::validate_mandate(request, payments::is_operation_confirm(self))?;
|
||||
let payment_id = core_utils::get_or_generate_id("payment_id", &given_payment_id, "pay")?;
|
||||
|
||||
Ok((
|
||||
|
||||
@ -434,7 +434,8 @@ impl<F: Send + Clone> ValidateRequest<F, api::PaymentsRequest> for PaymentCreate
|
||||
|
||||
let payment_id = core_utils::get_or_generate_id("payment_id", &given_payment_id, "pay")?;
|
||||
|
||||
let mandate_type = helpers::validate_mandate(request)?;
|
||||
let mandate_type =
|
||||
helpers::validate_mandate(request, payments::is_operation_confirm(self))?;
|
||||
|
||||
if request.confirm.unwrap_or(false) {
|
||||
helpers::validate_pm_or_token_given(
|
||||
|
||||
@ -45,7 +45,8 @@ impl<F: Send + Clone> ValidateRequest<F, api::VerifyRequest> for PaymentMethodVa
|
||||
helpers::validate_merchant_id(&merchant_account.merchant_id, request_merchant_id)
|
||||
.change_context(errors::ApiErrorResponse::MerchantAccountNotFound)?;
|
||||
|
||||
let mandate_type = helpers::validate_mandate(request)?;
|
||||
let mandate_type =
|
||||
helpers::validate_mandate(request, payments::is_operation_confirm(self))?;
|
||||
let validation_id = core_utils::get_or_generate_id("validation_id", &None, "val")?;
|
||||
|
||||
Ok((
|
||||
|
||||
@ -188,7 +188,7 @@ impl<F: Send + Clone> ValidateRequest<F, api::PaymentsStartRequest> for PaymentS
|
||||
field_name: "merchant_id".to_string(),
|
||||
expected_format: "merchant_id from merchant account".to_string(),
|
||||
})?;
|
||||
// let mandate_type = validate_mandate(request)?;
|
||||
|
||||
let payment_id = request.payment_id.clone();
|
||||
|
||||
Ok((
|
||||
|
||||
@ -532,7 +532,7 @@ impl<F: Send + Clone> ValidateRequest<F, api::PaymentsRequest> for PaymentUpdate
|
||||
|
||||
helpers::validate_payment_method_fields_present(request)?;
|
||||
|
||||
let mandate_type = helpers::validate_mandate(request)?;
|
||||
let mandate_type = helpers::validate_mandate(request, false)?;
|
||||
let payment_id = core_utils::get_or_generate_id("payment_id", &given_payment_id, "pay")?;
|
||||
|
||||
Ok((
|
||||
|
||||
Reference in New Issue
Block a user