Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::{
core::{
errors::{self, RouterResult, StorageErrorExt},
payments::{helpers, operations, PaymentData},
utils::ValidatePlatformMerchant,
},
events::audit_events::{AuditEvent, AuditEventType},
routes::{app::ReqState, SessionState},
Expand Down Expand Up @@ -45,7 +46,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsCaptureR
key_store: &domain::MerchantKeyStore,
_auth_flow: services::AuthFlow,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
_platform_merchant_account: Option<&domain::MerchantAccount>,
platform_merchant_account: Option<&domain::MerchantAccount>,
) -> RouterResult<
operations::GetTrackerResponse<'a, F, api::PaymentsCaptureRequest, PaymentData<F>>,
> {
Expand All @@ -70,6 +71,9 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsCaptureR
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;

payment_intent
.validate_platform_merchant(platform_merchant_account.map(|ma| ma.get_id()))?;

helpers::validate_payment_status_against_not_allowed_statuses(
payment_intent.status,
&[IntentStatus::Failed, IntentStatus::Succeeded],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
core::{
errors::{self, RouterResult, StorageErrorExt},
payments::{helpers, operations, PaymentData},
utils::ValidatePlatformMerchant,
},
events::audit_events::{AuditEvent, AuditEventType},
routes::{app::ReqState, SessionState},
Expand Down Expand Up @@ -46,7 +47,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsCancelRe
key_store: &domain::MerchantKeyStore,
_auth_flow: services::AuthFlow,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
_platform_merchant_account: Option<&domain::MerchantAccount>,
platform_merchant_account: Option<&domain::MerchantAccount>,
) -> RouterResult<
operations::GetTrackerResponse<'a, F, api::PaymentsCancelRequest, PaymentData<F>>,
> {
Expand All @@ -70,6 +71,9 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsCancelRe
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;

payment_intent
.validate_platform_merchant(platform_merchant_account.map(|ma| ma.get_id()))?;

helpers::validate_payment_status_against_not_allowed_statuses(
payment_intent.status,
&[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::{
core::{
errors::{self, RouterResult, StorageErrorExt},
payments::{self, helpers, operations, types::MultipleCaptureData},
utils::ValidatePlatformMerchant,
},
events::audit_events::{AuditEvent, AuditEventType},
routes::{app::ReqState, SessionState},
Expand Down Expand Up @@ -45,7 +46,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, payments::PaymentData<F>, api::Paymen
key_store: &domain::MerchantKeyStore,
_auth_flow: services::AuthFlow,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
_platform_merchant_account: Option<&domain::MerchantAccount>,
platform_merchant_account: Option<&domain::MerchantAccount>,
) -> RouterResult<
operations::GetTrackerResponse<
'a,
Expand Down Expand Up @@ -76,6 +77,9 @@ impl<F: Send + Clone + Sync> GetTracker<F, payments::PaymentData<F>, api::Paymen
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;

payment_intent
.validate_platform_merchant(platform_merchant_account.map(|ma| ma.get_id()))?;

payment_attempt = db
.find_payment_attempt_by_payment_id_merchant_id_attempt_id(
&payment_intent.payment_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ use super::{Domain, GetTracker, Operation, UpdateTracker, ValidateRequest};
use crate::{
core::{
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments::operations::{self, ValidateStatusForOperation},
payments::{
helpers,
operations::{self, ValidateStatusForOperation},
},
utils::ValidatePlatformMerchant,
},
routes::{app::ReqState, SessionState},
types::{
Expand Down Expand Up @@ -142,7 +146,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentCaptureData<F>, PaymentsCaptureReques
_profile: &domain::Profile,
key_store: &domain::MerchantKeyStore,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
_platform_merchant_account: Option<&domain::MerchantAccount>,
platform_merchant_account: Option<&domain::MerchantAccount>,
) -> RouterResult<operations::GetTrackerResponse<PaymentCaptureData<F>>> {
let db = &*state.store;
let key_manager_state = &state.into();
Expand All @@ -154,6 +158,9 @@ impl<F: Send + Clone> GetTracker<F, PaymentCaptureData<F>, PaymentsCaptureReques
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;

payment_intent
.validate_platform_merchant(platform_merchant_account.map(|ma| ma.get_id()))?;

self.validate_status_for_operation(payment_intent.status)?;

let active_attempt_id = payment_intent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
)
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;

// TODO (#7195): Add platform merchant account validation once client_secret auth is solved

payment_intent.setup_future_usage = request
.setup_future_usage
.or(payment_intent.setup_future_usage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;

// TODO (#7195): Add platform merchant account validation once client_secret auth is solved

if let Some(order_details) = &request.order_details {
helpers::validate_order_details_amount(
order_details.to_owned(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentConfirmData<F>, PaymentsConfir
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;

// TODO (#7195): Add platform merchant account validation once publishable key auth is solved

self.validate_status_for_operation(payment_intent.status)?;
let client_secret = header_payload
.client_secret
Expand Down
11 changes: 9 additions & 2 deletions crates/router/src/core/payments/operations/payment_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ use super::{Domain, GetTracker, Operation, UpdateTracker, ValidateRequest};
use crate::{
core::{
errors::{self, CustomResult, RouterResult, StorageErrorExt},
payments::operations::{self, ValidateStatusForOperation},
payments::{
helpers,
operations::{self, ValidateStatusForOperation},
},
utils::ValidatePlatformMerchant,
},
routes::{app::ReqState, SessionState},
types::{
Expand Down Expand Up @@ -119,7 +123,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentStatusData<F>, PaymentsRetriev
_profile: &domain::Profile,
key_store: &domain::MerchantKeyStore,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
_platform_merchant_account: Option<&domain::MerchantAccount>,
platform_merchant_account: Option<&domain::MerchantAccount>,
) -> RouterResult<operations::GetTrackerResponse<PaymentStatusData<F>>> {
let db = &*state.store;
let key_manager_state = &state.into();
Expand All @@ -131,6 +135,9 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentStatusData<F>, PaymentsRetriev
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;

payment_intent
.validate_platform_merchant(platform_merchant_account.map(|ma| ma.get_id()))?;

let payment_attempt = payment_intent
.active_attempt_id
.as_ref()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
core::{
errors::{self, RouterResult},
payments::{self, helpers, operations},
utils::ValidatePlatformMerchant,
},
db::errors::StorageErrorExt,
routes::{app::ReqState, SessionState},
Expand Down Expand Up @@ -89,7 +90,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, payments::PaymentIntentData<F>, Payme
_profile: &domain::Profile,
key_store: &domain::MerchantKeyStore,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
_platform_merchant_account: Option<&domain::MerchantAccount>,
platform_merchant_account: Option<&domain::MerchantAccount>,
) -> RouterResult<operations::GetTrackerResponse<payments::PaymentIntentData<F>>> {
let db = &*state.store;
let key_manager_state = &state.into();
Expand All @@ -99,6 +100,9 @@ impl<F: Send + Clone + Sync> GetTracker<F, payments::PaymentIntentData<F>, Payme
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;

payment_intent
.validate_platform_merchant(platform_merchant_account.map(|ma| ma.get_id()))?;

let payment_data = payments::PaymentIntentData {
flow: PhantomData,
payment_intent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsPostSess
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;

// TODO (#7195): Add platform merchant account validation once publishable key auth is solved

helpers::authenticate_client_secret(Some(request.client_secret.peek()), &payment_intent)?;

let mut payment_attempt = db
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::{
core::{
errors::{self, RouterResult, StorageErrorExt},
payments::{helpers, operations, PaymentAddress, PaymentData},
utils::ValidatePlatformMerchant,
},
events::audit_events::{AuditEvent, AuditEventType},
routes::{app::ReqState, SessionState},
Expand Down Expand Up @@ -43,7 +44,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, PaymentsCancelRequest
key_store: &domain::MerchantKeyStore,
_auth_flow: services::AuthFlow,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
_platform_merchant_account: Option<&domain::MerchantAccount>,
platform_merchant_account: Option<&domain::MerchantAccount>,
) -> RouterResult<operations::GetTrackerResponse<'a, F, PaymentsCancelRequest, PaymentData<F>>>
{
let db = &*state.store;
Expand All @@ -66,6 +67,9 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, PaymentsCancelRequest
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;

payment_intent
.validate_platform_merchant(platform_merchant_account.map(|ma| ma.get_id()))?;

helpers::validate_payment_status_against_not_allowed_statuses(
payment_intent.status,
&[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsSessionR
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;

// TODO (#7195): Add platform merchant account validation once publishable key auth is solved

helpers::validate_payment_status_against_not_allowed_statuses(
payment_intent.status,
&[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use super::{BoxedOperation, Domain, GetTracker, Operation, ValidateRequest};
use crate::{
core::{
errors::{self, RouterResult, StorageErrorExt},
payments::{self, operations, operations::ValidateStatusForOperation},
payments::{self, helpers, operations, operations::ValidateStatusForOperation},
},
routes::SessionState,
types::{api, domain, storage::enums},
Expand Down Expand Up @@ -112,6 +112,8 @@ impl<F: Send + Clone + Sync> GetTracker<F, payments::PaymentIntentData<F>, Payme
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;

// TODO (#7195): Add platform merchant account validation once publishable key auth is solved

self.validate_status_for_operation(payment_intent.status)?;

let client_secret = header_payload
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/core/payments/operations/payment_start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsStartReq
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;

// TODO (#7195): Add platform merchant account validation once Merchant ID auth is solved

helpers::validate_payment_status_against_not_allowed_statuses(
payment_intent.status,
&[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRetrieve
key_store: &domain::MerchantKeyStore,
_auth_flow: services::AuthFlow,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
_platform_merchant_account: Option<&domain::MerchantAccount>,
platform_merchant_account: Option<&domain::MerchantAccount>,
) -> RouterResult<
operations::GetTrackerResponse<'a, F, api::PaymentsRetrieveRequest, PaymentData<F>>,
> {
Expand All @@ -225,6 +225,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRetrieve
request,
self,
merchant_account.storage_scheme,
platform_merchant_account,
)
.await
}
Expand Down Expand Up @@ -252,6 +253,7 @@ async fn get_tracker_for_sync<
any(feature = "v2", feature = "v1"),
not(feature = "payment_methods_v2")
))]
#[allow(clippy::too_many_arguments)]
async fn get_tracker_for_sync<
'a,
F: Send + Clone,
Expand All @@ -264,6 +266,7 @@ async fn get_tracker_for_sync<
request: &api::PaymentsRetrieveRequest,
operation: Op,
storage_scheme: enums::MerchantStorageScheme,
platform_merchant_account: Option<&domain::MerchantAccount>,
) -> RouterResult<operations::GetTrackerResponse<'a, F, api::PaymentsRetrieveRequest, PaymentData<F>>>
{
let (payment_intent, mut payment_attempt, currency, amount);
Expand All @@ -274,6 +277,7 @@ async fn get_tracker_for_sync<
merchant_account.get_id(),
key_store,
storage_scheme,
platform_merchant_account,
)
.await?;

Expand Down Expand Up @@ -579,6 +583,7 @@ pub async fn get_payment_intent_payment_attempt(
merchant_id: &common_utils::id_type::MerchantId,
key_store: &domain::MerchantKeyStore,
storage_scheme: enums::MerchantStorageScheme,
_platform_merchant_account: Option<&domain::MerchantAccount>,
) -> RouterResult<(storage::PaymentIntent, storage::PaymentAttempt)> {
let key_manager_state: KeyManagerState = state.into();
let db = &*state.store;
Expand Down Expand Up @@ -662,4 +667,6 @@ pub async fn get_payment_intent_payment_attempt(
get_pi_pa()
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)

// TODO (#7195): Add platform merchant account validation once client_secret auth is solved
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;

// TODO (#7195): Add platform merchant account validation once publishable key auth is solved

if let Some(order_details) = &request.order_details {
helpers::validate_order_details_amount(
order_details.to_owned(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ use crate::{
core::{
errors::{self, RouterResult},
payments::{
self,
self, helpers,
operations::{self, ValidateStatusForOperation},
},
utils::ValidatePlatformMerchant,
},
db::errors::StorageErrorExt,
routes::{app::ReqState, SessionState},
Expand Down Expand Up @@ -135,7 +136,7 @@ impl<F: Send + Clone> GetTracker<F, payments::PaymentIntentData<F>, PaymentsUpda
_profile: &domain::Profile,
key_store: &domain::MerchantKeyStore,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
_platform_merchant_account: Option<&domain::MerchantAccount>,
platform_merchant_account: Option<&domain::MerchantAccount>,
) -> RouterResult<operations::GetTrackerResponse<payments::PaymentIntentData<F>>> {
let db = &*state.store;
let key_manager_state = &state.into();
Expand All @@ -145,6 +146,9 @@ impl<F: Send + Clone> GetTracker<F, payments::PaymentIntentData<F>, PaymentsUpda
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;

payment_intent
.validate_platform_merchant(platform_merchant_account.map(|ma| ma.get_id()))?;

self.validate_status_for_operation(payment_intent.status)?;

let PaymentsUpdateIntentRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::{
self, helpers, operations, CustomerDetails, IncrementalAuthorizationDetails,
PaymentAddress,
},
utils::ValidatePlatformMerchant,
},
routes::{app::ReqState, SessionState},
services,
Expand Down Expand Up @@ -48,7 +49,7 @@ impl<F: Send + Clone + Sync>
key_store: &domain::MerchantKeyStore,
_auth_flow: services::AuthFlow,
_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
_platform_merchant_account: Option<&domain::MerchantAccount>,
platform_merchant_account: Option<&domain::MerchantAccount>,
) -> RouterResult<
operations::GetTrackerResponse<
'a,
Expand Down Expand Up @@ -77,6 +78,9 @@ impl<F: Send + Clone + Sync>
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;

payment_intent
.validate_platform_merchant(platform_merchant_account.map(|ma| ma.get_id()))?;

helpers::validate_payment_status_against_allowed_statuses(
payment_intent.status,
&[enums::IntentStatus::RequiresCapture],
Expand Down
Loading
Loading