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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(connector): apple pay not working because of payment_method_type[] field stripe (#1759)
Hrithikesh039a85977b64
diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rsindex 3edcdecb35..45f7ffcd0f 100644--- a/crates/router/src/connector/stripe/transformers.rs+++ b/crates/router/src/connector/stripe/transformers.rs@@ -342,7 +342,7 @@ pub enum StripeCreditTransferSourceRequest {#[derive(Debug, Eq, PartialEq, Serialize)]pub struct AchCreditTransferSourceRequest {#[serde(rename = "type")]- pub transfer_type: StripePaymentMethodType,+ pub transfer_type: StripeCreditTransferTypes,#[serde(flatten)]pub payment_method_data: AchTransferData,pub currency: enums::Currency,@@ -351,7 +351,7 @@ pub struct AchCreditTransferSourceRequest {#[derive(Debug, Eq, PartialEq, Serialize)]pub struct MultibancoCreditTransferSourceRequest {#[serde(rename = "type")]- pub transfer_type: StripePaymentMethodType,+ pub transfer_type: StripeCreditTransferTypes,#[serde(flatten)]pub payment_method_data: MultibancoTransferData,pub currency: enums::Currency,@@ -487,34 +487,43 @@ pub struct GooglepayPayment {pub payment_method_types: StripePaymentMethodType,}-#[derive(Debug, Eq, PartialEq, Serialize, Clone, Copy)]+// All supported payment_method_types in stripe+// This enum goes in payment_method_types[] field in stripe request body+// https://stripe.com/docs/api/payment_intents/create#create_payment_intent-payment_method_types+#[derive(Eq, PartialEq, Serialize, Clone, Debug, Copy)]#[serde(rename_all = "snake_case")]pub enum StripePaymentMethodType {- Card,- Klarna,Affirm,AfterpayClearpay,+ Alipay,+ #[serde(rename = "au_becs_debit")]+ Becs,+ #[serde(rename = "bacs_debit")]+ Bacs,+ Bancontact,+ Blik,+ Card,+ CustomerBalance,Eps,Giropay,Ideal,+ Klarna,+ #[serde(rename = "p24")]+ Przelewy24,+ #[serde(rename = "sepa_debit")]+ Sepa,Sofort,- AchCreditTransfer,- ApplePay,#[serde(rename = "us_bank_account")]Ach,- #[serde(rename = "sepa_debit")]- Sepa,- #[serde(rename = "au_becs_debit")]- Becs,- #[serde(rename = "bacs_debit")]- Bacs,- Bancontact,#[serde(rename = "wechat_pay")]Wechatpay,- Alipay,- #[serde(rename = "p24")]- Przelewy24,- CustomerBalance,+}++#[derive(Debug, Eq, PartialEq, Serialize)]+#[serde(rename_all = "snake_case")]+#[allow(dead_code)]+pub enum StripeCreditTransferTypes {+ AchCreditTransfer,Multibanco,Blik,}@@ -532,7 +541,7 @@ impl TryFrom<enums::PaymentMethodType> for StripePaymentMethodType {enums::PaymentMethodType::Giropay => Ok(Self::Giropay),enums::PaymentMethodType::Ideal => Ok(Self::Ideal),enums::PaymentMethodType::Sofort => Ok(Self::Sofort),- enums::PaymentMethodType::ApplePay => Ok(Self::ApplePay),+ enums::PaymentMethodType::ApplePay => Ok(Self::Card),enums::PaymentMethodType::Ach => Ok(Self::Ach),enums::PaymentMethodType::Sepa => Ok(Self::Sepa),enums::PaymentMethodType::Becs => Ok(Self::Becs),@@ -741,9 +750,9 @@ impl TryFrom<&api_models::enums::BankNames> for StripeBankNames {fn validate_shipping_address_against_payment_method(shipping_address: &StripeShippingAddress,- payment_method: &StripePaymentMethodType,+ payment_method: Option<&StripePaymentMethodType>,) -> Result<(), error_stack::Report<errors::ConnectorError>> {- if let StripePaymentMethodType::AfterpayClearpay = payment_method {+ if let Some(StripePaymentMethodType::AfterpayClearpay) = payment_method {let missing_fields = collect_missing_value_keys!(("shipping.address.first_name", shipping_address.name),("shipping.address.line1", shipping_address.line1),@@ -1040,7 +1049,7 @@ fn create_stripe_payment_method() -> Result<(StripePaymentMethodData,- StripePaymentMethodType,+ Option<StripePaymentMethodType>,StripeBillingAddress,),error_stack::Report<errors::ConnectorError>,@@ -1060,7 +1069,7 @@ fn create_stripe_payment_method(payment_method_data_card_cvc: card_details.card_cvc.clone(),payment_method_auth_type,}),- StripePaymentMethodType::Card,+ Some(StripePaymentMethodType::Card),StripeBillingAddress::default(),))}@@ -1081,7 +1090,7 @@ fn create_stripe_payment_method(StripePaymentMethodData::PayLater(StripePayLaterData {payment_method_data_type: stripe_pm_type,}),- stripe_pm_type,+ Some(stripe_pm_type),billing_address,))}@@ -1102,7 +1111,7 @@ fn create_stripe_payment_method(bank_specific_data,code: blik_code,}),- pm_type,+ Some(pm_type),billing_address,))}@@ -1116,7 +1125,7 @@ fn create_stripe_payment_method(pk_token_payment_network: applepay_data.payment_method.network.to_owned(),pk_token_transaction_id: applepay_data.transaction_identifier.to_owned(),})),- StripePaymentMethodType::ApplePay,+ None,StripeBillingAddress::default(),)),payments::WalletData::WeChatPay(_) => Ok((@@ -1124,19 +1133,19 @@ fn create_stripe_payment_method(client: WechatClient::Web,payment_method_data_type: StripePaymentMethodType::Wechatpay,})),- StripePaymentMethodType::Wechatpay,+ Some(StripePaymentMethodType::Wechatpay),StripeBillingAddress::default(),)),payments::WalletData::AliPayRedirect(_) => Ok((StripePaymentMethodData::Wallet(StripeWallet::AlipayPayment(AlipayPayment {payment_method_data_type: StripePaymentMethodType::Alipay,})),- StripePaymentMethodType::Alipay,+ Some(StripePaymentMethodType::Alipay),StripeBillingAddress::default(),)),payments::WalletData::GooglePay(gpay_data) => Ok((StripePaymentMethodData::try_from(gpay_data)?,- StripePaymentMethodType::Card,+ Some(StripePaymentMethodType::Card),StripeBillingAddress::default(),)),_ => Err(errors::ConnectorError::NotImplemented(@@ -1151,7 +1160,7 @@ fn create_stripe_payment_method(bank_specific_data: bank_debit_data,});- Ok((pm_data, pm_type, billing_address))+ Ok((pm_data, Some(pm_type), billing_address))}payments::PaymentMethodData::BankTransfer(bank_transfer_data) => {match bank_transfer_data.deref() {@@ -1161,7 +1170,7 @@ fn create_stripe_payment_method(email: billing_details.email.to_owned(),}),)),- StripePaymentMethodType::AchCreditTransfer,+ None,StripeBillingAddress::default(),)),payments::BankTransferData::MultibancoBankTransfer { billing_details } => Ok((@@ -1172,7 +1181,7 @@ fn create_stripe_payment_method(},)),),- StripePaymentMethodType::Multibanco,+ None,StripeBillingAddress::default(),)),payments::BankTransferData::SepaBankTransfer {@@ -1197,7 +1206,7 @@ fn create_stripe_payment_method(},)),),- StripePaymentMethodType::CustomerBalance,+ Some(StripePaymentMethodType::CustomerBalance),billing_details,))}@@ -1219,7 +1228,7 @@ fn create_stripe_payment_method(},)),),- StripePaymentMethodType::CustomerBalance,+ Some(StripePaymentMethodType::CustomerBalance),billing_details,))}@@ -1261,7 +1270,10 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaymentIntentRequest {Some(mut shipping) => StripeShippingAddress {city: shipping.address.as_mut().and_then(|a| a.city.take()),country: shipping.address.as_mut().and_then(|a| a.country.take()),- line1: shipping.address.as_mut().and_then(|a| a.line1.take()),+ line1: shipping+ .address+ .as_mut()+ .and_then(|a: &mut payments::AddressDetails| a.line1.take()),line2: shipping.address.as_mut().and_then(|a| a.line2.take()),zip: shipping.address.as_mut().and_then(|a| a.zip.take()),state: shipping.address.as_mut().and_then(|a| a.state.take()),@@ -1302,7 +1314,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaymentIntentRequest {connector_mandate_ids.payment_method_id,connector_mandate_ids.connector_mandate_id,StripeBillingAddress::default(),- None,+ get_payment_method_type_for_saved_payment_method_payment(item)?,),Some(api_models::payments::MandateReferenceId::NetworkMandateId(network_transaction_id,@@ -1327,7 +1339,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaymentIntentRequest {validate_shipping_address_against_payment_method(&shipping_address,- &payment_method_type,+ payment_method_type.as_ref(),)?;(@@ -1335,21 +1347,12 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaymentIntentRequest {None,None,billing_address,- Some(payment_method_type),+ payment_method_type,)}}};- //if payment_method is Some(), That means, it is a recurring mandate payment.- //payment_method_types will not be not be available in router_data.request. But stripe requires that field.- //here we will get that field from router_data.recurring_mandate_payment_data- let payment_method_types = if payment_method.is_some() {- //if recurring payment get payment_method_type- get_payment_method_type_for_saved_payment_method_payment(item)?- } else {- payment_method_types- };payment_data = match item.request.payment_method_data {payments::PaymentMethodData::Wallet(payments::WalletData::ApplePay(_)) => Some(StripePaymentMethodData::Wallet(StripeWallet::ApplepayPayment(ApplepayPayment {@@ -2440,7 +2443,7 @@ impl TryFrom<&types::PaymentsPreProcessingRouterData> for StripeCreditTransferSomatch **bank_transfer_data {payments::BankTransferData::MultibancoBankTransfer { .. } => Ok(Self::MultibancoBankTansfer(MultibancoCreditTransferSourceRequest {- transfer_type: StripePaymentMethodType::Multibanco,+ transfer_type: StripeCreditTransferTypes::Multibanco,currency,payment_method_data: MultibancoTransferData {email: item.request.get_email()?,@@ -2451,7 +2454,7 @@ impl TryFrom<&types::PaymentsPreProcessingRouterData> for StripeCreditTransferSo),payments::BankTransferData::AchBankTransfer { .. } => {Ok(Self::AchBankTansfer(AchCreditTransferSourceRequest {- transfer_type: StripePaymentMethodType::AchCreditTransfer,+ transfer_type: StripeCreditTransferTypes::AchCreditTransfer,payment_method_data: AchTransferData {email: item.request.get_email()?,},@@ -3124,7 +3127,7 @@ mod test_validate_shipping_address_against_payment_method {//Actlet result = validate_shipping_address_against_payment_method(&stripe_shipping_address,- payment_method,+ Some(payment_method),);// Assert@@ -3146,7 +3149,7 @@ mod test_validate_shipping_address_against_payment_method {//Actlet result = validate_shipping_address_against_payment_method(&stripe_shipping_address,- payment_method,+ Some(payment_method),);// Assert@@ -3171,7 +3174,7 @@ mod test_validate_shipping_address_against_payment_method {//Actlet result = validate_shipping_address_against_payment_method(&stripe_shipping_address,- payment_method,+ Some(payment_method),);// Assert@@ -3196,7 +3199,7 @@ mod test_validate_shipping_address_against_payment_method {//Actlet result = validate_shipping_address_against_payment_method(&stripe_shipping_address,- payment_method,+ Some(payment_method),);// Assert@@ -3220,7 +3223,7 @@ mod test_validate_shipping_address_against_payment_method {//Actlet result = validate_shipping_address_against_payment_method(&stripe_shipping_address,- payment_method,+ Some(payment_method),);// Assert@@ -3246,7 +3249,7 @@ mod test_validate_shipping_address_against_payment_method {//Actlet result = validate_shipping_address_against_payment_method(&stripe_shipping_address,- payment_method,+ Some(payment_method),);// Assert