Skip to content

Commit 92ae2d9

Browse files
refactor(compatibility): refactor stripe compatibility routes using web::resource (#1022)
1 parent 64fa21e commit 92ae2d9

File tree

5 files changed

+61
-46
lines changed

5 files changed

+61
-46
lines changed

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

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,34 @@ pub struct PaymentIntents;
77

88
impl PaymentIntents {
99
pub fn server(state: routes::AppState) -> Scope {
10-
web::scope("/payment_intents")
11-
.app_data(web::Data::new(state))
12-
.service(payment_intents_retrieve_with_gateway_creds)
13-
.service(payment_intents_create)
14-
.service(payment_intents_retrieve)
15-
.service(payment_intents_update)
16-
.service(payment_intents_confirm)
17-
.service(payment_intents_capture)
10+
let mut route = web::scope("/payment_intents").app_data(web::Data::new(state));
11+
#[cfg(feature = "olap")]
12+
{
13+
route = route.service(web::resource("/list").route(web::get().to(payment_intent_list)))
14+
}
15+
route = route
16+
.service(web::resource("").route(web::post().to(payment_intents_create)))
17+
.service(
18+
web::resource("/sync")
19+
.route(web::post().to(payment_intents_retrieve_with_gateway_creds)),
20+
)
21+
.service(
22+
web::resource("/{payment_id}")
23+
.route(web::get().to(payment_intents_retrieve))
24+
.route(web::post().to(payment_intents_update)),
25+
)
26+
.service(
27+
web::resource("/{payment_id}/confirm")
28+
.route(web::post().to(payment_intents_confirm)),
29+
)
30+
.service(
31+
web::resource("/{payment_id}/capture")
32+
.route(web::post().to(payment_intents_capture)),
33+
)
34+
.service(
35+
web::resource("/{payment_id}/cancel").route(web::post().to(payment_intents_cancel)),
36+
);
37+
route
1838
}
1939
}
2040

@@ -24,10 +44,15 @@ impl SetupIntents {
2444
pub fn server(state: routes::AppState) -> Scope {
2545
web::scope("/setup_intents")
2646
.app_data(web::Data::new(state))
27-
.service(setup_intents_create)
28-
.service(setup_intents_retrieve)
29-
.service(setup_intents_update)
30-
.service(setup_intents_confirm)
47+
.service(web::resource("").route(web::post().to(setup_intents_create)))
48+
.service(
49+
web::resource("/{setup_id}")
50+
.route(web::get().to(setup_intents_retrieve))
51+
.route(web::post().to(setup_intents_update)),
52+
)
53+
.service(
54+
web::resource("/{setup_id}/confirm").route(web::post().to(setup_intents_confirm)),
55+
)
3156
}
3257
}
3358

@@ -37,10 +62,15 @@ impl Refunds {
3762
pub fn server(config: routes::AppState) -> Scope {
3863
web::scope("/refunds")
3964
.app_data(web::Data::new(config))
40-
.service(refund_create)
41-
.service(refund_retrieve)
42-
.service(refund_update)
43-
.service(refund_retrieve_with_gateway_creds)
65+
.service(web::resource("").route(web::post().to(refund_create)))
66+
.service(
67+
web::resource("/sync").route(web::post().to(refund_retrieve_with_gateway_creds)),
68+
)
69+
.service(
70+
web::resource("/{refund_id}")
71+
.route(web::get().to(refund_retrieve))
72+
.route(web::post().to(refund_update)),
73+
)
4474
}
4575
}
4676

@@ -50,11 +80,17 @@ impl Customers {
5080
pub fn server(config: routes::AppState) -> Scope {
5181
web::scope("/customers")
5282
.app_data(web::Data::new(config))
53-
.service(customer_create)
54-
.service(customer_retrieve)
55-
.service(customer_update)
56-
.service(customer_delete)
57-
.service(list_customer_payment_method_api)
83+
.service(web::resource("").route(web::post().to(customer_create)))
84+
.service(
85+
web::resource("/{customer_id}")
86+
.route(web::get().to(customer_retrieve))
87+
.route(web::post().to(customer_update))
88+
.route(web::delete().to(customer_delete)),
89+
)
90+
.service(
91+
web::resource("/{customer_id}/payment_methods")
92+
.route(web::get().to(list_customer_payment_method_api)),
93+
)
5894
}
5995
}
6096

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pub mod types;
22

3-
use actix_web::{delete, get, post, web, HttpRequest, HttpResponse};
3+
use actix_web::{web, HttpRequest, HttpResponse};
44
use error_stack::report;
55
use router_env::{instrument, tracing};
66

@@ -13,7 +13,6 @@ use crate::{
1313
};
1414

1515
#[instrument(skip_all)]
16-
#[post("")]
1716
pub async fn customer_create(
1817
state: web::Data<routes::AppState>,
1918
qs_config: web::Data<serde_qs::Config>,
@@ -51,7 +50,6 @@ pub async fn customer_create(
5150
}
5251

5352
#[instrument(skip_all)]
54-
#[get("/{customer_id}")]
5553
pub async fn customer_retrieve(
5654
state: web::Data<routes::AppState>,
5755
req: HttpRequest,
@@ -83,7 +81,6 @@ pub async fn customer_retrieve(
8381
}
8482

8583
#[instrument(skip_all)]
86-
#[post("/{customer_id}")]
8784
pub async fn customer_update(
8885
state: web::Data<routes::AppState>,
8986
qs_config: web::Data<serde_qs::Config>,
@@ -124,7 +121,6 @@ pub async fn customer_update(
124121
}
125122

126123
#[instrument(skip_all)]
127-
#[delete("/{customer_id}")]
128124
pub async fn customer_delete(
129125
state: web::Data<routes::AppState>,
130126
req: HttpRequest,
@@ -154,7 +150,6 @@ pub async fn customer_delete(
154150
}
155151

156152
#[instrument(skip_all)]
157-
#[get("/{customer_id}/payment_methods")]
158153
pub async fn list_customer_payment_method_api(
159154
state: web::Data<routes::AppState>,
160155
req: HttpRequest,

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pub mod types;
22

3-
use actix_web::{get, post, web, HttpRequest, HttpResponse};
3+
use actix_web::{web, HttpRequest, HttpResponse};
44
use api_models::payments as payment_types;
55
use error_stack::report;
66
use router_env::{instrument, tracing};
@@ -13,7 +13,6 @@ use crate::{
1313
types::api::{self as api_types},
1414
};
1515

16-
#[post("")]
1716
#[instrument(skip_all)]
1817
pub async fn payment_intents_create(
1918
state: web::Data<routes::AppState>,
@@ -63,7 +62,6 @@ pub async fn payment_intents_create(
6362
}
6463

6564
#[instrument(skip_all)]
66-
#[get("/{payment_id}")]
6765
pub async fn payment_intents_retrieve(
6866
state: web::Data<routes::AppState>,
6967
req: HttpRequest,
@@ -112,7 +110,6 @@ pub async fn payment_intents_retrieve(
112110
}
113111

114112
#[instrument(skip_all)]
115-
#[post("/sync")]
116113
pub async fn payment_intents_retrieve_with_gateway_creds(
117114
state: web::Data<routes::AppState>,
118115
qs_config: web::Data<serde_qs::Config>,
@@ -170,7 +167,6 @@ pub async fn payment_intents_retrieve_with_gateway_creds(
170167
}
171168

172169
#[instrument(skip_all)]
173-
#[post("/{payment_id}")]
174170
pub async fn payment_intents_update(
175171
state: web::Data<routes::AppState>,
176172
qs_config: web::Data<serde_qs::Config>,
@@ -229,7 +225,6 @@ pub async fn payment_intents_update(
229225
}
230226

231227
#[instrument(skip_all)]
232-
#[post("/{payment_id}/confirm")]
233228
pub async fn payment_intents_confirm(
234229
state: web::Data<routes::AppState>,
235230
qs_config: web::Data<serde_qs::Config>,
@@ -289,7 +284,6 @@ pub async fn payment_intents_confirm(
289284
.await
290285
}
291286

292-
#[post("/{payment_id}/capture")]
293287
pub async fn payment_intents_capture(
294288
state: web::Data<routes::AppState>,
295289
qs_config: web::Data<serde_qs::Config>,
@@ -340,7 +334,6 @@ pub async fn payment_intents_capture(
340334
}
341335

342336
#[instrument(skip_all)]
343-
#[post("/{payment_id}/cancel")]
344337
pub async fn payment_intents_cancel(
345338
state: web::Data<routes::AppState>,
346339
qs_config: web::Data<serde_qs::Config>,
@@ -395,7 +388,6 @@ pub async fn payment_intents_cancel(
395388
}
396389

397390
#[instrument(skip_all)]
398-
#[get("/list")]
399391
#[cfg(feature = "olap")]
400392
pub async fn payment_intent_list(
401393
state: web::Data<routes::AppState>,

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pub mod types;
22

3-
use actix_web::{get, post, web, HttpRequest, HttpResponse};
3+
use actix_web::{web, HttpRequest, HttpResponse};
44
use error_stack::report;
55
use router_env::{instrument, tracing};
66

@@ -13,7 +13,6 @@ use crate::{
1313
};
1414

1515
#[instrument(skip_all)]
16-
#[post("")]
1716
pub async fn refund_create(
1817
state: web::Data<routes::AppState>,
1918
qs_config: web::Data<serde_qs::Config>,
@@ -50,7 +49,6 @@ pub async fn refund_create(
5049
}
5150

5251
#[instrument(skip_all)]
53-
#[post("/sync")]
5452
pub async fn refund_retrieve_with_gateway_creds(
5553
state: web::Data<routes::AppState>,
5654
qs_config: web::Data<serde_qs::Config>,
@@ -91,7 +89,6 @@ pub async fn refund_retrieve_with_gateway_creds(
9189
}
9290

9391
#[instrument(skip_all)]
94-
#[get("/{refund_id}")]
9592
pub async fn refund_retrieve(
9693
state: web::Data<routes::AppState>,
9794
req: HttpRequest,
@@ -129,7 +126,6 @@ pub async fn refund_retrieve(
129126
}
130127

131128
#[instrument(skip_all)]
132-
#[post("/{refund_id}")]
133129
pub async fn refund_update(
134130
state: web::Data<routes::AppState>,
135131
req: HttpRequest,

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pub mod types;
22

3-
use actix_web::{get, post, web, HttpRequest, HttpResponse};
3+
use actix_web::{web, HttpRequest, HttpResponse};
44
use api_models::payments as payment_types;
55
use error_stack::report;
66
use router_env::{instrument, tracing};
@@ -13,7 +13,6 @@ use crate::{
1313
types::api as api_types,
1414
};
1515

16-
#[post("")]
1716
#[instrument(skip_all)]
1817
pub async fn setup_intents_create(
1918
state: web::Data<routes::AppState>,
@@ -60,7 +59,6 @@ pub async fn setup_intents_create(
6059
}
6160

6261
#[instrument(skip_all)]
63-
#[get("/{setup_id}")]
6462
pub async fn setup_intents_retrieve(
6563
state: web::Data<routes::AppState>,
6664
req: HttpRequest,
@@ -109,7 +107,6 @@ pub async fn setup_intents_retrieve(
109107
}
110108

111109
#[instrument(skip_all)]
112-
#[post("/{setup_id}")]
113110
pub async fn setup_intents_update(
114111
state: web::Data<routes::AppState>,
115112
qs_config: web::Data<serde_qs::Config>,
@@ -165,7 +162,6 @@ pub async fn setup_intents_update(
165162
}
166163

167164
#[instrument(skip_all)]
168-
#[post("/{setup_id}/confirm")]
169165
pub async fn setup_intents_confirm(
170166
state: web::Data<routes::AppState>,
171167
qs_config: web::Data<serde_qs::Config>,

0 commit comments

Comments
 (0)