Skip to content

Commit

Permalink
feat(core): api ,domain and diesel model changes for extended authori…
Browse files Browse the repository at this point in the history
…zation (#6607)
  • Loading branch information
hrithikesh026 authored Dec 16, 2024
1 parent ed276ec commit e4210b0
Show file tree
Hide file tree
Showing 34 changed files with 557 additions and 59 deletions.
22 changes: 22 additions & 0 deletions api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -15139,6 +15139,17 @@
"description": "You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. FRM Metadata is useful for storing additional, structured information on an object related to FRM.",
"nullable": true
},
"extended_authorization_applied": {
"type": "boolean",
"description": "flag that indicates if extended authorization is applied on this payment or not",
"nullable": true
},
"capture_before": {
"type": "string",
"format": "date-time",
"description": "date and time after which this payment cannot be captured",
"nullable": true
},
"merchant_order_reference_id": {
"type": "string",
"description": "Merchant's identifier for the payment/invoice. This will be sent to the connector\nif the connector provides support to accept multiple reference ids.\nIn case the connector supports only one reference id, Hyperswitch's Payment ID will be sent as reference.",
Expand Down Expand Up @@ -16039,6 +16050,17 @@
"description": "You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. FRM Metadata is useful for storing additional, structured information on an object related to FRM.",
"nullable": true
},
"extended_authorization_applied": {
"type": "boolean",
"description": "flag that indicates if extended authorization is applied on this payment or not",
"nullable": true
},
"capture_before": {
"type": "string",
"format": "date-time",
"description": "date and time after which this payment cannot be captured",
"nullable": true
},
"merchant_order_reference_id": {
"type": "string",
"description": "Merchant's identifier for the payment/invoice. This will be sent to the connector\nif the connector provides support to accept multiple reference ids.\nIn case the connector supports only one reference id, Hyperswitch's Payment ID will be sent as reference.",
Expand Down
56 changes: 56 additions & 0 deletions api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -17246,6 +17246,12 @@
],
"nullable": true
},
"request_extended_authorization": {
"type": "boolean",
"description": "Optional boolean value to extent authorization period of this payment\n\ncapture method must be manual or manual_multiple",
"default": false,
"nullable": true
},
"merchant_order_reference_id": {
"type": "string",
"description": "Merchant's identifier for the payment/invoice. This will be sent to the connector\nif the connector provides support to accept multiple reference ids.\nIn case the connector supports only one reference id, Hyperswitch's Payment ID will be sent as reference.",
Expand Down Expand Up @@ -17632,6 +17638,12 @@
],
"nullable": true
},
"request_extended_authorization": {
"type": "boolean",
"description": "Optional boolean value to extent authorization period of this payment\n\ncapture method must be manual or manual_multiple",
"default": false,
"nullable": true
},
"merchant_order_reference_id": {
"type": "string",
"description": "Merchant's identifier for the payment/invoice. This will be sent to the connector\nif the connector provides support to accept multiple reference ids.\nIn case the connector supports only one reference id, Hyperswitch's Payment ID will be sent as reference.",
Expand Down Expand Up @@ -18179,6 +18191,17 @@
"description": "You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. FRM Metadata is useful for storing additional, structured information on an object related to FRM.",
"nullable": true
},
"extended_authorization_applied": {
"type": "boolean",
"description": "flag that indicates if extended authorization is applied on this payment or not",
"nullable": true
},
"capture_before": {
"type": "string",
"format": "date-time",
"description": "date and time after which this payment cannot be captured",
"nullable": true
},
"merchant_order_reference_id": {
"type": "string",
"description": "Merchant's identifier for the payment/invoice. This will be sent to the connector\nif the connector provides support to accept multiple reference ids.\nIn case the connector supports only one reference id, Hyperswitch's Payment ID will be sent as reference.",
Expand Down Expand Up @@ -18842,6 +18865,12 @@
],
"nullable": true
},
"request_extended_authorization": {
"type": "boolean",
"description": "Optional boolean value to extent authorization period of this payment\n\ncapture method must be manual or manual_multiple",
"default": false,
"nullable": true
},
"merchant_order_reference_id": {
"type": "string",
"description": "Merchant's identifier for the payment/invoice. This will be sent to the connector\nif the connector provides support to accept multiple reference ids.\nIn case the connector supports only one reference id, Hyperswitch's Payment ID will be sent as reference.",
Expand Down Expand Up @@ -19415,6 +19444,17 @@
"description": "You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. FRM Metadata is useful for storing additional, structured information on an object related to FRM.",
"nullable": true
},
"extended_authorization_applied": {
"type": "boolean",
"description": "flag that indicates if extended authorization is applied on this payment or not",
"nullable": true
},
"capture_before": {
"type": "string",
"format": "date-time",
"description": "date and time after which this payment cannot be captured",
"nullable": true
},
"merchant_order_reference_id": {
"type": "string",
"description": "Merchant's identifier for the payment/invoice. This will be sent to the connector\nif the connector provides support to accept multiple reference ids.\nIn case the connector supports only one reference id, Hyperswitch's Payment ID will be sent as reference.",
Expand Down Expand Up @@ -19891,6 +19931,12 @@
],
"nullable": true
},
"request_extended_authorization": {
"type": "boolean",
"description": "Optional boolean value to extent authorization period of this payment\n\ncapture method must be manual or manual_multiple",
"default": false,
"nullable": true
},
"merchant_order_reference_id": {
"type": "string",
"description": "Merchant's identifier for the payment/invoice. This will be sent to the connector\nif the connector provides support to accept multiple reference ids.\nIn case the connector supports only one reference id, Hyperswitch's Payment ID will be sent as reference.",
Expand Down Expand Up @@ -21876,6 +21922,11 @@
"nullable": true,
"minimum": 0
},
"always_request_extended_authorization": {
"type": "boolean",
"description": "Bool indicating if extended authentication must be requested for all payments",
"nullable": true
},
"is_click_to_pay_enabled": {
"type": "boolean",
"description": "Indicates if click to pay is enabled or not."
Expand Down Expand Up @@ -22115,6 +22166,11 @@
"description": "Maximum number of auto retries allowed for a payment",
"nullable": true
},
"always_request_extended_authorization": {
"type": "boolean",
"description": "Bool indicating if extended authentication must be requested for all payments",
"nullable": true
},
"is_click_to_pay_enabled": {
"type": "boolean",
"description": "Indicates if click to pay is enabled or not.",
Expand Down
13 changes: 12 additions & 1 deletion crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -1967,6 +1970,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,
Expand Down Expand Up @@ -2219,6 +2226,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,
Expand Down
9 changes: 9 additions & 0 deletions crates/api_models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,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;
}
34 changes: 32 additions & 2 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{
num::NonZeroI64,
};
pub mod additional_info;
pub mod trait_impls;
use cards::CardNumber;
use common_enums::ProductType;
#[cfg(feature = "v2")]
Expand All @@ -16,7 +17,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};
Expand All @@ -32,7 +36,7 @@ use crate::{
disputes, enums as api_enums,
ephemeral_key::EphemeralKeyCreateResponse,
mandates::RecurringDetails,
refunds,
refunds, ValidateFieldAndGet,
};

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -998,6 +1002,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.
Expand Down Expand Up @@ -1057,6 +1067,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
Expand Down Expand Up @@ -4678,6 +4700,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.
Expand Down
29 changes: 29 additions & 0 deletions crates/api_models/src/payments/trait_impls.rs
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
2 changes: 1 addition & 1 deletion crates/common_enums/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ openapi = []
payouts = []

[dependencies]
diesel = { version = "2.2.3", features = ["postgres"] }
diesel = { version = "2.2.3", features = ["postgres", "128-column-tables"] }
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.115"
strum = { version = "0.26", features = ["derive"] }
Expand Down
7 changes: 7 additions & 0 deletions crates/common_utils/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ pub mod authentication;
/// Enum for Theme Lineage
pub mod theme;

/// types that are wrappers around primitive types
pub mod primitive_wrappers;

use std::{
borrow::Cow,
fmt::Display,
Expand All @@ -26,6 +29,10 @@ use diesel::{
AsExpression, FromSqlRow, Queryable,
};
use error_stack::{report, ResultExt};
pub use primitive_wrappers::bool_wrappers::{
AlwaysRequestExtendedAuthorization, ExtendedAuthorizationAppliedBool,
RequestExtendedAuthorizationBool,
};
use rust_decimal::{
prelude::{FromPrimitive, ToPrimitive},
Decimal,
Expand Down
Loading

0 comments on commit e4210b0

Please sign in to comment.