-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(router): Add support for storing multiple surcharge configurations at profile level #7570
base: main
Are you sure you want to change the base?
Conversation
…vel endpoint to list all surcharge configs
…ti-surcharge-configs
ToSchema, | ||
Default, | ||
)] | ||
#[router_derive::diesel_enum(storage_type = "db_enum")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[router_derive::diesel_enum(storage_type = "db_enum")] | |
#[router_derive::diesel_enum(storage_type = "text")] |
Making this db_enum would make it difficult to add new enum variant in future.
/// A wrapper type for `RoutingId` that can be used for surcharge routing ids | ||
pub struct SurchargeRoutingId(pub RoutingId); | ||
|
||
impl Deref for SurchargeRoutingId { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?
) | ||
.service( | ||
web::resource("/{algorithm_id}/surcharge/activate") | ||
.route(web::post().to(routing::surcharge_link_config)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
) | |
.service( | |
web::resource("/{algorithm_id}/surcharge/activate") | |
.route(web::post().to(routing::surcharge_link_config)), | |
) | |
.service( | |
web::resource("decision/surcharge/{algorithm_id}/activate") | |
.route(web::post().to(routing::surcharge_link_config)), |
req, | ||
payload, | ||
&TransactionType::Payment, | ||
AlgorithmType::Surcharge, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create a const for this and pass to this function.
@@ -0,0 +1,4 @@ | |||
-- Your SQL goes here | |||
CREATE TYPE "AlgorithmType" AS ENUM ('routing', 'surcharge', '3ds'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets not create a DB enum right now.
-- Your SQL goes here | ||
CREATE TYPE "AlgorithmType" AS ENUM ('routing', 'surcharge', '3ds'); | ||
|
||
ALTER TABLE routing_algorithm ADD COLUMN IF NOT EXISTS algorithm_type "AlgorithmType" NOT NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ALTER TABLE routing_algorithm ADD COLUMN IF NOT EXISTS algorithm_type "AlgorithmType" NOT NULL; | |
ALTER TABLE routing_algorithm ADD COLUMN IF NOT EXISTS algorithm_type VARCHAR(64) NOT NULL; |
let profile_id = profile_id | ||
.ok_or_else(|| errors::ApiErrorResponse::MissingRequiredField { | ||
field_name: "profile_id", | ||
}) | ||
.change_context(errors::ApiErrorResponse::MissingRequiredField { | ||
field_name: "profile_id", | ||
})?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets do this validation in the parent function get profile_id as non optional value int this function.
let profile_id = profile_id | ||
.ok_or_else(|| errors::ApiErrorResponse::MissingRequiredField { | ||
field_name: "profile_id", | ||
}) | ||
.change_context(errors::ApiErrorResponse::MissingRequiredField { | ||
field_name: "profile_id", | ||
})?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets do this validation in the parent function get profile_id as non optional value int this function.
let name = request | ||
.name | ||
.get_required_value("name") | ||
.change_context(errors::ApiErrorResponse::MissingRequiredField { field_name: "name" }) | ||
.attach_printable("Name of config not given")?; | ||
|
||
let description = request | ||
.description | ||
.get_required_value("description") | ||
.change_context(errors::ApiErrorResponse::MissingRequiredField { | ||
field_name: "description", | ||
}) | ||
.attach_printable("Description of config not given")?; | ||
|
||
let surcharge_algorithm_data = SurchargeDecisionManagerConfig { | ||
merchant_surcharge_configs: request.merchant_surcharge_configs.clone(), | ||
algorithm: request | ||
.algorithm | ||
.get_required_value("algorithm") | ||
.change_context(errors::ApiErrorResponse::MissingRequiredField { | ||
field_name: "algorithm", | ||
}) | ||
.attach_printable("Algorithm of config not given")?, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
introduce a new request type where are these values will be required.
.await | ||
.to_not_found_response(errors::ApiErrorResponse::ResourceIdNotFound)?; | ||
|
||
let new_record = SurchargeRecord { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return description as well
let profile_id = query.profile_id; | ||
|
||
let final_response; | ||
if let Some(profile_id) = profile_id.clone() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
profile_id can be amde required in SurchargeRetrieveLinkQuery
return Err(errors::ApiErrorResponse::ResourceIdNotFound) | ||
.change_context(errors::ApiErrorResponse::ResourceIdNotFound) | ||
.attach_printable("Active surcharge algorithm ID not found"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return Err(errors::ApiErrorResponse::ResourceIdNotFound) | |
.change_context(errors::ApiErrorResponse::ResourceIdNotFound) | |
.attach_printable("Active surcharge algorithm ID not found"); | |
return report!(errors::ApiErrorResponse::ResourceIdNotFound) | |
.attach_printable("Active surcharge algorithm ID not found"); |
state: SessionState, | ||
merchant_account: domain::MerchantAccount, | ||
key_store: domain::MerchantKeyStore, | ||
auth_profile_id: Option<id_type::ProfileId>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auth_profile_id: Option<id_type::ProfileId>, | |
auth_profile_id: id_type::ProfileId, |
merchant_account: domain::MerchantAccount, | ||
key_store: domain::MerchantKeyStore, | ||
auth_profile_id: Option<id_type::ProfileId>, | ||
algorithm_id: id_type::RoutingId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
algorithm_id: id_type::RoutingId, | |
algorithm_id: id_type::SurchargeRoutingId, |
active_surcharge_algorithm_id: Some(surcharge_algorithm_id), | ||
}; | ||
|
||
db.update_profile_by_profile_id( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
db.update_profile_by_profile_id( | |
let updated_profile = db.update_profile_by_profile_id( |
let updated_profile = db | ||
.find_business_profile_by_profile_id(key_manager_state, &key_store, &profile_id) | ||
.await | ||
.to_not_found_response(errors::ApiErrorResponse::ResourceIdNotFound)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let updated_profile = db | |
.find_business_profile_by_profile_id(key_manager_state, &key_store, &profile_id) | |
.await | |
.to_not_found_response(errors::ApiErrorResponse::ResourceIdNotFound)?; |
let record = db | ||
.find_routing_algorithm_by_profile_id_algorithm_id(&profile_id, &active_algorithm_id) | ||
.await | ||
.to_not_found_response(errors::ApiErrorResponse::ResourceIdNotFound)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should do this validation before updating business_profile.
steps
- validate business_profile_id
- validate surcharge_routing_id
- update business profile with active surcharge id.
@@ -120,6 +120,7 @@ impl RoutingAlgorithmUpdate { | |||
created_at: timestamp, | |||
modified_at: timestamp, | |||
algorithm_for: transaction_type, | |||
algorithm_type: enums::AlgorithmType::Routing, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use const wherever this is hardcoded.
Type of Change
Description
This PR adds support for storing multiple surcharge configurations at profile level by adding new endpoints to list, create, activate and retrieve active surcharge configurations.
Additional Changes
Motivation and Context
Closes #7569
How did you test it?
Checklist
cargo +nightly fmt --all
cargo clippy