Skip to content

Commit

Permalink
NTR: PISHPS-377: Pay by bank (#885)
Browse files Browse the repository at this point in the history
Co-authored-by: Vitalij Mik <[email protected]>
  • Loading branch information
BlackScorp and Vitalij Mik authored Nov 6, 2024
1 parent 4e9b41f commit 694f2ef
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/Handler/Method/PayByBankPayment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);

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\SalesChannel\SalesChannelContext;

/**
* @final
*/
class PayByBankPayment extends PaymentHandler
{
public const PAYMENT_METHOD_NAME = PaymentMethod::PAYBYBANK;
public const PAYMENT_METHOD_DESCRIPTION = 'Pay by Bank';

/** @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;
}
}
7 changes: 7 additions & 0 deletions src/Resources/config/services/handlers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@
<tag name="shopware.payment.method.async"/>
</service>

<!-- Pay by Bank PaymentHandler -->
<service id="Kiener\MolliePayments\Handler\Method\PayByBankPayment">
<argument type="service" id="mollie_payments.logger"/>
<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 @@ -23,6 +23,7 @@
use Kiener\MolliePayments\Handler\Method\KlarnaPayNowPayment;
use Kiener\MolliePayments\Handler\Method\KlarnaSliceItPayment;
use Kiener\MolliePayments\Handler\Method\MyBankPayment;
use Kiener\MolliePayments\Handler\Method\PayByBankPayment;
use Kiener\MolliePayments\Handler\Method\PayconiqPayment;
use Kiener\MolliePayments\Handler\Method\PayPalExpressPayment;
use Kiener\MolliePayments\Handler\Method\PayPalPayment;
Expand Down Expand Up @@ -459,6 +460,7 @@ public function getPaymentHandlers(): array
PayconiqPayment::class,
RivertyPayment::class,
SatispayPayment::class,
PayByBankPayment::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 @@ -59,6 +59,7 @@ const payments = [
{caseId: 'C3362897', key: 'payconiq', name: 'Payconiq', sanity: false},
{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},
// unfortunately address and product prices need to match, so we cannot do in3 automatically for now
// {caseId: '', key: 'in3', name: 'in3'},
];
Expand Down
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('Pay by Bank', () => {

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

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

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

it('C4212006: Pay by bank is existing in checkout', () => {

scenarioDummyBasket.execute();

paymentAction.switchPaymentMethod('Pay by Bank');

// 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\KlarnaOnePayment;
use Kiener\MolliePayments\Handler\Method\KlarnaPayLaterPayment;
use Kiener\MolliePayments\Handler\Method\PayByBankPayment;
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 PayByBankOrderBuilderTest extends AbstractMollieOrderBuilder
{
public function testOrderBuild(): void
{
$redirectWebhookUrl = 'https://foo';
$this->router->method('generate')->willReturn($redirectWebhookUrl);
$paymentMethod = PaymentMethod::PAYBYBANK;

$this->paymentHandler = new PayByBankPayment(
$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, $paymentMethod, $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' => $paymentMethod,
'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 @@ -22,6 +22,7 @@
use Kiener\MolliePayments\Handler\Method\KlarnaPayNowPayment;
use Kiener\MolliePayments\Handler\Method\KlarnaSliceItPayment;
use Kiener\MolliePayments\Handler\Method\MyBankPayment;
use Kiener\MolliePayments\Handler\Method\PayByBankPayment;
use Kiener\MolliePayments\Handler\Method\PayPalExpressPayment;
use Kiener\MolliePayments\Handler\Method\PayconiqPayment;
use Kiener\MolliePayments\Handler\Method\PayPalPayment;
Expand Down Expand Up @@ -147,6 +148,7 @@ public function testSupportedMethods(): void
PayconiqPayment::class,
RivertyPayment::class,
SatispayPayment::class,
PayByBankPayment::class,
PayPalExpressPayment::class,
];

Expand Down

0 comments on commit 694f2ef

Please sign in to comment.