-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MOL-1281: Add TWINT payment method (#388)
* add twint integration * fix an issue with getting all active methods * do not request twint explicit as order * do not block twint for payments api * fix test for twint * Update PaymentMethodType.php
- Loading branch information
1 parent
9c79a3e
commit c6f6a90
Showing
9 changed files
with
190 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace MollieShopware\Services\Mollie\Payments\Requests; | ||
|
||
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 Twint extends AbstractPayment implements PaymentInterface | ||
{ | ||
|
||
/** | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct( | ||
new AddressConverter(), | ||
new LineItemConverter(), | ||
'twint' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
Tests/PHPUnit/Services/Mollie/Payments/Requests/TwintTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\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\Twint; | ||
use MollieShopware\Tests\Utils\Traits\PaymentTestTrait; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class TwintTest 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 Twint(); | ||
|
||
$this->addressInvoice = $this->getAddressFixture1(); | ||
$this->addressShipping = $this->getAddressFixture2(); | ||
$this->lineItem = $this->getLineItemFixture(); | ||
|
||
$this->payment->setPayment( | ||
new Payment( | ||
'UUID-123', | ||
'Order 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' => 'twint', | ||
'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' => 'twint', | ||
'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']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters