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

[ECP-9482] Refactor HeaderDataBuilder and TransactionClient #2769

Closed
wants to merge 14 commits into from

Conversation

SushmitaThakur
Copy link
Contributor

@SushmitaThakur SushmitaThakur commented Oct 8, 2024

Description
This PR -

  • Refactors HeaderDatabuilder and moves buildHeaderData method from Data helper class to the builder.
  • It adds a HeaderDataBuiderInterface that declares all the header constants.
  • Adds a BaseTransaction client class that accommodates common methods used by all transactions clients
  • Updates all the TransactionClients and PaymentDetails class accordingly
  • Updates all the unit tests related to TransactionClients and PaymentDetails
  • Updates the path to header builder in di.xml
  • Updates relevant observers to use correct frontendType constant
  • Synchronises the frontendType value to luma in JS renderers

Tested Scenarios

  • TransactionPayment
  • TransactionCancel
  • TransactionCapture
  • PaymentDetails Call

sushmita added 2 commits October 8, 2024 15:28
…Builder class, Refactor all the usage of HeaderDataBuilder, Remover header builder from helper class and all its usage, Define header constants, Update dependency injection with new builder name, Synchronise the value of `frontendtype` to `luma` in relevant js files
@SushmitaThakur SushmitaThakur reopened this Oct 9, 2024
@SushmitaThakur SushmitaThakur marked this pull request as draft October 9, 2024 09:36
@SushmitaThakur SushmitaThakur changed the title [ECP-9482] Refactor header data builder [ECP-9482] Refactor HeaderDataBuilder Oct 15, 2024
@SushmitaThakur SushmitaThakur changed the title [ECP-9482] Refactor HeaderDataBuilder [ECP-9482] Refactor HeaderDataBuilder and TransactionClient Oct 15, 2024
@SushmitaThakur SushmitaThakur marked this pull request as ready for review October 15, 2024 13:45
Copy link

sonarcloud bot commented Nov 11, 2024

Comment on lines +14 to +15
const ADDITIONAL_DATA_FRONTEND_TYPE_KEY = 'frontendType';
const FRONTEND_TYPE_HEADLESS_VALUE = 'headless';
Copy link
Contributor

Choose a reason for hiding this comment

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

Love this


// If no headers exist, build them using HeaderDataBuilder
if (empty($headers)) {
$headerBuilder = new HeaderDataBuilder($this->adyenHelper);
Copy link
Member

@candemiralp candemiralp Nov 11, 2024

Choose a reason for hiding this comment

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

new notation is not a best practice carried on on Magento 2 as it uses dependency injection pattern. Here we can get rid of this usage via a design change.

However, if you strictly want to use a class' new instance created during the runtime, you can use factory design pattern.

{
$headers = $transferObject->getHeaders();

// If no headers exist, build them using HeaderDataBuilder
Copy link
Member

Choose a reason for hiding this comment

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

If any of the request builders add header H, this method will not be called. Thus, this will result in not adding desired headers. I would recommend adding header data builder to command chain of the transaction clients in di.xml. Let's have a catch-up if this is not clear.

@@ -53,20 +52,20 @@ public function __construct(
public function placeRequest(TransferInterface $transferObject): array
{
$requests = $transferObject->getBody();
$headers = $transferObject->getHeaders();
$clientConfig = $transferObject->getClientConfig();
$requestOptions['headers'] = $this->requestHeaders($transferObject);
Copy link
Member

Choose a reason for hiding this comment

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

Ideally $transferObject->getHeaders() should be sufficient to fetch the headers of the requests. Implementing an abstract class for an abstract method would increase the complexity of the design. Let's discuss this approach.

@@ -71,13 +70,12 @@ public function __construct(
public function placeRequest(TransferInterface $transferObject): array
{
$request = $transferObject->getBody();
$headers = $transferObject->getHeaders();
$clientConfig = $transferObject->getClientConfig();
$requestOptions['headers'] = $this->requestHeaders($transferObject);
Copy link
Member

Choose a reason for hiding this comment

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

Ideally $transferObject->getHeaders() should be sufficient to fetch the headers of the requests. Implementing an abstract class for an abstract method would increase the complexity of the design. Let's discuss this approach.

@@ -63,17 +61,15 @@ public function __construct(
public function placeRequest(TransferInterface $transferObject): array
{
$request = $transferObject->getBody();
$headers = $transferObject->getHeaders();

$requestOptions['headers'] = $this->requestHeaders($transferObject);
Copy link
Member

Choose a reason for hiding this comment

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

Ideally $transferObject->getHeaders() should be sufficient to fetch the headers of the requests. Implementing an abstract class for an abstract method would increase the complexity of the design. Let's discuss this approach.

@@ -55,9 +55,9 @@ public function __construct(
public function placeRequest(TransferInterface $transferObject): array
{
$requests = $transferObject->getBody();
$headers = $transferObject->getHeaders();
$clientConfig = $transferObject->getClientConfig();
$requestOptions['headers'] = $this->requestHeaders($transferObject);
Copy link
Member

Choose a reason for hiding this comment

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

Ideally $transferObject->getHeaders() should be sufficient to fetch the headers of the requests. Implementing an abstract class for an abstract method would increase the complexity of the design. Let's discuss this approach.

return ['headers' => $headers];
}

public function buildRequestHeaders($payment = null): array
Copy link
Member

Choose a reason for hiding this comment

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

What would you think about converting this class into a data builder?

Copy link
Member

Choose a reason for hiding this comment

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

Could you please cover all the lines in the unit tests? It looks like some coverage is missing in this report.

Copy link
Member

Choose a reason for hiding this comment

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

Could you please cover all the lines in the unit tests? It looks like some coverage is missing in this report.

Copy link
Member

Choose a reason for hiding this comment

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

Could you please cover all the lines in the unit tests? It looks like some coverage is missing in this report.

@SushmitaThakur SushmitaThakur marked this pull request as draft December 3, 2024 14:17
@SushmitaThakur SushmitaThakur deleted the ECP-9482 branch December 11, 2024 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants