feat(router): Support card in payment_method_subtype [V2] (#7662)

This commit is contained in:
Anurag Thakur
2025-04-08 15:18:55 +05:30
committed by GitHub
parent bce9d48277
commit 187cceb39d
33 changed files with 348 additions and 73 deletions

View File

@ -691,6 +691,8 @@ impl TryFrom<enums::PaymentMethodType> 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),

View File

@ -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<storage_enums::PaymentMethodType>,
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")?;

View File

@ -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()

View File

@ -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<storage::PaymentAttempt>)>
)),
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,

View File

@ -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

View File

@ -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()

View File

@ -532,6 +532,8 @@ impl ForeignFrom<api_enums::PaymentMethodType> 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