Skip to content

Commit

Permalink
NTR: PISHPS-337: add satispay (#809)
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 Aug 20, 2024
1 parent 1d6865c commit 3061a8b
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/Handler/Method/SatispayPayment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);

namespace Kiener\MolliePayments\Handler\Method;

use Kiener\MolliePayments\Handler\PaymentHandler;

class SatispayPayment extends PaymentHandler
{
public const PAYMENT_METHOD_NAME = 'satispay';
public const PAYMENT_METHOD_DESCRIPTION = 'Satispay';

/** @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 @@ -234,6 +234,14 @@
<tag name="shopware.payment.method.async"/>
</service>

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



</services>
</container>
2 changes: 2 additions & 0 deletions src/Service/PaymentMethodService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Kiener\MolliePayments\Handler\Method\PosPayment;
use Kiener\MolliePayments\Handler\Method\Przelewy24Payment;
use Kiener\MolliePayments\Handler\Method\RivertyPayment;
use Kiener\MolliePayments\Handler\Method\SatispayPayment;
use Kiener\MolliePayments\Handler\Method\SofortPayment;
use Kiener\MolliePayments\Handler\Method\TrustlyPayment;
use Kiener\MolliePayments\Handler\Method\TwintPayment;
Expand Down Expand Up @@ -450,6 +451,7 @@ public function getPaymentHandlers(): array
TrustlyPayment::class,
PayconiqPayment::class,
RivertyPayment::class,
SatispayPayment::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,8 @@ const payments = [
{caseId: 'C4143', key: 'voucher', name: 'Voucher', sanity: false},
{caseId: 'C3362894', key: 'trustly', name: 'Trustly', sanity: false},
{caseId: 'C3362897', key: 'payconiq', name: 'Payconiq', sanity: false},
{caseId: 'C3713510', key: 'riverty', name: 'Riverty', sanity: false},
{caseId: 'C3713512', key: 'satispay', name: 'Satispay', 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
43 changes: 43 additions & 0 deletions tests/Cypress/cypress/e2e/storefront/payment-methods/riverty.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('Riverty', () => {

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

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

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

it('C3713511: Riverty is existing in checkout', () => {

scenarioDummyBasket.execute();

paymentAction.switchPaymentMethod('Riverty');

// 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,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('Satispay', () => {

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

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

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

it('C3713513: Satispay is existing in checkout', () => {

scenarioDummyBasket.execute();

paymentAction.switchPaymentMethod('Satispay');

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

$this->paymentHandler = new SatispayPayment(
$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);
}
}
4 changes: 3 additions & 1 deletion tests/PHPUnit/Service/PaymentMethodServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Kiener\MolliePayments\Handler\Method\PosPayment;
use Kiener\MolliePayments\Handler\Method\Przelewy24Payment;
use Kiener\MolliePayments\Handler\Method\RivertyPayment;
use Kiener\MolliePayments\Handler\Method\SatispayPayment;
use Kiener\MolliePayments\Handler\Method\SofortPayment;
use Kiener\MolliePayments\Handler\Method\TrustlyPayment;
use Kiener\MolliePayments\Handler\Method\TwintPayment;
Expand Down Expand Up @@ -141,7 +142,8 @@ public function testSupportedMethods(): void
AlmaPayment::class,
TrustlyPayment::class,
PayconiqPayment::class,
RivertyPayment::class
RivertyPayment::class,
SatispayPayment::class,
];

$handlers = $this->paymentMethodService->getPaymentHandlers();
Expand Down

0 comments on commit 3061a8b

Please sign in to comment.