-
Notifications
You must be signed in to change notification settings - Fork 211
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
base: main
Are you sure you want to change the base?
Conversation
…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
Gateway/Request/Header/ExternalPlatformHeaderDataBuilderInterface.php
Outdated
Show resolved
Hide resolved
Gateway/Request/Header/ExternalPlatformHeaderDataBuilderInterface.php
Outdated
Show resolved
Hide resolved
…ts and tests, update header data builder tests, remove defaulting frontend type to headless
Quality Gate passedIssues Measures |
const ADDITIONAL_DATA_FRONTEND_TYPE_KEY = 'frontendType'; | ||
const FRONTEND_TYPE_HEADLESS_VALUE = 'headless'; |
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.
Love this
|
||
// If no headers exist, build them using HeaderDataBuilder | ||
if (empty($headers)) { | ||
$headerBuilder = new HeaderDataBuilder($this->adyenHelper); |
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.
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 |
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.
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); |
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.
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); |
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.
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); |
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.
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); |
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.
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 |
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.
What would you think about converting this class into a data builder?
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.
Could you please cover all the lines in the unit tests? It looks like some coverage is missing in this report.
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.
Could you please cover all the lines in the unit tests? It looks like some coverage is missing in this report.
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.
Could you please cover all the lines in the unit tests? It looks like some coverage is missing in this report.
Description
This PR -
HeaderDatabuilder
and movesbuildHeaderData
method fromData
helper class to the builder.HeaderDataBuiderInterface
that declares all the header constants.BaseTransaction
client class that accommodates common methods used by all transactions clientsTransactionClients
andPaymentDetails
class accordinglyTransactionClients
andPaymentDetails
di.xml
frontendType
constantfrontendType
value toluma
in JS renderersTested Scenarios