mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
refactor(connector): [Stripe] fix mandate flow (#4281)
This commit is contained in:
@ -124,7 +124,6 @@ pub struct PaymentIntentRequest {
|
|||||||
pub meta_data: HashMap<String, String>,
|
pub meta_data: HashMap<String, String>,
|
||||||
pub return_url: String,
|
pub return_url: String,
|
||||||
pub confirm: bool,
|
pub confirm: bool,
|
||||||
pub mandate: Option<Secret<String>>,
|
|
||||||
pub payment_method: Option<String>,
|
pub payment_method: Option<String>,
|
||||||
pub customer: Option<Secret<String>>,
|
pub customer: Option<Secret<String>>,
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
@ -1800,7 +1799,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaymentIntentRequest {
|
|||||||
};
|
};
|
||||||
let mut payment_method_options = None;
|
let mut payment_method_options = None;
|
||||||
|
|
||||||
let (mut payment_data, payment_method, mandate, billing_address, payment_method_types) = {
|
let (mut payment_data, payment_method, billing_address, payment_method_types) = {
|
||||||
match item
|
match item
|
||||||
.request
|
.request
|
||||||
.mandate_id
|
.mandate_id
|
||||||
@ -1811,7 +1810,6 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaymentIntentRequest {
|
|||||||
connector_mandate_ids,
|
connector_mandate_ids,
|
||||||
)) => (
|
)) => (
|
||||||
None,
|
None,
|
||||||
connector_mandate_ids.payment_method_id,
|
|
||||||
connector_mandate_ids.connector_mandate_id,
|
connector_mandate_ids.connector_mandate_id,
|
||||||
StripeBillingAddress::default(),
|
StripeBillingAddress::default(),
|
||||||
get_payment_method_type_for_saved_payment_method_payment(item)?,
|
get_payment_method_type_for_saved_payment_method_payment(item)?,
|
||||||
@ -1826,7 +1824,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaymentIntentRequest {
|
|||||||
network_transaction_id: Secret::new(network_transaction_id),
|
network_transaction_id: Secret::new(network_transaction_id),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
(None, None, None, StripeBillingAddress::default(), None)
|
(None, None, StripeBillingAddress::default(), None)
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let (payment_method_data, payment_method_type, billing_address) =
|
let (payment_method_data, payment_method_type, billing_address) =
|
||||||
@ -1848,7 +1846,6 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaymentIntentRequest {
|
|||||||
(
|
(
|
||||||
Some(payment_method_data),
|
Some(payment_method_data),
|
||||||
None,
|
None,
|
||||||
None,
|
|
||||||
billing_address,
|
billing_address,
|
||||||
payment_method_type,
|
payment_method_type,
|
||||||
)
|
)
|
||||||
@ -1965,7 +1962,6 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaymentIntentRequest {
|
|||||||
billing: billing_address,
|
billing: billing_address,
|
||||||
capture_method: StripeCaptureMethod::from(item.request.capture_method),
|
capture_method: StripeCaptureMethod::from(item.request.capture_method),
|
||||||
payment_data,
|
payment_data,
|
||||||
mandate: mandate.map(Secret::new),
|
|
||||||
payment_method_options,
|
payment_method_options,
|
||||||
payment_method,
|
payment_method,
|
||||||
customer: item.connector_customer.to_owned().map(Secret::new),
|
customer: item.connector_customer.to_owned().map(Secret::new),
|
||||||
@ -2416,40 +2412,6 @@ fn extract_payment_method_connector_response_from_latest_attempt(
|
|||||||
.map(types::ConnectorResponseData::with_additional_payment_method_data)
|
.map(types::ConnectorResponseData::with_additional_payment_method_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ForeignFrom<(Option<StripePaymentMethodOptions>, String)> for types::MandateReference {
|
|
||||||
fn foreign_from(
|
|
||||||
(payment_method_options, payment_method_id): (Option<StripePaymentMethodOptions>, String),
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
connector_mandate_id: payment_method_options.and_then(|options| match options {
|
|
||||||
StripePaymentMethodOptions::Card {
|
|
||||||
mandate_options, ..
|
|
||||||
} => mandate_options.map(|mandate_options| mandate_options.reference.expose()),
|
|
||||||
StripePaymentMethodOptions::Klarna {}
|
|
||||||
| StripePaymentMethodOptions::Affirm {}
|
|
||||||
| StripePaymentMethodOptions::AfterpayClearpay {}
|
|
||||||
| StripePaymentMethodOptions::Eps {}
|
|
||||||
| StripePaymentMethodOptions::Giropay {}
|
|
||||||
| StripePaymentMethodOptions::Ideal {}
|
|
||||||
| StripePaymentMethodOptions::Sofort {}
|
|
||||||
| StripePaymentMethodOptions::Ach {}
|
|
||||||
| StripePaymentMethodOptions::Bacs {}
|
|
||||||
| StripePaymentMethodOptions::Becs {}
|
|
||||||
| StripePaymentMethodOptions::WechatPay {}
|
|
||||||
| StripePaymentMethodOptions::Alipay {}
|
|
||||||
| StripePaymentMethodOptions::Sepa {}
|
|
||||||
| StripePaymentMethodOptions::Bancontact {}
|
|
||||||
| StripePaymentMethodOptions::Przelewy24 {}
|
|
||||||
| StripePaymentMethodOptions::CustomerBalance {}
|
|
||||||
| StripePaymentMethodOptions::Blik {}
|
|
||||||
| StripePaymentMethodOptions::Multibanco {}
|
|
||||||
| StripePaymentMethodOptions::Cashapp {} => None,
|
|
||||||
}),
|
|
||||||
payment_method_id: Some(payment_method_id),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<F, T>
|
impl<F, T>
|
||||||
TryFrom<types::ResponseRouterData<F, PaymentIntentResponse, T, types::PaymentsResponseData>>
|
TryFrom<types::ResponseRouterData<F, PaymentIntentResponse, T, types::PaymentsResponseData>>
|
||||||
for types::RouterData<F, T, types::PaymentsResponseData>
|
for types::RouterData<F, T, types::PaymentsResponseData>
|
||||||
@ -2465,11 +2427,16 @@ impl<F, T>
|
|||||||
services::RedirectForm::from((redirection_url, services::Method::Get))
|
services::RedirectForm::from((redirection_url, services::Method::Get))
|
||||||
});
|
});
|
||||||
|
|
||||||
let mandate_reference = item.response.payment_method.map(|pm| {
|
let mandate_reference = item.response.payment_method.map(|paymet_method_id| {
|
||||||
types::MandateReference::foreign_from((
|
// Implemented Save and re-use payment information for recurring charges
|
||||||
item.response.payment_method_options,
|
// For more info: https://docs.stripe.com/recurring-payments#accept-recurring-payments
|
||||||
pm.expose(),
|
// For backward compataibility payment_method_id & connector_mandate_id is being populated with the same value
|
||||||
))
|
let connector_mandate_id = Some(paymet_method_id.clone().expose());
|
||||||
|
let payment_method_id = Some(paymet_method_id.expose());
|
||||||
|
types::MandateReference {
|
||||||
|
connector_mandate_id,
|
||||||
|
payment_method_id,
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//Note: we might have to call retrieve_setup_intent to get the network_transaction_id in case its not sent in PaymentIntentResponse
|
//Note: we might have to call retrieve_setup_intent to get the network_transaction_id in case its not sent in PaymentIntentResponse
|
||||||
@ -2588,26 +2555,32 @@ impl<F, T>
|
|||||||
services::RedirectForm::from((redirection_url, services::Method::Get))
|
services::RedirectForm::from((redirection_url, services::Method::Get))
|
||||||
});
|
});
|
||||||
|
|
||||||
let mandate_reference = item.response.payment_method.clone().map(|pm| {
|
let mandate_reference = item
|
||||||
types::MandateReference::foreign_from((
|
.response
|
||||||
item.response.payment_method_options.clone(),
|
.payment_method
|
||||||
match item.response.latest_charge.clone() {
|
.clone()
|
||||||
|
.map(|paymet_method_id| {
|
||||||
|
// Implemented Save and re-use payment information for recurring charges
|
||||||
|
// For more info: https://docs.stripe.com/recurring-payments#accept-recurring-payments
|
||||||
|
// For backward compataibility payment_method_id & connector_mandate_id is being populated with the same value
|
||||||
|
let connector_mandate_id = Some(paymet_method_id.clone().expose());
|
||||||
|
let payment_method_id = match item.response.latest_charge.clone() {
|
||||||
Some(StripeChargeEnum::ChargeObject(charge)) => {
|
Some(StripeChargeEnum::ChargeObject(charge)) => {
|
||||||
match charge.payment_method_details {
|
match charge.payment_method_details {
|
||||||
Some(StripePaymentMethodDetailsResponse::Bancontact { bancontact }) => {
|
Some(StripePaymentMethodDetailsResponse::Bancontact { bancontact }) => {
|
||||||
bancontact
|
bancontact
|
||||||
.attached_payment_method
|
.attached_payment_method
|
||||||
.map(|attached_payment_method| attached_payment_method.expose())
|
.map(|attached_payment_method| attached_payment_method.expose())
|
||||||
.unwrap_or(pm.expose())
|
.unwrap_or(paymet_method_id.expose())
|
||||||
}
|
}
|
||||||
Some(StripePaymentMethodDetailsResponse::Ideal { ideal }) => ideal
|
Some(StripePaymentMethodDetailsResponse::Ideal { ideal }) => ideal
|
||||||
.attached_payment_method
|
.attached_payment_method
|
||||||
.map(|attached_payment_method| attached_payment_method.expose())
|
.map(|attached_payment_method| attached_payment_method.expose())
|
||||||
.unwrap_or(pm.expose()),
|
.unwrap_or(paymet_method_id.expose()),
|
||||||
Some(StripePaymentMethodDetailsResponse::Sofort { sofort }) => sofort
|
Some(StripePaymentMethodDetailsResponse::Sofort { sofort }) => sofort
|
||||||
.attached_payment_method
|
.attached_payment_method
|
||||||
.map(|attached_payment_method| attached_payment_method.expose())
|
.map(|attached_payment_method| attached_payment_method.expose())
|
||||||
.unwrap_or(pm.expose()),
|
.unwrap_or(paymet_method_id.expose()),
|
||||||
Some(StripePaymentMethodDetailsResponse::Blik)
|
Some(StripePaymentMethodDetailsResponse::Blik)
|
||||||
| Some(StripePaymentMethodDetailsResponse::Eps)
|
| Some(StripePaymentMethodDetailsResponse::Eps)
|
||||||
| Some(StripePaymentMethodDetailsResponse::Fpx)
|
| Some(StripePaymentMethodDetailsResponse::Fpx)
|
||||||
@ -2625,12 +2598,15 @@ impl<F, T>
|
|||||||
| Some(StripePaymentMethodDetailsResponse::Wechatpay)
|
| Some(StripePaymentMethodDetailsResponse::Wechatpay)
|
||||||
| Some(StripePaymentMethodDetailsResponse::Alipay)
|
| Some(StripePaymentMethodDetailsResponse::Alipay)
|
||||||
| Some(StripePaymentMethodDetailsResponse::CustomerBalance)
|
| Some(StripePaymentMethodDetailsResponse::CustomerBalance)
|
||||||
| None => pm.expose(),
|
| None => paymet_method_id.expose(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(StripeChargeEnum::ChargeId(_)) | None => pm.expose(),
|
Some(StripeChargeEnum::ChargeId(_)) | None => paymet_method_id.expose(),
|
||||||
},
|
};
|
||||||
))
|
types::MandateReference {
|
||||||
|
connector_mandate_id,
|
||||||
|
payment_method_id: Some(payment_method_id),
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let connector_metadata =
|
let connector_metadata =
|
||||||
@ -2687,8 +2663,16 @@ impl<F, T>
|
|||||||
services::RedirectForm::from((redirection_url, services::Method::Get))
|
services::RedirectForm::from((redirection_url, services::Method::Get))
|
||||||
});
|
});
|
||||||
|
|
||||||
let mandate_reference = item.response.payment_method.map(|pm| {
|
let mandate_reference = item.response.payment_method.map(|paymet_method_id| {
|
||||||
types::MandateReference::foreign_from((item.response.payment_method_options, pm))
|
// Implemented Save and re-use payment information for recurring charges
|
||||||
|
// For more info: https://docs.stripe.com/recurring-payments#accept-recurring-payments
|
||||||
|
// For backward compataibility payment_method_id & connector_mandate_id is being populated with the same value
|
||||||
|
let connector_mandate_id = Some(paymet_method_id.clone());
|
||||||
|
let payment_method_id = Some(paymet_method_id);
|
||||||
|
types::MandateReference {
|
||||||
|
connector_mandate_id,
|
||||||
|
payment_method_id,
|
||||||
|
}
|
||||||
});
|
});
|
||||||
let status = enums::AttemptStatus::from(item.response.status);
|
let status = enums::AttemptStatus::from(item.response.status);
|
||||||
let connector_response_data = item
|
let connector_response_data = item
|
||||||
|
|||||||
Reference in New Issue
Block a user