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): add amount conversion framework to Riskified #6359

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Sidharth-Singh10
Copy link
Contributor

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

This PR does amount conversion changes for Riskified Connector and it accepts the amount in MinorUnit

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

Fixes #6139

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@Sidharth-Singh10 Sidharth-Singh10 requested review from a team as code owners October 17, 2024 18:02
Copy link

semanticdiff-com bot commented Oct 17, 2024

Review changes with SemanticDiff.

Analyzed 4 of 4 files.

Overall, the semantic diff is 29% smaller than the GitHub diff.

Filename Status
✔️ crates/router/src/types/api/fraud_check.rs 85.57% smaller
✔️ crates/router/src/connector/riskified.rs 18.54% smaller
✔️ crates/router/src/connector/riskified/transformers/api.rs 38.53% smaller
✔️ crates/common_utils/src/types.rs 25.0% smaller

@gorakhnathy7 gorakhnathy7 added the hacktoberfest Issues that are up for grabs for Hacktoberfest participants label Oct 17, 2024
@swangi-kumari swangi-kumari added A-connector-integration Area: Connector integration C-refactor Category: Refactor labels Oct 22, 2024
@srujanchikke
Copy link
Contributor

Hi @Sidharth-Singh10 ,

Thanks for the PR,

There has been some correction in the issue, Actually Riskified accepts amount as Major unit(ex : Dollars in US), could you please make the same changes with amount type as Major Unit. Please let us know if need any other info.

Thanks

@Sidharth-Singh10
Copy link
Contributor Author

Hi @srujanchikke, so the change is to replace MinorUnit with StringMajorUnit for the amount, right? Let me know if that’s correct.
Thanks!

@srujanchikke
Copy link
Contributor

Hi @srujanchikke, so the change is to replace MinorUnit with StringMajorUnit for the amount, right? Let me know if that’s correct. Thanks!

Yes, you're right

@Sidharth-Singh10
Copy link
Contributor Author

@srujanchikke, I’ve made the requested changes.

crates/router/src/connector/riskified/transformers/api.rs Outdated Show resolved Hide resolved
cart_token: payment_data.attempt_id.clone(),
line_items: payment_data
.request
.get_order_details()?
.iter()
.map(|order_detail| LineItem {
price: order_detail.amount,
price: StringMajorUnit::new(order_detail.amount.to_string()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the requested changes at other places.
but here the amount' is field of OrderDetailsWithAmount struct which is i64, I am unable to grasp how to use it directly.

@@ -156,14 +176,14 @@ impl TryFrom<&frm_types::FrmCheckoutRouterData> for RiskifiedPaymentsCheckoutReq
created_at: common_utils::date_time::now(),
updated_at: common_utils::date_time::now(),
gateway: payment_data.request.gateway.clone(),
total_price: payment_data.request.amount,
total_price: StringMajorUnit::new(payment_data.request.amount.to_string()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
total_price: StringMajorUnit::new(payment_data.request.amount.to_string()),
total_price: payment.amount.clone(),

Comment on lines +187 to +195
let amount = convert_amount(
self.amount_converter,
MinorUnit::new(req.request.amount),
req.request
.currency
.ok_or(errors::ConnectorError::MissingRequiredField {
field_name: "currency",
})?,
)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar change needs to be done wherever amount is being used like FrmTransactionRouterData .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-connector-integration Area: Connector integration C-refactor Category: Refactor hacktoberfest Issues that are up for grabs for Hacktoberfest participants
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REFACTOR]: [RISKIFIED] Add amount conversion framework to Riskified
4 participants