diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.json index 0dfd749ec5..61cf7b26ac 100644 --- a/api-reference-v2/openapi_spec.json +++ b/api-reference-v2/openapi_spec.json @@ -15184,6 +15184,7 @@ "type": "object", "required": [ "payment_method_type", + "payment_method_subtype", "customer_id", "payment_method_data" ], @@ -15192,12 +15193,7 @@ "$ref": "#/components/schemas/PaymentMethod" }, "payment_method_subtype": { - "allOf": [ - { - "$ref": "#/components/schemas/PaymentMethodType" - } - ], - "nullable": true + "$ref": "#/components/schemas/PaymentMethodType" }, "metadata": { "type": "object", @@ -16664,7 +16660,8 @@ "description": "Request for Payment Intent Confirm", "required": [ "payment_method_data", - "payment_method_type" + "payment_method_type", + "payment_method_subtype" ], "properties": { "return_url": { @@ -16680,12 +16677,7 @@ "$ref": "#/components/schemas/PaymentMethod" }, "payment_method_subtype": { - "allOf": [ - { - "$ref": "#/components/schemas/PaymentMethodType" - } - ], - "nullable": true + "$ref": "#/components/schemas/PaymentMethodType" }, "shipping": { "allOf": [ @@ -17473,7 +17465,8 @@ "amount_details", "customer_id", "payment_method_data", - "payment_method_type" + "payment_method_type", + "payment_method_subtype" ], "properties": { "amount_details": { @@ -17665,12 +17658,7 @@ "$ref": "#/components/schemas/PaymentMethod" }, "payment_method_subtype": { - "allOf": [ - { - "$ref": "#/components/schemas/PaymentMethodType" - } - ], - "nullable": true + "$ref": "#/components/schemas/PaymentMethodType" }, "customer_acceptance": { "allOf": [ diff --git a/crates/api_models/src/payment_methods.rs b/crates/api_models/src/payment_methods.rs index 3590537a08..4313d22401 100644 --- a/crates/api_models/src/payment_methods.rs +++ b/crates/api_models/src/payment_methods.rs @@ -116,8 +116,8 @@ pub struct PaymentMethodCreate { pub payment_method_type: api_enums::PaymentMethod, /// This is a sub-category of payment method. - #[schema(value_type = Option,example = "credit")] - pub payment_method_subtype: Option, + #[schema(value_type = PaymentMethodType,example = "google_pay")] + pub payment_method_subtype: api_enums::PaymentMethodType, /// You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object. #[schema(value_type = Option,example = json!({ "city": "NY", "unit": "245" }))] @@ -2806,8 +2806,8 @@ pub struct PaymentMethodSessionConfirmRequest { pub payment_method_type: common_enums::PaymentMethod, /// The payment method subtype - #[schema(value_type = PaymentMethodType, example = "credit")] - pub payment_method_subtype: Option, + #[schema(value_type = PaymentMethodType, example = "google_pay")] + pub payment_method_subtype: common_enums::PaymentMethodType, /// The payment instrument data to be used for the payment #[schema(value_type = PaymentMethodDataRequest)] diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index 724204022d..859dba9b59 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -5259,8 +5259,8 @@ pub struct PaymentsConfirmIntentRequest { pub payment_method_type: api_enums::PaymentMethod, /// The payment method subtype to be used for the payment. This should match with the `payment_method_data` provided - #[schema(value_type = Option, example = "apple_pay")] - pub payment_method_subtype: Option, + #[schema(value_type = PaymentMethodType, example = "apple_pay")] + pub payment_method_subtype: api_enums::PaymentMethodType, /// The shipping address for the payment. This will override the shipping address provided in the create-intent request pub shipping: Option
, @@ -5428,8 +5428,8 @@ pub struct PaymentsRequest { pub payment_method_type: api_enums::PaymentMethod, /// The payment method subtype to be used for the payment. This should match with the `payment_method_data` provided - #[schema(value_type = Option, example = "apple_pay")] - pub payment_method_subtype: Option, + #[schema(value_type = PaymentMethodType, example = "apple_pay")] + pub payment_method_subtype: api_enums::PaymentMethodType, /// This "CustomerAcceptance" object is passed during Payments-Confirm request, it enlists the type, time, and mode of acceptance properties related to an acceptance done by the customer. The customer_acceptance sub object is usually passed by the SDK or client. #[schema(value_type = Option)] @@ -8522,7 +8522,7 @@ pub struct PaymentRevenueRecoveryMetadata { pub payment_method_type: common_enums::PaymentMethod, /// PaymentMethod Subtype #[schema(example = "klarna", value_type = PaymentMethodType)] - pub payment_method_subtype: Option, + pub payment_method_subtype: common_enums::PaymentMethodType, /// The name of the payment connector through which the payment attempt was made. #[schema(value_type = Connector, example = "stripe")] pub connector: common_enums::connector_enums::Connector, @@ -8603,7 +8603,7 @@ pub struct PaymentsAttemptRecordRequest { /// The payment method subtype to be used for the payment. This should match with the `payment_method_data` provided #[schema(value_type = PaymentMethodType, example = "apple_pay")] - pub payment_method_subtype: Option, + pub payment_method_subtype: api_enums::PaymentMethodType, /// The payment instrument data to be used for the payment attempt. pub payment_method_data: Option, diff --git a/crates/common_enums/Cargo.toml b/crates/common_enums/Cargo.toml index 5db5393644..6f2d96a583 100644 --- a/crates/common_enums/Cargo.toml +++ b/crates/common_enums/Cargo.toml @@ -11,6 +11,7 @@ license.workspace = true dummy_connector = [] openapi = [] payouts = [] +v2 = [] [dependencies] diesel = { version = "2.2.3", features = ["postgres", "128-column-tables"] } diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs index 1697b1386c..ca3968ed64 100644 --- a/crates/common_enums/src/enums.rs +++ b/crates/common_enums/src/enums.rs @@ -1755,6 +1755,8 @@ pub enum PaymentMethodType { BcaBankTransfer, BniVa, BriVa, + #[cfg(feature = "v2")] + Card, CardRedirect, CimbVa, #[serde(rename = "classic")] @@ -1867,6 +1869,8 @@ impl PaymentMethodType { Self::CardRedirect => "Card Redirect", Self::CimbVa => "CIMB Virtual Account", Self::ClassicReward => "Classic Reward", + #[cfg(feature = "v2")] + Self::Card => "Card", Self::Credit => "Credit Card", Self::CryptoCurrency => "Crypto", Self::Cashapp => "Cash App", diff --git a/crates/common_enums/src/transformers.rs b/crates/common_enums/src/transformers.rs index 6ff3bad4ad..2a130edbd8 100644 --- a/crates/common_enums/src/transformers.rs +++ b/crates/common_enums/src/transformers.rs @@ -1815,6 +1815,8 @@ impl From for PaymentMethod { PaymentMethodType::CimbVa => Self::BankTransfer, PaymentMethodType::ClassicReward => Self::Reward, PaymentMethodType::Credit => Self::Card, + #[cfg(feature = "v2")] + PaymentMethodType::Card => Self::Card, PaymentMethodType::CryptoCurrency => Self::Crypto, PaymentMethodType::Dana => Self::Wallet, PaymentMethodType::DanamonVa => Self::BankTransfer, diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs index 33b51ebdf9..a3599fc1b4 100644 --- a/crates/diesel_models/src/payment_attempt.rs +++ b/crates/diesel_models/src/payment_attempt.rs @@ -91,7 +91,7 @@ pub struct PaymentAttempt { pub charges: Option, pub payment_method_type_v2: storage_enums::PaymentMethod, pub connector_payment_id: Option, - pub payment_method_subtype: Option, + pub payment_method_subtype: storage_enums::PaymentMethodType, pub routing_result: Option, pub authentication_applied: Option, pub external_reference_id: Option, @@ -322,7 +322,7 @@ pub struct PaymentAttemptNew { pub feature_metadata: Option, pub payment_method_type_v2: storage_enums::PaymentMethod, pub connector_payment_id: Option, - pub payment_method_subtype: Option, + pub payment_method_subtype: storage_enums::PaymentMethodType, pub id: id_type::GlobalAttemptId, pub connector_token_details: Option, pub card_discovery: Option, diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs index 3481dc5e7f..d63f6295ea 100644 --- a/crates/diesel_models/src/schema_v2.rs +++ b/crates/diesel_models/src/schema_v2.rs @@ -878,7 +878,7 @@ diesel::table! { #[max_length = 128] connector_payment_id -> Nullable, #[max_length = 64] - payment_method_subtype -> Nullable, + payment_method_subtype -> Varchar, routing_result -> Nullable, authentication_applied -> Nullable, #[max_length = 128] diff --git a/crates/diesel_models/src/types.rs b/crates/diesel_models/src/types.rs index dc69c0a323..2314d2bf4c 100644 --- a/crates/diesel_models/src/types.rs +++ b/crates/diesel_models/src/types.rs @@ -63,7 +63,7 @@ impl FeatureMetadata { pub fn get_payment_method_sub_type(&self) -> Option { self.payment_revenue_recovery_metadata .as_ref() - .and_then(|val| val.payment_method_subtype) + .map(|rrm| rrm.payment_method_subtype) } pub fn get_payment_method_type(&self) -> Option { @@ -168,7 +168,7 @@ pub struct PaymentRevenueRecoveryMetadata { ///Payment Method Type pub payment_method_type: common_enums::enums::PaymentMethod, /// PaymentMethod Subtype - pub payment_method_subtype: Option, + pub payment_method_subtype: common_enums::enums::PaymentMethodType, /// The name of the payment connector through which the payment attempt was made. pub connector: common_enums::connector_enums::Connector, } diff --git a/crates/euclid/Cargo.toml b/crates/euclid/Cargo.toml index 8f1320db23..a607531d87 100644 --- a/crates/euclid/Cargo.toml +++ b/crates/euclid/Cargo.toml @@ -28,6 +28,7 @@ ast_parser = ["dep:nom"] valued_jit = [] dummy_connector = [] payouts = [] +v2 = ["common_enums/v2"] [dev-dependencies] criterion = "0.5" diff --git a/crates/euclid/src/frontend/dir/enums.rs b/crates/euclid/src/frontend/dir/enums.rs index ef7449e1c1..2cf8301417 100644 --- a/crates/euclid/src/frontend/dir/enums.rs +++ b/crates/euclid/src/frontend/dir/enums.rs @@ -27,6 +27,8 @@ pub use crate::enums::{PayoutBankTransferType, PayoutType, PayoutWalletType}; pub enum CardType { Credit, Debit, + #[cfg(feature = "v2")] + Card, } #[derive( diff --git a/crates/euclid/src/frontend/dir/lowering.rs b/crates/euclid/src/frontend/dir/lowering.rs index e58a6e28bd..ace617fb36 100644 --- a/crates/euclid/src/frontend/dir/lowering.rs +++ b/crates/euclid/src/frontend/dir/lowering.rs @@ -16,6 +16,8 @@ impl From for global_enums::PaymentMethodType { match value { enums::CardType::Credit => Self::Credit, enums::CardType::Debit => Self::Debit, + #[cfg(feature = "v2")] + enums::CardType::Card => Self::Card, } } } diff --git a/crates/euclid/src/frontend/dir/transformers.rs b/crates/euclid/src/frontend/dir/transformers.rs index d85c23e248..b4b512b523 100644 --- a/crates/euclid/src/frontend/dir/transformers.rs +++ b/crates/euclid/src/frontend/dir/transformers.rs @@ -8,6 +8,8 @@ impl IntoDirValue for (global_enums::PaymentMethodType, global_enums::PaymentMet match self.0 { global_enums::PaymentMethodType::Credit => Ok(dirval!(CardType = Credit)), global_enums::PaymentMethodType::Debit => Ok(dirval!(CardType = Debit)), + #[cfg(feature = "v2")] + global_enums::PaymentMethodType::Card => Ok(dirval!(CardType = Card)), global_enums::PaymentMethodType::Giropay => Ok(dirval!(BankRedirectType = Giropay)), global_enums::PaymentMethodType::Ideal => Ok(dirval!(BankRedirectType = Ideal)), global_enums::PaymentMethodType::Sofort => Ok(dirval!(BankRedirectType = Sofort)), diff --git a/crates/hyperswitch_connectors/src/connectors/adyen.rs b/crates/hyperswitch_connectors/src/connectors/adyen.rs index 7550fc2677..a9b2352251 100644 --- a/crates/hyperswitch_connectors/src/connectors/adyen.rs +++ b/crates/hyperswitch_connectors/src/connectors/adyen.rs @@ -163,6 +163,7 @@ impl ConnectorValidation for Adyen { let connector = self.id(); match pmt { Some(payment_method_type) => match payment_method_type { + #[cfg(feature = "v1")] PaymentMethodType::Affirm | PaymentMethodType::AfterpayClearpay | PaymentMethodType::ApplePay @@ -187,6 +188,32 @@ impl ConnectorValidation for Adyen { ) } }, + #[cfg(feature = "v2")] + PaymentMethodType::Affirm + | PaymentMethodType::AfterpayClearpay + | PaymentMethodType::ApplePay + | PaymentMethodType::Credit + | PaymentMethodType::Debit + | PaymentMethodType::Card + | PaymentMethodType::GooglePay + | PaymentMethodType::MobilePay + | PaymentMethodType::PayBright + | PaymentMethodType::Sepa + | PaymentMethodType::Vipps + | PaymentMethodType::Venmo + | PaymentMethodType::Paypal => match capture_method { + enums::CaptureMethod::Automatic + | enums::CaptureMethod::SequentialAutomatic + | enums::CaptureMethod::Manual + | enums::CaptureMethod::ManualMultiple => Ok(()), + enums::CaptureMethod::Scheduled => { + capture_method_not_supported!( + connector, + capture_method, + payment_method_type + ) + } + }, PaymentMethodType::Ach | PaymentMethodType::SamsungPay | PaymentMethodType::Paze diff --git a/crates/hyperswitch_connectors/src/connectors/chargebee/transformers.rs b/crates/hyperswitch_connectors/src/connectors/chargebee/transformers.rs index ba523fd623..101a9b753a 100644 --- a/crates/hyperswitch_connectors/src/connectors/chargebee/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/chargebee/transformers.rs @@ -447,9 +447,8 @@ impl TryFrom for revenue_recovery::RevenueRecoveryAttemptD let payment_method_details: ChargebeePaymentMethodDetails = serde_json::from_str(&item.content.transaction.payment_method_details) .change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?; - let payment_method_sub_type = Some(enums::PaymentMethodType::from( - payment_method_details.card.funding_type, - )); + let payment_method_sub_type = + enums::PaymentMethodType::from(payment_method_details.card.funding_type); Ok(Self { amount, currency, diff --git a/crates/hyperswitch_connectors/src/connectors/klarna.rs b/crates/hyperswitch_connectors/src/connectors/klarna.rs index bba7dd7e6a..d2be42a182 100644 --- a/crates/hyperswitch_connectors/src/connectors/klarna.rs +++ b/crates/hyperswitch_connectors/src/connectors/klarna.rs @@ -544,6 +544,7 @@ impl ConnectorIntegration Ok(format!( "{endpoint}payments/v1/authorizations/{token}/order", )), + #[cfg(feature = "v1")] ( common_enums::PaymentExperience::DisplayQrCode | common_enums::PaymentExperience::DisplayWaitScreen @@ -656,14 +657,7 @@ impl ConnectorIntegration { - match (payment_experience, payment_method_type) { - ( - common_enums::PaymentExperience::RedirectToUrl, - common_enums::PaymentMethodType::Klarna, - ) => Ok(format!("{endpoint}checkout/v3/orders",)), + #[cfg(feature = "v2")] ( common_enums::PaymentExperience::DisplayQrCode | common_enums::PaymentExperience::DisplayWaitScreen @@ -697,6 +691,242 @@ impl ConnectorIntegration Err(error_stack::report!(errors::ConnectorError::NotSupported { + message: payment_method_type.to_string(), + connector: "klarna", + })), + } + } + PaymentMethodData::PayLater(PayLaterData::KlarnaRedirect {}) => { + match (payment_experience, payment_method_type) { + ( + common_enums::PaymentExperience::RedirectToUrl, + common_enums::PaymentMethodType::Klarna, + ) => Ok(format!("{endpoint}checkout/v3/orders",)), + #[cfg(feature = "v1")] + ( + common_enums::PaymentExperience::DisplayQrCode + | common_enums::PaymentExperience::DisplayWaitScreen + | common_enums::PaymentExperience::InvokePaymentApp + | common_enums::PaymentExperience::InvokeSdkClient + | common_enums::PaymentExperience::LinkWallet + | common_enums::PaymentExperience::OneClick + | common_enums::PaymentExperience::RedirectToUrl + | common_enums::PaymentExperience::CollectOtp, + common_enums::PaymentMethodType::Ach + | common_enums::PaymentMethodType::Affirm + | common_enums::PaymentMethodType::AfterpayClearpay + | common_enums::PaymentMethodType::Alfamart + | common_enums::PaymentMethodType::AliPay + | common_enums::PaymentMethodType::AliPayHk + | common_enums::PaymentMethodType::Alma + | common_enums::PaymentMethodType::AmazonPay + | common_enums::PaymentMethodType::ApplePay + | common_enums::PaymentMethodType::Atome + | common_enums::PaymentMethodType::Bacs + | common_enums::PaymentMethodType::BancontactCard + | common_enums::PaymentMethodType::Becs + | common_enums::PaymentMethodType::Benefit + | common_enums::PaymentMethodType::Bizum + | common_enums::PaymentMethodType::Blik + | common_enums::PaymentMethodType::Boleto + | common_enums::PaymentMethodType::BcaBankTransfer + | common_enums::PaymentMethodType::BniVa + | common_enums::PaymentMethodType::BriVa + | common_enums::PaymentMethodType::CardRedirect + | common_enums::PaymentMethodType::CimbVa + | common_enums::PaymentMethodType::ClassicReward + | common_enums::PaymentMethodType::Credit + | common_enums::PaymentMethodType::CryptoCurrency + | common_enums::PaymentMethodType::Cashapp + | common_enums::PaymentMethodType::Dana + | common_enums::PaymentMethodType::DanamonVa + | common_enums::PaymentMethodType::Debit + | common_enums::PaymentMethodType::DirectCarrierBilling + | common_enums::PaymentMethodType::Efecty + | common_enums::PaymentMethodType::Eft + | common_enums::PaymentMethodType::Eps + | common_enums::PaymentMethodType::Evoucher + | common_enums::PaymentMethodType::Giropay + | common_enums::PaymentMethodType::Givex + | common_enums::PaymentMethodType::GooglePay + | common_enums::PaymentMethodType::GoPay + | common_enums::PaymentMethodType::Gcash + | common_enums::PaymentMethodType::Ideal + | common_enums::PaymentMethodType::Interac + | common_enums::PaymentMethodType::Indomaret + | common_enums::PaymentMethodType::Klarna + | common_enums::PaymentMethodType::KakaoPay + | common_enums::PaymentMethodType::MandiriVa + | common_enums::PaymentMethodType::Knet + | common_enums::PaymentMethodType::MbWay + | common_enums::PaymentMethodType::MobilePay + | common_enums::PaymentMethodType::Momo + | common_enums::PaymentMethodType::MomoAtm + | common_enums::PaymentMethodType::Multibanco + | common_enums::PaymentMethodType::LocalBankRedirect + | common_enums::PaymentMethodType::OnlineBankingThailand + | common_enums::PaymentMethodType::OnlineBankingCzechRepublic + | common_enums::PaymentMethodType::OnlineBankingFinland + | common_enums::PaymentMethodType::OnlineBankingFpx + | common_enums::PaymentMethodType::OnlineBankingPoland + | common_enums::PaymentMethodType::OnlineBankingSlovakia + | common_enums::PaymentMethodType::Oxxo + | common_enums::PaymentMethodType::PagoEfectivo + | common_enums::PaymentMethodType::PermataBankTransfer + | common_enums::PaymentMethodType::OpenBankingUk + | common_enums::PaymentMethodType::PayBright + | common_enums::PaymentMethodType::Paypal + | common_enums::PaymentMethodType::Paze + | common_enums::PaymentMethodType::Pix + | common_enums::PaymentMethodType::PaySafeCard + | common_enums::PaymentMethodType::Przelewy24 + | common_enums::PaymentMethodType::Pse + | common_enums::PaymentMethodType::RedCompra + | common_enums::PaymentMethodType::RedPagos + | common_enums::PaymentMethodType::SamsungPay + | common_enums::PaymentMethodType::Sepa + | common_enums::PaymentMethodType::SepaBankTransfer + | common_enums::PaymentMethodType::Sofort + | common_enums::PaymentMethodType::Swish + | common_enums::PaymentMethodType::TouchNGo + | common_enums::PaymentMethodType::Trustly + | common_enums::PaymentMethodType::Twint + | common_enums::PaymentMethodType::UpiCollect + | common_enums::PaymentMethodType::UpiIntent + | common_enums::PaymentMethodType::Venmo + | common_enums::PaymentMethodType::Vipps + | common_enums::PaymentMethodType::Walley + | common_enums::PaymentMethodType::WeChatPay + | common_enums::PaymentMethodType::SevenEleven + | common_enums::PaymentMethodType::Lawson + | common_enums::PaymentMethodType::LocalBankTransfer + | common_enums::PaymentMethodType::InstantBankTransfer + | common_enums::PaymentMethodType::MiniStop + | common_enums::PaymentMethodType::FamilyMart + | common_enums::PaymentMethodType::Seicomart + | common_enums::PaymentMethodType::PayEasy + | common_enums::PaymentMethodType::Mifinity + | common_enums::PaymentMethodType::Fps + | common_enums::PaymentMethodType::DuitNow + | common_enums::PaymentMethodType::PromptPay + | common_enums::PaymentMethodType::VietQr + | common_enums::PaymentMethodType::OpenBankingPIS, + ) => Err(error_stack::report!(errors::ConnectorError::NotSupported { + message: payment_method_type.to_string(), + connector: "klarna", + })), + #[cfg(feature = "v2")] + ( + common_enums::PaymentExperience::DisplayQrCode + | common_enums::PaymentExperience::DisplayWaitScreen + | common_enums::PaymentExperience::InvokePaymentApp + | common_enums::PaymentExperience::InvokeSdkClient + | common_enums::PaymentExperience::LinkWallet + | common_enums::PaymentExperience::OneClick + | common_enums::PaymentExperience::RedirectToUrl + | common_enums::PaymentExperience::CollectOtp, + common_enums::PaymentMethodType::Ach + | common_enums::PaymentMethodType::Affirm + | common_enums::PaymentMethodType::AfterpayClearpay + | common_enums::PaymentMethodType::Alfamart + | common_enums::PaymentMethodType::AliPay + | common_enums::PaymentMethodType::AliPayHk + | common_enums::PaymentMethodType::Alma + | common_enums::PaymentMethodType::AmazonPay + | common_enums::PaymentMethodType::ApplePay + | common_enums::PaymentMethodType::Atome + | common_enums::PaymentMethodType::Bacs + | common_enums::PaymentMethodType::BancontactCard + | common_enums::PaymentMethodType::Becs + | common_enums::PaymentMethodType::Benefit + | common_enums::PaymentMethodType::Bizum + | common_enums::PaymentMethodType::Blik + | common_enums::PaymentMethodType::Boleto + | common_enums::PaymentMethodType::BcaBankTransfer + | common_enums::PaymentMethodType::BniVa + | common_enums::PaymentMethodType::BriVa + | common_enums::PaymentMethodType::CardRedirect + | common_enums::PaymentMethodType::CimbVa + | common_enums::PaymentMethodType::ClassicReward + | common_enums::PaymentMethodType::Credit + | common_enums::PaymentMethodType::Card | common_enums::PaymentMethodType::CryptoCurrency | common_enums::PaymentMethodType::Cashapp | common_enums::PaymentMethodType::Dana diff --git a/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rs b/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rs index bc5d10620b..fdee202257 100644 --- a/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rs @@ -1117,11 +1117,20 @@ impl TryFrom<&PaypalRouterData<&PaymentsAuthorizeRouterData>> for PaypalPayments )?; let payment_source = match payment_method_type { + #[cfg(feature = "v1")] enums::PaymentMethodType::Credit | enums::PaymentMethodType::Debit => Ok(Some( PaymentSourceItem::Card(CardRequest::CardVaultStruct(VaultStruct { vault_id: connector_mandate_id.into(), })), )), + #[cfg(feature = "v2")] + enums::PaymentMethodType::Credit + | enums::PaymentMethodType::Debit + | enums::PaymentMethodType::Card => Ok(Some(PaymentSourceItem::Card( + CardRequest::CardVaultStruct(VaultStruct { + vault_id: connector_mandate_id.into(), + }), + ))), enums::PaymentMethodType::Paypal => Ok(Some(PaymentSourceItem::Paypal( PaypalRedirectionRequest::PaypalVaultStruct(VaultStruct { vault_id: connector_mandate_id.into(), diff --git a/crates/hyperswitch_domain_models/src/payments.rs b/crates/hyperswitch_domain_models/src/payments.rs index f82480163c..0c8dd08795 100644 --- a/crates/hyperswitch_domain_models/src/payments.rs +++ b/crates/hyperswitch_domain_models/src/payments.rs @@ -290,7 +290,7 @@ impl AmountDetails { let order_tax_amount = match self.skip_external_tax_calculation { common_enums::TaxCalculationOverride::Skip => { self.tax_details.as_ref().and_then(|tax_details| { - tax_details.get_tax_amount(confirm_intent_request.payment_method_subtype) + tax_details.get_tax_amount(Some(confirm_intent_request.payment_method_subtype)) }) } common_enums::TaxCalculationOverride::Calculate => None, diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs index bff233c258..d4d86641dc 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs @@ -436,7 +436,7 @@ pub struct PaymentAttempt { /// The reference to the payment at the connector side pub connector_payment_id: Option, /// The payment method subtype for the payment attempt. - pub payment_method_subtype: Option, + pub payment_method_subtype: storage_enums::PaymentMethodType, /// The authentication type that was applied for the payment attempt. pub authentication_applied: Option, /// A reference to the payment at connector side. This is returned by the connector @@ -476,7 +476,7 @@ impl PaymentAttempt { #[cfg(feature = "v2")] pub fn get_payment_method_type(&self) -> Option { // TODO: check if we can fix this - self.payment_method_subtype + Some(self.payment_method_subtype) } #[cfg(feature = "v1")] @@ -660,7 +660,8 @@ impl PaymentAttempt { .unwrap_or(common_enums::PaymentMethod::Card), payment_method_id: None, connector_payment_id: None, - payment_method_subtype: payment_method_subtype_data, + payment_method_subtype: payment_method_subtype_data + .unwrap_or(common_enums::PaymentMethodType::Credit), authentication_applied: None, external_reference_id: None, payment_method_billing_address, diff --git a/crates/hyperswitch_domain_models/src/revenue_recovery.rs b/crates/hyperswitch_domain_models/src/revenue_recovery.rs index e5ecc4321d..14af9a30dc 100644 --- a/crates/hyperswitch_domain_models/src/revenue_recovery.rs +++ b/crates/hyperswitch_domain_models/src/revenue_recovery.rs @@ -33,7 +33,7 @@ pub struct RevenueRecoveryAttemptData { /// payment method of payment attempt. pub payment_method_type: common_enums::PaymentMethod, /// payment method sub type of the payment attempt. - pub payment_method_sub_type: Option, + pub payment_method_sub_type: common_enums::PaymentMethodType, /// This field can be returned for both approved and refused Mastercard payments. /// This code provides additional information about the type of transaction or the reason why the payment failed. /// If the payment failed, the network advice code gives guidance on if and when you can retry the payment. @@ -227,7 +227,7 @@ impl From<&BillingConnectorPaymentsSyncResponse> for RevenueRecoveryAttemptData transaction_created_at: data.transaction_created_at, status: data.status, payment_method_type: data.payment_method_type, - payment_method_sub_type: Some(data.payment_method_sub_type), + payment_method_sub_type: data.payment_method_sub_type, network_advice_code: None, network_decline_code: None, network_error_message: None, diff --git a/crates/kgraph_utils/Cargo.toml b/crates/kgraph_utils/Cargo.toml index ac14087c08..6e58f03171 100644 --- a/crates/kgraph_utils/Cargo.toml +++ b/crates/kgraph_utils/Cargo.toml @@ -9,7 +9,7 @@ license.workspace = true [features] dummy_connector = ["api_models/dummy_connector", "euclid/dummy_connector"] v1 = ["api_models/v1", "common_utils/v1", "common_types/v1"] -v2 = ["api_models/v2", "common_utils/v2", "common_types/v2"] +v2 = ["api_models/v2", "common_utils/v2", "common_types/v2", "common_enums/v2"] [dependencies] api_models = { version = "0.1.0", path = "../api_models", package = "api_models" } diff --git a/crates/kgraph_utils/src/mca.rs b/crates/kgraph_utils/src/mca.rs index abaa9df563..64b79d1563 100644 --- a/crates/kgraph_utils/src/mca.rs +++ b/crates/kgraph_utils/src/mca.rs @@ -24,6 +24,8 @@ fn get_dir_value_payment_method( api_enums::PaymentMethodType::AmazonPay => Ok(dirval!(WalletType = AmazonPay)), api_enums::PaymentMethodType::Credit => Ok(dirval!(CardType = Credit)), api_enums::PaymentMethodType::Debit => Ok(dirval!(CardType = Debit)), + #[cfg(feature = "v2")] + api_enums::PaymentMethodType::Card => Ok(dirval!(CardType = Card)), api_enums::PaymentMethodType::Giropay => Ok(dirval!(BankRedirectType = Giropay)), api_enums::PaymentMethodType::Ideal => Ok(dirval!(BankRedirectType = Ideal)), api_enums::PaymentMethodType::Sofort => Ok(dirval!(BankRedirectType = Sofort)), diff --git a/crates/kgraph_utils/src/transformers.rs b/crates/kgraph_utils/src/transformers.rs index 14ff728453..93e4f8e040 100644 --- a/crates/kgraph_utils/src/transformers.rs +++ b/crates/kgraph_utils/src/transformers.rs @@ -133,6 +133,8 @@ impl IntoDirValue for (api_enums::PaymentMethodType, api_enums::PaymentMethod) { api_enums::PaymentMethodType::AmazonPay => Ok(dirval!(WalletType = AmazonPay)), api_enums::PaymentMethodType::Credit => Ok(dirval!(CardType = Credit)), api_enums::PaymentMethodType::Debit => Ok(dirval!(CardType = Debit)), + #[cfg(feature = "v2")] + api_enums::PaymentMethodType::Card => Ok(dirval!(CardType = Card)), api_enums::PaymentMethodType::Giropay => Ok(dirval!(BankRedirectType = Giropay)), api_enums::PaymentMethodType::Ideal => Ok(dirval!(BankRedirectType = Ideal)), api_enums::PaymentMethodType::Sofort => Ok(dirval!(BankRedirectType = Sofort)), diff --git a/crates/router/Cargo.toml b/crates/router/Cargo.toml index 548a24b8e3..0eae31ace8 100644 --- a/crates/router/Cargo.toml +++ b/crates/router/Cargo.toml @@ -33,7 +33,7 @@ payouts = ["api_models/payouts", "common_enums/payouts", "hyperswitch_connectors payout_retry = ["payouts"] recon = ["email", "api_models/recon"] retry = [] -v2 = ["customer_v2", "payment_methods_v2", "common_default", "api_models/v2", "diesel_models/v2", "hyperswitch_domain_models/v2", "storage_impl/v2", "kgraph_utils/v2", "common_utils/v2", "hyperswitch_connectors/v2","hyperswitch_interfaces/v2", "common_types/v2","revenue_recovery","refunds_v2","scheduler/v2"] +v2 = ["customer_v2", "payment_methods_v2", "common_default", "api_models/v2", "diesel_models/v2", "hyperswitch_domain_models/v2", "storage_impl/v2", "kgraph_utils/v2", "common_utils/v2", "hyperswitch_connectors/v2","hyperswitch_interfaces/v2", "common_types/v2","revenue_recovery","refunds_v2","scheduler/v2","euclid/v2"] v1 = ["common_default", "api_models/v1", "diesel_models/v1", "hyperswitch_domain_models/v1", "storage_impl/v1", "hyperswitch_interfaces/v1", "kgraph_utils/v1", "common_utils/v1", "hyperswitch_connectors/v1", "common_types/v1","scheduler/v1"] customer_v2 = ["api_models/customer_v2", "diesel_models/customer_v2", "hyperswitch_domain_models/customer_v2", "storage_impl/customer_v2"] payment_methods_v2 = ["api_models/payment_methods_v2", "diesel_models/payment_methods_v2", "hyperswitch_domain_models/payment_methods_v2", "storage_impl/payment_methods_v2", "common_utils/payment_methods_v2"] diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs index 183ed6adde..14dc0ec362 100644 --- a/crates/router/src/connector/stripe/transformers.rs +++ b/crates/router/src/connector/stripe/transformers.rs @@ -691,6 +691,8 @@ impl TryFrom for StripePaymentMethodType { match value { enums::PaymentMethodType::Credit => Ok(Self::Card), enums::PaymentMethodType::Debit => Ok(Self::Card), + #[cfg(feature = "v2")] + enums::PaymentMethodType::Card => Ok(Self::Card), enums::PaymentMethodType::Klarna => Ok(Self::Klarna), enums::PaymentMethodType::Affirm => Ok(Self::Affirm), enums::PaymentMethodType::AfterpayClearpay => Ok(Self::AfterpayClearpay), diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs index 64d3a8c42a..9676d573d2 100644 --- a/crates/router/src/core/payment_methods.rs +++ b/crates/router/src/core/payment_methods.rs @@ -713,7 +713,7 @@ pub async fn retrieve_payment_method_with_token( pub(crate) fn get_payment_method_create_request( payment_method_data: &api_models::payments::PaymentMethodData, payment_method_type: storage_enums::PaymentMethod, - payment_method_subtype: Option, + payment_method_subtype: storage_enums::PaymentMethodType, customer_id: id_type::GlobalCustomerId, billing_address: Option<&api_models::payments::Address>, payment_method_session: Option<&domain::payment_methods::PaymentMethodSession>, @@ -977,7 +977,7 @@ pub async fn create_payment_method_core( None, network_tokenization_resp, Some(req.payment_method_type), - req.payment_method_subtype, + Some(req.payment_method_subtype), ) .await .attach_printable("Unable to create Payment method data")?; diff --git a/crates/router/src/core/payments/routing.rs b/crates/router/src/core/payments/routing.rs index 0173d36cc4..889525ec6d 100644 --- a/crates/router/src/core/payments/routing.rs +++ b/crates/router/src/core/payments/routing.rs @@ -244,7 +244,7 @@ pub fn make_dsl_input( }; let payment_method_input = dsl_inputs::PaymentMethodInput { payment_method: Some(payments_dsl_input.payment_attempt.payment_method_type), - payment_method_type: payments_dsl_input.payment_attempt.payment_method_subtype, + payment_method_type: Some(payments_dsl_input.payment_attempt.payment_method_subtype), card_network: payments_dsl_input .payment_method_data .as_ref() diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 37bde6c1e2..5b6b014aca 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -284,7 +284,7 @@ pub async fn construct_payment_router_data_for_authorize<'a>( session_token: None, enrolled_for_3ds: true, related_transaction_id: None, - payment_method_type: payment_data.payment_attempt.payment_method_subtype, + payment_method_type: Some(payment_data.payment_attempt.payment_method_subtype), router_return_url: Some(router_return_url), webhook_url, complete_authorize_url, @@ -607,7 +607,7 @@ pub async fn construct_router_data_for_psync<'a>( capture_method: Some(payment_intent.capture_method), connector_meta: attempt.connector_metadata.clone().expose_option(), sync_type: types::SyncRequestType::SinglePaymentSync, - payment_method_type: attempt.payment_method_subtype, + payment_method_type: Some(attempt.payment_method_subtype), currency: payment_intent.amount_details.currency, // TODO: Get the charges object from feature metadata split_payments: None, @@ -948,7 +948,7 @@ pub async fn construct_payment_router_data_for_setup_mandate<'a>( email, customer_name: None, return_url: Some(router_return_url), - payment_method_type: payment_data.payment_attempt.payment_method_subtype, + payment_method_type: Some(payment_data.payment_attempt.payment_method_subtype), request_incremental_authorization: matches!( payment_data .payment_intent @@ -1666,7 +1666,7 @@ where created: payment_intent.created_at, payment_method_data, payment_method_type: Some(payment_attempt.payment_method_type), - payment_method_subtype: payment_attempt.payment_method_subtype, + payment_method_subtype: Some(payment_attempt.payment_method_subtype), next_action, connector_transaction_id: payment_attempt.connector_payment_id.clone(), connector_reference_id: None, @@ -1770,7 +1770,7 @@ where payment_method_subtype: self .payment_attempt .as_ref() - .and_then(|attempt| attempt.payment_method_subtype), + .map(|attempt| attempt.payment_method_subtype), connector_transaction_id: self .payment_attempt .as_ref() @@ -2901,7 +2901,7 @@ impl ForeignFrom<(storage::PaymentIntent, Option)> )), created: pi.created_at, payment_method_type: pa.as_ref().and_then(|p| p.payment_method_type.into()), - payment_method_subtype: pa.as_ref().and_then(|p| p.payment_method_subtype), + payment_method_subtype: pa.as_ref().and_then(|p| p.payment_method_subtype.into()), connector: pa.as_ref().and_then(|p| p.connector.clone()), merchant_connector_id: pa.as_ref().and_then(|p| p.merchant_connector_id.clone()), customer: None, diff --git a/crates/router/src/core/revenue_recovery/types.rs b/crates/router/src/core/revenue_recovery/types.rs index 1465629914..dc2118efc2 100644 --- a/crates/router/src/core/revenue_recovery/types.rs +++ b/crates/router/src/core/revenue_recovery/types.rs @@ -401,7 +401,7 @@ impl Action { merchant_reference_id, amount: payment_attempt.get_total_amount(), currency: payment_intent.amount_details.currency, - payment_method_type: payment_attempt.payment_method_subtype, + payment_method_type: Some(payment_attempt.payment_method_subtype), attempt_status: payment_attempt.status, connector_transaction_id: payment_attempt .connector_payment_id diff --git a/crates/router/src/types/api/payment_methods.rs b/crates/router/src/types/api/payment_methods.rs index 4c925b9d46..9c5030a30a 100644 --- a/crates/router/src/types/api/payment_methods.rs +++ b/crates/router/src/types/api/payment_methods.rs @@ -69,15 +69,10 @@ impl PaymentMethodCreateExt for PaymentMethodCreate { impl PaymentMethodCreateExt for PaymentMethodCreate { fn validate(&self) -> RouterResult<()> { utils::when( - !self - .payment_method_subtype - .map(|sub| { - validate_payment_method_type_against_payment_method( - self.payment_method_type, - sub, - ) - }) - .unwrap_or(true), // If payment_method_subtype is None, we assume it to be valid + !validate_payment_method_type_against_payment_method( + self.payment_method_type, + self.payment_method_subtype, + ), || { Err(report!(errors::ApiErrorResponse::InvalidRequestData { message: "Invalid 'payment_method_type' provided".to_string() diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs index c11751c832..6d529b1280 100644 --- a/crates/router/src/types/transformers.rs +++ b/crates/router/src/types/transformers.rs @@ -532,6 +532,8 @@ impl ForeignFrom for api_enums::PaymentMethod { api_enums::PaymentMethodType::Credit | api_enums::PaymentMethodType::Debit => { Self::Card } + #[cfg(feature = "v2")] + api_enums::PaymentMethodType::Card => Self::Card, api_enums::PaymentMethodType::Evoucher | api_enums::PaymentMethodType::ClassicReward => Self::Reward, api_enums::PaymentMethodType::Boleto diff --git a/v2_migrations/2025-03-25-074512_payment-method-subtype-mandatory/down.sql b/v2_migrations/2025-03-25-074512_payment-method-subtype-mandatory/down.sql new file mode 100644 index 0000000000..8022b97931 --- /dev/null +++ b/v2_migrations/2025-03-25-074512_payment-method-subtype-mandatory/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE payment_attempt ALTER COLUMN payment_method_subtype DROP NOT NULL; \ No newline at end of file diff --git a/v2_migrations/2025-03-25-074512_payment-method-subtype-mandatory/up.sql b/v2_migrations/2025-03-25-074512_payment-method-subtype-mandatory/up.sql new file mode 100644 index 0000000000..36985b0111 --- /dev/null +++ b/v2_migrations/2025-03-25-074512_payment-method-subtype-mandatory/up.sql @@ -0,0 +1,2 @@ +-- Your SQL goes here +ALTER TABLE payment_attempt ALTER COLUMN payment_method_subtype SET NOT NULL; \ No newline at end of file