mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-05 20:57:12 +00:00
[Test][Admin] Add contracts test for payment request
This commit is contained in:
parent
9054721d76
commit
24036f6832
5 changed files with 209 additions and 0 deletions
66
tests/Api/Admin/PaymentRequestsTest.php
Normal file
66
tests/Api/Admin/PaymentRequestsTest.php
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Sylius Sp. z o.o.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Tests\Api\Admin;
|
||||
|
||||
use Sylius\Component\Payment\Model\PaymentRequestInterface;
|
||||
use Sylius\Tests\Api\JsonApiTestCase;
|
||||
|
||||
final class PaymentRequestsTest extends JsonApiTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->setUpAdminContext();
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_payment_requests(): void
|
||||
{
|
||||
$this->setUpDefaultGetHeaders();
|
||||
|
||||
$this->loadFixturesFromFiles([
|
||||
'authentication/api_administrator.yaml',
|
||||
'channel.yaml',
|
||||
'payment_method.yaml',
|
||||
'payment_request/payment_request.yaml',
|
||||
'payment_request/order.yaml',
|
||||
]);
|
||||
|
||||
$this->requestGet(uri: '/api/v2/admin/payment-requests');
|
||||
|
||||
$this->assertResponseSuccessful('admin/payment_request/get_payment_requests');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_a_payment_request(): void
|
||||
{
|
||||
$this->setUpDefaultGetHeaders();
|
||||
|
||||
$fixtures = $this->loadFixturesFromFiles([
|
||||
'authentication/api_administrator.yaml',
|
||||
'channel.yaml',
|
||||
'payment_method.yaml',
|
||||
'payment_request/payment_request.yaml',
|
||||
'payment_request/order.yaml',
|
||||
]);
|
||||
|
||||
/** @var PaymentRequestInterface $paymentRequest */
|
||||
$paymentRequest = $fixtures['payment_request_authorize'];
|
||||
|
||||
$this->requestGet(uri: sprintf('/api/v2/admin/payment-requests/%s', $paymentRequest->getHash()));
|
||||
|
||||
$this->assertResponseSuccessful('admin/payment_request/get_payment_request');
|
||||
}
|
||||
}
|
||||
17
tests/Api/DataFixtures/ORM/payment_request/order.yaml
Normal file
17
tests/Api/DataFixtures/ORM/payment_request/order.yaml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
Sylius\Component\Core\Model\Payment:
|
||||
payment:
|
||||
method: "@payment_method_cash_on_delivery"
|
||||
order: "@order"
|
||||
state: "processing"
|
||||
amount: 1000
|
||||
currencyCode: "USD"
|
||||
|
||||
Sylius\Component\Core\Model\Order:
|
||||
order:
|
||||
channel: "@channel_web"
|
||||
currencyCode: "USD"
|
||||
localeCode: "en_US"
|
||||
state: "new"
|
||||
paymentState: "awaiting_payment"
|
||||
shippingState: "ready"
|
||||
tokenValue: "token"
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
Sylius\Component\Payment\Model\PaymentRequest:
|
||||
payment_request_status:
|
||||
__construct: [ '@payment', '@payment_method_cash_on_delivery' ]
|
||||
state: "completed"
|
||||
action: "status"
|
||||
payload: null
|
||||
responseData: []
|
||||
payment_request_authorize:
|
||||
__construct: [ '@payment', '@payment_method_cash_on_delivery' ]
|
||||
state: "completed"
|
||||
action: "authorize"
|
||||
payload: {
|
||||
"target_path": "https://myshop.tld/target-path",
|
||||
"after_path": "https://myshop.tld/after-path",
|
||||
}
|
||||
responseData: {
|
||||
"after_url": "https://myshop.tld/after-path",
|
||||
}
|
||||
payment_request_capture:
|
||||
__construct: [ '@payment', '@payment_method_cash_on_delivery' ]
|
||||
state: "processing"
|
||||
action: "capture"
|
||||
payload: {
|
||||
"http_request": {
|
||||
"query": {
|
||||
"token": "EC-2d9EV13959UR209410U",
|
||||
"PayerID": "UX8WBNYWGBVMG"
|
||||
}
|
||||
}
|
||||
}
|
||||
responseData: {
|
||||
"after_url": "https://myshop.tld/after-path",
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/PaymentRequest",
|
||||
"@id": "\/api\/v2\/admin\/payment-requests\/@string@",
|
||||
"@type": "PaymentRequest",
|
||||
"hash": "@string@",
|
||||
"state": "completed",
|
||||
"action": "authorize",
|
||||
"payload": {
|
||||
"target_path": "https:\/\/myshop.tld\/target-path",
|
||||
"after_path": "https:\/\/myshop.tld\/after-path"
|
||||
},
|
||||
"responseData": {
|
||||
"after_url": "https:\/\/myshop.tld\/after-path"
|
||||
},
|
||||
"payment": "\/api\/v2\/admin\/payments\/@integer@",
|
||||
"method": {
|
||||
"@id": "\/api\/v2\/admin\/payment-methods\/CASH_ON_DELIVERY",
|
||||
"@type": "PaymentMethod",
|
||||
"code": "CASH_ON_DELIVERY",
|
||||
"enabled": true,
|
||||
"translations": {
|
||||
"en_US": "\/api\/v2\/admin\/payment-method-translations\/@integer@"
|
||||
}
|
||||
},
|
||||
"createdAt": @datetime@,
|
||||
"updatedAt": @datetime@
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
{
|
||||
"@context": "\/api\/v2\/contexts\/PaymentRequest",
|
||||
"@id": "\/api\/v2\/admin\/payment-requests",
|
||||
"@type": "hydra:Collection",
|
||||
"hydra:member": [
|
||||
{
|
||||
"@id": "\/api\/v2\/admin\/payment-requests\/@string@",
|
||||
"@type": "PaymentRequest",
|
||||
"hash": "@string@",
|
||||
"state": "completed",
|
||||
"action": "status",
|
||||
"payment": "\/api\/v2\/admin\/payments\/@integer@",
|
||||
"method": "\/api\/v2\/admin\/payment-methods\/CASH_ON_DELIVERY"
|
||||
},
|
||||
{
|
||||
"@id": "\/api\/v2\/admin\/payment-requests\/@string@",
|
||||
"@type": "PaymentRequest",
|
||||
"hash": "@string@",
|
||||
"state": "completed",
|
||||
"action": "authorize",
|
||||
"payment": "\/api\/v2\/admin\/payments\/@integer@",
|
||||
"method": "\/api\/v2\/admin\/payment-methods\/CASH_ON_DELIVERY"
|
||||
},
|
||||
{
|
||||
"@id": "\/api\/v2\/admin\/payment-requests\/@string@",
|
||||
"@type": "PaymentRequest",
|
||||
"hash": "@string@",
|
||||
"state": "processing",
|
||||
"action": "capture",
|
||||
"payment": "\/api\/v2\/admin\/payments\/@integer@",
|
||||
"method": "\/api\/v2\/admin\/payment-methods\/CASH_ON_DELIVERY"
|
||||
}
|
||||
],
|
||||
"hydra:totalItems": 3,
|
||||
"hydra:search": {
|
||||
"@type": "hydra:IriTemplate",
|
||||
"hydra:template": "\/api\/v2\/admin\/payment-requests{?state,state[],method.code,method.code[]}",
|
||||
"hydra:variableRepresentation": "BasicRepresentation",
|
||||
"hydra:mapping": [
|
||||
{
|
||||
"@type": "IriTemplateMapping",
|
||||
"variable": "state",
|
||||
"property": "state",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"@type": "IriTemplateMapping",
|
||||
"variable": "state[]",
|
||||
"property": "state",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"@type": "IriTemplateMapping",
|
||||
"variable": "method.code",
|
||||
"property": "method.code",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"@type": "IriTemplateMapping",
|
||||
"variable": "method.code[]",
|
||||
"property": "method.code",
|
||||
"required": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue