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

Support only for offline payment methods #86

Conversation

Zales0123
Copy link
Contributor

See PS in #85 description

@Zales0123 Zales0123 added the Enhancement Minor issues and PRs improving the current solutions (optimizations, typo fixes, etc.). label Oct 2, 2018
@Zales0123 Zales0123 force-pushed the support-only-for-offline-payment-methods branch from f7d2fba to 0b44857 Compare October 2, 2018 13:25
'product_name' => $this->productName,
'total' => $this->total,
'taxes_total' => $this->taxesTotal,
]);

return ($serialized !== false) ? $serialized : '';
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should throw an exception instead of silently returning an empty string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed 👍

}
}

return $paymentMethods;
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a big one, but you can get rid of that unset and phpdoc by using array_filter:

return array_filter(
  $this->paymentMethodRepository->findEnabledForChannel($channel),
  function (PaymentMethodInterface $paymentMethod): bool {
    Assert::notNull($paymentMethod->getGatewayConfig());

    return $paymentMethod->getGatewayConfig()->getFactoryName() === 'offline';
  }
);

Copy link
Contributor Author

@Zales0123 Zales0123 Oct 3, 2018

Choose a reason for hiding this comment

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

Good idea 👍

@Zales0123 Zales0123 force-pushed the support-only-for-offline-payment-methods branch from e1aca17 to 309420d Compare October 3, 2018 20:07
@@ -46,6 +47,7 @@ public function __invoke(Request $request): Response

$this->session->getFlashBag()->add('success', 'sylius_refund.units_successfully_refunded');
} catch (CommandDispatchException $exception) {
Assert::notNull($exception->getPrevious());
Copy link
Contributor

@bartoszpietrzak1994 bartoszpietrzak1994 Oct 12, 2018

Choose a reason for hiding this comment

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

Using Assert::notNull() may result in throwing unhandled InvalidArgumentException - what about simple and more user friendly solution:

if (null === $exception->getPrevious()) {
    $this->session->getFlashBag()->add('error', 'sylius.ui.unexpected_error_occurred');
}

wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The thing is, there will always be a previous exception, as it's done automatically and silencing it could make more harm than good 😄 I'd leave it as it is (without it PHPStan is not passing)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok then 👍

@Zales0123 Zales0123 force-pushed the support-only-for-offline-payment-methods branch from 309420d to a97c5f2 Compare October 12, 2018 10:39
@Zales0123 Zales0123 requested a review from a team as a code owner October 12, 2018 10:39
@bartoszpietrzak1994 bartoszpietrzak1994 merged commit e23d0bb into Sylius:master Oct 12, 2018
@Zales0123 Zales0123 deleted the support-only-for-offline-payment-methods branch October 12, 2018 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Minor issues and PRs improving the current solutions (optimizations, typo fixes, etc.).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants