Skip to content

Commit

Permalink
NTR: add blik fix #411 (#417)
Browse files Browse the repository at this point in the history
Co-authored-by: Vitalij Mik <vitalij.mik@dasistweb.de>
  • Loading branch information
BlackScorp and Vitalij Mik authored Jun 19, 2024
1 parent 04f0a1b commit a67906e
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 1 deletion.
1 change: 1 addition & 0 deletions Components/Constants/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ class PaymentMethod
const IN3 = "in3";
const TWINT = "twint";
const BANCOMAT_PAY = "bancomatpay";
const BLIK = "blik";
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public static function getSupportedPaymentMethods()
PaymentMethod::IN3,
PaymentMethod::TWINT,
PaymentMethod::BANCOMAT_PAY,
PaymentMethod::BLIK,
];
}

Expand Down
4 changes: 4 additions & 0 deletions Services/Mollie/Payments/PaymentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use MollieShopware\Services\Mollie\Payments\Requests\BankTransfer;
use MollieShopware\Services\Mollie\Payments\Requests\Belfius;
use MollieShopware\Services\Mollie\Payments\Requests\Billie;
use MollieShopware\Services\Mollie\Payments\Requests\Blik;
use MollieShopware\Services\Mollie\Payments\Requests\CreditCard;
use MollieShopware\Services\Mollie\Payments\Requests\EPS;
use MollieShopware\Services\Mollie\Payments\Requests\Giftcard;
Expand Down Expand Up @@ -107,6 +108,9 @@ public function createByPaymentName($paymentMethod)

case PaymentMethod::BANCOMAT_PAY:
return new BancomatPay();

case PaymentMethod::BLIK:
return new Blik();
}

throw new \Exception('Payment handler not found for: ' . $paymentMethod);
Expand Down
25 changes: 25 additions & 0 deletions Services/Mollie/Payments/Requests/Blik.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace MollieShopware\Services\Mollie\Payments\Requests;

use MollieShopware\Components\Constants\PaymentMethod;
use MollieShopware\Services\Mollie\Payments\AbstractPayment;
use MollieShopware\Services\Mollie\Payments\Converters\AddressConverter;
use MollieShopware\Services\Mollie\Payments\Converters\LineItemConverter;
use MollieShopware\Services\Mollie\Payments\Exceptions\ApiNotSupportedException;
use MollieShopware\Services\Mollie\Payments\PaymentInterface;

class Blik extends AbstractPayment implements PaymentInterface
{

/**
*/
public function __construct()
{
parent::__construct(
new AddressConverter(),
new LineItemConverter(),
PaymentMethod::BLIK
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ configs.forEach(config => {
cy.contains('Vielen Dank für Ihre Bestellung');

// also verify that our address is correctly visible
cy.get('.billing--panel').contains('Max Mustermann');
cy.get('.billing--panel').should('be.visible').contains('Max Mustermann');
})

})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function getPaymentMethods()
[true, PaymentMethod::KBC],
[true, PaymentMethod::TWINT],
[true, PaymentMethod::BANCOMAT_PAY],
[true, PaymentMethod::BLIK],
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function testSupportedPaymentMethods()
PaymentMethod::IN3,
PaymentMethod::TWINT,
PaymentMethod::BANCOMAT_PAY,
PaymentMethod::BLIK
];

$this->assertEquals($expected, PaymentMethodsInstaller::getSupportedPaymentMethods());
Expand Down
143 changes: 143 additions & 0 deletions Tests/PHPUnit/Services/Mollie/Payments/Requests/BlikTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?php

namespace MollieShopware\Tests\PHPUnit\Services\Mollie\Payments\Requests;

use MollieShopware\Components\Constants\PaymentMethod;
use MollieShopware\Services\Mollie\Payments\Models\Payment;
use MollieShopware\Services\Mollie\Payments\Models\PaymentAddress;
use MollieShopware\Services\Mollie\Payments\Models\PaymentLineItem;
use MollieShopware\Services\Mollie\Payments\Requests\Blik;
use MollieShopware\Services\Mollie\Payments\Requests\Twint;
use MollieShopware\Tests\Utils\Traits\PaymentTestTrait;
use PHPUnit\Framework\TestCase;

class BlikTest extends TestCase
{
use PaymentTestTrait;


/**
* @var Twint
*/
private $payment;

/**
* @var PaymentAddress
*/
private $addressInvoice;

/**
* @var PaymentAddress
*/
private $addressShipping;

/**
* @var PaymentLineItem
*/
private $lineItem;

/**
* @var string
*/
private $methodName;

/**
*
*/
public function setUp(): void
{
$this->payment = new Blik();
$this->methodName = PaymentMethod::BLIK;
$this->addressInvoice = $this->getAddressFixture1();
$this->addressShipping = $this->getAddressFixture2();
$this->lineItem = $this->getLineItemFixture();

$this->payment->setPayment(
new Payment(
'UUID-123',
'Payment UUID-123',
'20004',
$this->addressInvoice,
$this->addressShipping,
49.98,
[$this->lineItem],
'CHF',
'de_DE',
'https://local/redirect',
'https://local/notify'
)
);
}

/**
* This test verifies that the Payments-API request
* for our payment is correct.
* Please note, Twint does not work with the payments API
* so this is just an empty array
*/
public function testPaymentsAPI()
{
$expected = [
'method' => $this->methodName,
'amount' => [
'currency' => 'CHF',
'value' => '49.98',
],
'description' => 'Payment UUID-123',
'redirectUrl' => 'https://local/redirect',
'webhookUrl' => 'https://local/notify',
'locale' => 'de_DE',
];

$requestBody = $this->payment->buildBodyPaymentsAPI();

$this->assertEquals($expected, $requestBody);
}

/**
* This test verifies that the Orders-API request
* for our payment is correct.
*/
public function testOrdersAPI()
{
$expected = [
'method' => $this->methodName,
'amount' => [
'currency' => 'CHF',
'value' => '49.98',
],
'redirectUrl' => 'https://local/redirect',
'webhookUrl' => 'https://local/notify',
'locale' => 'de_DE',
'orderNumber' => '20004',
'payment' => [
'webhookUrl' => 'https://local/notify',
],
'billingAddress' => $this->getExpectedAddressStructure($this->addressInvoice),
'shippingAddress' => $this->getExpectedAddressStructure($this->addressShipping),
'lines' => [
$this->getExpectedLineItemStructure($this->lineItem),
],
'metadata' => [],
];

$requestBody = $this->payment->buildBodyOrdersAPI();

$this->assertSame($expected, $requestBody);
}

/**
* This test verifies that we can set a custom expiration date
* for our Orders API request.
*/
public function testExpirationDate()
{
$dueInDays = 5;
$expectedDueDate = date('Y-m-d', strtotime(' + ' . $dueInDays . ' day'));

$this->payment->setExpirationDays($dueInDays);
$request = $this->payment->buildBodyOrdersAPI();

$this->assertEquals($expectedDueDate, $request['expiresAt']);
}
}

0 comments on commit a67906e

Please sign in to comment.