fix(core): payment_method_type not set in the payment attempt when making a recurring mandate payment (#1415)

Co-authored-by: Narayan Bhat <48803246+Narayanbhat166@users.noreply.github.com>
This commit is contained in:
Pa1NarK
2023-06-20 19:28:44 +05:30
committed by GitHub
parent c40617aea6
commit 38b9e59b75
5 changed files with 29 additions and 16 deletions

View File

@ -272,6 +272,7 @@ pub async fn get_token_pm_type_mandate_details(
) -> RouterResult<( ) -> RouterResult<(
Option<String>, Option<String>,
Option<storage_enums::PaymentMethod>, Option<storage_enums::PaymentMethod>,
Option<storage_enums::PaymentMethodType>,
Option<api::MandateData>, Option<api::MandateData>,
Option<String>, Option<String>,
)> { )> {
@ -284,18 +285,27 @@ pub async fn get_token_pm_type_mandate_details(
Ok(( Ok((
request.payment_token.to_owned(), request.payment_token.to_owned(),
request.payment_method.map(ForeignInto::foreign_into), request.payment_method.map(ForeignInto::foreign_into),
request.payment_method_type.map(ForeignInto::foreign_into),
Some(setup_mandate), Some(setup_mandate),
None, None,
)) ))
} }
Some(api::MandateTxnType::RecurringMandateTxn) => { Some(api::MandateTxnType::RecurringMandateTxn) => {
let (token_, payment_method_type_, mandate_connector) = let (token_, payment_method_, payment_method_type_, mandate_connector) =
get_token_for_recurring_mandate(state, request, merchant_account).await?; get_token_for_recurring_mandate(state, request, merchant_account).await?;
Ok((token_, payment_method_type_, None, mandate_connector)) Ok((
token_,
payment_method_,
payment_method_type_
.or_else(|| request.payment_method_type.map(ForeignInto::foreign_into)),
None,
mandate_connector,
))
} }
None => Ok(( None => Ok((
request.payment_token.to_owned(), request.payment_token.to_owned(),
request.payment_method.map(ForeignInto::foreign_into), request.payment_method.map(ForeignInto::foreign_into),
request.payment_method_type.map(ForeignInto::foreign_into),
request.mandate_data.clone(), request.mandate_data.clone(),
None, None,
)), )),
@ -309,6 +319,7 @@ pub async fn get_token_for_recurring_mandate(
) -> RouterResult<( ) -> RouterResult<(
Option<String>, Option<String>,
Option<storage_enums::PaymentMethod>, Option<storage_enums::PaymentMethod>,
Option<storage_enums::PaymentMethodType>,
Option<String>, Option<String>,
)> { )> {
let db = &*state.store; let db = &*state.store;
@ -368,12 +379,14 @@ pub async fn get_token_for_recurring_mandate(
Ok(( Ok((
Some(token), Some(token),
Some(payment_method.payment_method), Some(payment_method.payment_method),
payment_method.payment_method_type,
Some(mandate.connector), Some(mandate.connector),
)) ))
} else { } else {
Ok(( Ok((
None, None,
Some(payment_method.payment_method), Some(payment_method.payment_method),
payment_method.payment_method_type,
Some(mandate.connector), Some(mandate.connector),
)) ))
} }

View File

@ -70,7 +70,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Co
"confirm", "confirm",
)?; )?;
let (token, payment_method, setup_mandate, mandate_connector) = let (token, payment_method, payment_method_type, setup_mandate, mandate_connector) =
helpers::get_token_pm_type_mandate_details( helpers::get_token_pm_type_mandate_details(
state, state,
request, request,
@ -110,10 +110,8 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Co
payment_attempt.payment_method = payment_method.or(payment_attempt.payment_method); payment_attempt.payment_method = payment_method.or(payment_attempt.payment_method);
payment_attempt.browser_info = browser_info; payment_attempt.browser_info = browser_info;
payment_attempt.payment_method_type = request payment_attempt.payment_method_type =
.payment_method_type payment_method_type.or(payment_attempt.payment_method_type);
.map(|pmt| pmt.foreign_into())
.or(payment_attempt.payment_method_type);
payment_attempt.payment_experience = request payment_attempt.payment_experience = request
.payment_experience .payment_experience
.map(|experience| experience.foreign_into()); .map(|experience| experience.foreign_into());

View File

@ -103,7 +103,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
.map(ForeignInto::foreign_into) .map(ForeignInto::foreign_into)
.or(payment_intent.setup_future_usage); .or(payment_intent.setup_future_usage);
let (token, payment_method, setup_mandate, mandate_connector) = let (token, payment_method, payment_method_type, setup_mandate, mandate_connector) =
helpers::get_token_pm_type_mandate_details( helpers::get_token_pm_type_mandate_details(
state, state,
request, request,
@ -138,10 +138,8 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
payment_attempt.payment_method = payment_method.or(payment_attempt.payment_method); payment_attempt.payment_method = payment_method.or(payment_attempt.payment_method);
payment_attempt.browser_info = browser_info; payment_attempt.browser_info = browser_info;
payment_attempt.payment_method_type = request payment_attempt.payment_method_type =
.payment_method_type payment_method_type.or(payment_attempt.payment_method_type);
.map(|pmt| pmt.foreign_into())
.or(payment_attempt.payment_method_type);
payment_attempt.payment_experience = request payment_attempt.payment_experience = request
.payment_experience .payment_experience

View File

@ -65,7 +65,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
.get_payment_intent_id() .get_payment_intent_id()
.change_context(errors::ApiErrorResponse::PaymentNotFound)?; .change_context(errors::ApiErrorResponse::PaymentNotFound)?;
let (token, payment_method_type, setup_mandate, mandate_connector) = let (token, payment_method, payment_method_type, setup_mandate, mandate_connector) =
helpers::get_token_pm_type_mandate_details( helpers::get_token_pm_type_mandate_details(
state, state,
request, request,
@ -111,6 +111,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
&payment_id, &payment_id,
merchant_id, merchant_id,
money, money,
payment_method,
payment_method_type, payment_method_type,
request, request,
browser_info, browser_info,
@ -493,6 +494,7 @@ impl PaymentCreate {
merchant_id: &str, merchant_id: &str,
money: (api::Amount, enums::Currency), money: (api::Amount, enums::Currency),
payment_method: Option<enums::PaymentMethod>, payment_method: Option<enums::PaymentMethod>,
payment_method_type: Option<enums::PaymentMethodType>,
request: &api::PaymentsRequest, request: &api::PaymentsRequest,
browser_info: Option<serde_json::Value>, browser_info: Option<serde_json::Value>,
) -> RouterResult<storage::PaymentAttemptNew> { ) -> RouterResult<storage::PaymentAttemptNew> {
@ -528,7 +530,7 @@ impl PaymentCreate {
authentication_type: request.authentication_type.map(ForeignInto::foreign_into), authentication_type: request.authentication_type.map(ForeignInto::foreign_into),
browser_info, browser_info,
payment_experience: request.payment_experience.map(ForeignInto::foreign_into), payment_experience: request.payment_experience.map(ForeignInto::foreign_into),
payment_method_type: request.payment_method_type.map(ForeignInto::foreign_into), payment_method_type,
payment_method_data: additional_pm_data, payment_method_data: additional_pm_data,
amount_to_capture: request.amount_to_capture, amount_to_capture: request.amount_to_capture,
payment_token: request.payment_token.clone(), payment_token: request.payment_token.clone(),

View File

@ -75,7 +75,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
"update", "update",
)?; )?;
let (token, payment_method_type, setup_mandate, mandate_connector) = let (token, payment_method, payment_method_type, setup_mandate, mandate_connector) =
helpers::get_token_pm_type_mandate_details( helpers::get_token_pm_type_mandate_details(
state, state,
request, request,
@ -108,7 +108,9 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
None => payment_attempt.currency.get_required_value("currency")?, None => payment_attempt.currency.get_required_value("currency")?,
}; };
payment_attempt.payment_method = payment_method_type.or(payment_attempt.payment_method); payment_attempt.payment_method = payment_method.or(payment_attempt.payment_method);
payment_attempt.payment_method_type =
payment_method_type.or(payment_attempt.payment_method_type);
let customer_details = helpers::get_customer_details_from_request(request); let customer_details = helpers::get_customer_details_from_request(request);
let amount = request let amount = request