mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 12:15:40 +08:00
refactor(RouterData): move amount information inside request in RouterData (#36)
Co-authored-by: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com>
This commit is contained in:
@ -120,8 +120,8 @@ impl TryFrom<&types::PaymentsRouterData> for AciPaymentsRequest {
|
|||||||
let aci_payment_request = AciPaymentsRequest {
|
let aci_payment_request = AciPaymentsRequest {
|
||||||
payment_method: payment_details,
|
payment_method: payment_details,
|
||||||
entity_id: auth.entity_id,
|
entity_id: auth.entity_id,
|
||||||
amount: item.amount,
|
amount: item.request.amount,
|
||||||
currency: item.currency.to_string(),
|
currency: item.request.currency.to_string(),
|
||||||
payment_type: AciPaymentType::Debit,
|
payment_type: AciPaymentType::Debit,
|
||||||
};
|
};
|
||||||
Ok(aci_payment_request)
|
Ok(aci_payment_request)
|
||||||
@ -237,7 +237,7 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for AciRefundRequest {
|
|||||||
type Error = error_stack::Report<errors::ConnectorError>;
|
type Error = error_stack::Report<errors::ConnectorError>;
|
||||||
fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> {
|
fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> {
|
||||||
let amount = item.request.refund_amount;
|
let amount = item.request.refund_amount;
|
||||||
let currency = item.currency;
|
let currency = item.request.currency;
|
||||||
let payment_type = AciPaymentType::Refund;
|
let payment_type = AciPaymentType::Refund;
|
||||||
let auth = AciAuthType::try_from(&item.connector_auth_type)?;
|
let auth = AciAuthType::try_from(&item.connector_auth_type)?;
|
||||||
|
|
||||||
|
|||||||
@ -245,8 +245,8 @@ impl TryFrom<&types::PaymentsRouterData> for AdyenPaymentRequest {
|
|||||||
let auth_type = AdyenAuthType::try_from(&item.connector_auth_type)?;
|
let auth_type = AdyenAuthType::try_from(&item.connector_auth_type)?;
|
||||||
let reference = item.payment_id.to_string();
|
let reference = item.payment_id.to_string();
|
||||||
let amount = Amount {
|
let amount = Amount {
|
||||||
currency: item.currency.to_string(),
|
currency: item.request.currency.to_string(),
|
||||||
value: item.amount,
|
value: item.request.amount,
|
||||||
};
|
};
|
||||||
let ccard = match item.request.payment_method_data {
|
let ccard = match item.request.payment_method_data {
|
||||||
api::PaymentMethod::Card(ref ccard) => Some(ccard),
|
api::PaymentMethod::Card(ref ccard) => Some(ccard),
|
||||||
|
|||||||
@ -155,9 +155,9 @@ impl TryFrom<&types::PaymentsRouterData> for CreateTransactionRequest {
|
|||||||
});
|
});
|
||||||
let transaction_request = TransactionRequest {
|
let transaction_request = TransactionRequest {
|
||||||
transaction_type: TransactionType::Payment,
|
transaction_type: TransactionType::Payment,
|
||||||
amount: item.amount,
|
amount: item.request.amount,
|
||||||
payment: payment_details,
|
payment: payment_details,
|
||||||
currency_code: item.currency.to_string(),
|
currency_code: item.request.currency.to_string(),
|
||||||
authorization_indicator_type,
|
authorization_indicator_type,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -365,7 +365,7 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for CreateRefundRequest {
|
|||||||
transaction_type: TransactionType::Refund,
|
transaction_type: TransactionType::Refund,
|
||||||
amount: item.request.refund_amount,
|
amount: item.request.refund_amount,
|
||||||
payment: payment_details,
|
payment: payment_details,
|
||||||
currency_code: item.currency.to_string(),
|
currency_code: item.request.currency.to_string(),
|
||||||
reference_transaction_id: item.request.connector_transaction_id.clone(),
|
reference_transaction_id: item.request.connector_transaction_id.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -111,8 +111,8 @@ impl TryFrom<&types::PaymentsRouterData> for PaymentsRequest {
|
|||||||
let processing_channel_id = auth_type.processing_channel_id;
|
let processing_channel_id = auth_type.processing_channel_id;
|
||||||
Ok(PaymentsRequest {
|
Ok(PaymentsRequest {
|
||||||
source: source_var,
|
source: source_var,
|
||||||
amount: item.amount,
|
amount: item.request.amount,
|
||||||
currency: item.currency.to_string(),
|
currency: item.request.currency.to_string(),
|
||||||
processing_channel_id,
|
processing_channel_id,
|
||||||
three_ds,
|
three_ds,
|
||||||
return_url,
|
return_url,
|
||||||
|
|||||||
@ -192,8 +192,8 @@ impl TryFrom<&types::PaymentsRouterData> for PaymentIntentRequest {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(PaymentIntentRequest {
|
Ok(PaymentIntentRequest {
|
||||||
amount: item.amount, //hopefully we don't loose some cents here
|
amount: item.request.amount, //hopefully we don't loose some cents here
|
||||||
currency: item.currency.to_string(), //we need to copy the value and not transfer ownership
|
currency: item.request.currency.to_string(), //we need to copy the value and not transfer ownership
|
||||||
statement_descriptor_suffix: item.request.statement_descriptor_suffix.clone(),
|
statement_descriptor_suffix: item.request.statement_descriptor_suffix.clone(),
|
||||||
metadata_order_id,
|
metadata_order_id,
|
||||||
metadata_txn_id,
|
metadata_txn_id,
|
||||||
|
|||||||
@ -85,8 +85,6 @@ where
|
|||||||
connector: merchant_connector_account.connector_name,
|
connector: merchant_connector_account.connector_name,
|
||||||
payment_id: payment_data.payment_attempt.payment_id.clone(),
|
payment_id: payment_data.payment_attempt.payment_id.clone(),
|
||||||
status: payment_data.payment_attempt.status,
|
status: payment_data.payment_attempt.status,
|
||||||
amount: payment_data.amount,
|
|
||||||
currency: payment_data.currency,
|
|
||||||
payment_method,
|
payment_method,
|
||||||
connector_auth_type: auth_type,
|
connector_auth_type: auth_type,
|
||||||
description: payment_data.payment_intent.description.clone(),
|
description: payment_data.payment_intent.description.clone(),
|
||||||
@ -100,7 +98,6 @@ where
|
|||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
|
|
||||||
request: T::try_from(payment_data.clone())?,
|
request: T::try_from(payment_data.clone())?,
|
||||||
|
|
||||||
response: response.map_or_else(|| Err(types::ErrorResponse::default()), Ok),
|
response: response.map_or_else(|| Err(types::ErrorResponse::default()), Ok),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -282,6 +279,8 @@ impl<F: Clone> TryFrom<PaymentData<F>> for types::PaymentsRequestData {
|
|||||||
confirm: payment_data.payment_attempt.confirm,
|
confirm: payment_data.payment_attempt.confirm,
|
||||||
statement_descriptor_suffix: payment_data.payment_intent.statement_descriptor_suffix,
|
statement_descriptor_suffix: payment_data.payment_intent.statement_descriptor_suffix,
|
||||||
capture_method: payment_data.payment_attempt.capture_method,
|
capture_method: payment_data.payment_attempt.capture_method,
|
||||||
|
amount: payment_data.amount,
|
||||||
|
currency: payment_data.currency,
|
||||||
browser_info,
|
browser_info,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -446,8 +446,8 @@ impl<F> TryFrom<types::RefundsRouterData<F>> for refunds::RefundResponse {
|
|||||||
Ok(refunds::RefundResponse {
|
Ok(refunds::RefundResponse {
|
||||||
payment_id: data.payment_id,
|
payment_id: data.payment_id,
|
||||||
refund_id,
|
refund_id,
|
||||||
amount: data.amount / 100,
|
amount: data.request.amount / 100,
|
||||||
currency: data.currency.to_string(),
|
currency: data.request.currency.to_string(),
|
||||||
reason: Some("TODO: Not propagated".to_string()), // TODO: Not propagated
|
reason: Some("TODO: Not propagated".to_string()), // TODO: Not propagated
|
||||||
status,
|
status,
|
||||||
metadata: None,
|
metadata: None,
|
||||||
|
|||||||
@ -70,8 +70,6 @@ pub async fn construct_refund_router_data<'a, F>(
|
|||||||
connector: merchant_connector_account.connector_name,
|
connector: merchant_connector_account.connector_name,
|
||||||
payment_id: payment_attempt.payment_id.clone(),
|
payment_id: payment_attempt.payment_id.clone(),
|
||||||
status,
|
status,
|
||||||
amount,
|
|
||||||
currency,
|
|
||||||
payment_method: payment_method_type,
|
payment_method: payment_method_type,
|
||||||
connector_auth_type: auth_type,
|
connector_auth_type: auth_type,
|
||||||
description: None,
|
description: None,
|
||||||
@ -87,6 +85,8 @@ pub async fn construct_refund_router_data<'a, F>(
|
|||||||
payment_method_data,
|
payment_method_data,
|
||||||
connector_transaction_id: refund.transaction_id.clone(),
|
connector_transaction_id: refund.transaction_id.clone(),
|
||||||
refund_amount: refund.refund_amount,
|
refund_amount: refund.refund_amount,
|
||||||
|
currency,
|
||||||
|
amount,
|
||||||
},
|
},
|
||||||
|
|
||||||
response: Ok(types::RefundsResponseData {
|
response: Ok(types::RefundsResponseData {
|
||||||
|
|||||||
@ -40,8 +40,6 @@ pub struct RouterData<Flow, Request, Response> {
|
|||||||
pub connector: String,
|
pub connector: String,
|
||||||
pub payment_id: String,
|
pub payment_id: String,
|
||||||
pub status: enums::AttemptStatus,
|
pub status: enums::AttemptStatus,
|
||||||
pub amount: i32,
|
|
||||||
pub currency: enums::Currency,
|
|
||||||
pub payment_method: enums::PaymentMethodType,
|
pub payment_method: enums::PaymentMethodType,
|
||||||
pub connector_auth_type: ConnectorAuthType,
|
pub connector_auth_type: ConnectorAuthType,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
@ -63,6 +61,8 @@ pub struct RouterData<Flow, Request, Response> {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct PaymentsRequestData {
|
pub struct PaymentsRequestData {
|
||||||
pub payment_method_data: payments::PaymentMethod,
|
pub payment_method_data: payments::PaymentMethod,
|
||||||
|
pub amount: i32,
|
||||||
|
pub currency: enums::Currency,
|
||||||
pub confirm: bool,
|
pub confirm: bool,
|
||||||
pub statement_descriptor_suffix: Option<String>,
|
pub statement_descriptor_suffix: Option<String>,
|
||||||
// redirect form not used https://juspay.atlassian.net/browse/ORCA-301
|
// redirect form not used https://juspay.atlassian.net/browse/ORCA-301
|
||||||
@ -107,6 +107,10 @@ pub struct RefundsRequestData {
|
|||||||
pub refund_id: String,
|
pub refund_id: String,
|
||||||
pub payment_method_data: payments::PaymentMethod,
|
pub payment_method_data: payments::PaymentMethod,
|
||||||
pub connector_transaction_id: String,
|
pub connector_transaction_id: String,
|
||||||
|
pub currency: enums::Currency,
|
||||||
|
/// Amount for the payment against which this refund is issued
|
||||||
|
pub amount: i32,
|
||||||
|
/// Amount to be refunded
|
||||||
pub refund_amount: i32,
|
pub refund_amount: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,15 +23,15 @@ fn construct_payment_router_data() -> types::PaymentsRouterData {
|
|||||||
connector: "aci".to_string(),
|
connector: "aci".to_string(),
|
||||||
payment_id: uuid::Uuid::new_v4().to_string(),
|
payment_id: uuid::Uuid::new_v4().to_string(),
|
||||||
status: enums::AttemptStatus::default(),
|
status: enums::AttemptStatus::default(),
|
||||||
amount: 1000,
|
|
||||||
auth_type: enums::AuthenticationType::NoThreeDs,
|
auth_type: enums::AuthenticationType::NoThreeDs,
|
||||||
currency: enums::Currency::USD,
|
|
||||||
payment_method: enums::PaymentMethodType::Card,
|
payment_method: enums::PaymentMethodType::Card,
|
||||||
connector_auth_type: auth.into(),
|
connector_auth_type: auth.into(),
|
||||||
description: Some("This is a test".to_string()),
|
description: Some("This is a test".to_string()),
|
||||||
orca_return_url: None,
|
orca_return_url: None,
|
||||||
return_url: None,
|
return_url: None,
|
||||||
request: types::PaymentsRequestData {
|
request: types::PaymentsRequestData {
|
||||||
|
amount: 1000,
|
||||||
|
currency: enums::Currency::USD,
|
||||||
payment_method_data: types::api::PaymentMethod::Card(types::api::CCard {
|
payment_method_data: types::api::PaymentMethod::Card(types::api::CCard {
|
||||||
card_number: Secret::new("4200000000000000".to_string()),
|
card_number: Secret::new("4200000000000000".to_string()),
|
||||||
card_exp_month: Secret::new("10".to_string()),
|
card_exp_month: Secret::new("10".to_string()),
|
||||||
@ -65,15 +65,15 @@ fn construct_refund_router_data<F>() -> types::RefundsRouterData<F> {
|
|||||||
connector: "aci".to_string(),
|
connector: "aci".to_string(),
|
||||||
payment_id: uuid::Uuid::new_v4().to_string(),
|
payment_id: uuid::Uuid::new_v4().to_string(),
|
||||||
status: enums::AttemptStatus::default(),
|
status: enums::AttemptStatus::default(),
|
||||||
amount: 1000,
|
|
||||||
orca_return_url: None,
|
orca_return_url: None,
|
||||||
currency: enums::Currency::USD,
|
|
||||||
payment_method: enums::PaymentMethodType::Card,
|
payment_method: enums::PaymentMethodType::Card,
|
||||||
auth_type: enums::AuthenticationType::NoThreeDs,
|
auth_type: enums::AuthenticationType::NoThreeDs,
|
||||||
connector_auth_type: auth.into(),
|
connector_auth_type: auth.into(),
|
||||||
description: Some("This is a test".to_string()),
|
description: Some("This is a test".to_string()),
|
||||||
return_url: None,
|
return_url: None,
|
||||||
request: types::RefundsRequestData {
|
request: types::RefundsRequestData {
|
||||||
|
amount: 1000,
|
||||||
|
currency: enums::Currency::USD,
|
||||||
refund_id: uuid::Uuid::new_v4().to_string(),
|
refund_id: uuid::Uuid::new_v4().to_string(),
|
||||||
payment_method_data: types::api::PaymentMethod::Card(types::api::CCard {
|
payment_method_data: types::api::PaymentMethod::Card(types::api::CCard {
|
||||||
card_number: Secret::new("4200000000000000".to_string()),
|
card_number: Secret::new("4200000000000000".to_string()),
|
||||||
|
|||||||
@ -23,15 +23,15 @@ fn construct_payment_router_data() -> types::PaymentsRouterData {
|
|||||||
connector: "authorizedotnet".to_string(),
|
connector: "authorizedotnet".to_string(),
|
||||||
payment_id: uuid::Uuid::new_v4().to_string(),
|
payment_id: uuid::Uuid::new_v4().to_string(),
|
||||||
status: enums::AttemptStatus::default(),
|
status: enums::AttemptStatus::default(),
|
||||||
amount: 100,
|
|
||||||
orca_return_url: None,
|
orca_return_url: None,
|
||||||
currency: enums::Currency::USD,
|
|
||||||
payment_method: enums::PaymentMethodType::Card,
|
payment_method: enums::PaymentMethodType::Card,
|
||||||
connector_auth_type: auth.into(),
|
connector_auth_type: auth.into(),
|
||||||
auth_type: enums::AuthenticationType::NoThreeDs,
|
auth_type: enums::AuthenticationType::NoThreeDs,
|
||||||
description: Some("This is a test".to_string()),
|
description: Some("This is a test".to_string()),
|
||||||
return_url: None,
|
return_url: None,
|
||||||
request: types::PaymentsRequestData {
|
request: types::PaymentsRequestData {
|
||||||
|
amount: 100,
|
||||||
|
currency: enums::Currency::USD,
|
||||||
payment_method_data: types::api::PaymentMethod::Card(types::api::CCard {
|
payment_method_data: types::api::PaymentMethod::Card(types::api::CCard {
|
||||||
card_number: Secret::new("5424000000000015".to_string()),
|
card_number: Secret::new("5424000000000015".to_string()),
|
||||||
card_exp_month: Secret::new("10".to_string()),
|
card_exp_month: Secret::new("10".to_string()),
|
||||||
@ -65,15 +65,15 @@ fn construct_refund_router_data<F>() -> types::RefundsRouterData<F> {
|
|||||||
connector: "authorizedotnet".to_string(),
|
connector: "authorizedotnet".to_string(),
|
||||||
payment_id: uuid::Uuid::new_v4().to_string(),
|
payment_id: uuid::Uuid::new_v4().to_string(),
|
||||||
status: enums::AttemptStatus::default(),
|
status: enums::AttemptStatus::default(),
|
||||||
amount: 100,
|
|
||||||
orca_return_url: None,
|
orca_return_url: None,
|
||||||
currency: enums::Currency::USD,
|
|
||||||
auth_type: enums::AuthenticationType::NoThreeDs,
|
auth_type: enums::AuthenticationType::NoThreeDs,
|
||||||
payment_method: enums::PaymentMethodType::Card,
|
payment_method: enums::PaymentMethodType::Card,
|
||||||
connector_auth_type: auth.into(),
|
connector_auth_type: auth.into(),
|
||||||
description: Some("This is a test".to_string()),
|
description: Some("This is a test".to_string()),
|
||||||
return_url: None,
|
return_url: None,
|
||||||
request: router::types::RefundsRequestData {
|
request: router::types::RefundsRequestData {
|
||||||
|
amount: 100,
|
||||||
|
currency: enums::Currency::USD,
|
||||||
refund_id: uuid::Uuid::new_v4().to_string(),
|
refund_id: uuid::Uuid::new_v4().to_string(),
|
||||||
payment_method_data: types::api::PaymentMethod::Card(types::api::CCard {
|
payment_method_data: types::api::PaymentMethod::Card(types::api::CCard {
|
||||||
card_number: Secret::new("5424000000000015".to_string()),
|
card_number: Secret::new("5424000000000015".to_string()),
|
||||||
|
|||||||
@ -19,15 +19,15 @@ fn construct_payment_router_data() -> types::PaymentsRouterData {
|
|||||||
connector: "checkout".to_string(),
|
connector: "checkout".to_string(),
|
||||||
payment_id: uuid::Uuid::new_v4().to_string(),
|
payment_id: uuid::Uuid::new_v4().to_string(),
|
||||||
status: enums::AttemptStatus::default(),
|
status: enums::AttemptStatus::default(),
|
||||||
amount: 100,
|
|
||||||
orca_return_url: None,
|
orca_return_url: None,
|
||||||
currency: enums::Currency::USD,
|
|
||||||
auth_type: enums::AuthenticationType::NoThreeDs,
|
auth_type: enums::AuthenticationType::NoThreeDs,
|
||||||
payment_method: enums::PaymentMethodType::Card,
|
payment_method: enums::PaymentMethodType::Card,
|
||||||
connector_auth_type: auth.into(),
|
connector_auth_type: auth.into(),
|
||||||
description: Some("This is a test".to_string()),
|
description: Some("This is a test".to_string()),
|
||||||
return_url: None,
|
return_url: None,
|
||||||
request: types::PaymentsRequestData {
|
request: types::PaymentsRequestData {
|
||||||
|
amount: 100,
|
||||||
|
currency: enums::Currency::USD,
|
||||||
payment_method_data: types::api::PaymentMethod::Card(api::CCard {
|
payment_method_data: types::api::PaymentMethod::Card(api::CCard {
|
||||||
card_number: "4242424242424242".to_string().into(),
|
card_number: "4242424242424242".to_string().into(),
|
||||||
card_exp_month: "10".to_string().into(),
|
card_exp_month: "10".to_string().into(),
|
||||||
@ -61,8 +61,6 @@ fn construct_refund_router_data<F>() -> types::RefundsRouterData<F> {
|
|||||||
connector: "checkout".to_string(),
|
connector: "checkout".to_string(),
|
||||||
payment_id: uuid::Uuid::new_v4().to_string(),
|
payment_id: uuid::Uuid::new_v4().to_string(),
|
||||||
status: enums::AttemptStatus::default(),
|
status: enums::AttemptStatus::default(),
|
||||||
amount: 100,
|
|
||||||
currency: enums::Currency::USD,
|
|
||||||
orca_return_url: None,
|
orca_return_url: None,
|
||||||
payment_method: enums::PaymentMethodType::Card,
|
payment_method: enums::PaymentMethodType::Card,
|
||||||
auth_type: enums::AuthenticationType::NoThreeDs,
|
auth_type: enums::AuthenticationType::NoThreeDs,
|
||||||
@ -70,6 +68,8 @@ fn construct_refund_router_data<F>() -> types::RefundsRouterData<F> {
|
|||||||
description: Some("This is a test".to_string()),
|
description: Some("This is a test".to_string()),
|
||||||
return_url: None,
|
return_url: None,
|
||||||
request: types::RefundsRequestData {
|
request: types::RefundsRequestData {
|
||||||
|
amount: 100,
|
||||||
|
currency: enums::Currency::USD,
|
||||||
refund_id: uuid::Uuid::new_v4().to_string(),
|
refund_id: uuid::Uuid::new_v4().to_string(),
|
||||||
payment_method_data: types::api::PaymentMethod::Card(api::CCard {
|
payment_method_data: types::api::PaymentMethod::Card(api::CCard {
|
||||||
card_number: "4242424242424242".to_string().into(),
|
card_number: "4242424242424242".to_string().into(),
|
||||||
|
|||||||
Reference in New Issue
Block a user