refactor(compatibility): refactor stripe compatibility routes using web::resource (#1022)

This commit is contained in:
Nachiket Kanore
2023-05-04 19:28:06 +05:30
committed by GitHub
parent 64fa21eb4f
commit 92ae2d92f1
5 changed files with 61 additions and 46 deletions

View File

@ -7,14 +7,34 @@ pub struct PaymentIntents;
impl PaymentIntents {
pub fn server(state: routes::AppState) -> Scope {
web::scope("/payment_intents")
.app_data(web::Data::new(state))
.service(payment_intents_retrieve_with_gateway_creds)
.service(payment_intents_create)
.service(payment_intents_retrieve)
.service(payment_intents_update)
.service(payment_intents_confirm)
.service(payment_intents_capture)
let mut route = web::scope("/payment_intents").app_data(web::Data::new(state));
#[cfg(feature = "olap")]
{
route = route.service(web::resource("/list").route(web::get().to(payment_intent_list)))
}
route = route
.service(web::resource("").route(web::post().to(payment_intents_create)))
.service(
web::resource("/sync")
.route(web::post().to(payment_intents_retrieve_with_gateway_creds)),
)
.service(
web::resource("/{payment_id}")
.route(web::get().to(payment_intents_retrieve))
.route(web::post().to(payment_intents_update)),
)
.service(
web::resource("/{payment_id}/confirm")
.route(web::post().to(payment_intents_confirm)),
)
.service(
web::resource("/{payment_id}/capture")
.route(web::post().to(payment_intents_capture)),
)
.service(
web::resource("/{payment_id}/cancel").route(web::post().to(payment_intents_cancel)),
);
route
}
}
@ -24,10 +44,15 @@ impl SetupIntents {
pub fn server(state: routes::AppState) -> Scope {
web::scope("/setup_intents")
.app_data(web::Data::new(state))
.service(setup_intents_create)
.service(setup_intents_retrieve)
.service(setup_intents_update)
.service(setup_intents_confirm)
.service(web::resource("").route(web::post().to(setup_intents_create)))
.service(
web::resource("/{setup_id}")
.route(web::get().to(setup_intents_retrieve))
.route(web::post().to(setup_intents_update)),
)
.service(
web::resource("/{setup_id}/confirm").route(web::post().to(setup_intents_confirm)),
)
}
}
@ -37,10 +62,15 @@ impl Refunds {
pub fn server(config: routes::AppState) -> Scope {
web::scope("/refunds")
.app_data(web::Data::new(config))
.service(refund_create)
.service(refund_retrieve)
.service(refund_update)
.service(refund_retrieve_with_gateway_creds)
.service(web::resource("").route(web::post().to(refund_create)))
.service(
web::resource("/sync").route(web::post().to(refund_retrieve_with_gateway_creds)),
)
.service(
web::resource("/{refund_id}")
.route(web::get().to(refund_retrieve))
.route(web::post().to(refund_update)),
)
}
}
@ -50,11 +80,17 @@ impl Customers {
pub fn server(config: routes::AppState) -> Scope {
web::scope("/customers")
.app_data(web::Data::new(config))
.service(customer_create)
.service(customer_retrieve)
.service(customer_update)
.service(customer_delete)
.service(list_customer_payment_method_api)
.service(web::resource("").route(web::post().to(customer_create)))
.service(
web::resource("/{customer_id}")
.route(web::get().to(customer_retrieve))
.route(web::post().to(customer_update))
.route(web::delete().to(customer_delete)),
)
.service(
web::resource("/{customer_id}/payment_methods")
.route(web::get().to(list_customer_payment_method_api)),
)
}
}

View File

@ -1,6 +1,6 @@
pub mod types;
use actix_web::{delete, get, post, web, HttpRequest, HttpResponse};
use actix_web::{web, HttpRequest, HttpResponse};
use error_stack::report;
use router_env::{instrument, tracing};
@ -13,7 +13,6 @@ use crate::{
};
#[instrument(skip_all)]
#[post("")]
pub async fn customer_create(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
@ -51,7 +50,6 @@ pub async fn customer_create(
}
#[instrument(skip_all)]
#[get("/{customer_id}")]
pub async fn customer_retrieve(
state: web::Data<routes::AppState>,
req: HttpRequest,
@ -83,7 +81,6 @@ pub async fn customer_retrieve(
}
#[instrument(skip_all)]
#[post("/{customer_id}")]
pub async fn customer_update(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
@ -124,7 +121,6 @@ pub async fn customer_update(
}
#[instrument(skip_all)]
#[delete("/{customer_id}")]
pub async fn customer_delete(
state: web::Data<routes::AppState>,
req: HttpRequest,
@ -154,7 +150,6 @@ pub async fn customer_delete(
}
#[instrument(skip_all)]
#[get("/{customer_id}/payment_methods")]
pub async fn list_customer_payment_method_api(
state: web::Data<routes::AppState>,
req: HttpRequest,

View File

@ -1,6 +1,6 @@
pub mod types;
use actix_web::{get, post, web, HttpRequest, HttpResponse};
use actix_web::{web, HttpRequest, HttpResponse};
use api_models::payments as payment_types;
use error_stack::report;
use router_env::{instrument, tracing};
@ -13,7 +13,6 @@ use crate::{
types::api::{self as api_types},
};
#[post("")]
#[instrument(skip_all)]
pub async fn payment_intents_create(
state: web::Data<routes::AppState>,
@ -63,7 +62,6 @@ pub async fn payment_intents_create(
}
#[instrument(skip_all)]
#[get("/{payment_id}")]
pub async fn payment_intents_retrieve(
state: web::Data<routes::AppState>,
req: HttpRequest,
@ -112,7 +110,6 @@ pub async fn payment_intents_retrieve(
}
#[instrument(skip_all)]
#[post("/sync")]
pub async fn payment_intents_retrieve_with_gateway_creds(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
@ -170,7 +167,6 @@ pub async fn payment_intents_retrieve_with_gateway_creds(
}
#[instrument(skip_all)]
#[post("/{payment_id}")]
pub async fn payment_intents_update(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
@ -229,7 +225,6 @@ pub async fn payment_intents_update(
}
#[instrument(skip_all)]
#[post("/{payment_id}/confirm")]
pub async fn payment_intents_confirm(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
@ -289,7 +284,6 @@ pub async fn payment_intents_confirm(
.await
}
#[post("/{payment_id}/capture")]
pub async fn payment_intents_capture(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
@ -340,7 +334,6 @@ pub async fn payment_intents_capture(
}
#[instrument(skip_all)]
#[post("/{payment_id}/cancel")]
pub async fn payment_intents_cancel(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
@ -395,7 +388,6 @@ pub async fn payment_intents_cancel(
}
#[instrument(skip_all)]
#[get("/list")]
#[cfg(feature = "olap")]
pub async fn payment_intent_list(
state: web::Data<routes::AppState>,

View File

@ -1,6 +1,6 @@
pub mod types;
use actix_web::{get, post, web, HttpRequest, HttpResponse};
use actix_web::{web, HttpRequest, HttpResponse};
use error_stack::report;
use router_env::{instrument, tracing};
@ -13,7 +13,6 @@ use crate::{
};
#[instrument(skip_all)]
#[post("")]
pub async fn refund_create(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
@ -50,7 +49,6 @@ pub async fn refund_create(
}
#[instrument(skip_all)]
#[post("/sync")]
pub async fn refund_retrieve_with_gateway_creds(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
@ -91,7 +89,6 @@ pub async fn refund_retrieve_with_gateway_creds(
}
#[instrument(skip_all)]
#[get("/{refund_id}")]
pub async fn refund_retrieve(
state: web::Data<routes::AppState>,
req: HttpRequest,
@ -129,7 +126,6 @@ pub async fn refund_retrieve(
}
#[instrument(skip_all)]
#[post("/{refund_id}")]
pub async fn refund_update(
state: web::Data<routes::AppState>,
req: HttpRequest,

View File

@ -1,6 +1,6 @@
pub mod types;
use actix_web::{get, post, web, HttpRequest, HttpResponse};
use actix_web::{web, HttpRequest, HttpResponse};
use api_models::payments as payment_types;
use error_stack::report;
use router_env::{instrument, tracing};
@ -13,7 +13,6 @@ use crate::{
types::api as api_types,
};
#[post("")]
#[instrument(skip_all)]
pub async fn setup_intents_create(
state: web::Data<routes::AppState>,
@ -60,7 +59,6 @@ pub async fn setup_intents_create(
}
#[instrument(skip_all)]
#[get("/{setup_id}")]
pub async fn setup_intents_retrieve(
state: web::Data<routes::AppState>,
req: HttpRequest,
@ -109,7 +107,6 @@ pub async fn setup_intents_retrieve(
}
#[instrument(skip_all)]
#[post("/{setup_id}")]
pub async fn setup_intents_update(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,
@ -165,7 +162,6 @@ pub async fn setup_intents_update(
}
#[instrument(skip_all)]
#[post("/{setup_id}/confirm")]
pub async fn setup_intents_confirm(
state: web::Data<routes::AppState>,
qs_config: web::Data<serde_qs::Config>,