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

[PAYSHIP-3135] Refacto CapturePayPalOrderCommandHandler #1299

Open
wants to merge 5 commits into
base: prestashop/8.x
Choose a base branch
from

Conversation

CorentinFlament
Copy link

No description provided.

@CorentinFlament CorentinFlament marked this pull request as draft December 6, 2024 08:34
@@ -0,0 +1,31 @@
<?php

Copy link
Contributor

Choose a reason for hiding this comment

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

You need to add the license header (stuff like * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 ...) 😉

Copy link
Contributor

Choose a reason for hiding this comment

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

There a composer script set-license-header ;)

@matks
Copy link
Contributor

matks commented Dec 9, 2024

  • as discussed between @CorentinFlament and @Matt75 -> some refactoring to keep things inside the handler
  • try to follow naming convention for PR title ;)
  • I dont think it's draft anymore ;)

@CorentinFlament CorentinFlament changed the title [feat/3135] Refacto CapturePayPalOrderCommandHandler [PAYSHIP-3135] Refacto CapturePayPalOrderCommandHandler Dec 9, 2024

class CapturePayloadBuilder
{
private $payPalOrderRepository;
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
private $payPalOrderRepository;
private PayPalOrderRepository $payPalOrderRepository;

$this->payPalOrderRepository = $payPalOrderRepository;
}

public function buildPayload($mode, $orderId, $merchantId)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add phpdoc and type hinting, please ?


class CaptureOrderPayloadDTO
{
private $mode;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add types ?

private $payee;
private $vault = false;

private function __construct($mode, $orderId, $payee, $vault)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add type hinting ?

$this->vault = $vault;
}

public static function create($mode, $orderId, $merchantId, $vault)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add phpdoc and type hinting ?

return $paymentToken;
}

private function processTheCapture($orderPayPal)
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
private function processTheCapture($orderPayPal)
private function processCapture($orderPayPal)

}
}

return $this->processTheCapture($orderPayPal);
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
return $this->processTheCapture($orderPayPal);
return $this->processCapture($orderPayPal);


class CaptureOrderDTO
{
private $toto;
Copy link
Contributor

Choose a reason for hiding this comment

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

😄 ?

/**
* @var string
*/
private $environment;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it the paypal mode ? SANDBOX or LIVE ? If it's the case, it's better call it $mode

@matks matks marked this pull request as ready for review December 18, 2024 09:17
@matks
Copy link
Contributor

matks commented Dec 18, 2024

Missing before OK:

  • unit tests
  • code review


if ($orderPayPal['status'] === PayPalOrderStatus::COMPLETED) {
$this->logger->info('');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Empty log


if (isset($orderPayPal['payment_source'][$capturePayPalOrderCommand->getFundingSource()]['attributes']['vault'])) {
$vault = $orderPayPal['payment_source'][$capturePayPalOrderCommand->getFundingSource()]['attributes']['vault'];
$vault = $this->savePrestaShopPayPalCustomerRelationship($vault);
Copy link
Collaborator

Choose a reason for hiding this comment

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

To me this part of overwriting $vault variable feels a bit off. Why not wrap it in try-catch?

} catch (\Exception $exception) {
$this->logger->error(sprintf('An error occurs during process : %s', $exception->getMessage()));
return [];
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you decide to keep catch clauses here, then you don't need a return at each one. Just one at the end of the function

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.

5 participants