From a4d64eba7cbede9daa0e5f5bdfe41d873390b8ce Mon Sep 17 00:00:00 2001 From: kos-for-juspay <115210506+kos-for-juspay@users.noreply.github.com> Date: Wed, 14 Dec 2022 14:03:30 +0100 Subject: [PATCH] refactor(api_models): shrink `Amount` (#140) --- add_connector.md | 4 +- crates/api_models/src/payments.rs | 39 +++++++++---------- crates/api_models/src/refunds.rs | 4 +- .../stripe/payment_intents/types.rs | 12 +++--- .../src/compatibility/stripe/refunds/types.rs | 4 +- .../router/src/connector/aci/transformers.rs | 4 +- .../src/connector/adyen/transformers.rs | 4 +- .../connector/authorizedotnet/transformers.rs | 4 +- .../src/connector/checkout/transformers.rs | 6 +-- .../src/connector/klarna/transformers.rs | 6 +-- .../src/connector/stripe/transformers.rs | 14 +++---- crates/router/src/core/payments/helpers.rs | 10 ++--- crates/router/src/core/refunds.rs | 4 +- crates/router/src/core/refunds/validator.rs | 6 +-- crates/router/src/core/utils.rs | 2 +- crates/router/src/types.rs | 12 +++--- crates/router/src/types/api/payments.rs | 2 +- crates/router/tests/utils.rs | 4 +- crates/storage_models/src/mandate.rs | 14 +++---- crates/storage_models/src/payment_attempt.rs | 24 ++++++------ crates/storage_models/src/payment_intent.rs | 16 ++++---- crates/storage_models/src/refund.rs | 8 ++-- crates/storage_models/src/schema.rs | 22 +++++------ .../2022-12-14-092540_i32_to_i64/down.sql | 19 +++++++++ .../2022-12-14-092540_i32_to_i64/up.sql | 19 +++++++++ 25 files changed, 149 insertions(+), 114 deletions(-) create mode 100644 migrations/2022-12-14-092540_i32_to_i64/down.sql create mode 100644 migrations/2022-12-14-092540_i32_to_i64/up.sql diff --git a/add_connector.md b/add_connector.md index e2e533e63a..7ef93e82ce 100644 --- a/add_connector.md +++ b/add_connector.md @@ -91,7 +91,7 @@ Now let's implement Request type for checkout #[derive(Debug, Serialize)] pub struct CheckoutPaymentsRequest { pub source: Source, - pub amount: i32, + pub amount: i64, pub currency: String, #[serde(default = "generate_processing_channel_id")] pub processing_channel_id: Cow<'static, str>, @@ -223,7 +223,7 @@ Below is rest of the response type implementation for checkout #[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct CheckoutPaymentsResponse { id: String, - amount: i32, + amount: i64, status: CheckoutPaymentStatus, } diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index 2260bb9e33..a01dded02a 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -1,3 +1,5 @@ +use std::num::NonZeroI64; + use common_utils::pii; use masking::{PeekInterface, Secret}; use router_derive::Setter; @@ -22,7 +24,7 @@ pub struct PaymentsRequest { pub amount: Option, pub currency: Option, pub capture_method: Option, - pub amount_to_capture: Option, + pub amount_to_capture: Option, #[serde(default, with = "common_utils::custom_serde::iso8601::option")] pub capture_on: Option, pub confirm: Option, @@ -53,25 +55,23 @@ pub struct PaymentsRequest { #[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone, Copy, PartialEq, Eq)] pub enum Amount { - Value(i32), + Value(NonZeroI64), #[default] Zero, } -impl From for i32 { +impl From for i64 { fn from(amount: Amount) -> Self { match amount { - Amount::Value(v) => v, + Amount::Value(val) => val.get(), Amount::Zero => 0, } } } -impl From for Amount { - fn from(val: i32) -> Self { - match val { - 0 => Amount::Zero, - amount => Amount::Value(amount), - } + +impl From for Amount { + fn from(val: i64) -> Self { + NonZeroI64::new(val).map_or(Amount::Zero, Amount::Value) } } @@ -138,13 +138,13 @@ pub struct MandateData { #[derive(Clone, Eq, PartialEq, Copy, Debug, Default, serde::Serialize, serde::Deserialize)] pub struct SingleUseMandate { - pub amount: i32, + pub amount: i64, pub currency: api_enums::Currency, } #[derive(Clone, Eq, PartialEq, Copy, Debug, Default, serde::Serialize, serde::Deserialize)] pub struct MandateAmountData { - pub amount: i32, + pub amount: i64, pub currency: api_enums::Currency, } @@ -329,7 +329,7 @@ pub struct PhoneDetails { pub struct PaymentsCaptureRequest { pub payment_id: Option, pub merchant_id: Option, - pub amount_to_capture: Option, + pub amount_to_capture: Option, pub refund_uncaptured_amount: Option, pub statement_descriptor_suffix: Option, pub statement_descriptor_prefix: Option, @@ -364,9 +364,9 @@ pub struct PaymentsResponse { pub payment_id: Option, pub merchant_id: Option, pub status: api_enums::IntentStatus, - pub amount: i32, - pub amount_capturable: Option, - pub amount_received: Option, + pub amount: i64, + pub amount_capturable: Option, + pub amount_received: Option, pub connector: Option, pub client_secret: Option>, #[serde(with = "common_utils::custom_serde::iso8601::option")] @@ -656,7 +656,7 @@ pub struct PgRedirectResponse { pub status: api_enums::IntentStatus, pub gateway_id: String, pub customer_id: Option, - pub amount: Option, + pub amount: Option, } #[derive(Debug, serde::Serialize, PartialEq, Eq, serde::Deserialize)] @@ -844,10 +844,7 @@ mod amount { where E: de::Error, { - Ok(match v { - 0 => Amount::Zero, - amount => Amount::Value(amount as i32), - }) + Ok(Amount::from(v)) } } diff --git a/crates/api_models/src/refunds.rs b/crates/api_models/src/refunds.rs index 31abe43f82..77288eccfa 100644 --- a/crates/api_models/src/refunds.rs +++ b/crates/api_models/src/refunds.rs @@ -8,7 +8,7 @@ pub struct RefundRequest { pub refund_id: Option, pub payment_id: String, pub merchant_id: Option, - pub amount: Option, + pub amount: Option, pub reason: Option, pub refund_type: Option, pub metadata: Option, @@ -26,7 +26,7 @@ pub enum RefundType { pub struct RefundResponse { pub refund_id: String, pub payment_id: String, - pub amount: i32, + pub amount: i64, pub currency: String, pub reason: Option, pub status: RefundStatus, diff --git a/crates/router/src/compatibility/stripe/payment_intents/types.rs b/crates/router/src/compatibility/stripe/payment_intents/types.rs index 28c9eb98da..f4cf0933d7 100644 --- a/crates/router/src/compatibility/stripe/payment_intents/types.rs +++ b/crates/router/src/compatibility/stripe/payment_intents/types.rs @@ -113,10 +113,10 @@ impl From for Address { } #[derive(Default, PartialEq, Eq, Deserialize, Clone)] pub(crate) struct StripePaymentIntentRequest { - pub(crate) amount: Option, //amount in cents, hence passed as integer + pub(crate) amount: Option, //amount in cents, hence passed as integer pub(crate) currency: Option, #[serde(rename = "amount_to_capture")] - pub(crate) amount_capturable: Option, + pub(crate) amount_capturable: Option, pub(crate) confirm: Option, pub(crate) capture_method: Option, pub(crate) customer: Option, @@ -244,16 +244,16 @@ impl From for PaymentsCancelRequest { #[derive(Default, PartialEq, Eq, Deserialize, Clone)] pub(crate) struct StripeCaptureRequest { - pub(crate) amount_to_capture: Option, + pub(crate) amount_to_capture: Option, } #[derive(Default, Eq, PartialEq, Serialize)] pub(crate) struct StripePaymentIntentResponse { pub(crate) id: Option, pub(crate) object: String, - pub(crate) amount: i32, - pub(crate) amount_received: Option, - pub(crate) amount_capturable: Option, + pub(crate) amount: i64, + pub(crate) amount_received: Option, + pub(crate) amount_capturable: Option, pub(crate) currency: String, pub(crate) status: StripePaymentStatus, pub(crate) client_secret: Option>, diff --git a/crates/router/src/compatibility/stripe/refunds/types.rs b/crates/router/src/compatibility/stripe/refunds/types.rs index 79484d1367..2cae9b80c0 100644 --- a/crates/router/src/compatibility/stripe/refunds/types.rs +++ b/crates/router/src/compatibility/stripe/refunds/types.rs @@ -6,7 +6,7 @@ use crate::types::api::refunds::{RefundRequest, RefundResponse, RefundStatus}; #[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq)] pub(crate) struct StripeCreateRefundRequest { - pub(crate) amount: Option, + pub(crate) amount: Option, pub(crate) payment_intent: String, pub(crate) reason: Option, } @@ -14,7 +14,7 @@ pub(crate) struct StripeCreateRefundRequest { #[derive(Clone, Serialize, PartialEq, Eq)] pub(crate) struct StripeCreateRefundResponse { pub(crate) id: String, - pub(crate) amount: i32, + pub(crate) amount: i64, pub(crate) currency: String, pub(crate) payment_intent: String, pub(crate) status: StripeRefundStatus, diff --git a/crates/router/src/connector/aci/transformers.rs b/crates/router/src/connector/aci/transformers.rs index 6a868d7434..6696151e05 100644 --- a/crates/router/src/connector/aci/transformers.rs +++ b/crates/router/src/connector/aci/transformers.rs @@ -33,7 +33,7 @@ impl TryFrom<&types::ConnectorAuthType> for AciAuthType { #[serde(rename_all = "camelCase")] pub struct AciPaymentsRequest { pub entity_id: String, - pub amount: i32, + pub amount: i64, pub currency: String, pub payment_type: AciPaymentType, #[serde(flatten)] @@ -228,7 +228,7 @@ impl #[derive(Default, Debug, Serialize)] #[serde(rename_all = "camelCase")] pub struct AciRefundRequest { - pub amount: i32, + pub amount: i64, pub currency: String, pub payment_type: AciPaymentType, pub entity_id: String, diff --git a/crates/router/src/connector/adyen/transformers.rs b/crates/router/src/connector/adyen/transformers.rs index a4944f1c4f..63df99ae8b 100644 --- a/crates/router/src/connector/adyen/transformers.rs +++ b/crates/router/src/connector/adyen/transformers.rs @@ -136,7 +136,7 @@ pub struct AdyenRedirectionAction { #[derive(Default, Debug, Clone, Serialize, Deserialize)] pub struct Amount { currency: String, - value: i32, + value: i64, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -654,7 +654,7 @@ pub struct AdyenAdditionalDataWH { #[derive(Debug, Deserialize)] pub struct AdyenAmountWH { - pub value: i32, + pub value: i64, pub currency: String, } diff --git a/crates/router/src/connector/authorizedotnet/transformers.rs b/crates/router/src/connector/authorizedotnet/transformers.rs index 394da51276..5c8447e24f 100644 --- a/crates/router/src/connector/authorizedotnet/transformers.rs +++ b/crates/router/src/connector/authorizedotnet/transformers.rs @@ -67,7 +67,7 @@ enum PaymentDetails { #[serde(rename_all = "camelCase")] struct TransactionRequest { transaction_type: TransactionType, - amount: i32, + amount: i64, currency_code: String, payment: PaymentDetails, authorization_indicator_type: Option, @@ -315,7 +315,7 @@ impl #[serde(rename_all = "camelCase")] struct RefundTransactionRequest { transaction_type: TransactionType, - amount: i32, + amount: i64, currency_code: String, payment: PaymentDetails, #[serde(rename = "refTransId")] diff --git a/crates/router/src/connector/checkout/transformers.rs b/crates/router/src/connector/checkout/transformers.rs index d6e00c3b12..75cc03d1b1 100644 --- a/crates/router/src/connector/checkout/transformers.rs +++ b/crates/router/src/connector/checkout/transformers.rs @@ -43,7 +43,7 @@ pub struct ReturnUrl { #[derive(Debug, Serialize)] pub struct PaymentsRequest { pub source: Source, - pub amount: i32, + pub amount: i64, pub currency: String, pub processing_channel_id: String, #[serde(rename = "3ds")] @@ -303,7 +303,7 @@ impl TryFrom<&types::PaymentsCancelRouterData> for PaymentVoidRequest { #[derive(Clone, Debug, Serialize, Deserialize)] pub struct RefundRequest { - amount: Option, + amount: Option, reference: String, } @@ -401,7 +401,7 @@ pub enum ActionType { pub struct ActionResponse { #[serde(rename = "id")] pub action_id: String, - pub amount: i32, + pub amount: i64, #[serde(rename = "type")] pub action_type: ActionType, pub approved: Option, diff --git a/crates/router/src/connector/klarna/transformers.rs b/crates/router/src/connector/klarna/transformers.rs index f892359907..adedc49f42 100644 --- a/crates/router/src/connector/klarna/transformers.rs +++ b/crates/router/src/connector/klarna/transformers.rs @@ -14,7 +14,7 @@ pub struct KlarnaSessionRequest { purchase_country: String, purchase_currency: enums::Currency, locale: String, - order_amount: i32, + order_amount: i64, order_lines: Vec, } @@ -68,8 +68,8 @@ impl TryFrom> pub struct OrderLines { name: String, quantity: u64, - unit_price: i32, - total_amount: i32, + unit_price: i64, + total_amount: i64, } #[derive(Serialize)] diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs index e7cc99ec99..b43a2eedba 100644 --- a/crates/router/src/connector/stripe/transformers.rs +++ b/crates/router/src/connector/stripe/transformers.rs @@ -66,7 +66,7 @@ pub enum Auth3ds { #[derive(Debug, Eq, PartialEq, Serialize)] pub struct PaymentIntentRequest { - pub amount: i32, //amount in cents, hence passed as integer + pub amount: i64, //amount in cents, hence passed as integer pub currency: String, pub statement_descriptor_suffix: Option, #[serde(rename = "metadata[order_id]")] @@ -310,9 +310,9 @@ impl From for enums::AttemptStatus { pub struct PaymentIntentResponse { pub id: String, pub object: String, - pub amount: i32, - pub amount_received: i32, - pub amount_capturable: i32, + pub amount: i64, + pub amount_received: i64, + pub amount_capturable: i64, pub currency: String, pub status: StripePaymentStatus, pub client_secret: Secret, @@ -476,7 +476,7 @@ pub struct StripeRedirectToUrlResponse { #[derive(Default, Debug, Serialize)] pub struct RefundRequest { - pub amount: Option, //amount in cents, hence passed as integer + pub amount: Option, //amount in cents, hence passed as integer pub payment_intent: String, #[serde(rename = "metadata[order_id]")] pub metadata_order_id: String, @@ -535,7 +535,7 @@ impl From for enums::RefundStatus { pub struct RefundResponse { pub id: String, pub object: String, - pub amount: i32, + pub amount: i64, pub currency: String, pub metadata: StripeMetadata, pub payment_intent: String, @@ -673,7 +673,7 @@ pub struct StripeMandateOptions { #[derive(Debug, Serialize, Clone, Copy)] pub struct CaptureRequest { /// If amount_to_capture is None stripe captures the amount in the payment intent. - amount_to_capture: Option, + amount_to_capture: Option, } impl TryFrom<&types::PaymentsCaptureRouterData> for CaptureRequest { diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index ca895b8dc7..6f6ac66f19 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -224,7 +224,7 @@ pub fn validate_merchant_id( #[instrument(skip_all)] pub fn validate_request_amount_and_amount_to_capture( op_amount: Option, - op_amount_to_capture: Option, + op_amount_to_capture: Option, ) -> CustomResult<(), errors::ApiErrorResponse> { match (op_amount, op_amount_to_capture) { (None, _) => Ok(()), @@ -235,7 +235,7 @@ pub fn validate_request_amount_and_amount_to_capture( // If both amount and amount to capture is present // then amount to be capture should be less than or equal to request amount utils::when( - !amount_to_capture.le(&amount_inner), + !amount_to_capture.le(&amount_inner.get()), Err(report!(errors::ApiErrorResponse::PreconditionFailed { message: format!( "amount_to_capture is greater than amount capture_amount: {:?} request_amount: {:?}", @@ -359,7 +359,7 @@ fn validate_recurring_mandate(req: api::MandateValidationFields) -> RouterResult } pub fn verify_mandate_details( - request_amount: i32, + request_amount: i64, request_currency: String, mandate: storage::Mandate, ) -> RouterResult<()> { @@ -898,8 +898,8 @@ pub(crate) fn validate_status(status: storage_enums::IntentStatus) -> RouterResu #[instrument(skip_all)] pub(crate) fn validate_amount_to_capture( - amount: i32, - amount_to_capture: Option, + amount: i64, + amount_to_capture: Option, ) -> RouterResult<()> { utils::when( amount_to_capture.is_some() && (Some(amount) < amount_to_capture), diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs index b34f12f0db..13e8a37079 100644 --- a/crates/router/src/core/refunds.rs +++ b/crates/router/src/core/refunds.rs @@ -339,7 +339,7 @@ pub async fn validate_and_create_refund( merchant_account: &storage::merchant_account::MerchantAccount, payment_attempt: &storage::PaymentAttempt, payment_intent: &storage::PaymentIntent, - refund_amount: i32, + refund_amount: i64, req: refunds::RefundRequest, ) -> RouterResult { let db = &*state.store; @@ -459,7 +459,7 @@ fn mk_new_refund( currency: enums::Currency, refund_id: &str, merchant_id: &str, - refund_amount: i32, + refund_amount: i64, ) -> storage::RefundNew { let current_time = common_utils::date_time::now(); let connecter_transaction_id = match &payment_attempt.connector_transaction_id { diff --git a/crates/router/src/core/refunds/validator.rs b/crates/router/src/core/refunds/validator.rs index e47591658f..03d9277c58 100644 --- a/crates/router/src/core/refunds/validator.rs +++ b/crates/router/src/core/refunds/validator.rs @@ -41,11 +41,11 @@ pub fn validate_success_transaction( //todo: max refund request count #[instrument(skip_all)] pub fn validate_refund_amount( - payment_attempt_amount: i32, // &storage::PaymentAttempt, + payment_attempt_amount: i64, // &storage::PaymentAttempt, all_refunds: &[storage::Refund], - refund_amount: i32, + refund_amount: i64, ) -> CustomResult<(), RefundValidationError> { - let total_refunded_amount: i32 = all_refunds + let total_refunded_amount: i64 = all_refunds .iter() .filter_map(|refund| { if refund.refund_status != enums::RefundStatus::Failure diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs index 4fded79ee9..9534cc54d6 100644 --- a/crates/router/src/core/utils.rs +++ b/crates/router/src/core/utils.rs @@ -21,7 +21,7 @@ pub async fn construct_refund_router_data<'a, F>( state: &'a AppState, connector_id: &str, merchant_account: &storage::MerchantAccount, - money: (i32, enums::Currency), + money: (i64, enums::Currency), payment_method_data: Option<&'a api::PaymentMethod>, payment_intent: &'a storage::PaymentIntent, payment_attempt: &storage::PaymentAttempt, diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs index c0cd303694..308df41550 100644 --- a/crates/router/src/types.rs +++ b/crates/router/src/types.rs @@ -88,7 +88,7 @@ pub struct RouterData { #[derive(Debug, Clone)] pub struct PaymentsAuthorizeData { pub payment_method_data: payments::PaymentMethod, - pub amount: i32, + pub amount: i64, pub currency: storage_enums::Currency, pub confirm: bool, pub statement_descriptor_suffix: Option, @@ -105,7 +105,7 @@ pub struct PaymentsAuthorizeData { #[derive(Debug, Clone)] pub struct PaymentsCaptureData { - pub amount_to_capture: Option, + pub amount_to_capture: Option, pub connector_transaction_id: String, } @@ -125,7 +125,7 @@ pub struct PaymentsCancelData { #[derive(Debug, Clone)] pub struct PaymentsSessionData { //TODO: Add the fields here as required - pub amount: i32, + pub amount: i64, pub currency: storage_enums::Currency, } @@ -196,9 +196,9 @@ pub struct RefundsData { pub connector_transaction_id: String, pub currency: storage_enums::Currency, /// Amount for the payment against which this refund is issued - pub amount: i32, + pub amount: i64, /// Amount to be refunded - pub refund_amount: i32, + pub refund_amount: i64, } #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] @@ -233,7 +233,7 @@ pub struct ConnectorResponse { pub merchant_id: String, pub connector: String, pub payment_id: String, - pub amount: i32, + pub amount: i64, pub connector_transaction_id: String, pub return_url: Option, pub three_ds_form: Option, diff --git a/crates/router/src/types/api/payments.rs b/crates/router/src/types/api/payments.rs index eaf4b262a6..c9b898b18f 100644 --- a/crates/router/src/types/api/payments.rs +++ b/crates/router/src/types/api/payments.rs @@ -196,7 +196,7 @@ mod payments_test { #[allow(dead_code)] fn payments_request() -> PaymentsRequest { PaymentsRequest { - amount: Some(Amount::Value(200)), + amount: Some(Amount::from(200)), payment_method_data: Some(PaymentMethod::Card(card())), ..PaymentsRequest::default() } diff --git a/crates/router/tests/utils.rs b/crates/router/tests/utils.rs index fd0ec34c63..964ae87668 100644 --- a/crates/router/tests/utils.rs +++ b/crates/router/tests/utils.rs @@ -112,7 +112,7 @@ impl AppClient { pub async fn create_payment( &self, app: &S, - amount: i32, + amount: i64, amount_to_capture: i32, ) -> T where @@ -353,7 +353,7 @@ fn mk_merchant_account(merchant_id: Option) -> Value { }) } -fn mk_payment(amount: i32, amount_to_capture: i32) -> Value { +fn mk_payment(amount: i64, amount_to_capture: i32) -> Value { json!({ "amount": amount, "currency": "USD", diff --git a/crates/storage_models/src/mandate.rs b/crates/storage_models/src/mandate.rs index 62f6101184..5fd917a99d 100644 --- a/crates/storage_models/src/mandate.rs +++ b/crates/storage_models/src/mandate.rs @@ -21,9 +21,9 @@ pub struct Mandate { pub network_transaction_id: Option, pub previous_transaction_id: Option, pub created_at: PrimitiveDateTime, - pub mandate_amount: Option, + pub mandate_amount: Option, pub mandate_currency: Option, - pub amount_captured: Option, + pub amount_captured: Option, pub connector: String, pub connector_mandate_id: Option, } @@ -45,9 +45,9 @@ pub struct MandateNew { pub network_transaction_id: Option, pub previous_transaction_id: Option, pub created_at: Option, - pub mandate_amount: Option, + pub mandate_amount: Option, pub mandate_currency: Option, - pub amount_captured: Option, + pub amount_captured: Option, pub connector: String, pub connector_mandate_id: Option, } @@ -58,7 +58,7 @@ pub enum MandateUpdate { mandate_status: storage_enums::MandateStatus, }, CaptureAmountUpdate { - amount_captured: Option, + amount_captured: Option, }, ConnectorReferenceUpdate { connector_mandate_id: Option, @@ -67,7 +67,7 @@ pub enum MandateUpdate { #[derive(Clone, Eq, PartialEq, Copy, Debug, Default, serde::Serialize, serde::Deserialize)] pub struct SingleUseMandate { - pub amount: i32, + pub amount: i64, pub currency: storage_enums::Currency, } @@ -75,7 +75,7 @@ pub struct SingleUseMandate { #[diesel(table_name = mandate)] pub struct MandateUpdateInternal { mandate_status: Option, - amount_captured: Option, + amount_captured: Option, connector_mandate_id: Option, } diff --git a/crates/storage_models/src/payment_attempt.rs b/crates/storage_models/src/payment_attempt.rs index 7c9025e419..acceb61748 100644 --- a/crates/storage_models/src/payment_attempt.rs +++ b/crates/storage_models/src/payment_attempt.rs @@ -12,14 +12,14 @@ pub struct PaymentAttempt { pub merchant_id: String, pub txn_id: String, pub status: storage_enums::AttemptStatus, - pub amount: i32, + pub amount: i64, pub currency: Option, pub save_to_locker: Option, pub connector: Option, pub error_message: Option, - pub offer_amount: Option, - pub surcharge_amount: Option, - pub tax_amount: Option, + pub offer_amount: Option, + pub surcharge_amount: Option, + pub tax_amount: Option, pub payment_method_id: Option, pub payment_method: Option, pub payment_flow: Option, @@ -33,7 +33,7 @@ pub struct PaymentAttempt { pub modified_at: PrimitiveDateTime, pub last_synced: Option, pub cancellation_reason: Option, - pub amount_to_capture: Option, + pub amount_to_capture: Option, pub mandate_id: Option, pub browser_info: Option, pub error_code: Option, @@ -46,15 +46,15 @@ pub struct PaymentAttemptNew { pub merchant_id: String, pub txn_id: String, pub status: storage_enums::AttemptStatus, - pub amount: i32, + pub amount: i64, pub currency: Option, // pub auto_capture: Option, pub save_to_locker: Option, pub connector: Option, pub error_message: Option, - pub offer_amount: Option, - pub surcharge_amount: Option, - pub tax_amount: Option, + pub offer_amount: Option, + pub surcharge_amount: Option, + pub tax_amount: Option, pub payment_method_id: Option, pub payment_method: Option, pub payment_flow: Option, @@ -68,7 +68,7 @@ pub struct PaymentAttemptNew { pub modified_at: Option, pub last_synced: Option, pub cancellation_reason: Option, - pub amount_to_capture: Option, + pub amount_to_capture: Option, pub mandate_id: Option, pub browser_info: Option, pub error_code: Option, @@ -77,7 +77,7 @@ pub struct PaymentAttemptNew { #[derive(Debug, Clone)] pub enum PaymentAttemptUpdate { Update { - amount: i32, + amount: i64, currency: storage_enums::Currency, status: storage_enums::AttemptStatus, authentication_type: Option, @@ -119,7 +119,7 @@ pub enum PaymentAttemptUpdate { #[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)] #[diesel(table_name = payment_attempt)] pub struct PaymentAttemptUpdateInternal { - amount: Option, + amount: Option, currency: Option, status: Option, connector_transaction_id: Option, diff --git a/crates/storage_models/src/payment_intent.rs b/crates/storage_models/src/payment_intent.rs index 14b2b53a49..3424fbff51 100644 --- a/crates/storage_models/src/payment_intent.rs +++ b/crates/storage_models/src/payment_intent.rs @@ -11,9 +11,9 @@ pub struct PaymentIntent { pub payment_id: String, pub merchant_id: String, pub status: storage_enums::IntentStatus, - pub amount: i32, + pub amount: i64, pub currency: Option, - pub amount_captured: Option, + pub amount_captured: Option, pub customer_id: Option, pub description: Option, pub return_url: Option, @@ -37,9 +37,9 @@ pub struct PaymentIntentNew { pub payment_id: String, pub merchant_id: String, pub status: storage_enums::IntentStatus, - pub amount: i32, + pub amount: i64, pub currency: Option, - pub amount_captured: Option, + pub amount_captured: Option, pub customer_id: Option, pub description: Option, pub return_url: Option, @@ -61,7 +61,7 @@ pub struct PaymentIntentNew { pub enum PaymentIntentUpdate { ResponseUpdate { status: storage_enums::IntentStatus, - amount_captured: Option, + amount_captured: Option, return_url: Option, }, MetadataUpdate { @@ -83,7 +83,7 @@ pub enum PaymentIntentUpdate { status: storage_enums::IntentStatus, }, Update { - amount: i32, + amount: i64, currency: storage_enums::Currency, status: storage_enums::IntentStatus, customer_id: Option, @@ -96,10 +96,10 @@ pub enum PaymentIntentUpdate { #[diesel(table_name = payment_intent)] pub struct PaymentIntentUpdateInternal { - pub amount: Option, + pub amount: Option, pub currency: Option, pub status: Option, - pub amount_captured: Option, + pub amount_captured: Option, pub customer_id: Option, pub return_url: Option, pub setup_future_usage: Option, diff --git a/crates/storage_models/src/refund.rs b/crates/storage_models/src/refund.rs index adf189665a..e277f1575d 100644 --- a/crates/storage_models/src/refund.rs +++ b/crates/storage_models/src/refund.rs @@ -17,9 +17,9 @@ pub struct Refund { pub pg_refund_id: Option, pub external_reference_id: Option, pub refund_type: storage_enums::RefundType, - pub total_amount: i32, + pub total_amount: i64, pub currency: storage_enums::Currency, - pub refund_amount: i32, + pub refund_amount: i64, pub refund_status: storage_enums::RefundStatus, pub sent_to_gateway: bool, pub refund_error_message: Option, @@ -42,9 +42,9 @@ pub struct RefundNew { pub connector: String, pub pg_refund_id: Option, pub refund_type: storage_enums::RefundType, - pub total_amount: i32, + pub total_amount: i64, pub currency: storage_enums::Currency, - pub refund_amount: i32, + pub refund_amount: i64, pub refund_status: storage_enums::RefundStatus, pub sent_to_gateway: bool, pub refund_error_message: Option, diff --git a/crates/storage_models/src/schema.rs b/crates/storage_models/src/schema.rs index d08fef4e96..f8f9bad31e 100644 --- a/crates/storage_models/src/schema.rs +++ b/crates/storage_models/src/schema.rs @@ -129,9 +129,9 @@ diesel::table! { network_transaction_id -> Nullable, previous_transaction_id -> Nullable, created_at -> Timestamp, - mandate_amount -> Nullable, + mandate_amount -> Nullable, mandate_currency -> Nullable, - amount_captured -> Nullable, + amount_captured -> Nullable, connector -> Varchar, connector_mandate_id -> Nullable, } @@ -189,14 +189,14 @@ diesel::table! { merchant_id -> Varchar, txn_id -> Varchar, status -> AttemptStatus, - amount -> Int4, + amount -> Int8, currency -> Nullable, save_to_locker -> Nullable, connector -> Nullable, error_message -> Nullable, - offer_amount -> Nullable, - surcharge_amount -> Nullable, - tax_amount -> Nullable, + offer_amount -> Nullable, + surcharge_amount -> Nullable, + tax_amount -> Nullable, payment_method_id -> Nullable, payment_method -> Nullable, payment_flow -> Nullable, @@ -210,7 +210,7 @@ diesel::table! { modified_at -> Timestamp, last_synced -> Nullable, cancellation_reason -> Nullable, - amount_to_capture -> Nullable, + amount_to_capture -> Nullable, mandate_id -> Nullable, browser_info -> Nullable, error_code -> Nullable, @@ -226,9 +226,9 @@ diesel::table! { payment_id -> Varchar, merchant_id -> Varchar, status -> IntentStatus, - amount -> Int4, + amount -> Int8, currency -> Nullable, - amount_captured -> Nullable, + amount_captured -> Nullable, customer_id -> Nullable, description -> Nullable, return_url -> Nullable, @@ -312,9 +312,9 @@ diesel::table! { pg_refund_id -> Nullable, external_reference_id -> Nullable, refund_type -> RefundType, - total_amount -> Int4, + total_amount -> Int8, currency -> Currency, - refund_amount -> Int4, + refund_amount -> Int8, refund_status -> RefundStatus, sent_to_gateway -> Bool, refund_error_message -> Nullable, diff --git a/migrations/2022-12-14-092540_i32_to_i64/down.sql b/migrations/2022-12-14-092540_i32_to_i64/down.sql new file mode 100644 index 0000000000..323b249cbf --- /dev/null +++ b/migrations/2022-12-14-092540_i32_to_i64/down.sql @@ -0,0 +1,19 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE mandate + ALTER COLUMN mandate_amount TYPE integer, + ALTER COLUMN amount_captured TYPE integer; + +ALTER TABLE payment_attempt + ALTER COLUMN amount TYPE integer, + ALTER COLUMN offer_amount TYPE integer, + ALTER COLUMN surcharge_amount TYPE integer, + ALTER COLUMN tax_amount TYPE integer, + ALTER COLUMN amount_to_capture TYPE integer; + +ALTER TABLE payment_intent + ALTER COLUMN amount TYPE integer, + ALTER COLUMN amount_captured TYPE integer; + +ALTER TABLE refund + ALTER COLUMN total_amount TYPE integer, + ALTER COLUMN refund_amount TYPE integer; diff --git a/migrations/2022-12-14-092540_i32_to_i64/up.sql b/migrations/2022-12-14-092540_i32_to_i64/up.sql new file mode 100644 index 0000000000..81b90ae939 --- /dev/null +++ b/migrations/2022-12-14-092540_i32_to_i64/up.sql @@ -0,0 +1,19 @@ +-- Your SQL goes here +ALTER TABLE mandate + ALTER COLUMN mandate_amount TYPE bigint, + ALTER COLUMN amount_captured TYPE bigint; + +ALTER TABLE payment_attempt + ALTER COLUMN amount TYPE bigint, + ALTER COLUMN offer_amount TYPE bigint, + ALTER COLUMN surcharge_amount TYPE bigint, + ALTER COLUMN tax_amount TYPE bigint, + ALTER COLUMN amount_to_capture TYPE bigint; + +ALTER TABLE payment_intent + ALTER COLUMN amount TYPE bigint, + ALTER COLUMN amount_captured TYPE bigint; + +ALTER TABLE refund + ALTER COLUMN total_amount TYPE bigint, + ALTER COLUMN refund_amount TYPE bigint;