Skip to content

Commit

Permalink
Merge branch 'wordline' of https://github.com/Hangsaai/hyperswitch in…
Browse files Browse the repository at this point in the history
…to wordline
  • Loading branch information
Hangsaai committed Oct 24, 2023
2 parents 994539d + 8376baa commit 667207c
Show file tree
Hide file tree
Showing 34 changed files with 854 additions and 333 deletions.
40 changes: 40 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,46 @@ All notable changes to HyperSwitch will be documented here.

- - -

## 1.64.0 (2023-10-23)

### Features

- **events:** Add request body to api events logger ([#2660](https://github.com/juspay/hyperswitch/pull/2660)) ([`830eee9`](https://github.com/juspay/hyperswitch/commit/830eee94e1d35dcd14ef9989eb7b6003c1244a18))

### Bug Fixes

- **router:** Disable openapi examples ([#2648](https://github.com/juspay/hyperswitch/pull/2648)) ([`b39bdbf`](https://github.com/juspay/hyperswitch/commit/b39bdbf0c24730fea9cde0dcfa07ac43e4dd69a4))

### Refactors

- **connector:**
- Use connector_response_reference_id for Shift4 ([#2492](https://github.com/juspay/hyperswitch/pull/2492)) ([`83f0062`](https://github.com/juspay/hyperswitch/commit/83f0062aad9886a5a0c4ecff7412acfec63f7423))
- [PowerTranz] refactor powertranz payments to remove default cases ([#2547](https://github.com/juspay/hyperswitch/pull/2547)) ([`664093d`](https://github.com/juspay/hyperswitch/commit/664093dc79743203196d912c17570885718b1c02))

**Full Changelog:** [`v1.63.0...v1.64.0`](https://github.com/juspay/hyperswitch/compare/v1.63.0...v1.64.0)

- - -


## 1.63.0 (2023-10-20)

### Features

- Add support for updating surcharge_applicable field intent ([#2647](https://github.com/juspay/hyperswitch/pull/2647)) ([`949937e`](https://github.com/juspay/hyperswitch/commit/949937e3644346f8b2b952944efb884f270645a8))

### Bug Fixes

- Kms decryption of redis_temp_locker_encryption_key ([#2650](https://github.com/juspay/hyperswitch/pull/2650)) ([`5a6601f`](https://github.com/juspay/hyperswitch/commit/5a6601fad4d11cd7d2f1322a6453504494d20c6f))

### Refactors

- **router:** [Nexi nets] Remove Default Case Handling ([#2639](https://github.com/juspay/hyperswitch/pull/2639)) ([`4b64c56`](https://github.com/juspay/hyperswitch/commit/4b64c563558d7c0a02b248c23921ed47ff294980))

**Full Changelog:** [`v1.62.0...v1.63.0`](https://github.com/juspay/hyperswitch/compare/v1.62.0...v1.63.0)

- - -


## 1.62.0 (2023-10-19)

### Features
Expand Down
1 change: 0 additions & 1 deletion config/config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ host = "" # Locker host
mock_locker = true # Emulate a locker locally using Postgres
basilisk_host = "" # Basilisk host
locker_signing_key_id = "1" # Key_id to sign basilisk hs locker
redis_temp_locker_encryption_key = "000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f" # encryption key for redis temp locker

[delayed_session_response]
connectors_with_delayed_session_response = "trustpay,payme" # List of connectors which has delayed session response
Expand Down
1 change: 0 additions & 1 deletion config/development.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ applepay_endpoint = "DOMAIN SPECIFIC ENDPOINT"
host = ""
mock_locker = true
basilisk_host = ""
redis_temp_locker_encryption_key = "000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f"

[jwekey]
locker_key_identifier1 = ""
Expand Down
1 change: 0 additions & 1 deletion config/docker_compose.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ recon_admin_api_key = "recon_test_admin"
host = ""
mock_locker = true
basilisk_host = ""
redis_temp_locker_encryption_key = "000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f"

[jwekey]
locker_key_identifier1 = ""
Expand Down
7 changes: 7 additions & 0 deletions crates/api_models/src/payment_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,13 @@ pub struct DeleteTokenizeByTokenRequest {
pub service_name: String,
}

#[derive(Debug, serde::Serialize)] // Blocked: Yet to be implemented by `basilisk`
pub struct DeleteTokenizeByDateRequest {
pub buffer_minutes: i32,
pub service_name: String,
pub max_rows: i32,
}

#[derive(Debug, serde::Deserialize)]
pub struct GetTokenizePayloadResponse {
pub lookup_key: String,
Expand Down
13 changes: 11 additions & 2 deletions crates/common_utils/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,20 @@ pub enum QrCodeError {
}

/// Api Models construction error
#[derive(Debug, Clone, thiserror::Error, PartialEq, Eq)]
pub enum ApiModelsError {
#[derive(Debug, Clone, thiserror::Error, PartialEq)]
pub enum PercentageError {
/// Percentage Value provided was invalid
#[error("Invalid Percentage value")]
InvalidPercentageValue,

/// Error occurred while calculating percentage
#[error("Failed apply percentage of {percentage} on {amount}")]
UnableToApplyPercentage {
/// percentage value
percentage: f32,
/// amount value
amount: i64,
},
}

/// Allows [error_stack::Report] to change between error contexts
Expand Down
36 changes: 29 additions & 7 deletions crates/common_utils/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use error_stack::{IntoReport, ResultExt};
use serde::{de::Visitor, Deserialize, Deserializer};

use crate::errors::{ApiModelsError, CustomResult};
use crate::errors::{CustomResult, PercentageError};

/// Represents Percentage Value between 0 and 100 both inclusive
#[derive(Clone, Default, Debug, PartialEq, serde::Serialize)]
Expand All @@ -21,32 +21,54 @@ fn get_invalid_percentage_error_message(precision: u8) -> String {

impl<const PRECISION: u8> Percentage<PRECISION> {
/// construct percentage using a string representation of float value
pub fn from_string(value: String) -> CustomResult<Self, ApiModelsError> {
pub fn from_string(value: String) -> CustomResult<Self, PercentageError> {
if Self::is_valid_string_value(&value)? {
Ok(Self {
percentage: value
.parse()
.into_report()
.change_context(ApiModelsError::InvalidPercentageValue)?,
.change_context(PercentageError::InvalidPercentageValue)?,
})
} else {
Err(ApiModelsError::InvalidPercentageValue.into())
Err(PercentageError::InvalidPercentageValue.into())
.attach_printable(get_invalid_percentage_error_message(PRECISION))
}
}
/// function to get percentage value
pub fn get_percentage(&self) -> f32 {
self.percentage
}
fn is_valid_string_value(value: &str) -> CustomResult<bool, ApiModelsError> {

/// apply the percentage to amount and ceil the result
#[allow(clippy::as_conversions)]
pub fn apply_and_ceil_result(&self, amount: i64) -> CustomResult<i64, PercentageError> {
let max_amount = i64::MAX / 10000;
if amount > max_amount {
// value gets rounded off after i64::MAX/10000
Err(PercentageError::UnableToApplyPercentage {
percentage: self.percentage,
amount,
}
.into())
.attach_printable(format!(
"Cannot calculate percentage for amount greater than {}",
max_amount
))
} else {
let percentage_f64 = f64::from(self.percentage);
let result = (amount as f64 * (percentage_f64 / 100.0)).ceil() as i64;
Ok(result)
}
}
fn is_valid_string_value(value: &str) -> CustomResult<bool, PercentageError> {
let float_value = Self::is_valid_float_string(value)?;
Ok(Self::is_valid_range(float_value) && Self::is_valid_precision_length(value))
}
fn is_valid_float_string(value: &str) -> CustomResult<f32, ApiModelsError> {
fn is_valid_float_string(value: &str) -> CustomResult<f32, PercentageError> {
value
.parse()
.into_report()
.change_context(ApiModelsError::InvalidPercentageValue)
.change_context(PercentageError::InvalidPercentageValue)
}
fn is_valid_range(value: f32) -> bool {
(0.0..=100.0).contains(&value)
Expand Down
10 changes: 5 additions & 5 deletions crates/common_utils/tests/percentage.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(clippy::panic_in_result_fn)]
use common_utils::{errors::ApiModelsError, types::Percentage};
use common_utils::{errors::PercentageError, types::Percentage};
const PRECISION_2: u8 = 2;
const PRECISION_0: u8 = 0;

Expand All @@ -10,7 +10,7 @@ fn invalid_range_more_than_100() -> Result<(), Box<dyn std::error::Error + Send
if let Err(err) = percentage {
assert_eq!(
*err.current_context(),
ApiModelsError::InvalidPercentageValue
PercentageError::InvalidPercentageValue
)
}
Ok(())
Expand All @@ -22,7 +22,7 @@ fn invalid_range_less_than_0() -> Result<(), Box<dyn std::error::Error + Send +
if let Err(err) = percentage {
assert_eq!(
*err.current_context(),
ApiModelsError::InvalidPercentageValue
PercentageError::InvalidPercentageValue
)
}
Ok(())
Expand All @@ -35,7 +35,7 @@ fn invalid_string() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
if let Err(err) = percentage {
assert_eq!(
*err.current_context(),
ApiModelsError::InvalidPercentageValue
PercentageError::InvalidPercentageValue
)
}
Ok(())
Expand Down Expand Up @@ -92,7 +92,7 @@ fn invalid_precision() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
if let Err(err) = percentage {
assert_eq!(
*err.current_context(),
ApiModelsError::InvalidPercentageValue
PercentageError::InvalidPercentageValue
)
}
Ok(())
Expand Down
12 changes: 12 additions & 0 deletions crates/data_models/src/payments/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ pub enum PaymentIntentUpdate {
merchant_decision: Option<String>,
updated_by: String,
},
SurchargeApplicableUpdate {
surcharge_applicable: bool,
updated_by: String,
},
}

#[derive(Clone, Debug, Default)]
Expand Down Expand Up @@ -386,6 +390,14 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
updated_by,
..Default::default()
},
PaymentIntentUpdate::SurchargeApplicableUpdate {
surcharge_applicable,
updated_by,
} => Self {
surcharge_applicable: Some(surcharge_applicable),
updated_by,
..Default::default()
},
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions crates/diesel_models/src/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ pub enum PaymentIntentUpdate {
merchant_decision: Option<String>,
updated_by: String,
},
SurchargeApplicableUpdate {
surcharge_applicable: Option<bool>,
updated_by: String,
},
}

#[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)]
Expand Down Expand Up @@ -408,6 +412,14 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
updated_by,
..Default::default()
},
PaymentIntentUpdate::SurchargeApplicableUpdate {
surcharge_applicable,
updated_by,
} => Self {
surcharge_applicable,
updated_by,
..Default::default()
},
}
}
}
3 changes: 2 additions & 1 deletion crates/router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ default = ["kv_store", "stripe", "oltp", "olap", "accounts_cache", "dummy_connec
s3 = ["dep:aws-sdk-s3", "dep:aws-config"]
kms = ["external_services/kms", "dep:aws-config"]
email = ["external_services/email", "dep:aws-config"]
basilisk = ["kms"]
stripe = ["dep:serde_qs"]
release = ["kms", "stripe", "s3", "email","accounts_cache"]
release = ["kms", "stripe", "basilisk", "s3", "email","accounts_cache"]
olap = ["data_models/olap", "storage_impl/olap", "scheduler/olap"]
oltp = ["data_models/oltp", "storage_impl/oltp"]
kv_store = ["scheduler/kv_store"]
Expand Down
3 changes: 1 addition & 2 deletions crates/router/src/configs/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ impl Default for super::settings::Locker {
Self {
host: "localhost".into(),
mock_locker: true,

basilisk_host: "localhost".into(),
locker_signing_key_id: "1".into(),
redis_temp_locker_encryption_key: "".into(),
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/router/src/configs/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ pub enum Subcommand {
#[derive(Clone)]
pub struct ActiveKmsSecrets {
pub jwekey: masking::Secret<Jwekey>,
pub redis_temp_locker_encryption_key: masking::Secret<String>,
}

#[derive(Debug, Deserialize, Clone, Default)]
Expand Down Expand Up @@ -411,8 +410,8 @@ pub struct Secrets {
pub struct Locker {
pub host: String,
pub mock_locker: bool,
pub basilisk_host: String,
pub locker_signing_key_id: String,
pub redis_temp_locker_encryption_key: String,
}

#[derive(Debug, Deserialize, Clone)]
Expand Down
13 changes: 2 additions & 11 deletions crates/router/src/configs/validations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,10 @@ impl super::settings::Locker {
})?;

when(
self.redis_temp_locker_encryption_key.is_default_or_empty(),
!self.mock_locker && self.basilisk_host.is_default_or_empty(),
|| {
Err(ApplicationError::InvalidConfigurationValueError(
"redis_temp_locker_encryption_key must not be empty".into(),
))
},
)?;

when(
self.redis_temp_locker_encryption_key.is_default_or_empty(),
|| {
Err(ApplicationError::InvalidConfigurationValueError(
"redis_temp_locker_encryption_key must not be empty".into(),
"basilisk host must not be empty when mock locker is disabled".into(),
))
},
)
Expand Down
Loading

0 comments on commit 667207c

Please sign in to comment.