Skip to content
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 .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
->in(__DIR__ . '/src/Services/CRM/Timeline/')
->in(__DIR__ . '/src/Services/Entity/Section/')
->in(__DIR__ . '/src/Services/Department/')
->in(__DIR__ . '/src/Services/Paysystem/')
->in(__DIR__ . '/src/Services/Sale/')
->in(__DIR__ . '/src/Services/Task/')
->in(__DIR__ . '/src/Services/Sale/')
Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@

### Added

- Added service `Services\Paysystem\Handler\Service\Handler` with support methods,
see [pay_system.handler.* methods](https://github.com/bitrix24/b24phpsdk/issues/260):
- `add` adds a payment system handler
- `update` updates a payment system handler
- `list` returns a list of payment system handlers
- `delete` deletes a payment system handler
- Added service `Services\Paysystem\Service\Paysystem` with support methods,
see [sale.paysystem.* methods](https://github.com/bitrix24/b24phpsdk/issues/260):
- `add` adds a payment system
- `update` updates a payment system
- `get` returns a payment system by its identifier
- `list` returns a list of payment systems
- `delete` deletes a payment system
- `payPayment` pays a payment
- `payInvoice` pays an invoice (legacy version)
- Added service `Services\Paysystem\Settings\Service\Settings` with support methods,
see [sale.paysystem.settings.* methods](https://github.com/bitrix24/b24phpsdk/issues/260):
- `get` returns the settings of the payment system
- `update` updates the payment system settings
- `getForPayment` returns the payment system settings for a specific payment
- `getForInvoice` returns the payment system settings for a specific invoice (legacy version)
- Added service `Services\Sale\Shipment\Service\Shipment` with support methods,
see [sale.shipment.* methods](https://github.com/bitrix24/b24phpsdk/issues/250):
- `add` adds a shipment
Expand Down
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ help:
@echo ""
@echo "test-unit - run unit tests"
@echo "test-integration-sale-basket-property - run BasketProperty integration tests"
@echo "test-integration-scope-paysystem - run Payment System integration tests"
@echo "test-integration-sale-payment-item-basket - run PaymentItemBasket integration tests"
@echo "test-integration-sale-payment-item-shipment - run PaymentItemShipment integration tests"
@echo "test-integration-sale-property-relation - run PropertyRelation integration tests"
Expand Down Expand Up @@ -163,6 +164,18 @@ test-integration-scope-im:
test-integration-scope-placement:
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_scope_placement

.PHONY: test-integration-scope-paysystem
test-integration-scope-paysystem:
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_scope_paysystem

.PHONY: test-integration-paysystem-service
test-integration-paysystem-service:
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_paysystem_service

.PHONY: test-integration-paysystem-settings
test-integration-paysystem-settings:
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_paysystem_settings

.PHONY: test-integration-scope-im-open-lines
test-integration-scope-im-open-lines:
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_scope_im_open_lines
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ parameters:
- tests/Integration/Services/Catalog
- tests/Integration/Services/IMOpenLines
- tests/Integration/Services/Main
- tests/Integration/Services/Paysystem
- tests/Integration/Services/Placement
- tests/Integration/Services/CRM/Address
- tests/Integration/Services/CRM/Deal/Service/DealRecurringTest.php
Expand Down
9 changes: 9 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
<testsuite name="integration_tests_scope_placement">
<directory>./tests/Integration/Services/Placement/</directory>
</testsuite>
<testsuite name="integration_tests_scope_paysystem">
<directory>./tests/Integration/Services/Paysystem/</directory>
</testsuite>
<testsuite name="integration_tests_paysystem_service">
<directory>./tests/Integration/Services/Paysystem/Service/</directory>
</testsuite>
<testsuite name="integration_tests_paysystem_settings">
<directory>./tests/Integration/Services/Paysystem/Settings/</directory>
</testsuite>
<testsuite name="integration_tests_scope_user">
<directory>./tests/Integration/Services/User/</directory>
</testsuite>
Expand Down
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
__DIR__ . '/tests/Integration/Services/CRM/Address',
__DIR__ . '/src/Services/Main',
__DIR__ . '/tests/Integration/Services/Main',
__DIR__ . '/src/Services/Paysystem',
__DIR__ . '/tests/Integration/Services/Paysystem',
__DIR__ . '/src/Services/Placement',
__DIR__ . '/tests/Integration/Services/Placement',
__DIR__ . '/src/Services/CRM/Deal',
Expand Down
29 changes: 29 additions & 0 deletions src/Services/Paysystem/Handler/Result/HandlerItemResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* This file is part of the bitrix24-php-sdk package.
*
* © Sally Fancen <[email protected]>
*
* For the full copyright and license information, please view the MIT-LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Bitrix24\SDK\Services\Paysystem\Handler\Result;

use Bitrix24\SDK\Core\Result\AbstractItem;

/**
* Class HandlerItemResult
*
* @property-read int $ID Payment system handler identifier
* @property-read string $NAME Name of the REST handler
* @property-read string $CODE Code of the REST handler
* @property-read int $SORT Sorting order
* @property-read array $SETTINGS Handler settings containing currency, client type, form/checkout/iframe data, and codes
*/
class HandlerItemResult extends AbstractItem
{
}
37 changes: 37 additions & 0 deletions src/Services/Paysystem/Handler/Result/HandlersResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* This file is part of the bitrix24-php-sdk package.
*
* © Sally Fancen <[email protected]>
*
* For the full copyright and license information, please view the MIT-LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Bitrix24\SDK\Services\Paysystem\Handler\Result;

use Bitrix24\SDK\Core\Exceptions\BaseException;
use Bitrix24\SDK\Core\Result\AbstractResult;

/**
* List of payment system handlers result for sale.paysystem.handler.list
*/
class HandlersResult extends AbstractResult
{
/**
* @return HandlerItemResult[]
* @throws BaseException
*/
public function getHandlers(): array
{
$items = [];
foreach ($this->getCoreResponse()->getResponseData()->getResult() as $item) {
$items[] = new HandlerItemResult($item);
}

return $items;
}
}
136 changes: 136 additions & 0 deletions src/Services/Paysystem/Handler/Service/Handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?php

/**
* This file is part of the bitrix24-php-sdk package.
*
* © Sally Fancen <[email protected]>
*
* For the full copyright and license information, please view the MIT-LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Bitrix24\SDK\Services\Paysystem\Handler\Service;

use Bitrix24\SDK\Attributes\ApiEndpointMetadata;
use Bitrix24\SDK\Attributes\ApiServiceMetadata;
use Bitrix24\SDK\Core\Contracts\CoreInterface;
use Bitrix24\SDK\Core\Credentials\Scope;
use Bitrix24\SDK\Core\Exceptions\BaseException;
use Bitrix24\SDK\Core\Exceptions\TransportException;
use Bitrix24\SDK\Core\Result\AddedItemResult;
use Bitrix24\SDK\Core\Result\DeletedItemResult;
use Bitrix24\SDK\Core\Result\UpdatedItemResult;
use Bitrix24\SDK\Services\AbstractService;
use Bitrix24\SDK\Services\Paysystem\Handler\Result\HandlersResult;
use Psr\Log\LoggerInterface;

#[ApiServiceMetadata(new Scope(['pay_system']))]
class Handler extends AbstractService
{
public function __construct(CoreInterface $core, LoggerInterface $logger)
{
parent::__construct($core, $logger);
}

/**
* Adds a REST handler for the payment system.
*
* @link https://apidocs.bitrix24.com/api-reference/pay-system/sale-pay-system-handler-add.html
*
* @param string $name Name of the REST handler
* @param string $code Code of the REST handler. Must be unique among all handlers
* @param array $settings Handler settings
* @param int $sort Sorting. Default is 100
*
* @throws BaseException
* @throws TransportException
*/
#[ApiEndpointMetadata(
'sale.paysystem.handler.add',
'https://apidocs.bitrix24.com/api-reference/pay-system/sale-pay-system-handler-add.html',
'Adds a REST handler for the payment system.'
)]
public function add(string $name, string $code, array $settings, int $sort = 100): AddedItemResult
{
return new AddedItemResult(
$this->core->call('sale.paysystem.handler.add', [
'NAME' => $name,
'CODE' => $code,
'SETTINGS' => $settings,
'SORT' => $sort,
])
);
}

/**
* Updates a REST handler for the payment system.
*
* @link https://apidocs.bitrix24.com/api-reference/pay-system/sale-pay-system-handler-update.html
*
* @param int $id Identifier of the REST handler
* @param array $fields Set of values for updating
*
* @throws BaseException
* @throws TransportException
*/
#[ApiEndpointMetadata(
'sale.paysystem.handler.update',
'https://apidocs.bitrix24.com/api-reference/pay-system/sale-pay-system-handler-update.html',
'Updates a REST handler for the payment system.'
)]
public function update(int $id, array $fields): UpdatedItemResult
{
return new UpdatedItemResult(
$this->core->call('sale.paysystem.handler.update', [
'ID' => $id,
'FIELDS' => $fields,
])
);
}

/**
* Returns a list of REST handlers for the payment system.
*
* @link https://apidocs.bitrix24.com/api-reference/pay-system/sale-pay-system-handler-list.html
*
* @throws BaseException
* @throws TransportException
*/
#[ApiEndpointMetadata(
'sale.paysystem.handler.list',
'https://apidocs.bitrix24.com/api-reference/pay-system/sale-pay-system-handler-list.html',
'Returns a list of REST handlers for the payment system.'
)]
public function list(): HandlersResult
{
return new HandlersResult(
$this->core->call('sale.paysystem.handler.list')
);
}

/**
* Deletes a REST handler for the payment system.
*
* @link https://apidocs.bitrix24.com/api-reference/pay-system/sale-pay-system-handler-delete.html
*
* @param int $id Identifier of the REST handler
*
* @throws BaseException
* @throws TransportException
*/
#[ApiEndpointMetadata(
'sale.paysystem.handler.delete',
'https://apidocs.bitrix24.com/api-reference/pay-system/sale-pay-system-handler-delete.html',
'Deletes a REST handler for the payment system.'
)]
public function delete(int $id): DeletedItemResult
{
return new DeletedItemResult(
$this->core->call('sale.paysystem.handler.delete', [
'ID' => $id,
])
);
}
}
69 changes: 69 additions & 0 deletions src/Services/Paysystem/PaysystemServiceBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/**
* This file is part of the bitrix24-php-sdk package.
*
* © Sally Fancen <[email protected]>
*
* For the full copyright and license information, please view the MIT-LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Bitrix24\SDK\Services\Paysystem;

use Bitrix24\SDK\Attributes\ApiServiceBuilderMetadata;
use Bitrix24\SDK\Core\Credentials\Scope;
use Bitrix24\SDK\Services\AbstractServiceBuilder;
use Bitrix24\SDK\Services\Paysystem\Handler\Service\Handler;

/**
* Class PaysystemServiceBuilder
*
* @package Bitrix24\SDK\Services\Paysystem
*/
#[ApiServiceBuilderMetadata(new Scope(['pay_system']))]
class PaysystemServiceBuilder extends AbstractServiceBuilder
{
/**
* Payment system handlers service (sale.paysystem.handler.*)
*/
public function handler(): Handler
{
if (!isset($this->serviceCache[__METHOD__])) {
$this->serviceCache[__METHOD__] = new Handler($this->core, $this->log);
}

return $this->serviceCache[__METHOD__];
}

/**
* Payment systems service (sale.paysystem.*)
*/
public function paysystem(): Service\Paysystem
{
if (!isset($this->serviceCache[__METHOD__])) {
$this->serviceCache[__METHOD__] = new Service\Paysystem(
new Service\Batch($this->batch, $this->log),
$this->core,
$this->log
);
}

return $this->serviceCache[__METHOD__];
}

/**
* Payment system settings service (sale.paysystem.settings.*)
*/
public function settings(): Settings\Service\Settings
{
if (!isset($this->serviceCache[__METHOD__])) {
$this->serviceCache[__METHOD__] = new Settings\Service\Settings($this->core, $this->log);
}

return $this->serviceCache[__METHOD__];
}

}
Loading