refactor: AppState trait for utility functions (#499)

This commit is contained in:
Sangamesh Kulkarni
2023-02-06 16:34:29 +05:30
committed by GitHub
parent a2921ff835
commit 9381a37f8f
17 changed files with 147 additions and 92 deletions

View File

@ -35,10 +35,11 @@ pub async fn customer_create(
_,
_,
_,
_,
types::CreateCustomerResponse,
errors::StripeErrorCode,
>(
&state,
state.get_ref(),
&req,
create_cust_req,
|state, merchant_account, req| {
@ -66,10 +67,11 @@ pub async fn customer_retrieve(
_,
_,
_,
_,
types::CustomerRetrieveResponse,
errors::StripeErrorCode,
>(
&state,
state.get_ref(),
&req,
payload,
|state, merchant_account, req| {
@ -106,10 +108,11 @@ pub async fn customer_update(
_,
_,
_,
_,
types::CustomerUpdateResponse,
errors::StripeErrorCode,
>(
&state,
state.get_ref(),
&req,
cust_update_req,
|state, merchant_account, req| {
@ -137,10 +140,11 @@ pub async fn customer_delete(
_,
_,
_,
_,
types::CustomerDeleteResponse,
errors::StripeErrorCode,
>(
&state,
state.get_ref(),
&req,
payload,
customers::delete_customer,
@ -164,10 +168,11 @@ pub async fn list_customer_payment_method_api(
_,
_,
_,
_,
types::CustomerPaymentMethodListResponse,
errors::StripeErrorCode,
>(
&state,
state.get_ref(),
&req,
customer_id.as_ref(),
cards::list_customer_payment_method,

View File

@ -40,10 +40,11 @@ pub async fn payment_intents_create(
_,
_,
_,
_,
types::StripePaymentIntentResponse,
errors::StripeErrorCode,
>(
&state,
state.get_ref(),
&req,
create_payment_req,
|state, merchant_account, req| {
@ -87,10 +88,11 @@ pub async fn payment_intents_retrieve(
_,
_,
_,
_,
types::StripePaymentIntentResponse,
errors::StripeErrorCode,
>(
&state,
state.get_ref(),
&req,
payload,
|state, merchant_account, payload| {
@ -145,10 +147,11 @@ pub async fn payment_intents_update(
_,
_,
_,
_,
types::StripePaymentIntentResponse,
errors::StripeErrorCode,
>(
&state,
state.get_ref(),
&req,
payload,
|state, merchant_account, req| {
@ -205,10 +208,11 @@ pub async fn payment_intents_confirm(
_,
_,
_,
_,
types::StripePaymentIntentResponse,
errors::StripeErrorCode,
>(
&state,
state.get_ref(),
&req,
payload,
|state, merchant_account, req| {
@ -254,10 +258,11 @@ pub async fn payment_intents_capture(
_,
_,
_,
_,
types::StripePaymentIntentResponse,
errors::StripeErrorCode,
>(
&state,
state.get_ref(),
&req,
capture_payload,
|state, merchant_account, payload| {
@ -308,10 +313,11 @@ pub async fn payment_intents_cancel(
_,
_,
_,
_,
types::StripePaymentIntentResponse,
errors::StripeErrorCode,
>(
&state,
state.get_ref(),
&req,
payload,
|state, merchant_account, req| {
@ -347,10 +353,11 @@ pub async fn payment_intent_list(
_,
_,
_,
_,
types::StripePaymentIntentListResponse,
errors::StripeErrorCode,
>(
&state,
state.get_ref(),
&req,
payload,
|state, merchant_account, req| {

View File

@ -27,10 +27,11 @@ pub async fn refund_create(
_,
_,
_,
_,
types::StripeCreateRefundResponse,
errors::StripeErrorCode,
>(
&state,
state.get_ref(),
&req,
create_refund_req,
refunds::refund_create_core,
@ -53,10 +54,11 @@ pub async fn refund_retrieve(
_,
_,
_,
_,
types::StripeCreateRefundResponse,
errors::StripeErrorCode,
>(
&state,
state.get_ref(),
&req,
refund_id,
|state, merchant_account, refund_id| {
@ -90,10 +92,11 @@ pub async fn refund_update(
_,
_,
_,
_,
types::StripeCreateRefundResponse,
errors::StripeErrorCode,
>(
&state,
state.get_ref(),
&req,
create_refund_update_req,
|state, merchant_account, req| {

View File

@ -37,10 +37,11 @@ pub async fn setup_intents_create(
_,
_,
_,
_,
types::StripeSetupIntentResponse,
errors::StripeErrorCode,
>(
&state,
state.get_ref(),
&req,
create_payment_req,
|state, merchant_account, req| {
@ -84,10 +85,11 @@ pub async fn setup_intents_retrieve(
_,
_,
_,
_,
types::StripeSetupIntentResponse,
errors::StripeErrorCode,
>(
&state,
state.get_ref(),
&req,
payload,
|state, merchant_account, payload| {
@ -139,10 +141,11 @@ pub async fn setup_intents_update(
_,
_,
_,
_,
types::StripeSetupIntentResponse,
errors::StripeErrorCode,
>(
&state,
state.get_ref(),
&req,
payload,
|state, merchant_account, req| {
@ -195,10 +198,11 @@ pub async fn setup_intents_confirm(
_,
_,
_,
_,
types::StripeSetupIntentResponse,
errors::StripeErrorCode,
>(
&state,
state.get_ref(),
&req,
payload,
|state, merchant_account, req| {

View File

@ -7,25 +7,26 @@ use serde::Serialize;
use crate::{
core::errors::{self, RouterResult},
routes,
routes::app::AppStateInfo,
services::{api, authentication as auth, logger},
};
#[instrument(skip(request, payload, state, func, api_authentication))]
pub async fn compatibility_api_wrap<'a, 'b, U, T, Q, F, Fut, S, E>(
state: &'b routes::AppState,
pub async fn compatibility_api_wrap<'a, 'b, A, U, T, Q, F, Fut, S, E>(
state: &'b A,
request: &'a HttpRequest,
payload: T,
func: F,
api_authentication: &dyn auth::AuthenticateAndFetch<U>,
api_authentication: &dyn auth::AuthenticateAndFetch<U, A>,
) -> HttpResponse
where
F: Fn(&'b routes::AppState, U, T) -> Fut,
F: Fn(&'b A, U, T) -> Fut,
Fut: Future<Output = RouterResult<api::ApplicationResponse<Q>>>,
Q: Serialize + std::fmt::Debug + 'a,
S: From<Q> + Serialize,
E: From<errors::ApiErrorResponse> + Serialize + error_stack::Context + actix_web::ResponseError,
T: std::fmt::Debug,
A: AppStateInfo,
{
let resp = api::server_wrap_util(state, request, payload, func, api_authentication).await;
match resp {