Skip to content

Commit

Permalink
PAYOSWXP-115: amazon pay: allow B2B countries & fix issue that b2b-cu…
Browse files Browse the repository at this point in the history
…stomers got validated with b2c-countries too
  • Loading branch information
rommelfreddy committed Jan 18, 2024
1 parent 912501f commit bf9f893
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Components/PaymentFilter/DefaultPaymentFilterService.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ private function validateAddress(CustomerAddressEntity|OrderAddressEntity|null $
return;
}

if ($this->allowedCountries !== null && !\in_array($country->getIso(), $this->allowedCountries, true)) {
if ($this->allowedCountries !== null && empty($address->getCompany()) && !\in_array($country->getIso(), $this->allowedCountries, true)) {
throw new PaymentMethodNotAllowedException('Country is not allowed');
}

if ($this->allowedB2bCountries !== null && $address->getCompany() && !\in_array($country->getIso(), $this->allowedB2bCountries, true)) {
if ($this->allowedB2bCountries !== null && !empty($address->getCompany()) && !\in_array($country->getIso(), $this->allowedB2bCountries, true)) {
throw new PaymentMethodNotAllowedException('Country is not allowed for B2B');
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/DependencyInjection/payment_method_filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,18 @@
<argument>HU</argument>
<argument>DK</argument>
</argument>
<argument key="$allowedB2bCountries" type="collection">
<argument>DE</argument>
<argument>FR</argument>
<argument>IT</argument>
<argument>ES</argument>
<argument>LU</argument>
<argument>NL</argument>
<argument>SE</argument>
<argument>PT</argument>
<argument>HU</argument>
<argument>DK</argument>
</argument>
<argument key="$allowedCurrencies" type="collection">
<argument>EUR</argument>
</argument>
Expand Down
10 changes: 10 additions & 0 deletions tests/Components/PaymentFilter/DefaultPaymentFilterServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ public function testB2C(): void
$filterService = new DefaultPaymentFilterService(\stdClass::class, null, null, null);
$result = $filterService->filterPaymentMethods($methodCollection, $filterContext);
static::assertCount(3, $result->getElements(), 'no payment method should be removed, cause no country filter is provided');

$billingAddress->getCountry()->setIso('FR');
$filterService = new DefaultPaymentFilterService(\stdClass::class, [], ['FR'], null);
$result = $filterService->filterPaymentMethods($methodCollection, $filterContext);
static::assertNotContainsOnly(\stdClass::class, $result->getElements(), false, 'payment method stdclass should be removed, because country FR is only allowed for B2B customers and not B2C customers.');
}

public function testB2B(): void
Expand Down Expand Up @@ -158,6 +163,11 @@ public function testB2B(): void
$filterService = new DefaultPaymentFilterService(\stdClass::class, null, null, null);
$result = $filterService->filterPaymentMethods($methodCollection, $filterContext);
static::assertCount(3, $result->getElements(), 'no payment method should be removed, cause no country filter is provided');

$billingAddress->getCountry()->setIso('FR');
$filterService = new DefaultPaymentFilterService(\stdClass::class, ['FR'], [], null);
$result = $filterService->filterPaymentMethods($methodCollection, $filterContext);
static::assertNotContainsOnly(\stdClass::class, $result->getElements(), false, 'payment method stdclass should be removed, because country FR is only allowed for B2C customers and not B2B customers.');
}

private function getMethodCollection(): PaymentMethodCollection
Expand Down

0 comments on commit bf9f893

Please sign in to comment.