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
32 changes: 19 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
# b24-php-sdk change log

## 1.8.0 - 2025.11.01 (in progress)

### Added

- Added service `Services\CRM\Type\Service\Type` with support methods,
see [crm.type.* methods](https://github.com/bitrix24/b24phpsdk/issues/274):
- `fields` method retrieves information about the custom fields of the smart process settings
- `add` method creates a new SPA
- `update` updates an existing SPA by its identifier id
- `get` method retrieves information about the SPA with the identifier id
- `getByEntityTypeId` method retrieves information about the SPA with the smart process type identifier entityTypeId
- `list` Get a list of custom types crm.type.list
- `delete` This method deletes an existing smart process by the identifier id
- `fields` method retrieves information about the custom fields of the smart process settings
- `add` method creates a new SPA
- `update` updates an existing SPA by its identifier id
- `get` method retrieves information about the SPA with the identifier id
- `getByEntityTypeId` method retrieves information about the SPA with the smart process type identifier entityTypeId
- `list` Get a list of custom types crm.type.list
- `delete` This method deletes an existing smart process by the identifier id
- For `AbstractCrmItem` added method `getSmartProcessItem` to get smart process item, [see details](https://github.com/bitrix24/b24phpsdk/issues/282)
- Added support for events, [see details](https://github.com/bitrix24/b24phpsdk/issues/288)
- `onCrmContactAdd`
- `onCrmContactUpdate`
- `onCrmContactDelete`
- Added support for events, [see details](https://github.com/bitrix24/b24phpsdk/issues/288)
- `onCrmContactAdd`
- `onCrmContactUpdate`
- `onCrmContactDelete`
- Added separated methods `RemoteEventsFactory::create` and `RemoteEventsFactory::validate` for create and validate incoming
events, [see details](https://github.com/bitrix24/b24phpsdk/issues/291)

### Fixed

- Fixed wrong offset in `ItemsResult` [see details](https://github.com/bitrix24/b24phpsdk/issues/279)
- Fixed wrong exception for method `crm.item.get`, now it `ItemNotFoundException` [see details](https://github.com/bitrix24/b24phpsdk/issues/282)
- Fixed added type `project` in enum `PortalLicenseFamily` [see details](https://github.com/bitrix24/b24phpsdk/issues/286)

### Deprecated

- Method `RemoteEventsFactory::createEvent` marked as deprecated, use `RemoteEventsFactory::create` and `RemoteEventsFactory::validate` instead

### Statistics

```
Expand Down Expand Up @@ -239,6 +246,7 @@ Coverage percentage:
- `list` retrieves a list of property bindings
- `deleteByFilter` removes the property relation
- `getFields` returns the available fields for property binding

### Fixed

- Fixed Incorrect data loading in `Core\Batch::getTraversableList()` with desc sorting by ID [see details](https://github.com/bitrix24/b24phpsdk/issues/246)
Expand All @@ -251,7 +259,6 @@ Supported in bitrix24-php-sdk methods count: 632
Coverage percentage: 54.39% 🚀
```


## 1.6.0 – 2025.09.01

### Added
Expand Down Expand Up @@ -432,7 +439,6 @@ Supported in bitrix24-php-sdk methods count: 476
Coverage percentage: 41.03% 🚀
```


## 1.5.0 – 2025.08.01

### Added
Expand Down
72 changes: 69 additions & 3 deletions src/Services/RemoteEventsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Bitrix24\SDK\Services;

use Bitrix24\SDK\Application\Requests\Events\ApplicationLifeCycleEventsFabric;
use Bitrix24\SDK\Application\Requests\Events\ApplicationLifeCycleEventsFactory;
use Bitrix24\SDK\Application\Requests\Events\OnApplicationInstall\OnApplicationInstall;
use Bitrix24\SDK\Core\Contracts\Events\EventInterface;
Expand All @@ -24,8 +23,6 @@
use Bitrix24\SDK\Services\Calendar\Events\CalendarEventsFactory;
use Bitrix24\SDK\Services\CRM\Company\Events\CrmCompanyEventsFactory;
use Bitrix24\SDK\Services\CRM\Contact\Events\CrmContactEventsFactory;
use Bitrix24\SDK\Services\Sale;
use Bitrix24\SDK\Services\Telephony\Events\TelephonyEventsFabric;
use Bitrix24\SDK\Services\Telephony\Events\TelephonyEventsFactory;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -65,6 +62,74 @@ public static function isCanProcess(Request $request): bool
return array_key_exists('event', $payload);
}

/**
* Create an event object from a remote event request from Bitrix24
* If event supported in SDK it will create a concrete object, in other cases it will be created UnsupportedRemoteEvent object
*
* @throws InvalidArgumentException
*/
public function create(Request $request): EventInterface
{
$payload = [];
parse_str($request->getContent(), $payload);

if (!self::isCanProcess($request)) {
throw new InvalidArgumentException('event request is not valid');
}

$event = new UnsupportedRemoteEvent($request);
foreach ($this->eventsFabrics as $itemFabric) {
if ($itemFabric->isSupport($payload['event'])) {
$event = $itemFabric->create($request);
break;
}
}

$this->logger->debug('RemoteEventsFactory.create.eventCreated', [
'eventClassName' => $event::class,
'eventCode' => $event->getEventCode()
]);
return $event;
}

/**
* @param EventInterface $event
* @param non-empty-string $applicationToken
* @throws WrongSecuritySignatureException
* @throws InvalidArgumentException
*/
public function validate(EventInterface $event, string $applicationToken): void
{
if ($applicationToken === '') {
throw new InvalidArgumentException('application token cannot be empty string');
}

if ($event instanceof OnApplicationInstall) {
// skip OnApplicationInstall event check because application_token is null
// first event in application lifecycle is OnApplicationInstall and this event contains application_token
return;
}

// check event security signature
// see https://apidocs.bitrix24.com/api-reference/events/safe-event-handlers.html
// all next events MUST validate for application_token signature
if ($applicationToken !== $event->getAuth()->application_token) {
$this->logger->warning('RemoteEventsFactory.validate.eventNotValidSignature', [
'eventCode' => $event->getEventCode(),
'storedApplicationToken' => $applicationToken,
'eventApplicationToken' => $event->getAuth()->application_token,
'eventPayload' => $event->getEventPayload(),
]);

throw new WrongSecuritySignatureException(
sprintf(
'Wrong security signature for event %s',
$event->getEventCode()
)
);
}
}

/**
* Create event object from remote event request from Bitrix24
* If event supported in SDK it will create concrete object, in other cases it will be created UnsupportedRemoteEvent object
Expand All @@ -74,6 +139,7 @@ public static function isCanProcess(Request $request): bool
* @return EventInterface
* @throws InvalidArgumentException
* @throws WrongSecuritySignatureException
* @deprecated use RemoteEventsFactory::create and RemoteEventsFactory::validate instead
*/
public function createEvent(Request $request, ?string $applicationToken): EventInterface
{
Expand Down
Loading