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:
Nishant Joshi
2022-12-01 13:58:26 +05:30
committed by GitHub
parent b2e45e614c
commit e45e33c897
12 changed files with 36 additions and 33 deletions

View File

@ -120,8 +120,8 @@ impl TryFrom<&types::PaymentsRouterData> for AciPaymentsRequest {
let aci_payment_request = AciPaymentsRequest {
payment_method: payment_details,
entity_id: auth.entity_id,
amount: item.amount,
currency: item.currency.to_string(),
amount: item.request.amount,
currency: item.request.currency.to_string(),
payment_type: AciPaymentType::Debit,
};
Ok(aci_payment_request)
@ -237,7 +237,7 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for AciRefundRequest {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> {
let amount = item.request.refund_amount;
let currency = item.currency;
let currency = item.request.currency;
let payment_type = AciPaymentType::Refund;
let auth = AciAuthType::try_from(&item.connector_auth_type)?;

View File

@ -245,8 +245,8 @@ impl TryFrom<&types::PaymentsRouterData> for AdyenPaymentRequest {
let auth_type = AdyenAuthType::try_from(&item.connector_auth_type)?;
let reference = item.payment_id.to_string();
let amount = Amount {
currency: item.currency.to_string(),
value: item.amount,
currency: item.request.currency.to_string(),
value: item.request.amount,
};
let ccard = match item.request.payment_method_data {
api::PaymentMethod::Card(ref ccard) => Some(ccard),

View File

@ -155,9 +155,9 @@ impl TryFrom<&types::PaymentsRouterData> for CreateTransactionRequest {
});
let transaction_request = TransactionRequest {
transaction_type: TransactionType::Payment,
amount: item.amount,
amount: item.request.amount,
payment: payment_details,
currency_code: item.currency.to_string(),
currency_code: item.request.currency.to_string(),
authorization_indicator_type,
};
@ -365,7 +365,7 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for CreateRefundRequest {
transaction_type: TransactionType::Refund,
amount: item.request.refund_amount,
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(),
};

View File

@ -111,8 +111,8 @@ impl TryFrom<&types::PaymentsRouterData> for PaymentsRequest {
let processing_channel_id = auth_type.processing_channel_id;
Ok(PaymentsRequest {
source: source_var,
amount: item.amount,
currency: item.currency.to_string(),
amount: item.request.amount,
currency: item.request.currency.to_string(),
processing_channel_id,
three_ds,
return_url,

View File

@ -192,8 +192,8 @@ impl TryFrom<&types::PaymentsRouterData> for PaymentIntentRequest {
};
Ok(PaymentIntentRequest {
amount: item.amount, //hopefully we don't loose some cents here
currency: item.currency.to_string(), //we need to copy the value and not transfer ownership
amount: item.request.amount, //hopefully we don't loose some cents here
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(),
metadata_order_id,
metadata_txn_id,

View File

@ -85,8 +85,6 @@ where
connector: merchant_connector_account.connector_name,
payment_id: payment_data.payment_attempt.payment_id.clone(),
status: payment_data.payment_attempt.status,
amount: payment_data.amount,
currency: payment_data.currency,
payment_method,
connector_auth_type: auth_type,
description: payment_data.payment_intent.description.clone(),
@ -100,7 +98,6 @@ where
.unwrap_or_default(),
request: T::try_from(payment_data.clone())?,
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,
statement_descriptor_suffix: payment_data.payment_intent.statement_descriptor_suffix,
capture_method: payment_data.payment_attempt.capture_method,
amount: payment_data.amount,
currency: payment_data.currency,
browser_info,
})
}

View File

@ -446,8 +446,8 @@ impl<F> TryFrom<types::RefundsRouterData<F>> for refunds::RefundResponse {
Ok(refunds::RefundResponse {
payment_id: data.payment_id,
refund_id,
amount: data.amount / 100,
currency: data.currency.to_string(),
amount: data.request.amount / 100,
currency: data.request.currency.to_string(),
reason: Some("TODO: Not propagated".to_string()), // TODO: Not propagated
status,
metadata: None,

View File

@ -70,8 +70,6 @@ pub async fn construct_refund_router_data<'a, F>(
connector: merchant_connector_account.connector_name,
payment_id: payment_attempt.payment_id.clone(),
status,
amount,
currency,
payment_method: payment_method_type,
connector_auth_type: auth_type,
description: None,
@ -87,6 +85,8 @@ pub async fn construct_refund_router_data<'a, F>(
payment_method_data,
connector_transaction_id: refund.transaction_id.clone(),
refund_amount: refund.refund_amount,
currency,
amount,
},
response: Ok(types::RefundsResponseData {

View File

@ -40,8 +40,6 @@ pub struct RouterData<Flow, Request, Response> {
pub connector: String,
pub payment_id: String,
pub status: enums::AttemptStatus,
pub amount: i32,
pub currency: enums::Currency,
pub payment_method: enums::PaymentMethodType,
pub connector_auth_type: ConnectorAuthType,
pub description: Option<String>,
@ -63,6 +61,8 @@ pub struct RouterData<Flow, Request, Response> {
#[derive(Debug, Clone)]
pub struct PaymentsRequestData {
pub payment_method_data: payments::PaymentMethod,
pub amount: i32,
pub currency: enums::Currency,
pub confirm: bool,
pub statement_descriptor_suffix: Option<String>,
// redirect form not used https://juspay.atlassian.net/browse/ORCA-301
@ -107,6 +107,10 @@ pub struct RefundsRequestData {
pub refund_id: String,
pub payment_method_data: payments::PaymentMethod,
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,
}

View File

@ -23,15 +23,15 @@ fn construct_payment_router_data() -> types::PaymentsRouterData {
connector: "aci".to_string(),
payment_id: uuid::Uuid::new_v4().to_string(),
status: enums::AttemptStatus::default(),
amount: 1000,
auth_type: enums::AuthenticationType::NoThreeDs,
currency: enums::Currency::USD,
payment_method: enums::PaymentMethodType::Card,
connector_auth_type: auth.into(),
description: Some("This is a test".to_string()),
orca_return_url: None,
return_url: None,
request: types::PaymentsRequestData {
amount: 1000,
currency: enums::Currency::USD,
payment_method_data: types::api::PaymentMethod::Card(types::api::CCard {
card_number: Secret::new("4200000000000000".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(),
payment_id: uuid::Uuid::new_v4().to_string(),
status: enums::AttemptStatus::default(),
amount: 1000,
orca_return_url: None,
currency: enums::Currency::USD,
payment_method: enums::PaymentMethodType::Card,
auth_type: enums::AuthenticationType::NoThreeDs,
connector_auth_type: auth.into(),
description: Some("This is a test".to_string()),
return_url: None,
request: types::RefundsRequestData {
amount: 1000,
currency: enums::Currency::USD,
refund_id: uuid::Uuid::new_v4().to_string(),
payment_method_data: types::api::PaymentMethod::Card(types::api::CCard {
card_number: Secret::new("4200000000000000".to_string()),

View File

@ -23,15 +23,15 @@ fn construct_payment_router_data() -> types::PaymentsRouterData {
connector: "authorizedotnet".to_string(),
payment_id: uuid::Uuid::new_v4().to_string(),
status: enums::AttemptStatus::default(),
amount: 100,
orca_return_url: None,
currency: enums::Currency::USD,
payment_method: enums::PaymentMethodType::Card,
connector_auth_type: auth.into(),
auth_type: enums::AuthenticationType::NoThreeDs,
description: Some("This is a test".to_string()),
return_url: None,
request: types::PaymentsRequestData {
amount: 100,
currency: enums::Currency::USD,
payment_method_data: types::api::PaymentMethod::Card(types::api::CCard {
card_number: Secret::new("5424000000000015".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(),
payment_id: uuid::Uuid::new_v4().to_string(),
status: enums::AttemptStatus::default(),
amount: 100,
orca_return_url: None,
currency: enums::Currency::USD,
auth_type: enums::AuthenticationType::NoThreeDs,
payment_method: enums::PaymentMethodType::Card,
connector_auth_type: auth.into(),
description: Some("This is a test".to_string()),
return_url: None,
request: router::types::RefundsRequestData {
amount: 100,
currency: enums::Currency::USD,
refund_id: uuid::Uuid::new_v4().to_string(),
payment_method_data: types::api::PaymentMethod::Card(types::api::CCard {
card_number: Secret::new("5424000000000015".to_string()),

View File

@ -19,15 +19,15 @@ fn construct_payment_router_data() -> types::PaymentsRouterData {
connector: "checkout".to_string(),
payment_id: uuid::Uuid::new_v4().to_string(),
status: enums::AttemptStatus::default(),
amount: 100,
orca_return_url: None,
currency: enums::Currency::USD,
auth_type: enums::AuthenticationType::NoThreeDs,
payment_method: enums::PaymentMethodType::Card,
connector_auth_type: auth.into(),
description: Some("This is a test".to_string()),
return_url: None,
request: types::PaymentsRequestData {
amount: 100,
currency: enums::Currency::USD,
payment_method_data: types::api::PaymentMethod::Card(api::CCard {
card_number: "4242424242424242".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(),
payment_id: uuid::Uuid::new_v4().to_string(),
status: enums::AttemptStatus::default(),
amount: 100,
currency: enums::Currency::USD,
orca_return_url: None,
payment_method: enums::PaymentMethodType::Card,
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()),
return_url: None,
request: types::RefundsRequestData {
amount: 100,
currency: enums::Currency::USD,
refund_id: uuid::Uuid::new_v4().to_string(),
payment_method_data: types::api::PaymentMethod::Card(api::CCard {
card_number: "4242424242424242".to_string().into(),