mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	fix(core): save payment_method_type when creating a record in the payment_method table (#1378)
This commit is contained in:
		| @ -84,6 +84,7 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu | |||||||
|                 resp.to_owned(), |                 resp.to_owned(), | ||||||
|                 maybe_customer, |                 maybe_customer, | ||||||
|                 merchant_account, |                 merchant_account, | ||||||
|  |                 self.request.payment_method_type.clone(), | ||||||
|             ) |             ) | ||||||
|             .await?; |             .await?; | ||||||
|  |  | ||||||
|  | |||||||
| @ -67,6 +67,7 @@ impl Feature<api::Verify, types::VerifyRequestData> for types::VerifyRouterData | |||||||
|             resp.to_owned(), |             resp.to_owned(), | ||||||
|             maybe_customer, |             maybe_customer, | ||||||
|             merchant_account, |             merchant_account, | ||||||
|  |             self.request.payment_method_type.clone(), | ||||||
|         ) |         ) | ||||||
|         .await?; |         .await?; | ||||||
|  |  | ||||||
| @ -177,12 +178,14 @@ impl types::VerifyRouterData { | |||||||
|                 .await |                 .await | ||||||
|                 .to_verify_failed_response()?; |                 .to_verify_failed_response()?; | ||||||
|  |  | ||||||
|  |                 let payment_method_type = self.request.payment_method_type.clone(); | ||||||
|                 let pm_id = tokenization::save_payment_method( |                 let pm_id = tokenization::save_payment_method( | ||||||
|                     state, |                     state, | ||||||
|                     connector, |                     connector, | ||||||
|                     resp.to_owned(), |                     resp.to_owned(), | ||||||
|                     maybe_customer, |                     maybe_customer, | ||||||
|                     merchant_account, |                     merchant_account, | ||||||
|  |                     payment_method_type, | ||||||
|                 ) |                 ) | ||||||
|                 .await?; |                 .await?; | ||||||
|  |  | ||||||
|  | |||||||
| @ -729,13 +729,14 @@ where | |||||||
|  |  | ||||||
| #[instrument(skip_all)] | #[instrument(skip_all)] | ||||||
| pub(crate) async fn get_payment_method_create_request( | pub(crate) async fn get_payment_method_create_request( | ||||||
|     payment_method: Option<&api::PaymentMethodData>, |     payment_method_data: Option<&api::PaymentMethodData>, | ||||||
|     payment_method_type: Option<storage_enums::PaymentMethod>, |     payment_method: Option<storage_enums::PaymentMethod>, | ||||||
|  |     payment_method_type: Option<storage_enums::PaymentMethodType>, | ||||||
|     customer: &domain::Customer, |     customer: &domain::Customer, | ||||||
| ) -> RouterResult<api::PaymentMethodCreate> { | ) -> RouterResult<api::PaymentMethodCreate> { | ||||||
|     match payment_method { |     match payment_method_data { | ||||||
|         Some(pm_data) => match payment_method_type { |         Some(pm_data) => match payment_method { | ||||||
|             Some(payment_method_type) => match pm_data { |             Some(payment_method) => match pm_data { | ||||||
|                 api::PaymentMethodData::Card(card) => { |                 api::PaymentMethodData::Card(card) => { | ||||||
|                     let card_detail = api::CardDetail { |                     let card_detail = api::CardDetail { | ||||||
|                         card_number: card.card_number.clone(), |                         card_number: card.card_number.clone(), | ||||||
| @ -745,8 +746,8 @@ pub(crate) async fn get_payment_method_create_request( | |||||||
|                     }; |                     }; | ||||||
|                     let customer_id = customer.customer_id.clone(); |                     let customer_id = customer.customer_id.clone(); | ||||||
|                     let payment_method_request = api::PaymentMethodCreate { |                     let payment_method_request = api::PaymentMethodCreate { | ||||||
|                         payment_method: payment_method_type.foreign_into(), |                         payment_method: payment_method.foreign_into(), | ||||||
|                         payment_method_type: None, |                         payment_method_type: payment_method_type.map(ForeignInto::foreign_into), | ||||||
|                         payment_method_issuer: card.card_issuer.clone(), |                         payment_method_issuer: card.card_issuer.clone(), | ||||||
|                         payment_method_issuer_code: None, |                         payment_method_issuer_code: None, | ||||||
|                         card: Some(card_detail), |                         card: Some(card_detail), | ||||||
| @ -761,8 +762,8 @@ pub(crate) async fn get_payment_method_create_request( | |||||||
|                 } |                 } | ||||||
|                 _ => { |                 _ => { | ||||||
|                     let payment_method_request = api::PaymentMethodCreate { |                     let payment_method_request = api::PaymentMethodCreate { | ||||||
|                         payment_method: payment_method_type.foreign_into(), |                         payment_method: payment_method.foreign_into(), | ||||||
|                         payment_method_type: None, |                         payment_method_type: payment_method_type.map(ForeignInto::foreign_into), | ||||||
|                         payment_method_issuer: None, |                         payment_method_issuer: None, | ||||||
|                         payment_method_issuer_code: None, |                         payment_method_issuer_code: None, | ||||||
|                         card: None, |                         card: None, | ||||||
|  | |||||||
| @ -15,6 +15,7 @@ use crate::{ | |||||||
|         self, |         self, | ||||||
|         api::{self, PaymentMethodCreateExt}, |         api::{self, PaymentMethodCreateExt}, | ||||||
|         domain, |         domain, | ||||||
|  |         storage::enums as storage_enums, | ||||||
|     }, |     }, | ||||||
|     utils::OptionExt, |     utils::OptionExt, | ||||||
| }; | }; | ||||||
| @ -25,6 +26,7 @@ pub async fn save_payment_method<F: Clone, FData>( | |||||||
|     resp: types::RouterData<F, FData, types::PaymentsResponseData>, |     resp: types::RouterData<F, FData, types::PaymentsResponseData>, | ||||||
|     maybe_customer: &Option<domain::Customer>, |     maybe_customer: &Option<domain::Customer>, | ||||||
|     merchant_account: &domain::MerchantAccount, |     merchant_account: &domain::MerchantAccount, | ||||||
|  |     payment_method_type: Option<storage_enums::PaymentMethodType>, | ||||||
| ) -> RouterResult<Option<String>> | ) -> RouterResult<Option<String>> | ||||||
| where | where | ||||||
|     FData: mandate::MandateBehaviour, |     FData: mandate::MandateBehaviour, | ||||||
| @ -53,6 +55,7 @@ where | |||||||
|         let payment_method_create_request = helpers::get_payment_method_create_request( |         let payment_method_create_request = helpers::get_payment_method_create_request( | ||||||
|             Some(&resp.request.get_payment_method_data()), |             Some(&resp.request.get_payment_method_data()), | ||||||
|             Some(resp.payment_method), |             Some(resp.payment_method), | ||||||
|  |             payment_method_type, | ||||||
|             &customer, |             &customer, | ||||||
|         ) |         ) | ||||||
|         .await?; |         .await?; | ||||||
|  | |||||||
| @ -885,6 +885,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::VerifyRequestDat | |||||||
|             router_return_url, |             router_return_url, | ||||||
|             email: payment_data.email, |             email: payment_data.email, | ||||||
|             return_url: payment_data.payment_intent.return_url, |             return_url: payment_data.payment_intent.return_url, | ||||||
|  |             payment_method_type: attempt.payment_method_type.clone(), | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -339,6 +339,7 @@ pub struct VerifyRequestData { | |||||||
|     pub router_return_url: Option<String>, |     pub router_return_url: Option<String>, | ||||||
|     pub email: Option<Email>, |     pub email: Option<Email>, | ||||||
|     pub return_url: Option<String>, |     pub return_url: Option<String>, | ||||||
|  |     pub payment_method_type: Option<storage_enums::PaymentMethodType>, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Debug, Clone)] | #[derive(Debug, Clone)] | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Pa1NarK
					Pa1NarK