refactor(api_models): shrink Amount (#140)

This commit is contained in:
kos-for-juspay
2022-12-14 14:03:30 +01:00
committed by GitHub
parent 8b8ff8188f
commit a4d64eba7c
25 changed files with 149 additions and 114 deletions

View File

@ -113,10 +113,10 @@ impl From<Shipping> for Address {
}
#[derive(Default, PartialEq, Eq, Deserialize, Clone)]
pub(crate) struct StripePaymentIntentRequest {
pub(crate) amount: Option<i32>, //amount in cents, hence passed as integer
pub(crate) amount: Option<i64>, //amount in cents, hence passed as integer
pub(crate) currency: Option<String>,
#[serde(rename = "amount_to_capture")]
pub(crate) amount_capturable: Option<i32>,
pub(crate) amount_capturable: Option<i64>,
pub(crate) confirm: Option<bool>,
pub(crate) capture_method: Option<api_enums::CaptureMethod>,
pub(crate) customer: Option<String>,
@ -244,16 +244,16 @@ impl From<StripePaymentCancelRequest> for PaymentsCancelRequest {
#[derive(Default, PartialEq, Eq, Deserialize, Clone)]
pub(crate) struct StripeCaptureRequest {
pub(crate) amount_to_capture: Option<i32>,
pub(crate) amount_to_capture: Option<i64>,
}
#[derive(Default, Eq, PartialEq, Serialize)]
pub(crate) struct StripePaymentIntentResponse {
pub(crate) id: Option<String>,
pub(crate) object: String,
pub(crate) amount: i32,
pub(crate) amount_received: Option<i32>,
pub(crate) amount_capturable: Option<i32>,
pub(crate) amount: i64,
pub(crate) amount_received: Option<i64>,
pub(crate) amount_capturable: Option<i64>,
pub(crate) currency: String,
pub(crate) status: StripePaymentStatus,
pub(crate) client_secret: Option<Secret<String>>,

View File

@ -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<i32>,
pub(crate) amount: Option<i64>,
pub(crate) payment_intent: String,
pub(crate) reason: Option<String>,
}
@ -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,

View File

@ -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<F, T>
#[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,

View File

@ -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,
}

View File

@ -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<AuthorizationIndicator>,
@ -315,7 +315,7 @@ impl<F, T>
#[serde(rename_all = "camelCase")]
struct RefundTransactionRequest {
transaction_type: TransactionType,
amount: i32,
amount: i64,
currency_code: String,
payment: PaymentDetails,
#[serde(rename = "refTransId")]

View File

@ -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<i32>,
amount: Option<i64>,
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<bool>,

View File

@ -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<OrderLines>,
}
@ -68,8 +68,8 @@ impl TryFrom<types::PaymentsSessionResponseRouterData<KlarnaSessionResponse>>
pub struct OrderLines {
name: String,
quantity: u64,
unit_price: i32,
total_amount: i32,
unit_price: i64,
total_amount: i64,
}
#[derive(Serialize)]

View File

@ -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<String>,
#[serde(rename = "metadata[order_id]")]
@ -310,9 +310,9 @@ impl From<StripePaymentStatus> 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<String>,
@ -476,7 +476,7 @@ pub struct StripeRedirectToUrlResponse {
#[derive(Default, Debug, Serialize)]
pub struct RefundRequest {
pub amount: Option<i32>, //amount in cents, hence passed as integer
pub amount: Option<i64>, //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<self::RefundStatus> 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<i32>,
amount_to_capture: Option<i64>,
}
impl TryFrom<&types::PaymentsCaptureRouterData> for CaptureRequest {

View File

@ -224,7 +224,7 @@ pub fn validate_merchant_id(
#[instrument(skip_all)]
pub fn validate_request_amount_and_amount_to_capture(
op_amount: Option<api::Amount>,
op_amount_to_capture: Option<i32>,
op_amount_to_capture: Option<i64>,
) -> 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<i32>,
amount: i64,
amount_to_capture: Option<i64>,
) -> RouterResult<()> {
utils::when(
amount_to_capture.is_some() && (Some(amount) < amount_to_capture),

View File

@ -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<refunds::RefundResponse> {
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 {

View File

@ -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

View File

@ -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,

View File

@ -88,7 +88,7 @@ pub struct RouterData<Flow, Request, Response> {
#[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<String>,
@ -105,7 +105,7 @@ pub struct PaymentsAuthorizeData {
#[derive(Debug, Clone)]
pub struct PaymentsCaptureData {
pub amount_to_capture: Option<i32>,
pub amount_to_capture: Option<i64>,
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<String>,
pub three_ds_form: Option<services::RedirectForm>,

View File

@ -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()
}

View File

@ -112,7 +112,7 @@ impl AppClient<User> {
pub async fn create_payment<T: DeserializeOwned, S, B>(
&self,
app: &S,
amount: i32,
amount: i64,
amount_to_capture: i32,
) -> T
where
@ -353,7 +353,7 @@ fn mk_merchant_account(merchant_id: Option<String>) -> 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",