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): [Shift4] refactor connector authorize request struct #1888

Merged
merged 10 commits into from
Sep 1, 2023

Conversation

srujanchikke
Copy link
Contributor

@srujanchikke srujanchikke commented Aug 7, 2023

Type of Change

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

Description

problem statement : Currently Authorize request to the connector is a common struct and all payment method uses the same struct, So to support multiple payment methods, mandatory field of payment method is made optional. This will have impact on dynamic fields since in our system we never have validation so it is impossible for us to add in the dynamic fields config

Solution : Creating Payment Method or Flow specific Authorize request using enums, So that fields necessary for payment method can be made mandatory with out disturbing the other payment methods. On the longer run we will have the confident of making change in one payment method will not impact the others

Additional Changes

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

Motivation and Context

How did you test it?

Screenshot 2023-08-07 at 8 53 52 PM

Checklist

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

@srujanchikke srujanchikke added A-connector-integration Area: Connector integration C-refactor Category: Refactor R-waiting-on-L1 Review: Waiting on L1 reviewer labels Aug 7, 2023
@srujanchikke srujanchikke self-assigned this Aug 7, 2023
@srujanchikke srujanchikke requested a review from a team as a code owner August 7, 2023 15:30
@srujanchikke srujanchikke added this to the August 2023 Milestone milestone Aug 7, 2023
prasunna09
prasunna09 previously approved these changes Aug 9, 2023
@prasunna09 prasunna09 added R-waiting-on-L2 Review: Waiting on L2 reviewer R-L1-completed Review: L1 Review completed and removed R-waiting-on-L1 Review: Waiting on L1 reviewer labels Aug 9, 2023
@srujanchikke srujanchikke added the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Aug 9, 2023
description: item.description.clone(),
}))
};
Ok(Shift4PaymentsRequest {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we moved the payment method data into enum's, there is no need to return entire Shift4PaymentsRequest in get_card_payment_request & get_bank_redirect_request request. We should return only Shift4PaymentMethod from these method.
In fact we should move from get_card_payment_request & get_bank_redirect_request methods to try_from implementation, since these are type conversion.

}

fn get_bank_redirect_request<T>(
item: &types::RouterData<T, types::PaymentsAuthorizeData, types::PaymentsResponseData>,
redirect_data: &payments::BankRedirectData,
) -> Result<Shift4PaymentsRequest, Error> {
let submit_for_settlement = item.request.is_auto_capture()?;
let captured = item.request.is_auto_capture()?;
Copy link
Contributor

Choose a reason for hiding this comment

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

submit_for_settlement gives more meaning to the variable rather than captured. Please keep the existing name itself

@@ -242,20 +249,20 @@ fn get_flow<T>(

fn get_billing<T>(
item: &types::RouterData<T, types::PaymentsAuthorizeData, types::PaymentsResponseData>,
) -> Result<Option<Billing>, Error> {
) -> Result<Billing, Error> {
Copy link
Contributor

Choose a reason for hiding this comment

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

implement try_from for this conversion instead of get_billing method

method_type,
billing,
});
};
let flow = get_flow(item);
Copy link
Contributor

Choose a reason for hiding this comment

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

implement from instead of get_flow method

@@ -157,66 +169,61 @@ fn get_card_payment_request<T>(
item: &types::RouterData<T, types::PaymentsAuthorizeData, types::PaymentsResponseData>,
card: &api_models::payments::Card,
) -> Result<Shift4PaymentsRequest, Error> {
let submit_for_settlement = item.request.is_auto_capture()?;
let captured = item.request.is_auto_capture()?;
Copy link
Contributor

Choose a reason for hiding this comment

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

submit_for_settlement gives more meaning to the variable rather than captured. Please keep the existing name itself

@ArjunKarthik ArjunKarthik added S-waiting-on-author Status: This PR is incomplete or needs to address review comments and removed R-waiting-on-L2 Review: Waiting on L2 reviewer labels Aug 14, 2023
Comment on lines 183 to 186
item: (
&types::RouterData<T, types::PaymentsAuthorizeData, types::PaymentsResponseData>,
&api_models::payments::Card,
),
Copy link
Contributor

Choose a reason for hiding this comment

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

(item, card): (
&types::RouterData<T, types::PaymentsAuthorizeData, types::PaymentsResponseData>,
&api_models::payments::Card,
),

Comment on lines 224 to 227
items: (
&types::RouterData<T, types::PaymentsAuthorizeData, types::PaymentsResponseData>,
&payments::BankRedirectData,
),
Copy link
Contributor

Choose a reason for hiding this comment

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

(item, bank_redirect_data): (
&types::RouterData<T, types::PaymentsAuthorizeData, types::PaymentsResponseData>,
&payments::BankRedirectData,
)

| payments::PaymentMethodData::Upi(_)
| payments::PaymentMethodData::Voucher(_)
| payments::PaymentMethodData::GiftCard(_) => {
Err(errors::ConnectorError::NotImplemented(
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's have separate try_from for each payment_method_data and inside that throw NotImplemented for unimplemented PM's and throw NotSupported for PM's which is not supported by connector

@ArjunKarthik ArjunKarthik removed the S-waiting-on-author Status: This PR is incomplete or needs to address review comments label Sep 1, 2023
ArjunKarthik
ArjunKarthik previously approved these changes Sep 1, 2023
@ArjunKarthik ArjunKarthik added S-ready-for-merge and removed S-waiting-on-review Status: This PR has been implemented and needs to be reviewed labels Sep 1, 2023
@ArjunKarthik ArjunKarthik added this pull request to the merge queue Sep 1, 2023
Merged via the queue into main with commit e44c32d Sep 1, 2023
9 of 12 checks passed
@ArjunKarthik ArjunKarthik deleted the refactor_shift4 branch September 1, 2023 14:20
@SanchithHegde SanchithHegde removed S-ready-for-merge R-L1-completed Review: L1 Review completed ageing >2weeks Created > 2 weeks labels Sep 4, 2023
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
Projects
No open projects
Status: Merged
Development

Successfully merging this pull request may close these issues.

5 participants