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

NTR: add bancomat #416

Merged
merged 1 commit into from
Jun 19, 2024
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
1 change: 1 addition & 0 deletions Components/Constants/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ class PaymentMethod
const VOUCHERS = "voucher";
const IN3 = "in3";
const TWINT = "twint";
const BANCOMAT_PAY = "bancomatpay";
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public static function getSupportedPaymentMethods()
PaymentMethod::VOUCHERS,
PaymentMethod::IN3,
PaymentMethod::TWINT,
PaymentMethod::BANCOMAT_PAY,
];
}

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 @@ -5,6 +5,7 @@
use MollieShopware\Components\Constants\PaymentMethod;
use MollieShopware\Services\Mollie\Payments\Models\Payment;
use MollieShopware\Services\Mollie\Payments\Requests\ApplePay;
use MollieShopware\Services\Mollie\Payments\Requests\BancomatPay;
use MollieShopware\Services\Mollie\Payments\Requests\Bancontact;
use MollieShopware\Services\Mollie\Payments\Requests\BankTransfer;
use MollieShopware\Services\Mollie\Payments\Requests\Belfius;
Expand Down Expand Up @@ -103,6 +104,9 @@ public function createByPaymentName($paymentMethod)

case PaymentMethod::TWINT:
return new Twint();

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

throw new \Exception('Payment handler not found for: ' . $paymentMethod);
Expand Down
25 changes: 25 additions & 0 deletions Services/Mollie/Payments/Requests/BancomatPay.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 BancomatPay extends AbstractPayment implements PaymentInterface
{

/**
*/
public function __construct()
{
parent::__construct(
new AddressConverter(),
new LineItemConverter(),
PaymentMethod::BANCOMAT_PAY
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function getPaymentMethods()
[true, PaymentMethod::EPS],
[true, PaymentMethod::KBC],
[true, PaymentMethod::TWINT],
[true, PaymentMethod::BANCOMAT_PAY],
];
}

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

$this->assertEquals($expected, PaymentMethodsInstaller::getSupportedPaymentMethods());
Expand Down
136 changes: 136 additions & 0 deletions Tests/PHPUnit/Services/Mollie/Payments/Requests/BancomatPayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?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\BancomatPay;
use MollieShopware\Services\Mollie\Payments\Requests\Twint;
use MollieShopware\Tests\Utils\Traits\PaymentTestTrait;
use PHPUnit\Framework\TestCase;

class BancomatPayTest extends TestCase
{
use PaymentTestTrait;


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

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

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

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

/**
*
*/
public function setUp(): void
{
$this->payment = new BancomatPay();

$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],
'EUR',
'de_DE',
'https://local/redirect',
'https://local/notify'
)
);
}

/**
* This test verifies that the Payments-API request
* for our payment is correct.
*/
public function testPaymentsAPI()
{
$expected = [
'method' => PaymentMethod::BANCOMAT_PAY,
'amount' => [
'currency' => 'EUR',
'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' => PaymentMethod::BANCOMAT_PAY,
'amount' => [
'currency' => 'EUR',
'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']);
}
}
Loading