Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

refactor(connector): changed amount to minor Unit for stripe (#4786)

Sahkal Poddarb705757be37a
diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json
index c303f192cd..407fc9323d 100644
--- a/api-reference/openapi_spec.json
+++ b/api-reference/openapi_spec.json
@@ -12824,7 +12824,8 @@
"fees": {
"type": "integer",
"format": "int64",
- "description": "Platform fees to be collected on the payment"
+ "description": "Platform fees to be collected on the payment",
+ "example": 6540
},
"transfer_account_id": {
"type": "string",
@@ -12851,7 +12852,8 @@
"application_fees": {
"type": "integer",
"format": "int64",
- "description": "Platform fees collected on the payment"
+ "description": "Platform fees collected on the payment",
+ "example": 6540
},
"transfer_account_id": {
"type": "string",
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index 787ea33946..6519068d3d 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -512,7 +512,8 @@ pub struct PaymentChargeRequest {
pub charge_type: api_enums::PaymentChargeType,
/// Platform fees to be collected on the payment
- pub fees: i64,
+ #[schema(value_type = i64, example = 6540)]
+ pub fees: MinorUnit,
/// Identifier for the reseller's account to send the funds to
pub transfer_account_id: String,
@@ -3547,7 +3548,8 @@ pub struct PaymentChargeResponse {
pub charge_type: api_enums::PaymentChargeType,
/// Platform fees collected on the payment
- pub application_fees: i64,
+ #[schema(value_type = i64, example = 6540)]
+ pub application_fees: MinorUnit,
/// Identifier for the reseller's account where the funds were transferred
pub transfer_account_id: String,
diff --git a/crates/common_utils/src/types.rs b/crates/common_utils/src/types.rs
index 7ab78ce325..8e15997de3 100644
--- a/crates/common_utils/src/types.rs
+++ b/crates/common_utils/src/types.rs
@@ -317,6 +317,30 @@ impl AmountConvertor for FloatMajorUnitForConnector {
amount.to_minor_unit_as_i64(currency)
}
}
+
+/// Connector required amount type
+
+#[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone, Copy, PartialEq)]
+pub struct MinorUnitForConnector;
+
+impl AmountConvertor for MinorUnitForConnector {
+ type Output = MinorUnit;
+ fn convert(
+ &self,
+ amount: MinorUnit,
+ _currency: enums::Currency,
+ ) -> Result<Self::Output, error_stack::Report<ParsingError>> {
+ Ok(amount)
+ }
+ fn convert_back(
+ &self,
+ amount: MinorUnit,
+ _currency: enums::Currency,
+ ) -> Result<MinorUnit, error_stack::Report<ParsingError>> {
+ Ok(amount)
+ }
+}
+
/// This Unit struct represents MinorUnit in which core amount works
#[derive(
Default,
diff --git a/crates/hyperswitch_domain_models/src/router_data.rs b/crates/hyperswitch_domain_models/src/router_data.rs
index 00e13f5fce..01feefaa6c 100644
--- a/crates/hyperswitch_domain_models/src/router_data.rs
+++ b/crates/hyperswitch_domain_models/src/router_data.rs
@@ -1,6 +1,6 @@
use std::{collections::HashMap, marker::PhantomData};
-use common_utils::id_type;
+use common_utils::{id_type, types::MinorUnit};
use masking::Secret;
use crate::{payment_address::PaymentAddress, payment_method_data};
@@ -67,6 +67,9 @@ pub struct RouterData<Flow, Request, Response> {
/// This field is used to store various data regarding the response from connector
pub connector_response: Option<ConnectorResponseData>,
pub payment_method_status: Option<common_enums::PaymentMethodStatus>,
+
+ // minor amount for amount framework
+ pub minor_amount_captured: Option<MinorUnit>,
}
// Different patterns of authentication.
diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rs
index a82e9f6f28..939ca31c10 100644
--- a/crates/hyperswitch_domain_models/src/router_request_types.rs
+++ b/crates/hyperswitch_domain_models/src/router_request_types.rs
@@ -67,7 +67,7 @@ pub struct PaymentsAuthorizeData {
#[derive(Debug, serde::Deserialize, Clone)]
pub struct PaymentCharges {
pub charge_type: api_models::enums::PaymentChargeType,
- pub fees: i64,
+ pub fees: MinorUnit,
pub transfer_account_id: String,
}
@@ -245,6 +245,9 @@ pub struct PaymentsPreProcessingData {
pub mandate_id: Option<api_models::payments::MandateIds>,
pub related_transaction_id: Option<String>,
pub redirect_response: Option<CompleteAuthorizeRedirectResponse>,
+
+ // New amount for amount frame work
+ pub minor_amount: Option<MinorUnit>,
}
impl TryFrom<PaymentsAuthorizeData> for PaymentsPreProcessingData {
@@ -254,6 +257,7 @@ impl TryFrom<PaymentsAuthorizeData> for PaymentsPreProcessingData {
Ok(Self {
payment_method_data: Some(data.payment_method_data),
amount: Some(data.amount),
+ minor_amount: Some(data.minor_amount),
email: data.email,
currency: Some(data.currency),
payment_method_type: data.payment_method_type,
@@ -281,6 +285,7 @@ impl TryFrom<CompleteAuthorizeData> for PaymentsPreProcessingData {
Ok(Self {
payment_method_data: data.payment_method_data,
amount: Some(data.amount),
+ minor_amount: Some(data.minor_amount),
email: data.email,
currency: Some(data.currency),
payment_method_type: None,
diff --git a/crates/router/src/connector/bluesnap.rs b/crates/router/src/connector/bluesnap.rs
index f2a903c91f..ec294f5e1b 100644
--- a/crates/router/src/connector/bluesnap.rs
+++ b/crates/router/src/connector/bluesnap.rs
@@ -74,7 +74,6 @@ impl ConnectorCommon for Bluesnap {
fn common_get_content_type(&self) -> &'static str {
"application/json"
}
-
fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
connectors.bluesnap.base_url.as_ref()
}
diff --git a/crates/router/src/connector/stripe.rs b/crates/router/src/connector/stripe.rs
index 171cde7bc9..0874c3b7c5 100644
--- a/crates/router/src/connector/stripe.rs
+++ b/crates/router/src/connector/stripe.rs
@@ -2,7 +2,10 @@ pub mod transformers;
use std::{collections::HashMap, ops::Deref};
-use common_utils::request::RequestContent;
+use common_utils::{
+ request::RequestContent,
+ types::{AmountConvertor, MinorUnit, MinorUnitForConnector},
+};
use diesel_models::enums;
use error_stack::ResultExt;
use masking::PeekInterface;
@@ -15,6 +18,7 @@ use super::utils::{self as connector_utils, PaymentMethodDataType, RefundsReques
use super::utils::{PayoutsData, RouterData};
use crate::{
configs::settings,
+ connector::utils::PaymentsPreProcessingData,
consts,
core::{
errors::{self, CustomResult},
@@ -35,8 +39,18 @@ use crate::{
utils::{crypto, ByteSliceExt, BytesExt, OptionExt},
};
-#[derive(Debug, Clone)]
-pub struct Stripe;
+#[derive(Clone)]
+pub struct Stripe {
+ amount_converter: &'static (dyn AmountConvertor<Output = MinorUnit> + Sync),
+}
+
+impl Stripe {
+ pub const fn new() -> &'static Self {
+ &Self {
+ amount_converter: &MinorUnitForConnector,
+ }
+ }
+}
impl<Flow, Request, Response> ConnectorCommonExt<Flow, Request, Response> for Stripe
where
@@ -223,7 +237,12 @@ impl
req: &types::PaymentsPreProcessingRouterData,
_connectors: &settings::Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
- let connector_req = stripe::StripeCreditTransferSourceRequest::try_from(req)?;
+ let req_currency = req.request.get_currency()?;
+ let req_amount = req.request.get_minor_amount()?;
+ let amount =
+ connector_utils::convert_amount(self.amount_converter, req_amount, req_currency)?;
+ let connector_req =
+ stripe::StripeCreditTransferSourceRequest::try_from((req, amount, req_currency))?;
Ok(RequestContent::FormUrlEncoded(Box::new(connector_req)))
}
@@ -618,7 +637,12 @@ impl
req: &types::PaymentsCaptureRouterData,
_connectors: &settings::Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
- let connector_req = stripe::CaptureRequest::try_from(req)?;
+ let amount = connector_utils::convert_amount(
+ self.amount_converter,
+ req.request.minor_amount_to_capture,
+ req.request.currency,
+ )?;
+ let connector_req = stripe::CaptureRequest::try_from(amount)?;
Ok(RequestContent::FormUrlEncoded(Box::new(connector_req)))
}
@@ -931,12 +955,17 @@ impl
req: &types::PaymentsAuthorizeRouterData,
_connectors: &settings::Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
+ let amount = connector_utils::convert_amount(
+ self.amount_converter,
+ req.request.minor_amount,
+ req.request.currency,
+ )?;
match &req.request.payment_method_data {
domain::PaymentMethodData::BankTransfer(bank_transfer_data) => {
- stripe::get_bank_transfer_request_data(req, bank_transfer_data.deref())
+ stripe::get_bank_transfer_request_data(req, bank_transfer_data.deref(), amount)
}
_ => {
- let connector_req = stripe::PaymentIntentRequest::try_from(req)?;
+ let connector_req = stripe::PaymentIntentRequest::try_from((req, amount))?;
Ok(RequestContent::FormUrlEncoded(Box::new(connector_req)))
}
diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs
index cd7486ae70..37122aa08f 100644
--- a/crates/router/src/connector/stripe/transformers.rs
+++ b/crates/router/src/connector/stripe/transformers.rs
@@ -6,7 +6,9 @@ use common_utils::{
ext_traits::{ByteSliceExt, Encode},
pii::{self, Email},
request::RequestContent,
+ types::MinorUnit,
};
+use diesel_models::enums as storage_enums;
use error_stack::ResultExt;
use hyperswitch_domain_models::mandates::AcceptanceType;
use masking::{ExposeInterface, ExposeOptionInterface, PeekInterface, Secret};
@@ -14,7 +16,6 @@ use serde::{Deserialize, Serialize};
use serde_json::Value;
use time::PrimitiveDateTime;
use url::Url;
-
#[cfg(feature = "payouts")]
pub mod connect;
#[cfg(feature = "payouts")]
@@ -127,7 +128,7 @@ pub struct StripeBrowserInformation {
#[derive(Debug, Eq, PartialEq, Serialize)]
pub struct PaymentIntentRequest {
- pub amount: i64, //amount in cents, hence passed as integer
+ pub amount: MinorUnit, //amount in cents, hence passed as integer
pub currency: String,
pub statement_descriptor_suffix: Option<String>,
pub statement_descriptor: Option<String>,
@@ -163,7 +164,7 @@ pub struct PaymentIntentRequest {
#[derive(Debug, Eq, PartialEq, Serialize)]
pub struct IntentCharges {
- pub application_fee_amount: i64,
+ pub application_fee_amount: MinorUnit,
#[serde(
rename = "transfer_data[destination]",
skip_serializing_if = "Option::is_none"
@@ -259,7 +260,7 @@ pub struct StripeCustomerResponse {
#[derive(Debug, Eq, PartialEq, Serialize)]
pub struct ChargesRequest {
- pub amount: String,
+ pub amount: MinorUnit,
pub currency: String,
pub customer: Secret<String>,
pub source: Secret<String>,
@@ -270,8 +271,8 @@ pub struct ChargesRequest {
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
pub struct ChargesResponse {
pub id: String,
- pub amount: u64,
- pub amount_captured: u64,
+ pub amount: MinorUnit,
+ pub amount_captured: MinorUnit,
pub currency: String,
pub status: StripePaymentStatus,
pub source: StripeSourceResponse,
@@ -443,7 +444,7 @@ pub struct MultibancoCreditTransferSourceRequest {
#[serde(flatten)]
pub payment_method_data: MultibancoTransferData,
pub currency: enums::Currency,
- pub amount: Option<i64>,
+ pub amount: Option<MinorUnit>,
#[serde(rename = "redirect[return_url]")]
pub return_url: Option<String>,
}
@@ -1567,9 +1568,13 @@ impl TryFrom<&domain::GooglePayWalletData> for StripePaymentMethodData {
}
}
-impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaymentIntentRequest {
+impl TryFrom<(&types::PaymentsAuthorizeRouterData, MinorUnit)> for PaymentIntentRequest {
type Error = error_stack::Report<errors::ConnectorError>;
- fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result<Self, Self::Error> {
+ fn try_from(
+ data: (&types::PaymentsAuthorizeRouterData, MinorUnit),
+ ) -> Result<Self, Self::Error> {
+ let item = data.0;
+ let amount = data.1;
let order_id = item.connector_request_reference_id.clone();
let shipping_address = match item.get_optional_shipping() {
@@ -1858,7 +1863,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaymentIntentRequest {
};
Ok(Self {
- amount: item.request.amount, //hopefully we don't loose some cents here
+ 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(),
statement_descriptor: item.request.statement_descriptor.clone(),
@@ -2035,9 +2040,9 @@ impl From<StripePaymentStatus> for enums::AttemptStatus {
pub struct PaymentIntentResponse {
pub id: String,
pub object: String,
- pub amount: i64,
- pub amount_received: Option<i64>,
- pub amount_capturable: Option<i64>,
+ pub amount: MinorUnit,
+ pub amount_received: Option<MinorUnit>,
+ pub amount_capturable: Option<MinorUnit>,
pub currency: String,
pub status: StripePaymentStatus,
pub client_secret: Option<Secret<String>>,
@@ -2082,8 +2087,8 @@ pub struct MultibancoCreditTansferResponse {
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
pub struct AchReceiverDetails {
- pub amount_received: i64,
- pub amount_charged: i64,
+ pub amount_received: MinorUnit,
+ pub amount_charged: MinorUnit,
}
#[serde_with::skip_serializing_none]
@@ -2103,8 +2108,8 @@ pub struct QrCodeNextInstructions {
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
pub struct SepaAndBacsReceiver {
- pub amount_received: i64,
- pub amount_remaining: i64,
+ pub amount_received: MinorUnit,
+ pub amount_remaining: MinorUnit,
}
#[derive(Debug, Default, Eq, PartialEq, Deserialize)]
@@ -2415,7 +2420,11 @@ impl<F, T>
// statement_descriptor_suffix: item.response.statement_descriptor_suffix.map(|x| x.as_str()),
// three_ds_form,
response,
- amount_captured: item.response.amount_received,
+ amount_captured: item
+ .response
+ .amount_received
+ .map(|amount| amount.get_amount_as_i64()),
+ minor_amount_captured: item.response.amount_received,
connector_response: connector_response_data,
..item.data
})
@@ -2424,7 +2433,7 @@ impl<F, T>
pub fn get_connector_metadata(
next_action: Option<&StripeNextActionResponse>,
- amount: i64,
+ amount: MinorUnit,
) -> CustomResult<Option<Value>, errors::ConnectorError> {
let next_action_response = next_action
.and_then(|next_action_response| match next_action_response {
@@ -2597,7 +2606,11 @@ impl<F, T>
Ok(Self {
status: enums::AttemptStatus::from(item.response.status.to_owned()),
response,
- amount_captured: item.response.amount_received,
+ amount_captured: item
+ .response
+ .amount_received
+ .map(|amount| amount.get_amount_as_i64()),
+ minor_amount_captured: item.response.amount_received,
connector_response: connector_response_data,
..item.data
})
@@ -2794,7 +2807,7 @@ pub struct StripeVerifyWithMicroDepositsResponse {
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
pub struct StripeBankTransferDetails {
- pub amount_remaining: i64,
+ pub amount_remaining: MinorUnit,
pub currency: String,
pub financial_addresses: Vec<StripeFinancialInformation>,
pub hosted_instructions_url: Option<String>,
@@ -2846,7 +2859,7 @@ pub struct BacsFinancialDetails {
#[derive(Debug, Serialize)]
pub struct RefundRequest {
- pub amount: Option<i64>, //amount in cents, hence passed as integer
+ pub amount: Option<MinorUnit>, //amount in cents, hence passed as integer
pub payment_intent: String,
#[serde(flatten)]
pub meta_data: StripeMetadata,
@@ -2855,7 +2868,7 @@ pub struct RefundRequest {
impl<F> TryFrom<&types::RefundsRouterData<F>> for RefundRequest {
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 amount = item.request.minor_refund_amount;
let payment_intent = item.request.connector_transaction_id.clone();
Ok(Self {
amount: Some(amount),
@@ -2873,7 +2886,7 @@ pub struct ChargeRefundRequest {
pub charge: String,
pub refund_application_fee: Option<bool>,
pub reverse_transfer: Option<bool>,
- pub amount: Option<i64>, //amount in cents, hence passed as integer
+ pub amount: Option<MinorUnit>, //amount in cents, hence passed as integer
#[serde(flatten)]
pub meta_data: StripeMetadata,
}
@@ -2881,7 +2894,7 @@ pub struct ChargeRefundRequest {
impl<F> TryFrom<&types::RefundsRouterData<F>> for ChargeRefundRequest {
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 amount = item.request.minor_refund_amount;
match item.request.charges.as_ref() {
None => Err(errors::ConnectorError::MissingRequiredField {
field_name: "charges",
@@ -2939,7 +2952,7 @@ impl From<RefundStatus> for enums::RefundStatus {
pub struct RefundResponse {
pub id: String,
pub object: String,
- pub amount: i64,
+ pub amount: MinorUnit,
pub currency: String,
pub metadata: StripeMetadata,
pub payment_intent: String,
@@ -3169,23 +3182,36 @@ 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<i64>,
+ amount_to_capture: Option<MinorUnit>,
}
-impl TryFrom<&types::PaymentsCaptureRouterData> for CaptureRequest {
+impl TryFrom<MinorUnit> for CaptureRequest {
type Error = error_stack::Report<errors::ConnectorError>;
- fn try_from(item: &types::PaymentsCaptureRouterData) -> Result<Self, Self::Error> {
+ fn try_from(capture_amount: MinorUnit) -> Result<Self, Self::Error> {
Ok(Self {
- amount_to_capture: Some(item.request.amount_to_capture),
+ amount_to_capture: Some(capture_amount),
})
}
}
-impl TryFrom<&types::PaymentsPreProcessingRouterData> for StripeCreditTransferSourceRequest {
+impl
+ TryFrom<(
+ &types::PaymentsPreProcessingRouterData,
+ MinorUnit,
+ storage_enums::Currency,
+ )> for StripeCreditTransferSourceRequest
+{
type Error = error_stack::Report<errors::ConnectorError>;
- fn try_from(item: &types::PaymentsPreProcessingRouterData) -> Result<Self, Self::Error> {
- let currency = item.request.get_currency()?;
-
+ fn try_from(
+ data: (
+ &types::PaymentsPreProcessingRouterData,
+ MinorUnit,
+ storage_enums::Currency,
+ ),
+ ) -> Result<Self, Self::Error> {
+ let item = data.0;
+ let currency = data.2;
+ let amount = data.1;
match &item.request.payment_method_data {
Some(domain::PaymentMethodData::BankTransfer(bank_transfer_data)) => {
match **bank_transfer_data {
@@ -3196,7 +3222,7 @@ impl TryFrom<&types::PaymentsPreProcessingRouterData> for StripeCreditTransferSo
payment_method_data: MultibancoTransferData {
email: item.request.get_email()?,
},
- amount: Some(item.request.get_amount()?),
+ amount: Some(amount),
return_url: Some(item.get_return_url()?),
}),
),
@@ -3286,18 +3312,22 @@ impl<F, T>
}
}
-impl TryFrom<&types::PaymentsAuthorizeRouterData> for ChargesRequest {
+impl TryFrom<(&types::PaymentsAuthorizeRouterData, MinorUnit)> for ChargesRequest {
type Error = error_stack::Report<errors::ConnectorError>;
- fn try_from(value: &types::PaymentsAuthorizeRouterData) -> Result<Self, Self::Error> {
+ fn try_from(
+ data: (&types::PaymentsAuthorizeRouterData, MinorUnit),
+ ) -> Result<Self, Self::Error> {
{
+ let value = data.0;
+ let amount = data.1;
let order_id = value.connector_request_reference_id.clone();
let meta_data = Some(get_transaction_metadata(
value.request.metadata.clone(),
order_id,
));
Ok(Self {
- amount: value.request.amount.to_string(),
+ amount,
currency: value.request.currency.to_string(),
customer: Secret::new(value.get_connector_customer_id()?),
source: Secret::new(value.get_preprocessing_id()?),
@@ -3707,15 +3737,16 @@ pub struct StripeGpayToken {
pub fn get_bank_transfer_request_data(
req: &types::PaymentsAuthorizeRouterData,
bank_transfer_data: &domain::BankTransferData,
+ amount: MinorUnit,
) -> CustomResult<RequestContent, errors::ConnectorError> {
match bank_transfer_data {
domain::BankTransferData::AchBankTransfer { .. }
| domain::BankTransferData::MultibancoBankTransfer { .. } => {
- let req = ChargesRequest::try_from(req)?;
+ let req = ChargesRequest::try_from((req, amount))?;
Ok(RequestContent::FormUrlEncoded(Box::new(req)))
}
_ => {
- let req = PaymentIntentRequest::try_from(req)?;
+ let req = PaymentIntentRequest::try_from((req, amount))?;
Ok(RequestContent::FormUrlEncoded(Box::new(req)))
}
}
diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rs
index c2a5dc4c53..ee0a72d17c 100644
--- a/crates/router/src/connector/utils.rs
+++ b/crates/router/src/connector/utils.rs
@@ -609,6 +609,7 @@ pub trait PaymentsPreProcessingData {
fn get_payment_method_type(&self) -> Result<enums::PaymentMethodType, Error>;
fn get_currency(&self) -> Result<enums::Currency, Error>;
fn get_amount(&self) -> Result<i64, Error>;
+ fn get_minor_amount(&self) -> Result<MinorUnit, Error>;
fn is_auto_capture(&self) -> Result<bool, Error>;
fn get_order_details(&self) -> Result<Vec<OrderDetailsWithAmount>, Error>;
fn get_webhook_url(&self) -> Result<String, Error>;
@@ -633,6 +634,12 @@ impl PaymentsPreProcessingData for types::PaymentsPreProcessingData {
fn get_amount(&self) -> Result<i64, Error> {
self.amount.ok_or_else(missing_field_err("amount"))
}
+
+ // New minor amount function for amount framework
+ fn get_minor_amount(&self) -> Result<MinorUnit, Error> {
+ self.minor_amount.ok_or_else(missing_field_err("amount"))
+ }
+
fn is_auto_capture(&self) -> Result<bool, Error> {
match self.capture_method {
Some(enums::CaptureMethod::Automatic) | None => Ok(true),
diff --git a/crates/router/src/core/authentication/transformers.rs b/crates/router/src/core/authentication/transformers.rs
index 704784c485..5111ddcd15 100644
--- a/crates/router/src/core/authentication/transformers.rs
+++ b/crates/router/src/core/authentication/transformers.rs
@@ -155,6 +155,7 @@ pub fn construct_router_data<F: Clone, Req, Res>(
connector_meta_data: merchant_connector_account.get_metadata(),
connector_wallets_details: merchant_connector_account.get_connector_wallets_details(),
amount_captured: None,
+ minor_amount_captured: None,
access_token: None,
session_token: None,
reference_id: None,
diff --git a/crates/router/src/core/fraud_check/flows/checkout_flow.rs b/crates/router/src/core/fraud_check/flows/checkout_flow.rs
index 679a5dad29..430f74f0bb 100644
--- a/crates/router/src/core/fraud_check/flows/checkout_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/checkout_flow.rs
@@ -69,6 +69,7 @@ impl ConstructFlowSpecificData<frm_api::Checkout, FraudCheckCheckoutData, FraudC
connector_meta_data: None,
connector_wallets_details: None,
amount_captured: None,
+ minor_amount_captured: None,
request: FraudCheckCheckoutData {
amount: self.payment_attempt.amount.get_amount_as_i64(),
order_details: self.order_details.clone(),
diff --git a/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs b/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs
index 855b87f3ff..5d2a86150c 100644
--- a/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs
@@ -76,6 +76,7 @@ pub async fn construct_fulfillment_router_data<'a>(
amount_captured: payment_intent
.amount_captured
.map(|amt| amt.get_amount_as_i64()),
+ minor_amount_captured: payment_intent.amount_captured,
payment_method_status: None,
request: FraudCheckFulfillmentData {
amount: payment_attempt.amount.get_amount_as_i64(),
diff --git a/crates/router/src/core/fraud_check/flows/record_return.rs b/crates/router/src/core/fraud_check/flows/record_return.rs
index ac661231ec..b41d13933d 100644
--- a/crates/router/src/core/fraud_check/flows/record_return.rs
+++ b/crates/router/src/core/fraud_check/flows/record_return.rs
@@ -67,6 +67,7 @@ impl ConstructFlowSpecificData<RecordReturn, FraudCheckRecordReturnData, FraudCh
connector_meta_data: None,
connector_wallets_details: None,
amount_captured: None,
+ minor_amount_captured: None,
request: FraudCheckRecordReturnData {
amount: self.payment_attempt.amount.get_amount_as_i64(),
refund_method: RefundMethod::OriginalPaymentInstrument, //we dont consume this data now in payments...hence hardcoded
diff --git a/crates/router/src/core/fraud_check/flows/sale_flow.rs b/crates/router/src/core/fraud_check/flows/sale_flow.rs
index 6dbde23e3d..ebf762dfb5 100644
--- a/crates/router/src/core/fraud_check/flows/sale_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/sale_flow.rs
@@ -64,6 +64,7 @@ impl ConstructFlowSpecificData<frm_api::Sale, FraudCheckSaleData, FraudCheckResp
connector_meta_data: None,
connector_wallets_details: None,
amount_captured: None,
+ minor_amount_captured: None,
request: FraudCheckSaleData {
amount: self.payment_attempt.amount.get_amount_as_i64(),
order_details: self.order_details.clone(),
diff --git a/crates/router/src/core/fraud_check/flows/transaction_flow.rs b/crates/router/src/core/fraud_check/flows/transaction_flow.rs
index 4f5d0b30aa..d305f739f0 100644
--- a/crates/router/src/core/fraud_check/flows/transaction_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/transaction_flow.rs
@@ -74,6 +74,7 @@ impl
connector_meta_data: None,
connector_wallets_details: None,
amount_captured: None,
+ minor_amount_captured: None,
request: FraudCheckTransactionData {
amount: self.payment_attempt.amount.get_amount_as_i64(),
order_details: self.order_details.clone(),
diff --git a/crates/router/src/core/mandate/utils.rs b/crates/router/src/core/mandate/utils.rs
index 811b69e456..e25c1ab9e7 100644
--- a/crates/router/src/core/mandate/utils.rs
+++ b/crates/router/src/core/mandate/utils.rs
@@ -46,6 +46,7 @@ pub async fn construct_mandate_revoke_router_data(
connector_meta_data: None,
connector_wallets_details: None,
amount_captured: None,
+ minor_amount_captured: None,
access_token: None,
session_token: None,
reference_id: None,
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index f9f63c6cce..c94c1c714c 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -3343,6 +3343,7 @@ pub fn router_data_type_conversion<F1, F2, Req1, Req2, Res1, Res2>(
merchant_id: router_data.merchant_id,
address: router_data.address,
amount_captured: router_data.amount_captured,
+ minor_amount_captured: router_data.minor_amount_captured,
auth_type: router_data.auth_type,
connector: router_data.connector,
connector_auth_type: router_data.connector_auth_type,
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index abc1bdd0a1..df443a082f 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -162,6 +162,7 @@ where
.payment_intent
.amount_captured
.map(|amt| amt.get_amount_as_i64()),
+ minor_amount_captured: payment_data.payment_intent.amount_captured,
access_token: None,
session_token: None,
reference_id: None,
@@ -1795,6 +1796,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsPreProce
email: payment_data.email,
currency: Some(payment_data.currency),
amount: Some(amount.get_amount_as_i64()), // need to change this once we move to connector module
+ minor_amount: Some(amount),
payment_method_type: payment_data.payment_attempt.payment_method_type,
setup_mandate_details: payment_data.setup_mandate,
capture_method: payment_data.payment_attempt.capture_method,
diff --git a/crates/router/src/core/payouts.rs b/crates/router/src/core/payouts.rs
index 82d88f57eb..d6f28bda48 100644
--- a/crates/router/src/core/payouts.rs
+++ b/crates/router/src/core/payouts.rs
@@ -1331,13 +1331,13 @@ pub async fn complete_create_payout(
.attach_printable("Error updating payouts in db")?;
} else {
// create payout_object in connector as well as router
- create_payout(
+ Box::pin(create_payout(
state,
merchant_account,
key_store,
connector_data,
payout_data,
- )
+ ))
.await
.attach_printable("Payout creation failed for given Payout request")?;
}
diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs
index 3c4a119b9c..bcd7a451c9 100644
--- a/crates/router/src/core/utils.rs
+++ b/crates/router/src/core/utils.rs
@@ -166,6 +166,7 @@ pub async fn construct_payout_router_data<'a, F>(
connector_meta_data: merchant_connector_account.get_metadata(),
connector_wallets_details: merchant_connector_account.get_connector_wallets_details(),
amount_captured: None,
+ minor_amount_captured: None,
payment_method_status: None,
request: types::PayoutsData {
payout_id: payouts.payout_id.to_owned(),
@@ -322,6 +323,7 @@ pub async fn construct_refund_router_data<'a, F>(
.amount_captured
.map(|amt| amt.get_amount_as_i64()),
payment_method_status: None,
+ minor_amount_captured: payment_intent.amount_captured,
request: types::RefundsData {
refund_id: refund.refund_id.clone(),
connector_transaction_id: refund.connector_transaction_id.clone(),
@@ -571,6 +573,7 @@ pub async fn construct_accept_dispute_router_data<'a>(
amount_captured: payment_intent
.amount_captured
.map(|amt| amt.get_amount_as_i64()),
+ minor_amount_captured: payment_intent.amount_captured,
payment_method_status: None,
request: types::AcceptDisputeRequestData {
dispute_id: dispute.dispute_id.clone(),
@@ -668,6 +671,7 @@ pub async fn construct_submit_evidence_router_data<'a>(
amount_captured: payment_intent
.amount_captured
.map(|amt| amt.get_amount_as_i64()),
+ minor_amount_captured: payment_intent.amount_captured,
request: submit_evidence_request_data,
response: Err(ErrorResponse::default()),
access_token: None,
@@ -763,6 +767,7 @@ pub async fn construct_upload_file_router_data<'a>(
amount_captured: payment_intent
.amount_captured
.map(|amt| amt.get_amount_as_i64()),
+ minor_amount_captured: payment_intent.amount_captured,
payment_method_status: None,
request: types::UploadFileRequestData {
file_key,
@@ -862,6 +867,7 @@ pub async fn construct_defend_dispute_router_data<'a>(
amount_captured: payment_intent
.amount_captured
.map(|amt| amt.get_amount_as_i64()),
+ minor_amount_captured: payment_intent.amount_captured,
payment_method_status: None,
request: types::DefendDisputeRequestData {
dispute_id: dispute.dispute_id.clone(),
@@ -950,6 +956,7 @@ pub async fn construct_retrieve_file_router_data<'a>(
connector_meta_data: merchant_connector_account.get_metadata(),
connector_wallets_details: merchant_connector_account.get_connector_wallets_details(),
amount_captured: None,
+ minor_amount_captured: None,
payment_method_status: None,
request: types::RetrieveFileRequestData {
provider_file_id: file_metadata
diff --git a/crates/router/src/core/webhooks/utils.rs b/crates/router/src/core/webhooks/utils.rs
index 1394c68cfa..3c96dcaf91 100644
--- a/crates/router/src/core/webhooks/utils.rs
+++ b/crates/router/src/core/webhooks/utils.rs
@@ -88,6 +88,7 @@ pub async fn construct_webhook_router_data<'a>(
connector_meta_data: None,
connector_wallets_details: None,
amount_captured: None,
+ minor_amount_captured: None,
request: types::VerifyWebhookSourceRequestData {
webhook_headers: request_details.headers.clone(),
webhook_body: request_details.body.to_vec().clone(),
diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs
index 56a645f00b..d864eabd09 100644
--- a/crates/router/src/types.rs
+++ b/crates/router/src/types.rs
@@ -809,6 +809,7 @@ impl<F1, F2, T1, T2> ForeignFrom<(&RouterData<F1, T1, PaymentsResponseData>, T2)
connector_meta_data: data.connector_meta_data.clone(),
connector_wallets_details: data.connector_wallets_details.clone(),
amount_captured: data.amount_captured,
+ minor_amount_captured: data.minor_amount_captured,
access_token: data.access_token.clone(),
response: data.response.clone(),
payment_id: data.payment_id.clone(),
@@ -870,6 +871,7 @@ impl<F1, F2>
connector_meta_data: data.connector_meta_data.clone(),
connector_wallets_details: data.connector_wallets_details.clone(),
amount_captured: data.amount_captured,
+ minor_amount_captured: data.minor_amount_captured,
access_token: data.access_token.clone(),
response: data.response.clone(),
payment_id: data.payment_id.clone(),
diff --git a/crates/router/src/types/api.rs b/crates/router/src/types/api.rs
index 498da04c6a..deac4ec2e8 100644
--- a/crates/router/src/types/api.rs
+++ b/crates/router/src/types/api.rs
@@ -372,7 +372,7 @@ impl ConnectorData {
enums::Connector::Shift4 => Ok(Box::new(&connector::Shift4)),
enums::Connector::Square => Ok(Box::new(&connector::Square)),
enums::Connector::Stax => Ok(Box::new(&connector::Stax)),
- enums::Connector::Stripe => Ok(Box::new(&connector::Stripe)),
+ enums::Connector::Stripe => Ok(Box::new(connector::Stripe::new())),
enums::Connector::Wise => Ok(Box::new(&connector::Wise)),
enums::Connector::Worldline => Ok(Box::new(&connector::Worldline)),
enums::Connector::Worldpay => Ok(Box::new(&connector::Worldpay)),
diff --git a/crates/router/src/types/api/verify_connector.rs b/crates/router/src/types/api/verify_connector.rs
index 7e296d0b4a..378056112b 100644
--- a/crates/router/src/types/api/verify_connector.rs
+++ b/crates/router/src/types/api/verify_connector.rs
@@ -81,6 +81,7 @@ impl VerifyConnectorData {
session_token: None,
payment_method: storage_enums::PaymentMethod::Card,
amount_captured: None,
+ minor_amount_captured: None,
preprocessing_id: None,
connector_customer: None,
connector_auth_type: self.connector_auth.clone(),
diff --git a/crates/router/tests/connectors/aci.rs b/crates/router/tests/connectors/aci.rs
index b01c5abb96..5129ca922b 100644
--- a/crates/router/tests/connectors/aci.rs
+++ b/crates/router/tests/connectors/aci.rs
@@ -99,6 +99,7 @@ fn construct_payment_router_data() -> types::PaymentsAuthorizeRouterData {
connector_meta_data: None,
connector_wallets_details: None,
amount_captured: None,
+ minor_amount_captured: None,
access_token: None,
session_token: None,
reference_id: None,
@@ -162,6 +163,7 @@ fn construct_refund_router_data<F>() -> types::RefundsRouterData<F> {
connector_meta_data: None,
connector_wallets_details: None,
amount_captured: None,
+ minor_amount_captured: None,
access_token: None,
session_token: None,
reference_id: None,
diff --git a/crates/router/tests/connectors/stripe.rs b/crates/router/tests/connectors/stripe.rs
index 2d6b3e0cfd..012f3a8ca4 100644
--- a/crates/router/tests/connectors/stripe.rs
+++ b/crates/router/tests/connectors/stripe.rs
@@ -14,7 +14,7 @@ impl utils::Connector for Stripe {
fn get_data(&self) -> types::api::ConnectorData {
use router::connector::Stripe;
types::api::ConnectorData {
- connector: Box::new(&Stripe),
+ connector: Box::new(Stripe::new()),
connector_name: types::Connector::Stripe,
get_token: types::api::GetToken::Connector,
merchant_connector_id: None,
diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs
index b2c4e92901..d071ac28c9 100644
--- a/crates/router/tests/connectors/utils.rs
+++ b/crates/router/tests/connectors/utils.rs
@@ -492,6 +492,7 @@ pub trait ConnectorActions: Connector {
.and_then(|a| a.connector_meta_data.map(Secret::new)),
connector_wallets_details: None,
amount_captured: None,
+ minor_amount_captured: None,
access_token: info.clone().and_then(|a| a.access_token),
session_token: None,
reference_id: None,