refactor(router): make stripe compatibility and certain core routes public (#190)

This commit is contained in:
ItsMeShashank
2022-12-21 14:35:43 +05:30
committed by GitHub
parent bf857cb8ee
commit 60d1ad52b1
9 changed files with 232 additions and 183 deletions

View File

@ -10,7 +10,7 @@ use crate::routes;
pub struct StripeApis;
impl StripeApis {
pub(crate) fn server(state: routes::AppState) -> Scope {
pub fn server(state: routes::AppState) -> Scope {
let max_depth = 10;
let strict = false;
web::scope("/vs/v1")

View File

@ -23,13 +23,21 @@ pub async fn customer_create(
let payload: types::CreateCustomerRequest = match qs_config.deserialize_bytes(&form_payload) {
Ok(p) => p,
Err(err) => {
return api::log_and_return_error_response(report!(errors::ErrorCode::from(err)))
return api::log_and_return_error_response(report!(errors::StripeErrorCode::from(err)))
}
};
let create_cust_req: customer_types::CustomerRequest = payload.into();
wrap::compatibility_api_wrap::<_, _, _, _, _, types::CreateCustomerResponse, errors::ErrorCode>(
wrap::compatibility_api_wrap::<
_,
_,
_,
_,
_,
types::CreateCustomerResponse,
errors::StripeErrorCode,
>(
&state,
&req,
create_cust_req,
@ -52,7 +60,15 @@ pub async fn customer_retrieve(
customer_id: path.into_inner(),
};
wrap::compatibility_api_wrap::<_, _, _, _, _, types::CustomerRetrieveResponse, errors::ErrorCode>(
wrap::compatibility_api_wrap::<
_,
_,
_,
_,
_,
types::CustomerRetrieveResponse,
errors::StripeErrorCode,
>(
&state,
&req,
payload,
@ -76,7 +92,7 @@ pub async fn customer_update(
let payload: types::CustomerUpdateRequest = match qs_config.deserialize_bytes(&form_payload) {
Ok(p) => p,
Err(err) => {
return api::log_and_return_error_response(report!(errors::ErrorCode::from(err)))
return api::log_and_return_error_response(report!(errors::StripeErrorCode::from(err)))
}
};
@ -84,7 +100,15 @@ pub async fn customer_update(
let mut cust_update_req: customer_types::CustomerRequest = payload.into();
cust_update_req.customer_id = customer_id;
wrap::compatibility_api_wrap::<_, _, _, _, _, types::CustomerUpdateResponse, errors::ErrorCode>(
wrap::compatibility_api_wrap::<
_,
_,
_,
_,
_,
types::CustomerUpdateResponse,
errors::StripeErrorCode,
>(
&state,
&req,
cust_update_req,
@ -107,7 +131,15 @@ pub async fn customer_delete(
customer_id: path.into_inner(),
};
wrap::compatibility_api_wrap::<_, _, _, _, _, types::CustomerDeleteResponse, errors::ErrorCode>(
wrap::compatibility_api_wrap::<
_,
_,
_,
_,
_,
types::CustomerDeleteResponse,
errors::StripeErrorCode,
>(
&state,
&req,
payload,

View File

@ -3,7 +3,7 @@ use crate::core::errors;
#[derive(Debug, router_derive::ApiError)]
#[error(error_type_enum = StripeErrorType)]
pub(crate) enum ErrorCode {
pub enum StripeErrorCode {
/*
"error": {
"message": "Invalid API Key provided: sk_jkjgs****nlgs",
@ -291,7 +291,7 @@ pub(crate) enum ErrorCode {
// TransfersNotAllowed,
}
impl ::core::fmt::Display for ErrorCode {
impl ::core::fmt::Display for StripeErrorCode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
@ -304,21 +304,21 @@ impl ::core::fmt::Display for ErrorCode {
#[derive(Clone, Debug, serde::Serialize)]
#[serde(rename_all = "snake_case")]
#[allow(clippy::enum_variant_names)]
pub(crate) enum StripeErrorType {
pub enum StripeErrorType {
ApiError,
CardError,
InvalidRequestError,
}
impl From<errors::ApiErrorResponse> for ErrorCode {
impl From<errors::ApiErrorResponse> for StripeErrorCode {
fn from(value: errors::ApiErrorResponse) -> Self {
match value {
errors::ApiErrorResponse::Unauthorized
| errors::ApiErrorResponse::InvalidEphermeralKey => ErrorCode::Unauthorized,
| errors::ApiErrorResponse::InvalidEphermeralKey => StripeErrorCode::Unauthorized,
errors::ApiErrorResponse::InvalidRequestUrl
| errors::ApiErrorResponse::InvalidHttpMethod => ErrorCode::InvalidRequestUrl,
| errors::ApiErrorResponse::InvalidHttpMethod => StripeErrorCode::InvalidRequestUrl,
errors::ApiErrorResponse::MissingRequiredField { field_name } => {
ErrorCode::ParameterMissing {
StripeErrorCode::ParameterMissing {
field_name: field_name.to_owned(),
param: field_name,
}
@ -327,88 +327,98 @@ impl From<errors::ApiErrorResponse> for ErrorCode {
errors::ApiErrorResponse::InvalidDataFormat {
field_name,
expected_format,
} => ErrorCode::ParameterUnknown {
} => StripeErrorCode::ParameterUnknown {
field_name,
expected_format,
},
errors::ApiErrorResponse::RefundAmountExceedsPaymentAmount => {
ErrorCode::RefundAmountExceedsPaymentAmount {
StripeErrorCode::RefundAmountExceedsPaymentAmount {
param: "amount".to_owned(),
}
}
errors::ApiErrorResponse::PaymentAuthorizationFailed { data }
| errors::ApiErrorResponse::PaymentAuthenticationFailed { data } => {
ErrorCode::PaymentIntentAuthenticationFailure { data }
StripeErrorCode::PaymentIntentAuthenticationFailure { data }
}
errors::ApiErrorResponse::VerificationFailed { data } => {
ErrorCode::VerificationFailed { data }
StripeErrorCode::VerificationFailed { data }
}
errors::ApiErrorResponse::PaymentCaptureFailed { data } => {
ErrorCode::PaymentIntentPaymentAttemptFailed { data }
StripeErrorCode::PaymentIntentPaymentAttemptFailed { data }
}
errors::ApiErrorResponse::InvalidCardData { data } => ErrorCode::InvalidCardType, // Maybe it is better to de generalize this router error
errors::ApiErrorResponse::CardExpired { data } => ErrorCode::ExpiredCard,
errors::ApiErrorResponse::RefundFailed { data } => ErrorCode::RefundFailed, // Nothing at stripe to map
errors::ApiErrorResponse::InvalidCardData { data } => StripeErrorCode::InvalidCardType, // Maybe it is better to de generalize this router error
errors::ApiErrorResponse::CardExpired { data } => StripeErrorCode::ExpiredCard,
errors::ApiErrorResponse::RefundFailed { data } => StripeErrorCode::RefundFailed, // Nothing at stripe to map
errors::ApiErrorResponse::InternalServerError => ErrorCode::InternalServerError, // not a stripe code
errors::ApiErrorResponse::IncorrectConnectorNameGiven => ErrorCode::InternalServerError,
errors::ApiErrorResponse::MandateActive => ErrorCode::MandateActive, //not a stripe code
errors::ApiErrorResponse::CustomerRedacted => ErrorCode::CustomerRedacted, //not a stripe code
errors::ApiErrorResponse::DuplicateRefundRequest => ErrorCode::DuplicateRefundRequest,
errors::ApiErrorResponse::RefundNotFound => ErrorCode::RefundNotFound,
errors::ApiErrorResponse::CustomerNotFound => ErrorCode::CustomerNotFound,
errors::ApiErrorResponse::PaymentNotFound => ErrorCode::PaymentNotFound,
errors::ApiErrorResponse::PaymentMethodNotFound => ErrorCode::PaymentMethodNotFound,
errors::ApiErrorResponse::ClientSecretNotGiven => ErrorCode::ClientSecretNotFound,
errors::ApiErrorResponse::MerchantAccountNotFound => ErrorCode::MerchantAccountNotFound,
errors::ApiErrorResponse::ResourceIdNotFound => ErrorCode::ResourceIdNotFound,
errors::ApiErrorResponse::InternalServerError => StripeErrorCode::InternalServerError, // not a stripe code
errors::ApiErrorResponse::IncorrectConnectorNameGiven => {
StripeErrorCode::InternalServerError
}
errors::ApiErrorResponse::MandateActive => StripeErrorCode::MandateActive, //not a stripe code
errors::ApiErrorResponse::CustomerRedacted => StripeErrorCode::CustomerRedacted, //not a stripe code
errors::ApiErrorResponse::DuplicateRefundRequest => {
StripeErrorCode::DuplicateRefundRequest
}
errors::ApiErrorResponse::RefundNotFound => StripeErrorCode::RefundNotFound,
errors::ApiErrorResponse::CustomerNotFound => StripeErrorCode::CustomerNotFound,
errors::ApiErrorResponse::PaymentNotFound => StripeErrorCode::PaymentNotFound,
errors::ApiErrorResponse::PaymentMethodNotFound => {
StripeErrorCode::PaymentMethodNotFound
}
errors::ApiErrorResponse::ClientSecretNotGiven => StripeErrorCode::ClientSecretNotFound,
errors::ApiErrorResponse::MerchantAccountNotFound => {
StripeErrorCode::MerchantAccountNotFound
}
errors::ApiErrorResponse::ResourceIdNotFound => StripeErrorCode::ResourceIdNotFound,
errors::ApiErrorResponse::MerchantConnectorAccountNotFound => {
ErrorCode::MerchantConnectorAccountNotFound
StripeErrorCode::MerchantConnectorAccountNotFound
}
errors::ApiErrorResponse::MandateNotFound => ErrorCode::MandateNotFound,
errors::ApiErrorResponse::MandateNotFound => StripeErrorCode::MandateNotFound,
errors::ApiErrorResponse::MandateValidationFailed { reason } => {
ErrorCode::PaymentIntentMandateInvalid { message: reason }
StripeErrorCode::PaymentIntentMandateInvalid { message: reason }
}
errors::ApiErrorResponse::ReturnUrlUnavailable => ErrorCode::ReturnUrlUnavailable,
errors::ApiErrorResponse::ReturnUrlUnavailable => StripeErrorCode::ReturnUrlUnavailable,
errors::ApiErrorResponse::DuplicateMerchantAccount => {
ErrorCode::DuplicateMerchantAccount
StripeErrorCode::DuplicateMerchantAccount
}
errors::ApiErrorResponse::DuplicateMerchantConnectorAccount => {
ErrorCode::DuplicateMerchantConnectorAccount
StripeErrorCode::DuplicateMerchantConnectorAccount
}
errors::ApiErrorResponse::DuplicatePaymentMethod => {
StripeErrorCode::DuplicatePaymentMethod
}
errors::ApiErrorResponse::DuplicatePaymentMethod => ErrorCode::DuplicatePaymentMethod,
errors::ApiErrorResponse::ClientSecretInvalid => {
ErrorCode::PaymentIntentInvalidParameter {
StripeErrorCode::PaymentIntentInvalidParameter {
param: "client_secret".to_owned(),
}
}
errors::ApiErrorResponse::InvalidRequestData { message } => {
ErrorCode::InvalidRequestData { message }
StripeErrorCode::InvalidRequestData { message }
}
errors::ApiErrorResponse::PreconditionFailed { message } => {
ErrorCode::PreconditionFailed { message }
StripeErrorCode::PreconditionFailed { message }
}
errors::ApiErrorResponse::BadCredentials => ErrorCode::Unauthorized,
errors::ApiErrorResponse::BadCredentials => StripeErrorCode::Unauthorized,
errors::ApiErrorResponse::InvalidDataValue { field_name } => {
ErrorCode::ParameterMissing {
StripeErrorCode::ParameterMissing {
field_name: field_name.to_owned(),
param: field_name.to_owned(),
}
}
errors::ApiErrorResponse::MaximumRefundCount => ErrorCode::MaximumRefundCount,
errors::ApiErrorResponse::PaymentNotSucceeded => ErrorCode::PaymentFailed,
errors::ApiErrorResponse::DuplicateMandate => ErrorCode::DuplicateMandate,
errors::ApiErrorResponse::MaximumRefundCount => StripeErrorCode::MaximumRefundCount,
errors::ApiErrorResponse::PaymentNotSucceeded => StripeErrorCode::PaymentFailed,
errors::ApiErrorResponse::DuplicateMandate => StripeErrorCode::DuplicateMandate,
errors::ApiErrorResponse::SuccessfulPaymentNotFound => {
ErrorCode::SuccessfulPaymentNotFound
StripeErrorCode::SuccessfulPaymentNotFound
}
errors::ApiErrorResponse::AddressNotFound => ErrorCode::AddressNotFound,
errors::ApiErrorResponse::NotImplemented => ErrorCode::Unauthorized,
errors::ApiErrorResponse::AddressNotFound => StripeErrorCode::AddressNotFound,
errors::ApiErrorResponse::NotImplemented => StripeErrorCode::Unauthorized,
errors::ApiErrorResponse::PaymentUnexpectedState {
current_flow,
field_name,
current_value,
states,
} => ErrorCode::PaymentIntentUnexpectedState {
} => StripeErrorCode::PaymentIntentUnexpectedState {
current_flow,
field_name,
current_value,
@ -418,50 +428,50 @@ impl From<errors::ApiErrorResponse> for ErrorCode {
}
}
impl actix_web::ResponseError for ErrorCode {
impl actix_web::ResponseError for StripeErrorCode {
fn status_code(&self) -> reqwest::StatusCode {
use reqwest::StatusCode;
match self {
ErrorCode::Unauthorized => StatusCode::UNAUTHORIZED,
ErrorCode::InvalidRequestUrl => StatusCode::NOT_FOUND,
ErrorCode::ParameterUnknown { .. } => StatusCode::UNPROCESSABLE_ENTITY,
ErrorCode::ParameterMissing { .. }
| ErrorCode::RefundAmountExceedsPaymentAmount { .. }
| ErrorCode::PaymentIntentAuthenticationFailure { .. }
| ErrorCode::PaymentIntentPaymentAttemptFailed { .. }
| ErrorCode::ExpiredCard
| ErrorCode::InvalidCardType
| ErrorCode::DuplicateRefundRequest
| ErrorCode::RefundNotFound
| ErrorCode::CustomerNotFound
| ErrorCode::ClientSecretNotFound
| ErrorCode::PaymentNotFound
| ErrorCode::PaymentMethodNotFound
| ErrorCode::MerchantAccountNotFound
| ErrorCode::MerchantConnectorAccountNotFound
| ErrorCode::MandateNotFound
| ErrorCode::DuplicateMerchantAccount
| ErrorCode::DuplicateMerchantConnectorAccount
| ErrorCode::DuplicatePaymentMethod
| ErrorCode::PaymentFailed
| ErrorCode::VerificationFailed { .. }
| ErrorCode::MaximumRefundCount
| ErrorCode::PaymentIntentInvalidParameter { .. }
| ErrorCode::SerdeQsError { .. }
| ErrorCode::InvalidRequestData { .. }
| ErrorCode::PreconditionFailed { .. }
| ErrorCode::DuplicateMandate
| ErrorCode::SuccessfulPaymentNotFound
| ErrorCode::AddressNotFound
| ErrorCode::ResourceIdNotFound
| ErrorCode::PaymentIntentMandateInvalid { .. }
| ErrorCode::PaymentIntentUnexpectedState { .. } => StatusCode::BAD_REQUEST,
ErrorCode::RefundFailed
| ErrorCode::InternalServerError
| ErrorCode::MandateActive
| ErrorCode::CustomerRedacted => StatusCode::INTERNAL_SERVER_ERROR,
ErrorCode::ReturnUrlUnavailable => StatusCode::SERVICE_UNAVAILABLE,
StripeErrorCode::Unauthorized => StatusCode::UNAUTHORIZED,
StripeErrorCode::InvalidRequestUrl => StatusCode::NOT_FOUND,
StripeErrorCode::ParameterUnknown { .. } => StatusCode::UNPROCESSABLE_ENTITY,
StripeErrorCode::ParameterMissing { .. }
| StripeErrorCode::RefundAmountExceedsPaymentAmount { .. }
| StripeErrorCode::PaymentIntentAuthenticationFailure { .. }
| StripeErrorCode::PaymentIntentPaymentAttemptFailed { .. }
| StripeErrorCode::ExpiredCard
| StripeErrorCode::InvalidCardType
| StripeErrorCode::DuplicateRefundRequest
| StripeErrorCode::RefundNotFound
| StripeErrorCode::CustomerNotFound
| StripeErrorCode::ClientSecretNotFound
| StripeErrorCode::PaymentNotFound
| StripeErrorCode::PaymentMethodNotFound
| StripeErrorCode::MerchantAccountNotFound
| StripeErrorCode::MerchantConnectorAccountNotFound
| StripeErrorCode::MandateNotFound
| StripeErrorCode::DuplicateMerchantAccount
| StripeErrorCode::DuplicateMerchantConnectorAccount
| StripeErrorCode::DuplicatePaymentMethod
| StripeErrorCode::PaymentFailed
| StripeErrorCode::VerificationFailed { .. }
| StripeErrorCode::MaximumRefundCount
| StripeErrorCode::PaymentIntentInvalidParameter { .. }
| StripeErrorCode::SerdeQsError { .. }
| StripeErrorCode::InvalidRequestData { .. }
| StripeErrorCode::PreconditionFailed { .. }
| StripeErrorCode::DuplicateMandate
| StripeErrorCode::SuccessfulPaymentNotFound
| StripeErrorCode::AddressNotFound
| StripeErrorCode::ResourceIdNotFound
| StripeErrorCode::PaymentIntentMandateInvalid { .. }
| StripeErrorCode::PaymentIntentUnexpectedState { .. } => StatusCode::BAD_REQUEST,
StripeErrorCode::RefundFailed
| StripeErrorCode::InternalServerError
| StripeErrorCode::MandateActive
| StripeErrorCode::CustomerRedacted => StatusCode::INTERNAL_SERVER_ERROR,
StripeErrorCode::ReturnUrlUnavailable => StatusCode::SERVICE_UNAVAILABLE,
}
}
@ -475,36 +485,36 @@ impl actix_web::ResponseError for ErrorCode {
}
}
impl From<serde_qs::Error> for ErrorCode {
impl From<serde_qs::Error> for StripeErrorCode {
fn from(item: serde_qs::Error) -> Self {
match item {
serde_qs::Error::Custom(s) => ErrorCode::SerdeQsError {
serde_qs::Error::Custom(s) => StripeErrorCode::SerdeQsError {
error_message: s,
param: None,
},
serde_qs::Error::Parse(param, position) => ErrorCode::SerdeQsError {
serde_qs::Error::Parse(param, position) => StripeErrorCode::SerdeQsError {
error_message: format!(
"parsing failed with error: '{param}' at position: {position}"
),
param: Some(param),
},
serde_qs::Error::Unsupported => ErrorCode::SerdeQsError {
serde_qs::Error::Unsupported => StripeErrorCode::SerdeQsError {
error_message: "Given request format is not supported".to_owned(),
param: None,
},
serde_qs::Error::FromUtf8(_) => ErrorCode::SerdeQsError {
serde_qs::Error::FromUtf8(_) => StripeErrorCode::SerdeQsError {
error_message: "Failed to parse request to from utf-8".to_owned(),
param: None,
},
serde_qs::Error::Io(_) => ErrorCode::SerdeQsError {
serde_qs::Error::Io(_) => StripeErrorCode::SerdeQsError {
error_message: "Failed to parse request".to_owned(),
param: None,
},
serde_qs::Error::ParseInt(_) => ErrorCode::SerdeQsError {
serde_qs::Error::ParseInt(_) => StripeErrorCode::SerdeQsError {
error_message: "Failed to parse integer in request".to_owned(),
param: None,
},
serde_qs::Error::Utf8(_) => ErrorCode::SerdeQsError {
serde_qs::Error::Utf8(_) => StripeErrorCode::SerdeQsError {
error_message: "Failed to convert utf8 to string".to_owned(),
param: None,
},

View File

@ -21,11 +21,12 @@ pub async fn payment_intents_create(
req: HttpRequest,
form_payload: web::Bytes,
) -> HttpResponse {
let payload: types::StripePaymentIntentRequest =
match qs_config.deserialize_bytes(&form_payload) {
let payload: types::StripePaymentIntentRequest = match qs_config
.deserialize_bytes(&form_payload)
{
Ok(p) => p,
Err(err) => {
return api::log_and_return_error_response(report!(errors::ErrorCode::from(err)))
return api::log_and_return_error_response(report!(errors::StripeErrorCode::from(err)))
}
};
@ -38,7 +39,7 @@ pub async fn payment_intents_create(
_,
_,
types::StripePaymentIntentResponse,
errors::ErrorCode,
errors::StripeErrorCode,
>(
&state,
&req,
@ -88,7 +89,7 @@ pub async fn payment_intents_retrieve(
_,
_,
types::StripePaymentIntentResponse,
errors::ErrorCode,
errors::StripeErrorCode,
>(
&state,
&req,
@ -119,11 +120,12 @@ pub async fn payment_intents_update(
path: web::Path<String>,
) -> HttpResponse {
let payment_id = path.into_inner();
let stripe_payload: types::StripePaymentIntentRequest =
match qs_config.deserialize_bytes(&form_payload) {
let stripe_payload: types::StripePaymentIntentRequest = match qs_config
.deserialize_bytes(&form_payload)
{
Ok(p) => p,
Err(err) => {
return api::log_and_return_error_response(report!(errors::ErrorCode::from(err)))
return api::log_and_return_error_response(report!(errors::StripeErrorCode::from(err)))
}
};
@ -143,7 +145,7 @@ pub async fn payment_intents_update(
_,
_,
types::StripePaymentIntentResponse,
errors::ErrorCode,
errors::StripeErrorCode,
>(
&state,
&req,
@ -175,11 +177,12 @@ pub async fn payment_intents_confirm(
path: web::Path<String>,
) -> HttpResponse {
let payment_id = path.into_inner();
let stripe_payload: types::StripePaymentIntentRequest =
match qs_config.deserialize_bytes(&form_payload) {
let stripe_payload: types::StripePaymentIntentRequest = match qs_config
.deserialize_bytes(&form_payload)
{
Ok(p) => p,
Err(err) => {
return api::log_and_return_error_response(report!(errors::ErrorCode::from(err)))
return api::log_and_return_error_response(report!(errors::StripeErrorCode::from(err)))
}
};
@ -200,7 +203,7 @@ pub async fn payment_intents_confirm(
_,
_,
types::StripePaymentIntentResponse,
errors::ErrorCode,
errors::StripeErrorCode,
>(
&state,
&req,
@ -230,11 +233,12 @@ pub async fn payment_intents_capture(
form_payload: web::Bytes,
path: web::Path<String>,
) -> HttpResponse {
let stripe_payload: payment_types::PaymentsCaptureRequest =
match qs_config.deserialize_bytes(&form_payload) {
let stripe_payload: payment_types::PaymentsCaptureRequest = match qs_config
.deserialize_bytes(&form_payload)
{
Ok(p) => p,
Err(err) => {
return api::log_and_return_error_response(report!(errors::ErrorCode::from(err)))
return api::log_and_return_error_response(report!(errors::StripeErrorCode::from(err)))
}
};
@ -250,7 +254,7 @@ pub async fn payment_intents_capture(
_,
_,
types::StripePaymentIntentResponse,
errors::ErrorCode,
errors::StripeErrorCode,
>(
&state,
&req,
@ -281,11 +285,12 @@ pub async fn payment_intents_cancel(
path: web::Path<String>,
) -> HttpResponse {
let payment_id = path.into_inner();
let stripe_payload: types::StripePaymentCancelRequest =
match qs_config.deserialize_bytes(&form_payload) {
let stripe_payload: types::StripePaymentCancelRequest = match qs_config
.deserialize_bytes(&form_payload)
{
Ok(p) => p,
Err(err) => {
return api::log_and_return_error_response(report!(errors::ErrorCode::from(err)))
return api::log_and_return_error_response(report!(errors::StripeErrorCode::from(err)))
}
};
@ -304,7 +309,7 @@ pub async fn payment_intents_cancel(
_,
_,
types::StripePaymentIntentResponse,
errors::ErrorCode,
errors::StripeErrorCode,
>(
&state,
&req,
@ -343,7 +348,7 @@ pub async fn payment_intent_list(
_,
_,
types::StripePaymentIntentListResponse,
errors::ErrorCode,
errors::StripeErrorCode,
>(
&state,
&req,

View File

@ -13,7 +13,7 @@ use crate::{
#[instrument(skip_all)]
#[post("")]
pub(crate) async fn refund_create(
pub async fn refund_create(
state: web::Data<routes::AppState>,
req: HttpRequest,
form_payload: web::Form<types::StripeCreateRefundRequest>,
@ -28,7 +28,7 @@ pub(crate) async fn refund_create(
_,
_,
types::StripeCreateRefundResponse,
errors::ErrorCode,
errors::StripeErrorCode,
>(
&state,
&req,
@ -41,7 +41,7 @@ pub(crate) async fn refund_create(
#[instrument(skip_all)]
#[get("/{refund_id}")]
pub(crate) async fn refund_retrieve(
pub async fn refund_retrieve(
state: web::Data<routes::AppState>,
req: HttpRequest,
path: web::Path<String>,
@ -54,7 +54,7 @@ pub(crate) async fn refund_retrieve(
_,
_,
types::StripeCreateRefundResponse,
errors::ErrorCode,
errors::StripeErrorCode,
>(
&state,
&req,
@ -74,7 +74,7 @@ pub(crate) async fn refund_retrieve(
#[instrument(skip_all)]
#[post("/{refund_id}")]
pub(crate) async fn refund_update(
pub async fn refund_update(
state: web::Data<routes::AppState>,
req: HttpRequest,
path: web::Path<String>,
@ -91,7 +91,7 @@ pub(crate) async fn refund_update(
_,
_,
types::StripeCreateRefundResponse,
errors::ErrorCode,
errors::StripeErrorCode,
>(
&state,
&req,

View File

@ -5,24 +5,24 @@ use serde::{Deserialize, Serialize};
use crate::types::api::refunds;
#[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
pub(crate) struct StripeCreateRefundRequest {
pub(crate) amount: Option<i64>,
pub(crate) payment_intent: String,
pub(crate) reason: Option<String>,
pub struct StripeCreateRefundRequest {
pub amount: Option<i64>,
pub payment_intent: String,
pub reason: Option<String>,
}
#[derive(Clone, Serialize, PartialEq, Eq)]
pub(crate) struct StripeCreateRefundResponse {
pub(crate) id: String,
pub(crate) amount: i64,
pub(crate) currency: String,
pub(crate) payment_intent: String,
pub(crate) status: StripeRefundStatus,
pub struct StripeCreateRefundResponse {
pub id: String,
pub amount: i64,
pub currency: String,
pub payment_intent: String,
pub status: StripeRefundStatus,
}
#[derive(Clone, Serialize, Deserialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub(crate) enum StripeRefundStatus {
pub enum StripeRefundStatus {
Succeeded,
Failed,
Pending,

View File

@ -10,7 +10,7 @@ use crate::{
core::payments,
routes,
services::api,
types::api::{self as api_types},
types::api as api_types,
};
#[post("")]
@ -25,7 +25,7 @@ pub async fn setup_intents_create(
{
Ok(p) => p,
Err(err) => {
return api::log_and_return_error_response(report!(errors::ErrorCode::from(err)))
return api::log_and_return_error_response(report!(errors::StripeErrorCode::from(err)))
}
};
@ -38,7 +38,7 @@ pub async fn setup_intents_create(
_,
_,
types::StripeSetupIntentResponse,
errors::ErrorCode,
errors::StripeErrorCode,
>(
&state,
&req,
@ -88,7 +88,7 @@ pub async fn setup_intents_retrieve(
_,
_,
types::StripeSetupIntentResponse,
errors::ErrorCode,
errors::StripeErrorCode,
>(
&state,
&req,
@ -119,11 +119,12 @@ pub async fn setup_intents_update(
path: web::Path<String>,
) -> HttpResponse {
let setup_id = path.into_inner();
let stripe_payload: types::StripeSetupIntentRequest =
match qs_config.deserialize_bytes(&form_payload) {
let stripe_payload: types::StripeSetupIntentRequest = match qs_config
.deserialize_bytes(&form_payload)
{
Ok(p) => p,
Err(err) => {
return api::log_and_return_error_response(report!(errors::ErrorCode::from(err)))
return api::log_and_return_error_response(report!(errors::StripeErrorCode::from(err)))
}
};
@ -143,7 +144,7 @@ pub async fn setup_intents_update(
_,
_,
types::StripeSetupIntentResponse,
errors::ErrorCode,
errors::StripeErrorCode,
>(
&state,
&req,
@ -175,11 +176,12 @@ pub async fn setup_intents_confirm(
path: web::Path<String>,
) -> HttpResponse {
let setup_id = path.into_inner();
let stripe_payload: types::StripeSetupIntentRequest =
match qs_config.deserialize_bytes(&form_payload) {
let stripe_payload: types::StripeSetupIntentRequest = match qs_config
.deserialize_bytes(&form_payload)
{
Ok(p) => p,
Err(err) => {
return api::log_and_return_error_response(report!(errors::ErrorCode::from(err)))
return api::log_and_return_error_response(report!(errors::StripeErrorCode::from(err)))
}
};
@ -200,7 +202,7 @@ pub async fn setup_intents_confirm(
_,
_,
types::StripeSetupIntentResponse,
errors::ErrorCode,
errors::StripeErrorCode,
>(
&state,
&req,

View File

@ -13,7 +13,7 @@ use crate::{
};
#[instrument(skip(request, payload, state, func))]
pub(crate) async fn compatibility_api_wrap<'a, 'b, A, T, Q, F, Fut, S, E>(
pub async fn compatibility_api_wrap<'a, 'b, A, T, Q, F, Fut, S, E>(
state: &'b routes::AppState,
request: &'a HttpRequest,
payload: T,

View File

@ -249,7 +249,7 @@ pub async fn payments_confirm(
#[instrument(skip_all, fields(flow = ?Flow::PaymentsCapture))]
// #[post("/{payment_id}/capture")]
pub(crate) async fn payments_capture(
pub async fn payments_capture(
state: web::Data<AppState>,
req: HttpRequest,
json_payload: web::Json<PaymentsCaptureRequest>,
@ -281,7 +281,7 @@ pub(crate) async fn payments_capture(
}
#[instrument(skip_all, fields(flow = ?Flow::PaymentsSessionToken))]
pub(crate) async fn payments_connector_session(
pub async fn payments_connector_session(
state: web::Data<AppState>,
req: HttpRequest,
json_payload: web::Json<PaymentsSessionRequest>,