mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 11:24:45 +08:00
feat(router): Save payment method on payments confirm (V2) (#8090)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -5,23 +5,29 @@ use super::{
|
||||
PaymentStartRedirectionRequest, PaymentsCreateIntentRequest, PaymentsGetIntentRequest,
|
||||
PaymentsIntentResponse, PaymentsRequest,
|
||||
};
|
||||
#[cfg(feature = "v2")]
|
||||
use crate::payment_methods::PaymentMethodListResponseForSession;
|
||||
#[cfg(feature = "v1")]
|
||||
use crate::payments::{
|
||||
ExtendedCardInfoResponse, PaymentIdType, PaymentListFilterConstraints, PaymentListResponseV2,
|
||||
PaymentsApproveRequest, PaymentsCancelRequest, PaymentsCaptureRequest,
|
||||
PaymentsCompleteAuthorizeRequest, PaymentsDynamicTaxCalculationRequest,
|
||||
PaymentsDynamicTaxCalculationResponse, PaymentsExternalAuthenticationRequest,
|
||||
PaymentsExternalAuthenticationResponse, PaymentsIncrementalAuthorizationRequest,
|
||||
PaymentsManualUpdateRequest, PaymentsManualUpdateResponse, PaymentsPostSessionTokensRequest,
|
||||
PaymentsPostSessionTokensResponse, PaymentsRejectRequest, PaymentsRetrieveRequest,
|
||||
PaymentsStartRequest, PaymentsUpdateMetadataRequest, PaymentsUpdateMetadataResponse,
|
||||
use crate::{
|
||||
payment_methods::PaymentMethodListResponse,
|
||||
payments::{
|
||||
ExtendedCardInfoResponse, PaymentIdType, PaymentListFilterConstraints,
|
||||
PaymentListResponseV2, PaymentsApproveRequest, PaymentsCancelRequest,
|
||||
PaymentsCaptureRequest, PaymentsCompleteAuthorizeRequest,
|
||||
PaymentsDynamicTaxCalculationRequest, PaymentsDynamicTaxCalculationResponse,
|
||||
PaymentsExternalAuthenticationRequest, PaymentsExternalAuthenticationResponse,
|
||||
PaymentsIncrementalAuthorizationRequest, PaymentsManualUpdateRequest,
|
||||
PaymentsManualUpdateResponse, PaymentsPostSessionTokensRequest,
|
||||
PaymentsPostSessionTokensResponse, PaymentsRejectRequest, PaymentsRetrieveRequest,
|
||||
PaymentsStartRequest, PaymentsUpdateMetadataRequest, PaymentsUpdateMetadataResponse,
|
||||
},
|
||||
};
|
||||
use crate::{
|
||||
payment_methods::{
|
||||
self, ListCountriesCurrenciesRequest, ListCountriesCurrenciesResponse,
|
||||
PaymentMethodCollectLinkRenderRequest, PaymentMethodCollectLinkRequest,
|
||||
PaymentMethodCollectLinkResponse, PaymentMethodListRequest, PaymentMethodListResponse,
|
||||
PaymentMethodMigrateResponse, PaymentMethodResponse, PaymentMethodUpdate,
|
||||
PaymentMethodCollectLinkResponse, PaymentMethodListRequest, PaymentMethodMigrateResponse,
|
||||
PaymentMethodResponse, PaymentMethodUpdate,
|
||||
},
|
||||
payments::{
|
||||
self, PaymentListConstraints, PaymentListFilters, PaymentListFiltersV2,
|
||||
@ -304,6 +310,8 @@ impl ApiEventMetric for PaymentMethodListRequest {
|
||||
impl ApiEventMetric for ListCountriesCurrenciesRequest {}
|
||||
|
||||
impl ApiEventMetric for ListCountriesCurrenciesResponse {}
|
||||
|
||||
#[cfg(feature = "v1")]
|
||||
impl ApiEventMetric for PaymentMethodListResponse {}
|
||||
|
||||
#[cfg(feature = "v1")]
|
||||
@ -454,6 +462,9 @@ impl ApiEventMetric for payments::PaymentMethodListResponseForPayments {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
impl ApiEventMetric for PaymentMethodListResponseForSession {}
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
impl ApiEventMetric for payments::PaymentsCaptureResponse {
|
||||
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
||||
|
||||
@ -1225,12 +1225,12 @@ impl From<CardDetailFromLocker> for payments::AdditionalCardInfo {
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
#[derive(Debug, serde::Serialize, ToSchema)]
|
||||
pub struct PaymentMethodListResponse {
|
||||
pub struct PaymentMethodListResponseForSession {
|
||||
/// The list of payment methods that are enabled for the business profile
|
||||
pub payment_methods_enabled: Vec<ResponsePaymentMethodTypes>,
|
||||
|
||||
/// The list of saved payment methods of the customer
|
||||
pub customer_payment_methods: Vec<CustomerPaymentMethod>,
|
||||
pub customer_payment_methods: Vec<CustomerPaymentMethodResponseItem>,
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
@ -1930,11 +1930,12 @@ pub struct CustomerPaymentMethodsListResponse {
|
||||
pub is_guest_customer: Option<bool>,
|
||||
}
|
||||
|
||||
// OLAP PML Response
|
||||
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
|
||||
#[derive(Debug, serde::Serialize, ToSchema)]
|
||||
pub struct CustomerPaymentMethodsListResponse {
|
||||
/// List of payment methods for customer
|
||||
pub customer_payment_methods: Vec<CustomerPaymentMethod>,
|
||||
pub customer_payment_methods: Vec<PaymentMethodResponseItem>,
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
|
||||
@ -2073,7 +2074,7 @@ pub struct CustomerDefaultPaymentMethodResponse {
|
||||
|
||||
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
|
||||
#[derive(Debug, Clone, serde::Serialize, ToSchema)]
|
||||
pub struct CustomerPaymentMethod {
|
||||
pub struct PaymentMethodResponseItem {
|
||||
/// The unique identifier of the payment method.
|
||||
#[schema(value_type = String, example = "12345_pm_01926c58bc6e77c09e809964e72af8c8")]
|
||||
pub id: id_type::GlobalPaymentMethodId,
|
||||
@ -2136,6 +2137,68 @@ pub struct CustomerPaymentMethod {
|
||||
pub psp_tokenization_enabled: bool,
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
|
||||
#[derive(Debug, Clone, serde::Serialize, ToSchema)]
|
||||
pub struct CustomerPaymentMethodResponseItem {
|
||||
/// The unique identifier of the payment method.
|
||||
#[schema(value_type = String, example = "12345_pm_01926c58bc6e77c09e809964e72af8c8")]
|
||||
pub id: id_type::GlobalPaymentMethodId,
|
||||
|
||||
/// Temporary Token for payment method in vault which gets refreshed for every payment
|
||||
#[schema(example = "7ebf443f-a050-4067-84e5-e6f6d4800aef")]
|
||||
pub payment_token: String,
|
||||
|
||||
/// The unique identifier of the customer.
|
||||
#[schema(
|
||||
min_length = 32,
|
||||
max_length = 64,
|
||||
example = "12345_cus_01926c58bc6e77c09e809964e72af8c8",
|
||||
value_type = String
|
||||
)]
|
||||
pub customer_id: id_type::GlobalCustomerId,
|
||||
|
||||
/// The type of payment method use for the payment.
|
||||
#[schema(value_type = PaymentMethod,example = "card")]
|
||||
pub payment_method_type: api_enums::PaymentMethod,
|
||||
|
||||
/// This is a sub-category of payment method.
|
||||
#[schema(value_type = PaymentMethodType,example = "credit")]
|
||||
pub payment_method_subtype: api_enums::PaymentMethodType,
|
||||
|
||||
/// Indicates whether the payment method is eligible for recurring payments
|
||||
#[schema(example = true)]
|
||||
pub recurring_enabled: bool,
|
||||
|
||||
/// PaymentMethod Data from locker
|
||||
pub payment_method_data: Option<PaymentMethodListData>,
|
||||
|
||||
/// Masked bank details from PM auth services
|
||||
#[schema(example = json!({"mask": "0000"}))]
|
||||
pub bank: Option<MaskedBankDetails>,
|
||||
|
||||
/// A timestamp (ISO 8601 code) that determines when the payment method was created
|
||||
#[schema(value_type = PrimitiveDateTime, example = "2023-01-18T11:04:09.922Z")]
|
||||
#[serde(with = "common_utils::custom_serde::iso8601")]
|
||||
pub created: time::PrimitiveDateTime,
|
||||
|
||||
/// Whether this payment method requires CVV to be collected
|
||||
#[schema(example = true)]
|
||||
pub requires_cvv: bool,
|
||||
|
||||
/// A timestamp (ISO 8601 code) that determines when the payment method was last used
|
||||
#[schema(value_type = PrimitiveDateTime,example = "2024-02-24T11:04:09.922Z")]
|
||||
#[serde(with = "common_utils::custom_serde::iso8601")]
|
||||
pub last_used_at: time::PrimitiveDateTime,
|
||||
|
||||
/// Indicates if the payment method has been set to default or not
|
||||
#[schema(example = true)]
|
||||
pub is_default: bool,
|
||||
|
||||
/// The billing details of the payment method
|
||||
#[schema(value_type = Option<Address>)]
|
||||
pub billing: Option<payments::Address>,
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
|
||||
#[derive(Debug, Clone, serde::Serialize, ToSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
|
||||
@ -5328,6 +5328,10 @@ pub struct PaymentsConfirmIntentRequest {
|
||||
/// The payment_method_id to be associated with the payment
|
||||
#[schema(value_type = Option<String>)]
|
||||
pub payment_method_id: Option<id_type::GlobalPaymentMethodId>,
|
||||
|
||||
/// Provide a reference to a stored payment method
|
||||
#[schema(example = "187282ab-40ef-47a9-9206-5099ba31e432")]
|
||||
pub payment_token: Option<String>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
@ -5550,6 +5554,7 @@ impl From<&PaymentsRequest> for PaymentsConfirmIntentRequest {
|
||||
customer_acceptance: request.customer_acceptance.clone(),
|
||||
browser_info: request.browser_info.clone(),
|
||||
payment_method_id: request.payment_method_id.clone(),
|
||||
payment_token: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -7624,8 +7629,8 @@ pub struct PaymentMethodListResponseForPayments {
|
||||
|
||||
/// The list of payment methods that are saved by the given customer
|
||||
/// This field is only returned if the customer_id is provided in the request
|
||||
#[schema(value_type = Option<Vec<CustomerPaymentMethod>>)]
|
||||
pub customer_payment_methods: Option<Vec<payment_methods::CustomerPaymentMethod>>,
|
||||
#[schema(value_type = Option<Vec<CustomerPaymentMethodResponseItem>>)]
|
||||
pub customer_payment_methods: Option<Vec<payment_methods::CustomerPaymentMethodResponseItem>>,
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
|
||||
|
||||
Reference in New Issue
Block a user