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

NTR: PIHPS-205 - add new payment method blik #701

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/build-plugin/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ runs:
- name: Start Docker
shell: bash
run: |
docker run --rm --name shop --env NODE_VERSION=18 --env PHP_VERSION=8.1 -d dockware/dev:6.5.8.2
docker run --rm --name shop --env NODE_VERSION=18 --env PHP_VERSION=8.1 -d dockware/dev:6.5.8.4
sleep 20
docker logs shop

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_pipe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ jobs:
fail-fast: false
matrix:
include:
- shopware: '6.5.8.2'
- shopware: '6.5.8.4'
php: '8.2'
- shopware: '6.5.6.1'
php: '8.2'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly_pipe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ jobs:
fail-fast: false
matrix:
include:
- shopware: '6.5.8.2'
- shopware: '6.5.8.4'
php: '8.2'
- shopware: '6.5.6.1'
php: '8.2'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr_pipe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ jobs:
fail-fast: false
matrix:
include:
- shopware: '6.5.8.2'
- shopware: '6.5.8.4'
php: '8.2'
- shopware: '6.5.5.2'
php: '8.2'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Kiener\MolliePayments\Components\MollieLimits\Service;
namespace Kiener\MolliePayments\Components\MollieAvailability\Service;

use Exception;
use Kiener\MolliePayments\Exception\MissingCartServiceException;
Expand All @@ -22,7 +22,7 @@
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
use Symfony\Component\HttpFoundation\RequestStack;

class MollieLimitsRemover extends PaymentMethodRemover
class MolliePaymentMethodAvailabilityRemover extends PaymentMethodRemover
{
/**
* @var ActivePaymentMethodsProviderInterface
Expand Down Expand Up @@ -65,6 +65,8 @@ public function removePaymentMethods(PaymentMethodRouteResponse $originalData, S
if (!$this->isAllowedRoute()) {
return $originalData;
}
$billingAddress = null;
$countryIsoCode = null;

if ($this->isCartRoute()) {
try {
Expand All @@ -77,8 +79,13 @@ public function removePaymentMethods(PaymentMethodRouteResponse $originalData, S
}

$price = $cart->getPrice()->getTotalPrice();
$customer = $context->getCustomer();
if ($customer !== null) {
$billingAddress = $customer->getDefaultBillingAddress();
}
}


if ($this->isOrderRoute()) {
try {
$order = $this->getOrder($context->getContext());
Expand All @@ -90,15 +97,27 @@ public function removePaymentMethods(PaymentMethodRouteResponse $originalData, S
}

$price = $order->getAmountTotal();

$billingAddress = $order->getBillingAddress();
}

if (!isset($price)) {
return $originalData;
}

if ($billingAddress !== null) {
$billingCountry = $billingAddress->getCountry();
if ($billingCountry !== null) {
$countryIsoCode = $billingCountry->getIso();
}
}



$availableMolliePayments = $this->paymentMethodsProvider->getActivePaymentMethodsForAmount(
$price,
$context->getCurrency()->getIsoCode(),
(string) $countryIsoCode,
[
$context->getSalesChannel()->getId(),
]
Expand Down
32 changes: 32 additions & 0 deletions src/Handler/Method/BlikPayment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Kiener\MolliePayments\Handler\Method;

use Kiener\MolliePayments\Handler\PaymentHandler;
use Mollie\Api\Types\PaymentMethod;
use Shopware\Core\Checkout\Customer\CustomerEntity;
use Shopware\Core\Checkout\Order\OrderEntity;
use Shopware\Core\System\Locale\LocaleEntity;
use Shopware\Core\System\SalesChannel\SalesChannelContext;

class BlikPayment extends PaymentHandler
{
public const PAYMENT_METHOD_NAME = 'blik';
public const PAYMENT_METHOD_DESCRIPTION = 'Blik';

/** @var string */
protected $paymentMethod = self::PAYMENT_METHOD_NAME;


/**
* @param array<mixed> $orderData
* @param OrderEntity $orderEntity
* @param SalesChannelContext $salesChannelContext
* @param CustomerEntity $customer
* @return array<mixed>
*/
public function processPaymentMethodSpecificParameters(array $orderData, OrderEntity $orderEntity, SalesChannelContext $salesChannelContext, CustomerEntity $customer): array
{
return $orderData;
}
}
2 changes: 1 addition & 1 deletion src/Resources/app/administration/src/snippet/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"failed": "Die Zahlungsarten konnten nicht aktualisiert werden."
},
"mollieLimits": {
"link": "Öffne Mollie Zahlungs Limits"
"link": "Zeige Mollie-Verfügbarkeitregeln für Zahlungsmethoden"
}
},
"rounding": {
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/app/administration/src/snippet/en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"failed": "The payment methods couldn't be updated."
},
"mollieLimits": {
"link": "Open Mollie Payment Limits"
"link": "Show mollie availability rules for payment methods"
}
},
"rounding": {
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/app/administration/src/snippet/nl-NL.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"failed": "De betaalmethoden konden niet worden geupdated."
},
"mollieLimits": {
"link": "Open betalingslimieten van Mollie"
"link": "Toon Mollie-beschikbaarheidsregels voor betaalmethoden"
}
},
"rounding": {
Expand Down
12 changes: 6 additions & 6 deletions src/Resources/config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@
<input-field type="bool">
<name>useMolliePaymentMethodLimits</name>
<defaultValue>false</defaultValue>
<label>Use Mollie Payment Method Limits</label>
<label lang="de-DE">Mollies Limits für Zahlungsarten verwenden</label>
<label lang="nl-NL">Mollie's limieten voor betaalmethoden gebruiken</label>
<helpText>Automatically hides payment methods in the checkout based on the limits of Mollie. For instance, if you can only accept credit card payments up to 500 euros, the checkout for a cart of 600 euros will not display credit card as a payment method.</helpText>
<helpText lang="de-DE">Blendet automatisch Zahlungsart im Checkout basierend auf den Limits von Mollie aus. Wenn Sie beispielsweise nur Kreditkartenzahlungen bis zu 500 Euro akzeptieren können, wird an der Kasse für einen Warenkorb von 600 Euro keine Kreditkarte als Zahlungsarte angezeigt.</helpText>
<helpText lang="nl-NL">Verbergt automatisch betaalmethoden in de checkout op basis van Mollie's limieten. Als je bijvoorbeeld alleen creditcardbetalingen tot 500 euro kan accepteren, wordt bij een winkelwagen van 600 euro geen creditcard weergegeven als betaalmethode bij het afrekenen.</helpText>
<label>Use Mollie's availability rules for payment methods</label>
<label lang="de-DE">Mollies Verfügbarkeitsregeln für Zahlungsarten verwenden</label>
<label lang="nl-NL">Gebruik de beschikbaarheidsregels van Mollie voor betaalmethoden</label>
<helpText>Automatically hides payment methods in the checkout based on the availability rules for payment methods. Only active payment methods from your mollie dashboard will be shown. If the payment method has a cart limit, currency restriction or billing address restriction, it will be hidden during checkout.</helpText>
<helpText lang="de-DE">Blendet automatisch Zahlungsart im Checkout basierend auf Verfügbarkeitsregeln von Mollie. Es werden nur die aktiven Zahlungsarten aus dem Mollie Dashboard angezeigt. Wenn die Zahlungsart eine Einschränkung auf den Warenkorbwert, Währung oder Rechnungsadresse hat, wird diese auch ausgeblendet.</helpText>
<helpText lang="nl-NL">Automatische betalingsmethode wordt verborgen tijdens het afrekenen op basis van beschikbaarheidsregels van Mollie. Alleen actieve betalingsmethoden uit het Mollie-dashboard worden weergegeven. Als de betalingsmethode beperkingen heeft op de winkelwagenwaarde, valuta of factuuradres, wordt deze ook verborgen.</helpText>
</input-field>
<input-field type="text">
<name>formatOrderNumber</name>
Expand Down
8 changes: 8 additions & 0 deletions src/Resources/config/services/handlers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,13 @@
<tag name="shopware.payment.method.async"/>
</service>

<!-- Blick PaymentHandler -->
<service id="Kiener\MolliePayments\Handler\Method\BlikPayment">
<argument type="service" id="mollie_payments.logger"/>
<argument type="service" id="service_container"/>
<tag name="shopware.payment.method.async"/>
</service>


</services>
</container>
3 changes: 2 additions & 1 deletion src/Resources/config/services/payment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
<tag name="mollie_payments.payment_method.remover.sw64"/>
</service>

<service id="Kiener\MolliePayments\Components\MollieLimits\Service\MollieLimitsRemover">

<service id="Kiener\MolliePayments\Components\MollieAvailability\Service\MolliePaymentMethodAvailabilityRemover">
<argument type="service" id="service_container"/>
<argument type="service" id="request_stack"/>
<argument type="service" id="Kiener\MolliePayments\Service\OrderService"/>
Expand Down
9 changes: 7 additions & 2 deletions src/Service/Payment/Provider/ActivePaymentMethodsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ public function __construct(MollieApiFactory $mollieApiFactory, MollieOrderPrice
*
* @param float $price
* @param string $currency
* @param string $billingCountryCode
* @param array<mixed> $salesChannelIDs
* @return Method[]
*/
public function getActivePaymentMethodsForAmount(float $price, string $currency, array $salesChannelIDs): array
public function getActivePaymentMethodsForAmount(float $price, string $currency, string $billingCountryCode, array $salesChannelIDs): array
{
if ($price < 0.01) {
return [];
Expand All @@ -61,9 +62,13 @@ public function getActivePaymentMethodsForAmount(float $price, string $currency,
'amount' => [
'value' => $this->priceFormatter->formatValue($price),
'currency' => strtoupper($currency),
]
],
];

if (mb_strlen($billingCountryCode) > 0) {
$params['billingCountry'] = $billingCountryCode;
}

return $this->getActivePaymentMethods($params, $salesChannelIDs);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
interface ActivePaymentMethodsProviderInterface
{
/**
* @param float $price
* @param string $currency
* @param float $price
* @param string $currency
* @param string $billingCountryCode
* @param array<string> $salesChannelIDs
* @return array<Method>
*/
public function getActivePaymentMethodsForAmount(float $price, string $currency, array $salesChannelIDs): array;
public function getActivePaymentMethodsForAmount(float $price, string $currency, string $billingCountryCode, array $salesChannelIDs): array;
}
2 changes: 2 additions & 0 deletions src/Service/PaymentMethodService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Kiener\MolliePayments\Handler\Method\BankTransferPayment;
use Kiener\MolliePayments\Handler\Method\BelfiusPayment;
use Kiener\MolliePayments\Handler\Method\BilliePayment;
use Kiener\MolliePayments\Handler\Method\BlikPayment;
use Kiener\MolliePayments\Handler\Method\CreditCardPayment;
use Kiener\MolliePayments\Handler\Method\EpsPayment;
use Kiener\MolliePayments\Handler\Method\GiftCardPayment;
Expand Down Expand Up @@ -417,6 +418,7 @@ public function getPaymentHandlers(): array
In3Payment::class,
PosPayment::class,
TwintPayment::class,
BlikPayment::class,
// IngHomePayPayment::class, // not allowed anymore
// DirectDebitPayment::class, // only allowed when updating subsriptions, aka => not allowed anymore
];
Expand Down
43 changes: 43 additions & 0 deletions tests/Cypress/cypress/e2e/storefront/payment-methods/blik.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import Devices from "Services/utils/Devices";
import Session from "Services/utils/Session"
// ------------------------------------------------------
import PaymentAction from "Actions/storefront/checkout/PaymentAction";
import DummyBasketScenario from "Scenarios/DummyBasketScenario";
// ------------------------------------------------------


const devices = new Devices();
const session = new Session();

const paymentAction = new PaymentAction();
const scenarioDummyBasket = new DummyBasketScenario(1);

const device = devices.getFirstDevice();


describe('Blik payment method', () => {

context(devices.getDescription(device), () => {

before(function () {
devices.setDevice(device);
})

beforeEach(() => {
session.resetBrowserSession();
devices.setDevice(device);
});

it('Blik is existing in checkout', () => {

scenarioDummyBasket.execute();

paymentAction.switchPaymentMethod('Blik');

// payment would only work using currency CHF which cannot be done at the moment
})

})

})

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php declare(strict_types=1);

namespace MolliePayments\Tests\Service\MollieApi\Builder\Payments;

use DateTime;
use DateTimeZone;
use Faker\Extension\Container;
use Kiener\MolliePayments\Handler\Method\BlikPayment;
use Kiener\MolliePayments\Handler\Method\KlarnaPayLaterPayment;
use Kiener\MolliePayments\Handler\Method\TwintPayment;
use Kiener\MolliePayments\Service\MollieApi\Builder\MollieOrderPriceBuilder;
use Mollie\Api\Types\PaymentMethod;
use MolliePayments\Tests\Fakes\FakeContainer;
use MolliePayments\Tests\Service\MollieApi\Builder\AbstractMollieOrderBuilder;
use Shopware\Core\Checkout\Cart\Price\Struct\CartPrice;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\System\Currency\CurrencyEntity;

class BlikOrderBuilderTest extends AbstractMollieOrderBuilder
{
public function testOrderBuild(): void
{
$redirectWebhookUrl = 'https://foo';
$this->router->method('generate')->willReturn($redirectWebhookUrl);


$this->paymentHandler = new BlikPayment(
$this->loggerService,
new FakeContainer()
);

$transactionId = Uuid::randomHex();
$amountTotal = 27.0;
$taxStatus = CartPrice::TAX_STATE_GROSS;
$currencyISO = 'EUR';

$currency = new CurrencyEntity();
$currency->setId(Uuid::randomHex());
$currency->setIsoCode($currencyISO);

$orderNumber = 'foo number';
$lineItems = $this->getDummyLineItems();

$order = $this->getOrderEntity($amountTotal, $taxStatus, $currencyISO, $lineItems, $orderNumber);

$actual = $this->builder->buildOrderPayload($order, $transactionId, $this->paymentHandler::PAYMENT_METHOD_NAME, $this->salesChannelContext, $this->paymentHandler, []);

$expectedOrderLifeTime = (new DateTime())->setTimezone(new DateTimeZone('UTC'))
->modify(sprintf('+%d day', $this->expiresAt))
->format('Y-m-d');

$expected = [
'amount' => (new MollieOrderPriceBuilder())->build($amountTotal, $currencyISO),
'locale' => $this->localeCode,
'method' => $this->paymentHandler::PAYMENT_METHOD_NAME,
'orderNumber' => $orderNumber,
'payment' => ['webhookUrl' => $redirectWebhookUrl],
'redirectUrl' => $redirectWebhookUrl,
'webhookUrl' => $redirectWebhookUrl,
'lines' => $this->getExpectedLineItems($taxStatus, $lineItems, $currency),
'billingAddress' => $this->getExpectedTestAddress($this->address, $this->email),
'shippingAddress' => $this->getExpectedTestAddress($this->address, $this->email),
'expiresAt' => $expectedOrderLifeTime
];

self::assertSame($expected, $actual);
}
}
Loading
Loading