-
-
Notifications
You must be signed in to change notification settings - Fork 73
Support only for offline payment methods #86
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
Merged
bartoszpietrzak1994
merged 4 commits into
Sylius:master
from
Zales0123:support-only-for-offline-payment-methods
Oct 12, 2018
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace spec\Sylius\RefundPlugin\Provider; | ||
|
|
||
| use Payum\Core\Model\GatewayConfigInterface; | ||
| use PhpSpec\ObjectBehavior; | ||
| use Sylius\Component\Core\Model\ChannelInterface; | ||
| use Sylius\Component\Core\Model\PaymentMethodInterface; | ||
| use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface; | ||
| use Sylius\RefundPlugin\Provider\RefundPaymentMethodsProviderInterface; | ||
|
|
||
| final class OfflineRefundPaymentMethodsProviderSpec extends ObjectBehavior | ||
| { | ||
| function let(PaymentMethodRepositoryInterface $paymentMethodRepository): void | ||
| { | ||
| $this->beConstructedWith($paymentMethodRepository); | ||
| } | ||
|
|
||
| function it_implements_refund_payment_methods_provider_interface(): void | ||
| { | ||
| $this->shouldImplement(RefundPaymentMethodsProviderInterface::class); | ||
| } | ||
|
|
||
| function it_provides_only_offline_payment_methods( | ||
| PaymentMethodRepositoryInterface $paymentMethodRepository, | ||
| ChannelInterface $channel, | ||
| PaymentMethodInterface $offlinePaymentMethod, | ||
| PaymentMethodInterface $payPalPaymentMethod, | ||
| PaymentMethodInterface $stripePaymentMethod, | ||
| GatewayConfigInterface $offlineGatewayConfig, | ||
| GatewayConfigInterface $payPalGatewayConfig, | ||
| GatewayConfigInterface $stripeGatewayConfig | ||
| ): void { | ||
| $paymentMethodRepository->findEnabledForChannel($channel)->willReturn([ | ||
| $offlinePaymentMethod, | ||
| $payPalPaymentMethod, | ||
| $stripePaymentMethod, | ||
| ]); | ||
|
|
||
| $offlinePaymentMethod->getGatewayConfig()->willReturn($offlineGatewayConfig); | ||
| $offlineGatewayConfig->getFactoryName()->willReturn('offline'); | ||
|
|
||
| $payPalPaymentMethod->getGatewayConfig()->willReturn($payPalGatewayConfig); | ||
| $payPalGatewayConfig->getFactoryName()->willReturn('paypal'); | ||
|
|
||
| $stripePaymentMethod->getGatewayConfig()->willReturn($stripeGatewayConfig); | ||
| $stripeGatewayConfig->getFactoryName()->willReturn('stripe'); | ||
|
|
||
| $this->findForChannel($channel)->shouldReturn([$offlinePaymentMethod]); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Sylius\RefundPlugin\Provider; | ||
|
|
||
| use Sylius\Component\Core\Model\ChannelInterface; | ||
| use Sylius\Component\Core\Model\PaymentMethodInterface; | ||
| use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface; | ||
| use Webmozart\Assert\Assert; | ||
|
|
||
| final class OfflineRefundPaymentMethodsProvider implements RefundPaymentMethodsProviderInterface | ||
| { | ||
| /** @var PaymentMethodRepositoryInterface */ | ||
| private $paymentMethodRepository; | ||
|
|
||
| public function __construct(PaymentMethodRepositoryInterface $paymentMethodRepository) | ||
| { | ||
| $this->paymentMethodRepository = $paymentMethodRepository; | ||
| } | ||
|
|
||
| public function findForChannel(ChannelInterface $channel): array | ||
| { | ||
| return array_filter( | ||
| $this->paymentMethodRepository->findEnabledForChannel($channel), | ||
| function (PaymentMethodInterface $paymentMethod): bool { | ||
| Assert::notNull($paymentMethod->getGatewayConfig()); | ||
|
|
||
| return $paymentMethod->getGatewayConfig()->getFactoryName() === 'offline'; | ||
| } | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Sylius\RefundPlugin\Provider; | ||
|
|
||
| use Sylius\Component\Core\Model\ChannelInterface; | ||
| use Sylius\Component\Core\Model\PaymentMethodInterface; | ||
|
|
||
| interface RefundPaymentMethodsProviderInterface | ||
| { | ||
| /** @return array|PaymentMethodInterface[] */ | ||
| public function findForChannel(ChannelInterface $channel): array; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Using Assert::notNull() may result in throwing unhandled InvalidArgumentException - what about simple and more user friendly solution:
wdyt?
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.
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)
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.
Ok then 👍