mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	feat(rapyd): ApplePay and GooglePay integration (#425)
This commit is contained in:
		| @ -11,6 +11,7 @@ use crate::{ | |||||||
|         storage::enums, |         storage::enums, | ||||||
|         transformers::{self, ForeignFrom}, |         transformers::{self, ForeignFrom}, | ||||||
|     }, |     }, | ||||||
|  |     utils::OptionExt, | ||||||
| }; | }; | ||||||
|  |  | ||||||
| #[derive(Default, Debug, Serialize)] | #[derive(Default, Debug, Serialize)] | ||||||
| @ -18,8 +19,9 @@ pub struct RapydPaymentsRequest { | |||||||
|     pub amount: i64, |     pub amount: i64, | ||||||
|     pub currency: enums::Currency, |     pub currency: enums::Currency, | ||||||
|     pub payment_method: PaymentMethod, |     pub payment_method: PaymentMethod, | ||||||
|     pub payment_method_options: PaymentMethodOptions, |     pub payment_method_options: Option<PaymentMethodOptions>, | ||||||
|     pub capture: bool, |     pub capture: Option<bool>, | ||||||
|  |     pub description: Option<String>, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Default, Debug, Serialize)] | #[derive(Default, Debug, Serialize)] | ||||||
| @ -31,7 +33,9 @@ pub struct PaymentMethodOptions { | |||||||
| pub struct PaymentMethod { | pub struct PaymentMethod { | ||||||
|     #[serde(rename = "type")] |     #[serde(rename = "type")] | ||||||
|     pub pm_type: String, |     pub pm_type: String, | ||||||
|     pub fields: PaymentFields, |     pub fields: Option<PaymentFields>, | ||||||
|  |     pub address: Option<Address>, | ||||||
|  |     pub digital_wallet: Option<RapydWallet>, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Default, Debug, Serialize)] | #[derive(Default, Debug, Serialize)] | ||||||
| @ -43,38 +47,94 @@ pub struct PaymentFields { | |||||||
|     pub cvv: Secret<String>, |     pub cvv: Secret<String>, | ||||||
| } | } | ||||||
|  |  | ||||||
|  | #[derive(Default, Debug, Serialize)] | ||||||
|  | pub struct Address { | ||||||
|  |     name: String, | ||||||
|  |     line_1: String, | ||||||
|  |     line_2: Option<String>, | ||||||
|  |     line_3: Option<String>, | ||||||
|  |     city: Option<String>, | ||||||
|  |     state: Option<String>, | ||||||
|  |     country: Option<String>, | ||||||
|  |     zip: Option<String>, | ||||||
|  |     phone_number: Option<String>, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #[derive(Debug, Clone, Serialize, Deserialize)] | ||||||
|  | pub struct RapydWallet { | ||||||
|  |     #[serde(rename = "type")] | ||||||
|  |     payment_type: String, | ||||||
|  |     #[serde(rename = "details")] | ||||||
|  |     apple_pay_token: Option<String>, | ||||||
|  | } | ||||||
|  |  | ||||||
| impl TryFrom<&types::PaymentsAuthorizeRouterData> for RapydPaymentsRequest { | impl TryFrom<&types::PaymentsAuthorizeRouterData> for RapydPaymentsRequest { | ||||||
|     type Error = error_stack::Report<errors::ConnectorError>; |     type Error = error_stack::Report<errors::ConnectorError>; | ||||||
|     fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result<Self, Self::Error> { |     fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result<Self, Self::Error> { | ||||||
|         match item.request.payment_method_data { |         let (capture, payment_method_options) = match item.payment_method { | ||||||
|  |             storage_models::enums::PaymentMethodType::Card => { | ||||||
|  |                 let three_ds_enabled = matches!(item.auth_type, enums::AuthenticationType::ThreeDs); | ||||||
|  |                 let payment_method_options = PaymentMethodOptions { | ||||||
|  |                     three_ds: three_ds_enabled, | ||||||
|  |                 }; | ||||||
|  |                 ( | ||||||
|  |                     Some(matches!( | ||||||
|  |                         item.request.capture_method, | ||||||
|  |                         Some(enums::CaptureMethod::Automatic) | None | ||||||
|  |                     )), | ||||||
|  |                     Some(payment_method_options), | ||||||
|  |                 ) | ||||||
|  |             } | ||||||
|  |             _ => (None, None), | ||||||
|  |         }; | ||||||
|  |         let payment_method = match item.request.payment_method_data { | ||||||
|             api_models::payments::PaymentMethod::Card(ref ccard) => { |             api_models::payments::PaymentMethod::Card(ref ccard) => { | ||||||
|                 let payment_method = PaymentMethod { |                 Some(PaymentMethod { | ||||||
|                     pm_type: "in_amex_card".to_owned(), //[#369] Map payment method type based on country |                     pm_type: "in_amex_card".to_owned(), //[#369] Map payment method type based on country | ||||||
|                     fields: PaymentFields { |                     fields: Some(PaymentFields { | ||||||
|                         number: ccard.card_number.to_owned(), |                         number: ccard.card_number.to_owned(), | ||||||
|                         expiration_month: ccard.card_exp_month.to_owned(), |                         expiration_month: ccard.card_exp_month.to_owned(), | ||||||
|                         expiration_year: ccard.card_exp_year.to_owned(), |                         expiration_year: ccard.card_exp_year.to_owned(), | ||||||
|                         name: ccard.card_holder_name.to_owned(), |                         name: ccard.card_holder_name.to_owned(), | ||||||
|                         cvv: ccard.card_cvc.to_owned(), |                         cvv: ccard.card_cvc.to_owned(), | ||||||
|                     }, |                     }), | ||||||
|                 }; |                     address: None, | ||||||
|                 let three_ds_enabled = matches!(item.auth_type, enums::AuthenticationType::ThreeDs); |                     digital_wallet: None, | ||||||
|                 let payment_method_options = PaymentMethodOptions { |  | ||||||
|                     three_ds: three_ds_enabled, |  | ||||||
|                 }; |  | ||||||
|                 Ok(Self { |  | ||||||
|                     amount: item.request.amount, |  | ||||||
|                     currency: item.request.currency, |  | ||||||
|                     payment_method, |  | ||||||
|                     capture: matches!( |  | ||||||
|                         item.request.capture_method, |  | ||||||
|                         Some(enums::CaptureMethod::Automatic) | None |  | ||||||
|                     ), |  | ||||||
|                     payment_method_options, |  | ||||||
|                 }) |                 }) | ||||||
|             } |             } | ||||||
|             _ => Err(errors::ConnectorError::NotImplemented("Payment methods".to_string()).into()), |             api_models::payments::PaymentMethod::Wallet(ref wallet_data) => { | ||||||
|  |                 let digital_wallet = match wallet_data.issuer_name { | ||||||
|  |                     api_models::enums::WalletIssuer::GooglePay => Some(RapydWallet { | ||||||
|  |                         payment_type: "google_pay".to_string(), | ||||||
|  |                         apple_pay_token: wallet_data.token.to_owned(), | ||||||
|  |                     }), | ||||||
|  |                     api_models::enums::WalletIssuer::ApplePay => Some(RapydWallet { | ||||||
|  |                         payment_type: "apple_pay".to_string(), | ||||||
|  |                         apple_pay_token: wallet_data.token.to_owned(), | ||||||
|  |                     }), | ||||||
|  |                     _ => None, | ||||||
|  |                 }; | ||||||
|  |                 Some(PaymentMethod { | ||||||
|  |                     pm_type: "by_visa_card".to_string(), //[#369] | ||||||
|  |                     fields: None, | ||||||
|  |                     address: None, | ||||||
|  |                     digital_wallet, | ||||||
|  |                 }) | ||||||
|  |             } | ||||||
|  |             _ => None, | ||||||
|         } |         } | ||||||
|  |         .get_required_value("payment_method not implemnted") | ||||||
|  |         .change_context(errors::ConnectorError::NotImplemented( | ||||||
|  |             "payment_method".to_owned(), | ||||||
|  |         ))?; | ||||||
|  |         Ok(Self { | ||||||
|  |             amount: item.request.amount, | ||||||
|  |             currency: item.request.currency, | ||||||
|  |             payment_method, | ||||||
|  |             capture, | ||||||
|  |             payment_method_options, | ||||||
|  |             description: None, | ||||||
|  |         }) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Manoj Ghorela
					Manoj Ghorela