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

PISHPS-407: add mbway payment #927

Merged
merged 3 commits into from
Jan 28, 2025
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added

- Returns for Shopware Commercial plugins are now transferred to Mollie when the return status is set to "Done" and can be canceled with the "Cancelled" status. Please note that refunds cannot be canceled after two hours.
- MB Way payment method is now available for Mollie Payments.
- Multibanco payment method is now available for Mollie Payments.


### Changed

- The minimum supported Shopware version is now 6.4.5.0.
Expand Down
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;
}
8 changes: 8 additions & 0 deletions src/Resources/config/services/handlers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@
<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>

<!-- Multibanco PaymentHandler -->
<service id="Kiener\MolliePayments\Handler\Method\MultibancoPayment">
<argument type="service" id="monolog.logger.mollie"/>
Expand Down
4 changes: 3 additions & 1 deletion 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\MultibancoPayment;
use Kiener\MolliePayments\Handler\Method\MyBankPayment;
use Kiener\MolliePayments\Handler\Method\PayByBankPayment;
Expand Down Expand Up @@ -462,7 +463,8 @@ public function getPaymentHandlers(): array
RivertyPayment::class,
SatispayPayment::class,
PayByBankPayment::class,
MultibancoPayment::class
MbWayPayment::class,
MultibancoPayment::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,7 +60,9 @@ 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},
{caseId: '', key: 'multibanco', name: 'Multibanco', 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\MultibancoPayment;
use Kiener\MolliePayments\Handler\Method\MyBankPayment;
use Kiener\MolliePayments\Handler\Method\PayByBankPayment;
Expand Down Expand Up @@ -148,6 +149,7 @@ public function testSupportedMethods(): void
RivertyPayment::class,
SatispayPayment::class,
PayByBankPayment::class,
MbWayPayment::class,
MultibancoPayment::class,
PayPalExpressPayment::class,
];
Expand Down
Loading