Skip to content

Commit

Permalink
PISHPS-226: Add riverty payment (#422)
Browse files Browse the repository at this point in the history
* NTR: PISHPW-226: add riverty payment

* NTR: remove girpoay from cypress

---------

Co-authored-by: Vitalij Mik <[email protected]>
  • Loading branch information
BlackScorp and Vitalij Mik authored Sep 9, 2024
1 parent b15fe1e commit a5b724c
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 6 deletions.
1 change: 1 addition & 0 deletions Components/Constants/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ class PaymentMethod
const TWINT = "twint";
const BANCOMAT_PAY = "bancomatpay";
const BLIK = "blik";
const RIVERTY = "riverty";
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ public static function getSupportedPaymentMethods()
PaymentMethod::TWINT,
PaymentMethod::BANCOMAT_PAY,
PaymentMethod::BLIK,
PaymentMethod::KLARNA_ONE
PaymentMethod::KLARNA_ONE,
PaymentMethod::RIVERTY
];
}

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 @@ -24,6 +24,7 @@
use MollieShopware\Services\Mollie\Payments\Requests\PayPal;
use MollieShopware\Services\Mollie\Payments\Requests\Paysafecard;
use MollieShopware\Services\Mollie\Payments\Requests\Przelewy24;
use MollieShopware\Services\Mollie\Payments\Requests\Riverty;
use MollieShopware\Services\Mollie\Payments\Requests\SepaDirectDebit;
use MollieShopware\Services\Mollie\Payments\Requests\SliceIt;
use MollieShopware\Services\Mollie\Payments\Requests\Sofort;
Expand Down Expand Up @@ -115,6 +116,9 @@ public function createByPaymentName($paymentMethod)

case PaymentMethod::KLARNA_ONE:
return new Klarna();

case PaymentMethod::RIVERTY:
return new Riverty();
}

throw new \Exception('Payment handler not found for: ' . $paymentMethod);
Expand Down
34 changes: 34 additions & 0 deletions Services/Mollie/Payments/Requests/Riverty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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 Riverty extends AbstractPayment implements PaymentInterface
{

/**
*/
public function __construct()
{
parent::__construct(
new AddressConverter(),
new LineItemConverter(),
PaymentMethod::RIVERTY
);
}

/**
* @throws ApiNotSupportedException
* @return mixed[]|void
*/
public function buildBodyPaymentsAPI()
{
throw new ApiNotSupportedException('Klarna One does not support the Payments API!');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ const payments = [
{caseId: 'C24802', key: 'eps', name: 'eps', paymentsAPI: false, createOrderBeforePayment: true},
{caseId: 'C24803', key: 'eps', name: 'eps', paymentsAPI: false, createOrderBeforePayment: false},

{caseId: 'C4252', key: 'giropay', name: 'giropay', paymentsAPI: true, createOrderBeforePayment: true},
{caseId: 'C24804', key: 'giropay', name: 'giropay', paymentsAPI: true, createOrderBeforePayment: false},
{caseId: 'C24805', key: 'giropay', name: 'giropay', paymentsAPI: false, createOrderBeforePayment: true},
{caseId: 'C24806', key: 'giropay', name: 'giropay', paymentsAPI: false, createOrderBeforePayment: false},

{caseId: 'C4235', key: 'ideal', name: 'iDEAL', paymentsAPI: true, createOrderBeforePayment: true},
{caseId: 'C24807', key: 'ideal', name: 'iDEAL', paymentsAPI: true, createOrderBeforePayment: false},
{caseId: 'C24808', key: 'ideal', name: 'iDEAL', paymentsAPI: false, createOrderBeforePayment: true},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function testSupportedPaymentMethods()
PaymentMethod::BANCOMAT_PAY,
PaymentMethod::BLIK,
PaymentMethod::KLARNA_ONE,
PaymentMethod::RIVERTY,
];

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

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

use MollieShopware\Components\Constants\PaymentMethod;
use MollieShopware\Services\Mollie\Payments\Exceptions\ApiNotSupportedException;
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\Riverty;
use MollieShopware\Services\Mollie\Payments\Requests\Twint;
use MollieShopware\Tests\Utils\Traits\PaymentTestTrait;
use PHPUnit\Framework\TestCase;

class RivertyTest 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 Riverty();

$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()
{
$this->expectException(ApiNotSupportedException::class);

$this->payment->buildBodyPaymentsAPI();
}

/**
* This test verifies that the Orders-API request
* for our payment is correct.
*/
public function testOrdersAPI()
{
$expected = [
'method' => PaymentMethod::RIVERTY,
'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 a5b724c

Please sign in to comment.