mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 11:06:50 +08:00
fix: fixing TODO/FIXMEs from router/core (#257)
This commit is contained in:
@ -23,14 +23,16 @@ pub async fn payment_intents_create(
|
||||
) -> HttpResponse {
|
||||
let payload: types::StripePaymentIntentRequest = match qs_config
|
||||
.deserialize_bytes(&form_payload)
|
||||
.map_err(|err| report!(errors::StripeErrorCode::from(err)))
|
||||
{
|
||||
Ok(p) => p,
|
||||
Err(err) => {
|
||||
return api::log_and_return_error_response(report!(errors::StripeErrorCode::from(err)))
|
||||
}
|
||||
Err(err) => return api::log_and_return_error_response(err),
|
||||
};
|
||||
|
||||
let create_payment_req: payment_types::PaymentsRequest = payload.into();
|
||||
let create_payment_req: payment_types::PaymentsRequest = match payload.try_into() {
|
||||
Ok(req) => req,
|
||||
Err(err) => return api::log_and_return_error_response(err),
|
||||
};
|
||||
|
||||
wrap::compatibility_api_wrap::<
|
||||
_,
|
||||
@ -129,7 +131,11 @@ pub async fn payment_intents_update(
|
||||
}
|
||||
};
|
||||
|
||||
let mut payload: payment_types::PaymentsRequest = stripe_payload.into();
|
||||
let mut payload: payment_types::PaymentsRequest = match stripe_payload.try_into() {
|
||||
Ok(req) => req,
|
||||
Err(err) => return api::log_and_return_error_response(err),
|
||||
};
|
||||
|
||||
payload.payment_id = Some(api_types::PaymentIdType::PaymentIntentId(payment_id));
|
||||
|
||||
let auth_type;
|
||||
@ -186,7 +192,11 @@ pub async fn payment_intents_confirm(
|
||||
}
|
||||
};
|
||||
|
||||
let mut payload: payment_types::PaymentsRequest = stripe_payload.into();
|
||||
let mut payload: payment_types::PaymentsRequest = match stripe_payload.try_into() {
|
||||
Ok(req) => req,
|
||||
Err(err) => return api::log_and_return_error_response(err),
|
||||
};
|
||||
|
||||
payload.payment_id = Some(api_types::PaymentIdType::PaymentIntentId(payment_id));
|
||||
payload.confirm = Some(true);
|
||||
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
use api_models::{payments, refunds};
|
||||
use common_utils::ext_traits::StringExt;
|
||||
use error_stack::ResultExt;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
@ -131,12 +133,20 @@ pub struct StripePaymentIntentRequest {
|
||||
pub client_secret: Option<pii::Secret<String>>,
|
||||
}
|
||||
|
||||
impl From<StripePaymentIntentRequest> for payments::PaymentsRequest {
|
||||
fn from(item: StripePaymentIntentRequest) -> Self {
|
||||
Self {
|
||||
impl TryFrom<StripePaymentIntentRequest> for payments::PaymentsRequest {
|
||||
type Error = error_stack::Report<errors::ApiErrorResponse>;
|
||||
fn try_from(item: StripePaymentIntentRequest) -> errors::RouterResult<Self> {
|
||||
Ok(Self {
|
||||
amount: item.amount.map(|amount| amount.into()),
|
||||
connector: item.connector,
|
||||
currency: item.currency.as_ref().map(|c| c.to_uppercase()),
|
||||
currency: item
|
||||
.currency
|
||||
.as_ref()
|
||||
.map(|c| c.to_uppercase().parse_enum("currency"))
|
||||
.transpose()
|
||||
.change_context(errors::ApiErrorResponse::InvalidDataValue {
|
||||
field_name: "currency",
|
||||
})?,
|
||||
capture_method: item.capture_method,
|
||||
amount_to_capture: item.amount_capturable,
|
||||
confirm: item.confirm,
|
||||
@ -171,7 +181,7 @@ impl From<StripePaymentIntentRequest> for payments::PaymentsRequest {
|
||||
metadata: item.metadata,
|
||||
client_secret: item.client_secret.map(|s| s.peek().clone()),
|
||||
..Default::default()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -130,7 +130,7 @@ impl From<StripeSetupIntentRequest> for payments::PaymentsRequest {
|
||||
fn from(item: StripeSetupIntentRequest) -> Self {
|
||||
Self {
|
||||
amount: Some(api_types::Amount::Zero),
|
||||
currency: Some(api_enums::Currency::default().to_string()),
|
||||
currency: Some(api_enums::Currency::default()),
|
||||
capture_method: None,
|
||||
amount_to_capture: None,
|
||||
confirm: item.confirm,
|
||||
|
||||
Reference in New Issue
Block a user