mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
feat(core): api ,domain and diesel model changes for extended authorization (#6607)
Co-authored-by: Gnanasundari24 <118818938+Gnanasundari24@users.noreply.github.com> Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -8,7 +8,10 @@ use common_utils::{
|
||||
id_type, link_utils, pii,
|
||||
};
|
||||
#[cfg(feature = "v1")]
|
||||
use common_utils::{crypto::OptionalEncryptableName, ext_traits::ValueExt};
|
||||
use common_utils::{
|
||||
crypto::OptionalEncryptableName, ext_traits::ValueExt,
|
||||
types::AlwaysRequestExtendedAuthorization,
|
||||
};
|
||||
#[cfg(feature = "v2")]
|
||||
use masking::ExposeInterface;
|
||||
use masking::{PeekInterface, Secret};
|
||||
@ -1897,6 +1900,10 @@ pub struct ProfileCreate {
|
||||
/// Maximum number of auto retries allowed for a payment
|
||||
pub max_auto_retries_enabled: Option<u8>,
|
||||
|
||||
/// Bool indicating if extended authentication must be requested for all payments
|
||||
#[schema(value_type = Option<bool>)]
|
||||
pub always_request_extended_authorization: Option<AlwaysRequestExtendedAuthorization>,
|
||||
|
||||
/// Indicates if click to pay is enabled or not.
|
||||
#[serde(default)]
|
||||
pub is_click_to_pay_enabled: bool,
|
||||
@ -2152,6 +2159,10 @@ pub struct ProfileResponse {
|
||||
/// Maximum number of auto retries allowed for a payment
|
||||
pub max_auto_retries_enabled: Option<i16>,
|
||||
|
||||
/// Bool indicating if extended authentication must be requested for all payments
|
||||
#[schema(value_type = Option<bool>)]
|
||||
pub always_request_extended_authorization: Option<AlwaysRequestExtendedAuthorization>,
|
||||
|
||||
/// Indicates if click to pay is enabled or not.
|
||||
#[schema(default = false, example = false)]
|
||||
pub is_click_to_pay_enabled: bool,
|
||||
|
||||
@ -41,3 +41,12 @@ pub mod verifications;
|
||||
pub mod verify_connector;
|
||||
pub mod webhook_events;
|
||||
pub mod webhooks;
|
||||
|
||||
pub trait ValidateFieldAndGet<Request> {
|
||||
fn validate_field_and_get(
|
||||
&self,
|
||||
request: &Request,
|
||||
) -> common_utils::errors::CustomResult<Self, common_utils::errors::ValidationError>
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ use std::{
|
||||
num::NonZeroI64,
|
||||
};
|
||||
pub mod additional_info;
|
||||
pub mod trait_impls;
|
||||
use cards::CardNumber;
|
||||
#[cfg(feature = "v2")]
|
||||
use common_enums::enums::PaymentConnectorTransmission;
|
||||
@ -18,7 +19,10 @@ use common_utils::{
|
||||
hashing::HashedString,
|
||||
id_type,
|
||||
pii::{self, Email},
|
||||
types::{MinorUnit, StringMajorUnit},
|
||||
types::{
|
||||
ExtendedAuthorizationAppliedBool, MinorUnit, RequestExtendedAuthorizationBool,
|
||||
StringMajorUnit,
|
||||
},
|
||||
};
|
||||
use error_stack::ResultExt;
|
||||
use masking::{PeekInterface, Secret, WithType};
|
||||
@ -37,7 +41,7 @@ use crate::{
|
||||
admin::{self, MerchantConnectorInfo},
|
||||
disputes, enums as api_enums,
|
||||
mandates::RecurringDetails,
|
||||
refunds,
|
||||
refunds, ValidateFieldAndGet,
|
||||
};
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
@ -1042,6 +1046,12 @@ pub struct PaymentsRequest {
|
||||
#[schema(value_type = Option<SplitPaymentsRequest>)]
|
||||
pub split_payments: Option<common_types::payments::SplitPaymentsRequest>,
|
||||
|
||||
/// Optional boolean value to extent authorization period of this payment
|
||||
///
|
||||
/// capture method must be manual or manual_multiple
|
||||
#[schema(value_type = Option<bool>, default = false)]
|
||||
pub request_extended_authorization: Option<RequestExtendedAuthorizationBool>,
|
||||
|
||||
/// Merchant's identifier for the payment/invoice. This will be sent to the connector
|
||||
/// if the connector provides support to accept multiple reference ids.
|
||||
/// In case the connector supports only one reference id, Hyperswitch's Payment ID will be sent as reference.
|
||||
@ -1101,6 +1111,18 @@ impl PaymentsRequest {
|
||||
.or(self.customer.as_ref().map(|customer| &customer.id))
|
||||
}
|
||||
|
||||
pub fn validate_and_get_request_extended_authorization(
|
||||
&self,
|
||||
) -> common_utils::errors::CustomResult<Option<RequestExtendedAuthorizationBool>, ValidationError>
|
||||
{
|
||||
self.request_extended_authorization
|
||||
.as_ref()
|
||||
.map(|request_extended_authorization| {
|
||||
request_extended_authorization.validate_field_and_get(self)
|
||||
})
|
||||
.transpose()
|
||||
}
|
||||
|
||||
/// Checks if the customer details are passed in both places
|
||||
/// If they are passed in both places, check for both the values to be equal
|
||||
/// Or else, return the field which has inconsistent data
|
||||
@ -4842,6 +4864,14 @@ pub struct PaymentsResponse {
|
||||
#[schema(value_type = Option<Object>, example = r#"{ "fulfillment_method" : "deliver", "coverage_request" : "fraud" }"#)]
|
||||
pub frm_metadata: Option<pii::SecretSerdeValue>,
|
||||
|
||||
/// flag that indicates if extended authorization is applied on this payment or not
|
||||
#[schema(value_type = Option<bool>)]
|
||||
pub extended_authorization_applied: Option<ExtendedAuthorizationAppliedBool>,
|
||||
|
||||
/// date and time after which this payment cannot be captured
|
||||
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
|
||||
pub capture_before: Option<PrimitiveDateTime>,
|
||||
|
||||
/// Merchant's identifier for the payment/invoice. This will be sent to the connector
|
||||
/// if the connector provides support to accept multiple reference ids.
|
||||
/// In case the connector supports only one reference id, Hyperswitch's Payment ID will be sent as reference.
|
||||
|
||||
29
crates/api_models/src/payments/trait_impls.rs
Normal file
29
crates/api_models/src/payments/trait_impls.rs
Normal file
@ -0,0 +1,29 @@
|
||||
#[cfg(feature = "v1")]
|
||||
use common_enums::enums;
|
||||
#[cfg(feature = "v1")]
|
||||
use common_utils::errors;
|
||||
|
||||
#[cfg(feature = "v1")]
|
||||
use crate::payments;
|
||||
|
||||
#[cfg(feature = "v1")]
|
||||
impl crate::ValidateFieldAndGet<payments::PaymentsRequest>
|
||||
for common_utils::types::RequestExtendedAuthorizationBool
|
||||
{
|
||||
fn validate_field_and_get(
|
||||
&self,
|
||||
request: &payments::PaymentsRequest,
|
||||
) -> errors::CustomResult<Self, errors::ValidationError>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
match request.capture_method{
|
||||
Some(enums::CaptureMethod::Automatic)
|
||||
| Some(enums::CaptureMethod::Scheduled)
|
||||
| Some(enums::CaptureMethod::SequentialAutomatic)
|
||||
| None => Err(error_stack::report!(errors::ValidationError::InvalidValue { message: "request_extended_authorization must be sent only if capture method is manual or manual_multiple".to_string() })),
|
||||
Some(enums::CaptureMethod::Manual)
|
||||
| Some(enums::CaptureMethod::ManualMultiple) => Ok(*self)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user