-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat(connector): [Noon] Currency Unit Conversion #2786
Open
SagarDevAchar
wants to merge
12
commits into
juspay:main
Choose a base branch
from
Syntaks-Code-Vault:noon_issue_2237
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
538ead4
Create NoonRouterData and implementations
SagarDevAchar f69b381
Modify implementation for NoonPaymentsActionRequest
SagarDevAchar 20ebd75
Modify ConnectionIntegration implementations
SagarDevAchar 0dd8e62
Merge branch 'juspay:main' into noon_issue_2237
SagarDevAchar 95a61a6
Fix currency unit, amount datatype and implementations
SagarDevAchar 9ebd1ac
Merge branch 'main' into noon_issue_2237
SagarDevAchar 78801d9
Fix NoonRouterData usage
SagarDevAchar 6073bc2
Merge branch 'main' into noon_issue_2237
SagarDevAchar d78ab2a
Merge branch 'main' into noon_issue_2237
SagarDevAchar 7565bcd
Merge branch 'main' into noon_issue_2237
SagarDevAchar 0ccc4e9
Merge branch 'main' into noon_issue_2237
SagarDevAchar db5eb21
Merge branch 'main' into noon_issue_2237
SagarDevAchar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,6 +175,39 @@ pub enum NoonApiOperations { | |
Reverse, | ||
Refund, | ||
} | ||
|
||
#[derive(Debug, Serialize)] | ||
pub struct NoonRouterData<T> { | ||
pub amount: String, | ||
pub router_data: T, | ||
} | ||
|
||
impl<T> | ||
TryFrom<( | ||
&types::api::CurrencyUnit, | ||
types::storage::enums::Currency, | ||
i64, | ||
T, | ||
)> for NoonRouterData<T> | ||
{ | ||
type Error = error_stack::Report<errors::ConnectorError>; | ||
|
||
fn try_from( | ||
(currency_unit, currency, amount, router_data): ( | ||
&types::api::CurrencyUnit, | ||
types::storage::enums::Currency, | ||
i64, | ||
T, | ||
), | ||
) -> Result<Self, Self::Error> { | ||
let amount = conn_utils::get_amount_as_string(currency_unit, amount, currency)?; | ||
Ok(Self { | ||
amount, | ||
router_data, | ||
}) | ||
} | ||
} | ||
|
||
#[derive(Debug, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct NoonPaymentsRequest { | ||
|
@@ -186,10 +219,16 @@ pub struct NoonPaymentsRequest { | |
billing: Option<NoonBilling>, | ||
} | ||
|
||
impl TryFrom<&types::PaymentsAuthorizeRouterData> for NoonPaymentsRequest { | ||
impl TryFrom<&NoonRouterData<&types::PaymentsAuthorizeRouterData>> for NoonPaymentsRequest { | ||
type Error = error_stack::Report<errors::ConnectorError>; | ||
fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result<Self, Self::Error> { | ||
let (payment_data, currency, category) = match item.request.connector_mandate_id() { | ||
fn try_from( | ||
item: &NoonRouterData<&types::PaymentsAuthorizeRouterData>, | ||
) -> Result<Self, Self::Error> { | ||
let (payment_data, currency, category) = match item | ||
.router_data | ||
.request | ||
.connector_mandate_id() | ||
{ | ||
Some(subscription_identifier) => ( | ||
NoonPaymentData::Subscription(NoonSubscription { | ||
subscription_identifier, | ||
|
@@ -198,7 +237,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for NoonPaymentsRequest { | |
None, | ||
), | ||
_ => ( | ||
match item.request.payment_method_data.clone() { | ||
match item.router_data.request.payment_method_data.clone() { | ||
api::PaymentMethodData::Card(req_card) => Ok(NoonPaymentData::Card(NoonCard { | ||
name_on_card: req_card.card_holder_name.clone(), | ||
number_plain: req_card.card_number.clone(), | ||
|
@@ -242,7 +281,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for NoonPaymentsRequest { | |
} | ||
api_models::payments::WalletData::PaypalRedirect(_) => { | ||
Ok(NoonPaymentData::PayPal(NoonPayPal { | ||
return_url: item.request.get_router_return_url()?, | ||
return_url: item.router_data.request.get_router_return_url()?, | ||
})) | ||
} | ||
api_models::payments::WalletData::AliPayQr(_) | ||
|
@@ -291,25 +330,27 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for NoonPaymentsRequest { | |
}) | ||
} | ||
}?, | ||
Some(item.request.currency), | ||
item.request.order_category.clone(), | ||
Some(item.router_data.request.currency), | ||
item.router_data.request.order_category.clone(), | ||
), | ||
}; | ||
|
||
// The description should not have leading or trailing whitespaces, also it should not have double whitespaces and a max 50 chars according to Noon's Docs | ||
let name: String = item | ||
.router_data | ||
.get_description()? | ||
.trim() | ||
.replace(" ", " ") | ||
.chars() | ||
.take(50) | ||
.collect(); | ||
|
||
let ip_address = item.request.get_ip_address_as_optional(); | ||
let ip_address = item.router_data.request.get_ip_address_as_optional(); | ||
|
||
let channel = NoonChannels::Web; | ||
|
||
let billing = item | ||
.router_data | ||
.address | ||
.billing | ||
.clone() | ||
|
@@ -326,27 +367,34 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for NoonPaymentsRequest { | |
}, | ||
}); | ||
|
||
let (subscription, tokenize_c_c) = | ||
match item.request.setup_future_usage.is_some().then_some(( | ||
let (subscription, tokenize_c_c) = match item | ||
.router_data | ||
.request | ||
.setup_future_usage | ||
.is_some() | ||
.then_some(( | ||
NoonSubscriptionData { | ||
subscription_type: NoonSubscriptionType::Unscheduled, | ||
name: name.clone(), | ||
}, | ||
true, | ||
)) { | ||
Some((a, b)) => (Some(a), Some(b)), | ||
None => (None, None), | ||
}; | ||
Some((a, b)) => (Some(a), Some(b)), | ||
None => (None, None), | ||
}; | ||
let order = NoonOrder { | ||
amount: conn_utils::to_currency_base_unit(item.request.amount, item.request.currency)?, | ||
amount: conn_utils::to_currency_base_unit( | ||
item.router_data.request.amount, | ||
item.router_data.request.currency, | ||
)?, | ||
currency, | ||
channel, | ||
category, | ||
reference: item.connector_request_reference_id.clone(), | ||
reference: item.router_data.connector_request_reference_id.clone(), | ||
name, | ||
ip_address, | ||
}; | ||
let payment_action = if item.request.is_auto_capture()? { | ||
let payment_action = if item.router_data.request.is_auto_capture()? { | ||
NoonPaymentActions::Sale | ||
} else { | ||
NoonPaymentActions::Authorize | ||
|
@@ -357,7 +405,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for NoonPaymentsRequest { | |
billing, | ||
configuration: NoonConfiguration { | ||
payment_action, | ||
return_url: item.request.router_return_url.clone(), | ||
return_url: item.router_data.request.router_return_url.clone(), | ||
tokenize_c_c, | ||
}, | ||
payment_data, | ||
|
@@ -598,19 +646,19 @@ impl TryFrom<&types::PaymentsCancelRouterData> for NoonPaymentsCancelRequest { | |
} | ||
} | ||
|
||
impl<F> TryFrom<&types::RefundsRouterData<F>> for NoonPaymentsActionRequest { | ||
impl<F> TryFrom<&NoonRouterData<&types::RefundsRouterData<F>>> for NoonPaymentsActionRequest { | ||
type Error = error_stack::Report<errors::ConnectorError>; | ||
fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> { | ||
fn try_from(item: &NoonRouterData<&types::RefundsRouterData<F>>) -> Result<Self, Self::Error> { | ||
let order = NoonActionOrder { | ||
id: item.request.connector_transaction_id.clone(), | ||
id: item.router_data.request.connector_transaction_id.clone(), | ||
}; | ||
let transaction = NoonActionTransaction { | ||
amount: conn_utils::to_currency_base_unit( | ||
item.request.refund_amount, | ||
item.request.currency, | ||
item.router_data.request.refund_amount, | ||
item.router_data.request.currency, | ||
Comment on lines
656
to
+658
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
)?, | ||
currency: item.request.currency, | ||
transaction_reference: Some(item.request.refund_id.clone()), | ||
currency: item.router_data.request.currency, | ||
transaction_reference: Some(item.router_data.request.refund_id.clone()), | ||
}; | ||
Ok(Self { | ||
api_operation: NoonApiOperations::Refund, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.