Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
9ef9de9
refactor(router): added a new type minor unit to amount
sahkal May 13, 2024
a1bb647
chore: run formatter
hyperswitch-bot[bot] May 13, 2024
f6c4946
refactor(router): fixed clippy issue
sahkal May 13, 2024
937687a
Merge branch 'change_core_amount_to_domain_type' of https://github.co…
sahkal May 13, 2024
61850dc
refactor(router): fixed openapi specs
sahkal May 13, 2024
c840348
Merge branch 'main' into change_core_amount_to_domain_type
sahkal May 13, 2024
6103485
refactor(router): fixed capture amount unequal bug
sahkal May 13, 2024
0c214b7
Merge branch 'change_core_amount_to_domain_type' of https://github.co…
sahkal May 13, 2024
a994132
refactor(router): fixed open-api issue
sahkal May 13, 2024
02a7048
refactor(router): addressed pr comments
sahkal May 14, 2024
fe6dd36
refactor(router): resolved merge conflicts
sahkal May 15, 2024
9852bf4
refactor(router): fixed spell check issue
sahkal May 15, 2024
41af58f
refactor(router): resolved pr comments:
sahkal May 16, 2024
3df68ba
Merge branch 'main' into change_core_amount_to_domain_type
hrithikesh026 May 16, 2024
6e6726f
refactor(router): resolved pr comments
sahkal May 17, 2024
68034cb
Merge branch 'change_core_amount_to_domain_type' of https://github.co…
sahkal May 17, 2024
1b623a8
refactor(router): fixed clippy issue
sahkal May 17, 2024
eff793f
refactor(router): fixed clippy issue
sahkal May 17, 2024
bce3de0
refactor(router): fixed open-api-specs
sahkal May 17, 2024
63ef54c
refactor(router): fixed open-api specs
sahkal May 17, 2024
17c58f4
chore: run formatter
hyperswitch-bot[bot] May 17, 2024
f76ba1d
refactor(router): fixed clippy issue
sahkal May 17, 2024
5b657f9
Merge branch 'change_core_amount_to_domain_type' of https://github.co…
sahkal May 17, 2024
59ffc34
refactor(router): resolved comments
sahkal May 17, 2024
9ba21c4
chore: run formatter
hyperswitch-bot[bot] May 17, 2024
3bce742
refactor(router): resolved comments
sahkal May 17, 2024
5b8cf34
Merge branch 'change_core_amount_to_domain_type' of https://github.co…
sahkal May 17, 2024
23e9158
refactor(router): fixed clippy issue
sahkal May 17, 2024
78d71ba
feat(router
sahkal May 20, 2024
d4c363f
wip: reduce errors
Narayanbhat166 May 20, 2024
ddee2bd
chore: make it finally compile
Narayanbhat166 May 20, 2024
6e0070d
chore: run formatter
hyperswitch-bot[bot] May 20, 2024
44caf0b
feat(router): added conversion trait in core for connector to use
sahkal May 21, 2024
d5f951f
Merge branch 'move-newType-amount-to-connector-module' of https://git…
sahkal May 21, 2024
c0f549e
chore: run formatter
hyperswitch-bot[bot] May 21, 2024
1a9fe2a
refactor
sahkal May 23, 2024
53f0465
refactor(router): resolved merge conflicts
sahkal May 23, 2024
f30b388
refactor(router): fixed clippy issues
sahkal May 23, 2024
8647c28
refactor(router): resolved merge conflicts
sahkal May 23, 2024
fc05741
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] May 23, 2024
db98d60
refactor(router):fixed open-api issue
sahkal May 23, 2024
4ddb24c
Merge branch 'move-newType-amount-to-connector-module' of https://git…
sahkal May 23, 2024
d94ef10
refactor(router): removed unnecessary code
sahkal May 23, 2024
4910dec
refactor(router): added unit test case for amount conversions
sahkal May 27, 2024
37f5b1c
refactor(router): added unit case for three_decimal_currency
sahkal May 27, 2024
bc00c63
refactor(router): addressed pr comments
sahkal May 28, 2024
11a6b2c
refactor(router): resolved merge conflicts
sahkal May 28, 2024
3547356
refactor(router): removed test_amount from tests
sahkal May 28, 2024
7a916a5
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] May 28, 2024
d9b564b
refactor(router): fixed clippy issues
sahkal May 28, 2024
5b9c363
Merge branch 'move-newType-amount-to-connector-module' of https://git…
sahkal May 28, 2024
6b8c733
refactor(router): fixed open api issue
sahkal May 28, 2024
56ea730
refactor(connector): changed amount to minor Unit for stripe
sahkal May 28, 2024
96f9aa3
chore: run formatter
hyperswitch-bot[bot] May 28, 2024
5be12e1
refactor(router): mapped error to error message
sahkal May 28, 2024
fa440df
chore: run formatter
hyperswitch-bot[bot] May 28, 2024
0ba13c1
refactor(router): resolved merge conflict
sahkal May 29, 2024
34f220c
Merge branch 'move-newType-amount-to-connector-module' of https://git…
sahkal May 29, 2024
6967e5f
chore: run formatter
hyperswitch-bot[bot] May 29, 2024
773b458
refactor(router): addressed pr comments
sahkal May 29, 2024
8d51b46
Merge branch 'move-newType-amount-to-connector-module' of https://git…
sahkal May 29, 2024
64b8693
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] May 29, 2024
1939b5f
refactor(router): fixed open-api specs'
sahkal May 29, 2024
1daa5a9
refactor(router): fixed open-api specs'
sahkal May 29, 2024
7edf17b
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] May 29, 2024
8ac5ecc
refactor(router): fixed clippy issue
sahkal May 29, 2024
511322c
Merge branch 'move-newType-amount-to-connector-module' of https://git…
sahkal May 29, 2024
97113c9
chore: run formatter
hyperswitch-bot[bot] May 29, 2024
7fd1af9
refactor(router): fixed open-api specs
sahkal May 29, 2024
f2a70b5
Merge branch 'move-newType-amount-to-connector-module' of https://git…
sahkal May 29, 2024
9cdea2d
refactor(router): resolved merge conflicts
sahkal May 29, 2024
c4bd128
chore: run formatter
hyperswitch-bot[bot] May 29, 2024
35c47fe
refactor(router): fixed cargo hack issue
sahkal May 29, 2024
d009312
Merge branch 'move-newType-amount-to-connector-module' of https://git…
sahkal May 29, 2024
3135548
chore: run formatter
hyperswitch-bot[bot] May 29, 2024
d20810c
Merge branch 'move-newType-amount-to-connector-module' of https://git…
sahkal May 30, 2024
4a259a4
refactor(connector): added amount frame work support for stripe
sahkal May 30, 2024
3366b2e
chore: run formatter
hyperswitch-bot[bot] May 30, 2024
94f6f55
refactor(connector): addressed pr comments
sahkal May 30, 2024
0dceb91
refactor(connector): added captured amount to router data
sahkal May 30, 2024
2867fb6
chore: run formatter
hyperswitch-bot[bot] May 30, 2024
bf9393a
refactor(connector):added amount framework to charged object
sahkal May 30, 2024
80efa5a
Merge branch '5177-amount-conversion-do-amount-conversion-for-stripe'…
sahkal May 30, 2024
8efa34e
refactor(connector): resolved pr comments
sahkal May 30, 2024
4be4348
refactor(connector): resolved merge conflicts
sahkal May 31, 2024
b63687d
refactor(connector): added uniformity in stripe for amount framework
sahkal May 31, 2024
c5ff47f
chore: run formatter
hyperswitch-bot[bot] May 31, 2024
f227337
Merge branch 'main' of https://github.com/juspay/hyperswitch into 517…
sahkal Jun 7, 2024
b0894c6
refactor(router): fixed clippy issue
sahkal Jun 10, 2024
b42ea86
Merge branch 'main' into 5177-amount-conversion-do-amount-conversion-…
sahkal Jun 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -12814,7 +12814,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",
Expand All @@ -12841,7 +12842,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",
Expand Down
6 changes: 4 additions & 2 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions crates/common_utils/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion crates/hyperswitch_domain_models/src/router_data.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion crates/router/src/connector/bluesnap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
43 changes: 36 additions & 7 deletions crates/router/src/connector/stripe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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},
Expand All @@ -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
Expand Down Expand Up @@ -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)))
}

Expand Down Expand Up @@ -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)))
}

Expand Down Expand Up @@ -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)))
}
Expand Down
Loading
Loading