-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not show Pagolight payment methods on some circumstances
- Loading branch information
Showing
17 changed files
with
332 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Symfony\Component\DependencyInjection\Loader\Configurator; | ||
|
||
use Webgriffe\SyliusPagolightPlugin\Resolver\PagolightPaymentMethodsResolver; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator) { | ||
$services = $containerConfigurator->services(); | ||
|
||
$services->set('webgriffe_sylius_pagolight.payment_methods_resolver.pagolight', PagolightPaymentMethodsResolver::class) | ||
->args([ | ||
service('sylius.repository.payment_method'), | ||
]) | ||
->tag('sylius.payment_method_resolver', [ | ||
'type' => 'pagolight', | ||
'label' => 'Pagolight', | ||
'priority' => 2, | ||
]) | ||
; | ||
}; |
This file contains 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
File renamed without changes.
This file contains 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 |
---|---|---|
|
@@ -10,7 +10,7 @@ Feature: Paying with Pagolight PRO during checkout | |
And the store ships to "Italy" | ||
And there is a user "[email protected]" identified by "password123" | ||
And the store has a payment method "Pagolight PRO" with a code "PAGOLIGHT_PRO_PAYMENT_METHOD" and Pagolight Payment Checkout gateway | ||
And the store has a product "PHP T-Shirt" priced at "$19.99" | ||
And the store has a product "PHP T-Shirt" priced at "€109.99" | ||
And the store ships everywhere for free | ||
And I am logged in as "[email protected]" | ||
|
||
|
26 changes: 26 additions & 0 deletions
26
features/checkout/paying_for_order/preventing_not_available_payment_method_selection.feature
This file contains 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,26 @@ | ||
@paying_for_order | ||
Feature: Preventing not available payment method selection | ||
In order to pay for my order properly | ||
As a Customer | ||
I want to be prevented from selecting not available payment methods | ||
|
||
Background: | ||
Given the store operates on a single channel in "EUR" currency | ||
And there is a zone "The Rest of the World" containing all other countries | ||
And the store ships to "Italy" | ||
And there is a user "[email protected]" identified by "password123" | ||
And the store has a payment method "Pagolight" with a code "PAGOLIGHT_PAYMENT_METHOD" and Pagolight Payment Checkout gateway | ||
And the store has a payment method "Pagolight PRO" with a code "PAGOLIGHT_PRO_PAYMENT_METHOD" and Pagolight Payment Checkout gateway | ||
And the store has a product "PHP T-Shirt" priced at "€19.99" | ||
And the store ships everywhere for free | ||
And I am logged in as "[email protected]" | ||
|
||
@ui | ||
Scenario: Not being able to select Pagolight PRO payment method if order total is less than 100 EUR | ||
Given I have product "PHP T-Shirt" in the cart | ||
And I am at the checkout addressing step | ||
When I specify the billing address as "Via Franceschini 3", "Casalgrande", "42013", "Italy" for "Mario Rossi" | ||
And I complete the addressing step | ||
And I select "Free" shipping method | ||
And I complete the shipping step | ||
Then I should not be able to select "Pagolight PRO" payment method |
This file contains 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,136 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\Webgriffe\SyliusPagolightPlugin\Resolver; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Sylius\Bundle\PayumBundle\Model\GatewayConfigInterface; | ||
use Sylius\Component\Core\Model\AddressInterface; | ||
use Sylius\Component\Core\Model\ChannelInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Core\Model\PaymentInterface; | ||
use Sylius\Component\Core\Model\PaymentMethodInterface; | ||
use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface; | ||
use Sylius\Component\Payment\Resolver\PaymentMethodsResolverInterface; | ||
use Webgriffe\SyliusPagolightPlugin\Payum\PagolightApi; | ||
use Webgriffe\SyliusPagolightPlugin\Resolver\PagolightPaymentMethodsResolver; | ||
|
||
final class PagolightPaymentMethodsResolverSpec extends ObjectBehavior | ||
{ | ||
public function let( | ||
PaymentMethodRepositoryInterface $paymentMethodRepository, | ||
PaymentInterface $payment, | ||
PaymentMethodInterface $pagolightPaymentMethod, | ||
PaymentMethodInterface $pagolightProPaymentMethod, | ||
PaymentMethodInterface $otherPaymentMethod, | ||
OrderInterface $order, | ||
ChannelInterface $channel, | ||
AddressInterface $billingAddress, | ||
AddressInterface $shippingAddress, | ||
GatewayConfigInterface $pagolightGatewayConfig, | ||
GatewayConfigInterface $pagolightProGatewayConfig, | ||
GatewayConfigInterface $otherGatewayConfig, | ||
): void { | ||
$billingAddress->getCountryCode()->willReturn('IT'); | ||
$shippingAddress->getCountryCode()->willReturn('IT'); | ||
|
||
$order->getChannel()->willReturn($channel); | ||
$order->getBillingAddress()->willReturn($billingAddress); | ||
$order->getShippingAddress()->willReturn($shippingAddress); | ||
$order->getCurrencyCode()->willReturn('EUR'); | ||
$order->getTotal()->willReturn(19000); | ||
|
||
$payment->getOrder()->willReturn($order); | ||
$payment->getMethod()->willReturn($pagolightPaymentMethod); | ||
|
||
$pagolightGatewayConfig->getGatewayName()->willReturn(PagolightApi::PAGOLIGHT_GATEWAY_CODE); | ||
$pagolightProGatewayConfig->getGatewayName()->willReturn(PagolightApi::PAGOLIGHT_PRO_GATEWAY_CODE); | ||
$otherGatewayConfig->getGatewayName()->willReturn('other'); | ||
|
||
$pagolightPaymentMethod->getCode()->willReturn('PAGOLIGHT_PAYMENT_METHOD_CODE'); | ||
$pagolightPaymentMethod->getGatewayConfig()->willReturn($pagolightGatewayConfig); | ||
$pagolightProPaymentMethod->getCode()->willReturn('PAGOLIGHT_PRO_PAYMENT_METHOD_CODE'); | ||
$pagolightProPaymentMethod->getGatewayConfig()->willReturn($pagolightProGatewayConfig); | ||
$otherPaymentMethod->getCode()->willReturn('other_payment_method'); | ||
$otherPaymentMethod->getGatewayConfig()->willReturn($otherGatewayConfig); | ||
|
||
$paymentMethodRepository->findEnabledForChannel($channel)->willReturn([ | ||
$pagolightPaymentMethod, | ||
$pagolightProPaymentMethod, | ||
$otherPaymentMethod, | ||
]); | ||
|
||
$this->beConstructedWith($paymentMethodRepository); | ||
} | ||
|
||
public function it_is_initializable(): void | ||
{ | ||
$this->shouldHaveType(PagolightPaymentMethodsResolver::class); | ||
} | ||
|
||
public function it_implements_payment_methods_resolver_interface(): void | ||
{ | ||
$this->shouldImplement(PaymentMethodsResolverInterface::class); | ||
} | ||
|
||
public function it_resolves_pagolight_payment_methods_if_eligible( | ||
PaymentInterface $payment, | ||
PaymentMethodInterface $pagolightPaymentMethod, | ||
PaymentMethodInterface $pagolightProPaymentMethod, | ||
PaymentMethodInterface $otherPaymentMethod, | ||
): void { | ||
$this->getSupportedMethods($payment)->shouldReturn([ | ||
0 => $pagolightPaymentMethod, | ||
1 => $pagolightProPaymentMethod, | ||
2 => $otherPaymentMethod, | ||
]); | ||
} | ||
|
||
public function it_does_not_resolve_pagolight_pro_payment_method_if_order_amount_is_equal_or_under_100( | ||
PaymentInterface $payment, | ||
PaymentMethodInterface $pagolightPaymentMethod, | ||
PaymentMethodInterface $otherPaymentMethod, | ||
OrderInterface $order, | ||
): void { | ||
$order->getTotal()->willReturn(10000); | ||
$this->getSupportedMethods($payment)->shouldReturn([ | ||
0 => $pagolightPaymentMethod, | ||
2 => $otherPaymentMethod, | ||
]); | ||
|
||
$order->getTotal()->willReturn(9900); | ||
$this->getSupportedMethods($payment)->shouldReturn([ | ||
0 => $pagolightPaymentMethod, | ||
2 => $otherPaymentMethod, | ||
]); | ||
} | ||
|
||
public function it_does_not_resolve_pagolight_payment_methods_if_order_currency_is_not_supported( | ||
PaymentInterface $payment, | ||
PaymentMethodInterface $otherPaymentMethod, | ||
OrderInterface $order, | ||
): void { | ||
$order->getCurrencyCode()->willReturn('USD'); | ||
$this->getSupportedMethods($payment)->shouldReturn([ | ||
2 => $otherPaymentMethod, | ||
]); | ||
} | ||
|
||
public function it_does_not_resolve_pagolight_payment_methods_if_country_code_is_not_supported( | ||
PaymentInterface $payment, | ||
PaymentMethodInterface $otherPaymentMethod, | ||
AddressInterface $billingAddress, | ||
AddressInterface $shippingAddress, | ||
): void { | ||
$billingAddress->getCountryCode()->willReturn('US'); | ||
$this->getSupportedMethods($payment)->shouldReturn([ | ||
2 => $otherPaymentMethod, | ||
]); | ||
|
||
$shippingAddress->getCountryCode()->willReturn('US'); | ||
$this->getSupportedMethods($payment)->shouldReturn([ | ||
2 => $otherPaymentMethod, | ||
]); | ||
} | ||
} |
This file contains 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 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 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 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 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 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
Oops, something went wrong.