Skip to content

Commit a0a8ef2

Browse files
Abhicodes-cryptokritikmodiNitesh Balla
authored
refactor(core): Add additional parameters in AppState and refactor AppState references (#2123)
Co-authored-by: Kritik Modi <[email protected]> Co-authored-by: Kritik Modi <[email protected]> Co-authored-by: Nitesh Balla <[email protected]>
1 parent b39369c commit a0a8ef2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+531
-395
lines changed

crates/router/src/compatibility/stripe/customers.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ pub async fn customer_create(
4242
_,
4343
>(
4444
flow,
45-
state.get_ref(),
45+
state.into_inner(),
4646
&req,
4747
create_cust_req,
4848
|state, auth, req| {
49-
customers::create_customer(&*state.store, auth.merchant_account, auth.key_store, req)
49+
customers::create_customer(state, auth.merchant_account, auth.key_store, req)
5050
},
5151
&auth::ApiKeyAuth,
5252
))
@@ -77,11 +77,11 @@ pub async fn customer_retrieve(
7777
_,
7878
>(
7979
flow,
80-
state.get_ref(),
80+
state.into_inner(),
8181
&req,
8282
payload,
8383
|state, auth, req| {
84-
customers::retrieve_customer(&*state.store, auth.merchant_account, auth.key_store, req)
84+
customers::retrieve_customer(state, auth.merchant_account, auth.key_store, req)
8585
},
8686
&auth::ApiKeyAuth,
8787
))
@@ -121,11 +121,11 @@ pub async fn customer_update(
121121
_,
122122
>(
123123
flow,
124-
state.get_ref(),
124+
state.into_inner(),
125125
&req,
126126
cust_update_req,
127127
|state, auth, req| {
128-
customers::update_customer(&*state.store, auth.merchant_account, req, auth.key_store)
128+
customers::update_customer(state, auth.merchant_account, req, auth.key_store)
129129
},
130130
&auth::ApiKeyAuth,
131131
))
@@ -156,7 +156,7 @@ pub async fn customer_delete(
156156
_,
157157
>(
158158
flow,
159-
state.get_ref(),
159+
state.into_inner(),
160160
&req,
161161
payload,
162162
|state, auth, req| {
@@ -190,7 +190,7 @@ pub async fn list_customer_payment_method_api(
190190
_,
191191
>(
192192
flow,
193-
state.get_ref(),
193+
state.into_inner(),
194194
&req,
195195
payload,
196196
|state, auth, req| {

crates/router/src/compatibility/stripe/payment_intents.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub async fn payment_intents_create(
4747
_,
4848
>(
4949
flow,
50-
state.get_ref(),
50+
state.into_inner(),
5151
&req,
5252
create_payment_req,
5353
|state, auth, req| {
@@ -106,7 +106,7 @@ pub async fn payment_intents_retrieve(
106106
_,
107107
>(
108108
flow,
109-
state.get_ref(),
109+
state.into_inner(),
110110
&req,
111111
payload,
112112
|state, auth, payload| {
@@ -169,7 +169,7 @@ pub async fn payment_intents_retrieve_with_gateway_creds(
169169
_,
170170
>(
171171
flow,
172-
state.get_ref(),
172+
state.into_inner(),
173173
&req,
174174
payload,
175175
|state, auth, req| {
@@ -233,7 +233,7 @@ pub async fn payment_intents_update(
233233
_,
234234
>(
235235
flow,
236-
state.get_ref(),
236+
state.into_inner(),
237237
&req,
238238
payload,
239239
|state, auth, req| {
@@ -299,7 +299,7 @@ pub async fn payment_intents_confirm(
299299
_,
300300
>(
301301
flow,
302-
state.get_ref(),
302+
state.into_inner(),
303303
&req,
304304
payload,
305305
|state, auth, req| {
@@ -355,7 +355,7 @@ pub async fn payment_intents_capture(
355355
_,
356356
>(
357357
flow,
358-
state.get_ref(),
358+
state.into_inner(),
359359
&req,
360360
capture_payload,
361361
|state, auth, payload| {
@@ -415,7 +415,7 @@ pub async fn payment_intents_cancel(
415415
_,
416416
>(
417417
flow,
418-
state.get_ref(),
418+
state.into_inner(),
419419
&req,
420420
payload,
421421
|state, auth, req| {
@@ -461,10 +461,10 @@ pub async fn payment_intent_list(
461461
_,
462462
>(
463463
flow,
464-
state.get_ref(),
464+
state.into_inner(),
465465
&req,
466466
payload,
467-
|state, auth, req| payments::list_payments(&*state.store, auth.merchant_account, req),
467+
|state, auth, req| payments::list_payments(state, auth.merchant_account, req),
468468
&auth::ApiKeyAuth,
469469
))
470470
.await

crates/router/src/compatibility/stripe/refunds.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub async fn refund_create(
4343
_,
4444
>(
4545
flow,
46-
state.get_ref(),
46+
state.into_inner(),
4747
&req,
4848
create_refund_req,
4949
|state, auth, req| {
@@ -83,7 +83,7 @@ pub async fn refund_retrieve_with_gateway_creds(
8383
_,
8484
>(
8585
flow,
86-
state.get_ref(),
86+
state.into_inner(),
8787
&req,
8888
refund_request,
8989
|state, auth, refund_request| {
@@ -126,7 +126,7 @@ pub async fn refund_retrieve(
126126
_,
127127
>(
128128
flow,
129-
state.get_ref(),
129+
state.into_inner(),
130130
&req,
131131
refund_request,
132132
|state, auth, refund_request| {
@@ -167,11 +167,11 @@ pub async fn refund_update(
167167
_,
168168
>(
169169
flow,
170-
state.get_ref(),
170+
state.into_inner(),
171171
&req,
172172
create_refund_update_req,
173173
|state, auth, req| {
174-
refunds::refund_update_core(&*state.store, auth.merchant_account, &refund_id, req)
174+
refunds::refund_update_core(state, auth.merchant_account, &refund_id, req)
175175
},
176176
&auth::ApiKeyAuth,
177177
))

crates/router/src/compatibility/stripe/setup_intents.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub async fn setup_intents_create(
5151
_,
5252
>(
5353
flow,
54-
state.get_ref(),
54+
state.into_inner(),
5555
&req,
5656
create_payment_req,
5757
|state, auth, req| {
@@ -110,7 +110,7 @@ pub async fn setup_intents_retrieve(
110110
_,
111111
>(
112112
flow,
113-
state.get_ref(),
113+
state.into_inner(),
114114
&req,
115115
payload,
116116
|state, auth, payload| {
@@ -175,7 +175,7 @@ pub async fn setup_intents_update(
175175
_,
176176
>(
177177
flow,
178-
state.get_ref(),
178+
state.into_inner(),
179179
&req,
180180
payload,
181181
|state, auth, req| {
@@ -241,7 +241,7 @@ pub async fn setup_intents_confirm(
241241
_,
242242
>(
243243
flow,
244-
state.get_ref(),
244+
state.into_inner(),
245245
&req,
246246
payload,
247247
|state, auth, req| {

crates/router/src/compatibility/wrap.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{future::Future, time::Instant};
1+
use std::{future::Future, sync::Arc, time::Instant};
22

33
use actix_web::{HttpRequest, HttpResponse, Responder};
44
use common_utils::errors::{CustomResult, ErrorSwitch};
@@ -14,14 +14,14 @@ use crate::{
1414
#[instrument(skip(request, payload, state, func, api_authentication))]
1515
pub async fn compatibility_api_wrap<'a, 'b, A, U, T, Q, F, Fut, S, E, E2>(
1616
flow: impl router_env::types::FlowMetric,
17-
state: &'b A,
17+
state: Arc<A>,
1818
request: &'a HttpRequest,
1919
payload: T,
2020
func: F,
2121
api_authentication: &dyn auth::AuthenticateAndFetch<U, A>,
2222
) -> HttpResponse
2323
where
24-
F: Fn(&'b A, U, T) -> Fut,
24+
F: Fn(A, U, T) -> Fut,
2525
Fut: Future<Output = CustomResult<api::ApplicationResponse<Q>, E2>>,
2626
E2: ErrorSwitch<E> + std::error::Error + Send + Sync + 'static,
2727
Q: Serialize + std::fmt::Debug + 'a,
@@ -31,7 +31,7 @@ where
3131
error_stack::Report<E>: services::EmbedError,
3232
errors::ApiErrorResponse: ErrorSwitch<E>,
3333
T: std::fmt::Debug,
34-
A: AppStateInfo,
34+
A: AppStateInfo + Clone,
3535
{
3636
let request_method = request.method().as_str();
3737
let url_path = request.path();
@@ -42,7 +42,14 @@ where
4242
logger::info!(tag = ?Tag::BeginRequest, payload = ?payload);
4343

4444
let res = match metrics::request::record_request_time_metric(
45-
api::server_wrap_util(&flow, state, request, payload, func, api_authentication),
45+
api::server_wrap_util(
46+
&flow,
47+
state.clone().into(),
48+
request,
49+
payload,
50+
func,
51+
api_authentication,
52+
),
4653
&flow,
4754
)
4855
.await

0 commit comments

Comments
 (0)