Skip to content

Commit

Permalink
PISHPS-407: add mbway payment
Browse files Browse the repository at this point in the history
  • Loading branch information
Thilo Lindner committed Jan 23, 2025
1 parent 24d6636 commit 18aebce
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Handler/Method/MbWayPayment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php declare(strict_types=1);

namespace Kiener\MolliePayments\Handler\Method;

use Kiener\MolliePayments\Handler\PaymentHandler;

class MbWayPayment extends PaymentHandler
{
public const PAYMENT_METHOD_NAME = "mbway";
public const PAYMENT_METHOD_DESCRIPTION = 'MB Way';

/** @var string */
protected $paymentMethod = self::PAYMENT_METHOD_NAME;
}
7 changes: 7 additions & 0 deletions src/Resources/config/services/handlers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@
<tag name="shopware.payment.method.async"/>
</service>

<!-- MB Way PaymentHandler -->
<service id="Kiener\MolliePayments\Handler\Method\MbWayPayment">
<argument type="service" id="monolog.logger.mollie"/>
<argument type="service" id="service_container"/>
<tag name="shopware.payment.method.async"/>
</service>



</services>
Expand Down
2 changes: 2 additions & 0 deletions src/Service/PaymentMethodService.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Kiener\MolliePayments\Handler\Method\KlarnaPayLaterPayment;
use Kiener\MolliePayments\Handler\Method\KlarnaPayNowPayment;
use Kiener\MolliePayments\Handler\Method\KlarnaSliceItPayment;
use Kiener\MolliePayments\Handler\Method\MbWayPayment;
use Kiener\MolliePayments\Handler\Method\MyBankPayment;
use Kiener\MolliePayments\Handler\Method\PayByBankPayment;
use Kiener\MolliePayments\Handler\Method\PayconiqPayment;
Expand Down Expand Up @@ -461,6 +462,7 @@ public function getPaymentHandlers(): array
RivertyPayment::class,
SatispayPayment::class,
PayByBankPayment::class,
MbWayPayment::class
// IngHomePayPayment::class, // not allowed anymore
// DirectDebitPayment::class, // only allowed when updating subsriptions, aka => not allowed anymore
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const payments = [
{caseId: 'C3713510', key: 'riverty', name: 'Riverty', sanity: false},
{caseId: 'C3713512', key: 'satispay', name: 'Satispay', sanity: false},
{caseId: 'C4212005', key: 'paybybank', name: 'Pay by Bank', sanity: false},
{caseId: '', key: 'mbway', name: 'MB Way', sanity: false},
// unfortunately address and product prices need to match, so we cannot do in3 automatically for now
// {caseId: '', key: 'in3', name: 'in3'},
];
Expand Down
44 changes: 44 additions & 0 deletions tests/Cypress/cypress/e2e/storefront/payment-methods/mbway.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Devices from "Services/utils/Devices";
import Session from "Services/utils/Session"
// ------------------------------------------------------
import PaymentAction from "Actions/storefront/checkout/PaymentAction";
import DummyBasketScenario from "Scenarios/DummyBasketScenario";
import CheckoutAction from "Actions/storefront/checkout/CheckoutAction";
// ------------------------------------------------------


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

const paymentAction = new PaymentAction();
const scenarioDummyBasket = new DummyBasketScenario(1);
const checkout = new CheckoutAction();
const device = devices.getFirstDevice();


describe('MW Way', () => {

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

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

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

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

scenarioDummyBasket.execute();
checkout.changeBillingCountry('Portugal');
paymentAction.switchPaymentMethod('mbway');

// 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,63 @@
<?php declare(strict_types=1);

namespace PHPUnit\Service\MollieApi\Builder\Payments;

use DateTime;
use DateTimeZone;
use Kiener\MolliePayments\Handler\Method\MbWayPayment;
use Kiener\MolliePayments\Service\MollieApi\Builder\MollieOrderPriceBuilder;
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 MbWayOrderBuilderTest extends AbstractMollieOrderBuilder
{
public function testOrderBuild(): void
{
$redirectWebhookUrl = 'https://foo';
$this->router->method('generate')->willReturn($redirectWebhookUrl);

$this->paymentHandler = new MbWayPayment(
$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);
}
}
2 changes: 2 additions & 0 deletions tests/PHPUnit/Service/PaymentMethodServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Kiener\MolliePayments\Handler\Method\KlarnaPayLaterPayment;
use Kiener\MolliePayments\Handler\Method\KlarnaPayNowPayment;
use Kiener\MolliePayments\Handler\Method\KlarnaSliceItPayment;
use Kiener\MolliePayments\Handler\Method\MbWayPayment;
use Kiener\MolliePayments\Handler\Method\MyBankPayment;
use Kiener\MolliePayments\Handler\Method\PayByBankPayment;
use Kiener\MolliePayments\Handler\Method\PayconiqPayment;
Expand Down Expand Up @@ -147,6 +148,7 @@ public function testSupportedMethods(): void
RivertyPayment::class,
SatispayPayment::class,
PayByBankPayment::class,
MbWayPayment::class,
PayPalExpressPayment::class,
];

Expand Down

0 comments on commit 18aebce

Please sign in to comment.