-
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
refactor(connector): add amount conversion framework to cybersource #6335
base: main
Are you sure you want to change the base?
refactor(connector): add amount conversion framework to cybersource #6335
Conversation
Changed Files
|
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.
Please implement the suggested changes.
let minor_amount = | ||
req.request | ||
.minor_amount | ||
.ok_or(errors::ConnectorError::MissingRequiredField { | ||
field_name: "minor_amount", | ||
})?; | ||
let amount = convert_amount(self.amount_converter, minor_amount, req.request.currency)?; | ||
let connector_router_data = cybersource::CybersourceRouterData::from((amount, req)); | ||
|
||
let connector_req = | ||
cybersource::CybersourceZeroMandateRequest::try_from(&connector_router_data)?; |
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.
This change is not required because amount is always 0 for setup mandate flow. Please revert this change.
// let connector_router_data = cybersource::CybersourceRouterData::try_from(( | ||
// &self.get_currency_unit(), | ||
// req.request.currency, | ||
// req.request.amount_to_capture, | ||
// req, | ||
// )); |
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.
Please remove these comments.
// impl<T> TryFrom<(&api::CurrencyUnit, enums::Currency, i64, T)> for CybersourceRouterData<T> { | ||
// type Error = error_stack::Report<errors::ConnectorError>; | ||
// fn try_from( | ||
// (currency_unit, currency, amount, item): (&api::CurrencyUnit, enums::Currency, i64, T), | ||
// ) -> Result<Self, Self::Error> { | ||
// // This conversion function is used at different places in the file, if updating this, keep a check for those | ||
// let amount = utils::get_amount_as_string(currency_unit, amount, currency)?; | ||
// Ok(Self { | ||
// amount, | ||
// router_data: item, | ||
// }) | ||
// } | ||
// } |
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.
Remove these comments
impl TryFrom<&CybersourceRouterData<&types::SetupMandateRouterData>> | ||
for CybersourceZeroMandateRequest | ||
{ | ||
type Error = error_stack::Report<errors::ConnectorError>; | ||
fn try_from(item: &types::SetupMandateRouterData) -> Result<Self, Self::Error> { | ||
fn try_from( | ||
item_data: &CybersourceRouterData<&types::SetupMandateRouterData>, | ||
) -> Result<Self, Self::Error> { | ||
let item = item_data.router_data.clone(); | ||
let email = item.get_billing_email().or(item.request.get_email())?; | ||
let bill_to = build_bill_to(item.get_optional_billing(), email)?; | ||
|
||
let order_information = OrderInformationWithBill { | ||
amount_details: Amount { | ||
total_amount: "0".to_string(), | ||
total_amount: item_data.amount.clone(), | ||
currency: item.request.currency, | ||
}, | ||
bill_to: Some(bill_to), |
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.
These changes are not required. Hard code the value to zero.
StringMajorUnit("0".to_string())
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.
hey @deepanshu-iiitu,
when i make this change, cargo clippy
gives this error
error[E0423]: cannot initialize a tuple struct which contains private fields --> crates/router/src/connector/cybersource/transformers.rs:97:31 | 97 | total_amount: StringMajorUnit("0".to_string()), | ^^^^^^^^^^^^^^^ | note: constructor is not visible here due to private fields --> /media/gaurav/hyperswitch/crates/common_utils/src/types.rs:552:28 | 552 | pub struct StringMajorUnit(String); | ^^^^^^ private field help: you might have meant to use the
newassociated function | 97 | total_amount: StringMajorUnit::new("0".to_string()), | +++++
after using the StringMajorUnit::new("0".to_string())
gives this error
error[E0624]: associated function
new is private --> crates/router/src/connector/cybersource/transformers.rs:97:48 | 97 | total_amount: StringMajorUnit::new("0".to_string()), | ^^^ private associated function | ::: /media/gaurav/hyperswitch/crates/common_utils/src/types.rs:556:5 | 556 | fn new(value: String) -> Self { | ----------------------------- private associated function defined here
there are two fixes to this problem that require to make changes in crates/common_utils/src/types.rs
file
- make the
fn new
public ->pub fn new
forStringMajorUnit
pub fn new(value: String) -> Self { Self(value) }
- make a public function zero and use it instead
pub fn zero() -> Self { Self("0".to_string()) }
&
amount_details: Amount { total_amount: StringMajorUnit::zero(), currency: item.request.currency, },
in crates/router/src/connector/cybersource/transformers.rs
what changes do u suggest?
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.
You can make the function public
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.
sure making the new function public
item_data: &CybersourceRouterData<&types::RefundsRouterData<F>>, | ||
) -> Result<Self, Self::Error> { | ||
let item = item_data.router_data; | ||
Ok(Self { | ||
order_information: OrderInformation { | ||
amount_details: Amount { | ||
total_amount: item.amount.clone(), | ||
currency: item.router_data.request.currency, | ||
total_amount: item_data.amount.clone(), | ||
currency: item.request.currency, | ||
}, | ||
}, | ||
client_reference_information: ClientReferenceInformation { | ||
code: Some(item.router_data.request.refund_id.clone()), | ||
code: Some(item.request.refund_id.clone()), |
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.
These changes are not required.
item_data: &CybersourceRouterData<&types::PaymentsPreProcessingRouterData>, | ||
) -> Result<Self, Self::Error> { | ||
let item = item_data.router_data.clone(); | ||
let client_reference_information = ClientReferenceInformation { | ||
code: Some(item.router_data.connector_request_reference_id.clone()), | ||
code: Some(item.connector_request_reference_id.clone()), | ||
}; | ||
let payment_method_data = item.router_data.request.payment_method_data.clone().ok_or( | ||
let payment_method_data = item.request.payment_method_data.clone().ok_or( |
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.
These changes are not required. please revert them
let redirect_response = item.request.redirect_response.clone().ok_or( | ||
errors::ConnectorError::MissingRequiredField { | ||
field_name: "redirect_response", | ||
}, | ||
)?; | ||
|
||
let amount_details = Amount { | ||
total_amount: item.amount.clone(), | ||
currency: item.router_data.request.currency.ok_or( | ||
total_amount: item_data.amount.clone(), | ||
currency: item.request.currency.ok_or( |
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.
These changes are not required. please revert them
.router_data | ||
.request | ||
.get_complete_authorize_url()?, | ||
return_url: item.request.get_complete_authorize_url()?, |
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.
These changes are not required. please revert them
@gauravghodinde Please implement the suggested changes |
@deepanshu-iiitu please check this out, #6335 (comment) |
hey @deepanshu-iiitu, i please review i have made the requested changes |
crates/common_utils/src/types.rs
Outdated
/// forms a new StringMajorUnit default unit i.e zero | ||
pub fn zero() -> Self { | ||
Self("0".to_string()) | ||
} | ||
|
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.
Why do we need this? You can call StringMajorUnit::new(String::new("0"))
I've tested the Payin flows, and everything is working as expected. We can proceed with the merge once @Sakilmostak completes the testing on the payouts side and provides his approval. |
@deepanshu-iiitu Can you add the testcases for cybersource |
hey @deepanshu-iiitu can you explain why the checks failed? |
3464530
@@ -93,7 +88,7 @@ impl TryFrom<&types::SetupMandateRouterData> for CybersourceZeroMandateRequest { | |||
|
|||
let order_information = OrderInformationWithBill { | |||
amount_details: Amount { | |||
total_amount: "0".to_string(), | |||
total_amount: StringMajorUnit::new("0".to_string()), |
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.
total_amount: StringMajorUnit::new("0".to_string()), | |
total_amount: StringMajorUnit::zero(), |
And can you also make StringMajorUnit::new()
private for now?
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.
sure
Type of Change
Description
added StringMajorUnit for amount conversion
Additional Changes
Motivation and Context
fixes #5942
How did you test it?
Tested through postman:
Checklist
cargo +nightly fmt --all
cargo clippy