Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AnuthaDev committed Oct 25, 2024
1 parent 9f3cf5a commit 70f4253
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 44 deletions.
2 changes: 1 addition & 1 deletion api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -1879,7 +1879,7 @@
}
},
"404": {
"description": "Payment ID not found"
"description": "Payment Intent not found"
}
},
"security": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ pub struct CalculateTax;
pub struct SdkSessionUpdate;

#[derive(Debug, Clone)]
pub struct Intent;
pub struct PaymentCreateIntent;

#[derive(Debug, Clone)]
pub struct PaymentGetIntent;

#[derive(Debug, Clone)]
pub struct PostSessionTokens;
2 changes: 1 addition & 1 deletion crates/openapi/src/routes/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ pub fn payments_create_intent() {}
params (("id" = String, Path, description = "The unique identifier for the Payment Intent")),
responses(
(status = 200, description = "Payment Intent", body = PaymentsIntentResponse),
(status = 404, description = "Payment ID not found")
(status = 404, description = "Payment Intent not found")
),
tag = "Payments",
operation_id = "Get the Payment Intent details",
Expand Down
4 changes: 2 additions & 2 deletions crates/router/src/core/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ pub async fn payments_intent_operation_core<F, Req, Op, D>(
) -> RouterResult<(D, Req, Option<domain::Customer>)>
where
F: Send + Clone + Sync,
Req: Authenticate + Clone,
Req: Clone,
Op: Operation<F, Req, Data = D> + Send + Sync,
D: OperationSessionGetters<F> + OperationSessionSetters<F> + Send + Sync + Clone,
{
Expand Down Expand Up @@ -1454,7 +1454,7 @@ pub async fn payments_intent_core<F, Res, Req, Op, D>(
where
F: Send + Clone + Sync,
Op: Operation<F, Req, Data = D> + Send + Sync + Clone,
Req: Debug + Authenticate + Clone,
Req: Debug + Clone,
D: OperationSessionGetters<F> + OperationSessionSetters<F> + Send + Sync + Clone,
Res: transformers::ToResponse<F, D, Op>,
{
Expand Down
19 changes: 2 additions & 17 deletions crates/router/src/core/payments/operations/payment_get_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::marker::PhantomData;
use api_models::{enums::FrmSuggestion, payments::PaymentsGetIntentRequest};
use async_trait::async_trait;
use common_utils::errors::CustomResult;
use error_stack::ResultExt;
use router_env::{instrument, tracing};

use super::{BoxedOperation, Domain, GetTracker, Operation, UpdateTracker, ValidateRequest};
Expand All @@ -12,8 +11,8 @@ use crate::{
errors::{self, RouterResult},
payments::{self, helpers, operations},
},
db::errors::StorageErrorExt,
routes::{app::ReqState, SessionState},
services,
types::{
api, domain,
storage::{self, enums},
Expand Down Expand Up @@ -104,8 +103,7 @@ impl<F: Send + Clone> GetTracker<F, payments::PaymentIntentData<F>, PaymentsGetI
let payment_intent = db
.find_payment_intent_by_id(key_manager_state, &request.id, key_store, storage_scheme)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Payment Intent Not Found")?;
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;

let payment_data = payments::PaymentIntentData {
flow: PhantomData,
Expand Down Expand Up @@ -189,19 +187,6 @@ impl<F: Clone + Send> Domain<F, PaymentsGetIntentRequest, payments::PaymentInten
),
errors::StorageError,
> {
// validate customer_id if sent in the request
if let Some(id) = payment_data.payment_intent.customer_id.clone() {
state
.store
.find_customer_by_global_id(
&state.into(),
id.get_string_repr(),
&payment_data.payment_intent.merchant_id,
merchant_key_store,
storage_scheme,
)
.await?;
}
Ok((Box::new(self), None))
}

Expand Down
20 changes: 5 additions & 15 deletions crates/router/src/routes/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ pub async fn payments_create_intent(
json_payload.into_inner(),
|state, auth: auth::AuthenticationDataV2, req, req_state| {
payments::payments_intent_core::<
api_types::Intent,
api_types::PaymentCreateIntent,
payment_types::PaymentsIntentResponse,
_,
_,
PaymentIntentData<api_types::Intent>,
PaymentIntentData<api_types::PaymentCreateIntent>,
>(
state,
req_state,
Expand Down Expand Up @@ -188,11 +188,11 @@ pub async fn payments_get_intent(
payload,
|state, auth: auth::AuthenticationDataV2, req, req_state| {
payments::payments_intent_core::<
api_types::Intent,
api_types::PaymentGetIntent,
payment_types::PaymentsIntentResponse,
_,
_,
PaymentIntentData<api_types::Intent>,
PaymentIntentData<api_types::PaymentGetIntent>,
>(
state,
req_state,
Expand All @@ -204,17 +204,7 @@ pub async fn payments_get_intent(
header_payload.clone(),
)
},
match env::which() {
env::Env::Production => &auth::HeaderAuth(auth::ApiKeyAuth),
_ => auth::auth_type(
&auth::HeaderAuth(auth::ApiKeyAuth),
&auth::JWTAuth {
permission: Permission::PaymentWrite,
minimum_entity_level: EntityType::Profile,
},
req.headers(),
),
},
&auth::HeaderAuth(auth::ApiKeyAuth),
api_locking::LockAction::NotApplicable,
))
.await
Expand Down
4 changes: 0 additions & 4 deletions crates/router/src/services/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1263,10 +1263,6 @@ impl Authenticate for api_models::payments::PaymentsIncrementalAuthorizationRequ
impl Authenticate for api_models::payments::PaymentsStartRequest {}
// impl Authenticate for api_models::payments::PaymentsApproveRequest {}
impl Authenticate for api_models::payments::PaymentsRejectRequest {}
#[cfg(feature = "v2")]
impl Authenticate for api_models::payments::PaymentsCreateIntentRequest {}
#[cfg(feature = "v2")]
impl Authenticate for api_models::payments::PaymentsGetIntentRequest {}
// #[cfg(feature = "v2")]
// impl Authenticate for api_models::payments::PaymentsIntentResponse {}

Expand Down
6 changes: 3 additions & 3 deletions crates/router/src/types/api/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ pub use api_models::payments::{PaymentsCreateIntentRequest, PaymentsIntentRespon
use error_stack::ResultExt;
pub use hyperswitch_domain_models::router_flow_types::payments::{
Approve, Authorize, AuthorizeSessionToken, Balance, CalculateTax, Capture, CompleteAuthorize,
CreateConnectorCustomer, IncrementalAuthorization, InitPayment, Intent, PSync,
PaymentMethodToken, PostProcessing, PostSessionTokens, PreProcessing, Reject, SdkSessionUpdate,
Session, SetupMandate, Void,
CreateConnectorCustomer, IncrementalAuthorization, InitPayment, PSync, PaymentConfirmIntent,
PaymentCreateIntent, PaymentGetIntent, PaymentMethodToken, PostProcessing, PostSessionTokens,
PreProcessing, Reject, SdkSessionUpdate, Session, SetupMandate, Void,
};
pub use hyperswitch_interfaces::api::payments::{
ConnectorCustomer, MandateSetup, Payment, PaymentApprove, PaymentAuthorize,
Expand Down

0 comments on commit 70f4253

Please sign in to comment.