From 252a36475cabce20021b422ebc6b53fdc93edc24 Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Wed, 7 Jun 2023 18:52:14 +0300 Subject: [PATCH 01/28] PSPD-12317 [PHP Client] Add new media methods and field --- README.md | 10 ++ src/Facade.php | 5 + src/MediaStorage/Builder.php | 113 ++++++++++++++++ src/MediaStorage/MediaStorage.php | 176 +++++++++++++++++++++++++ src/MediaStorageInterface.php | 38 ++++++ src/MediaStorageResult.php | 82 ++++++++++++ src/MediaStorageResultBaseField.php | 14 ++ src/PublicAPIClient.php | 16 +++ src/Requests/MediaStorage.php | 30 +++++ tests/Covery/BuildMediaStorageTest.php | 24 ++++ 10 files changed, 508 insertions(+) create mode 100644 src/MediaStorage/Builder.php create mode 100644 src/MediaStorage/MediaStorage.php create mode 100644 src/MediaStorageInterface.php create mode 100644 src/MediaStorageResult.php create mode 100644 src/MediaStorageResultBaseField.php create mode 100644 src/Requests/MediaStorage.php create mode 100644 tests/Covery/BuildMediaStorageTest.php diff --git a/README.md b/README.md index 650683c..8203ed8 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,15 @@ $event = Builder::cardIdEvent('curdNumber')->build(); $result = Facade::sendCardId($event); ``` +Media Storage event example: +```php +use Covery\Client\MediaStorage\Builder; +use Covery\Client\Facade; + +$event = Builder::mediaStorageEvent('image/jpeg', 'personal_photo', '', false)->build(); +$result = Facade::sendMediaStorage($event); +``` + # Tech Details @@ -191,6 +200,7 @@ You may provide the following as envelopes: ## Changelog +* `1.3.14` Added MediaStorage method * `1.3.13` Added StaleDataException exception * `1.3.12` Added sendCardId method * `1.3.11` Added VarDumpLogger and FileLogger diff --git a/src/Facade.php b/src/Facade.php index 5664899..1db2604 100644 --- a/src/Facade.php +++ b/src/Facade.php @@ -157,4 +157,9 @@ public static function sendCardId(CardIdInterface $cardId) { return self::getClient()->sendCardId($cardId); } + + public static function sendMediaStorage(MediaStorageInterface $mediaStorage) + { + return self::getClient()->sendMediaStorage($mediaStorage); + } } diff --git a/src/MediaStorage/Builder.php b/src/MediaStorage/Builder.php new file mode 100644 index 0000000..8221bff --- /dev/null +++ b/src/MediaStorage/Builder.php @@ -0,0 +1,113 @@ +addMediaStorageData($contentType, $contentDescription, $fileName, $ocr); + } + + /** + * Provides MediaStorage value + * + * @param $contentType + * @param $contentDescription + * @param $fileName + * @param $ocr + * @return Builder + */ + public function addMediaStorageData($contentType, $contentDescription, $fileName = '', $ocr = false) + { + if (!is_string($contentType)) { + throw new \InvalidArgumentException('Content type must be string'); + } + if (!is_string($contentDescription)) { + throw new \InvalidArgumentException('Content Description must be string'); + } + if (!is_string($fileName)) { + throw new \InvalidArgumentException('File name must be string'); + } + if (!is_bool($ocr)) { + throw new \InvalidArgumentException('Ocr must be bool'); + } + + $this->contentType = $contentType; + $this->contentDescription = $contentDescription; + $this->fileName = $fileName; + $this->ocr = $ocr; + + $this->replace('content_type', $contentType); + $this->replace('content_description', $contentDescription); + $this->replace('file_name', $fileName); + $this->replace('ocr', $ocr); + + return $this; + } + + /** + * Returns built MediaStorage + * + * @return MediaStorage + */ + public function build() + { + return new MediaStorage( + $this->contentType, + $this->contentDescription, + $this->fileName, + $this->ocr, + array_filter($this->data, function ($data) { + return $data !== null; + }) + ); + } + + /** + * Replaces value in internal array if provided value not empty + * + * @param string $key + * @param string|int|float|bool|null $value + */ + private function replace($key, $value) + { + if ($value !== null && $value !== '' && $value !== 0 && $value !== 0.0) { + $this->data[$key] = $value; + } + } +} diff --git a/src/MediaStorage/MediaStorage.php b/src/MediaStorage/MediaStorage.php new file mode 100644 index 0000000..73e40f2 --- /dev/null +++ b/src/MediaStorage/MediaStorage.php @@ -0,0 +1,176 @@ +contentType = $contentType; + $this->contentDescription = $contentDescription; + $this->fileName = $fileName; + $this->ocr = $ocr; + $this->data = $data; + } + + /** + * @return array + */ + public function toArray() + { + return $this->data; + } + + /** + * @return int + */ + public function count() + { + return count($this->data); + } + + /** + * @inheritDoc + */ + public function offsetExists($offset) + { + return array_key_exists($offset, $this->data); + } + + /** + * @inheritDoc + */ + public function offsetGet($offset) + { + if (!$this->offsetExists($offset)) { + throw new \OutOfBoundsException("No offset {$offset}"); + } + + return $this->data[$offset]; + } + + /** + * @inheritDoc + */ + public function offsetSet($offset, $value) + { + $this->data[$offset] = $value; + } + + /** + * @inheritDoc + */ + public function offsetUnset($offset) + { + if ($this->offsetExists($offset)) { + unset($this->data[$offset]); + } + } + + /** + * @inheritDoc + */ + public function getIterator() + { + return new \ArrayIterator($this->data); + } + + /** + * @return string + */ + public function getOcr() + { + return $this->ocr; + } + + /** + * @return string + */ + public function getFileName() + { + return $this->fileName; + } + + /** + * @return string + */ + public function getContentType() + { + return $this->contentType; + } + + /** + * @return string + */ + public function getContentDescription() + { + return $this->contentDescription; + } +} diff --git a/src/MediaStorageInterface.php b/src/MediaStorageInterface.php new file mode 100644 index 0000000..2fca150 --- /dev/null +++ b/src/MediaStorageInterface.php @@ -0,0 +1,38 @@ +uploadUrl = $uploadUrl; + $this->mediaId = $mediaId; + $this->createdAt = $createdAt; + } + + + /** + * @return string + */ + public function getUploadUrl() + { + return $this->uploadUrl; + } + + /** + * @return int + */ + public function getMediaId() + { + return $this->mediaId; + } + + /** + * @return float + */ + public function getCreatedAt() + { + return $this->createdAt; + } +} diff --git a/src/MediaStorageResultBaseField.php b/src/MediaStorageResultBaseField.php new file mode 100644 index 0000000..60f4090 --- /dev/null +++ b/src/MediaStorageResultBaseField.php @@ -0,0 +1,14 @@ +readJson($this->send(new MediaStorage($media))); + + if (!is_array($data)) { + throw new Exception("Malformed response"); + } + + return new MediaStorageResult( + $data[MediaStorageResultBaseField::UPLOAD_URL], + $data[MediaStorageResultBaseField::MEDIA_ID], + $data[MediaStorageResultBaseField::CREATED_AT] + ); + } } diff --git a/src/Requests/MediaStorage.php b/src/Requests/MediaStorage.php new file mode 100644 index 0000000..8b79331 --- /dev/null +++ b/src/Requests/MediaStorage.php @@ -0,0 +1,30 @@ +toArray()) + ); + } +} diff --git a/tests/Covery/BuildMediaStorageTest.php b/tests/Covery/BuildMediaStorageTest.php new file mode 100644 index 0000000..aac1db1 --- /dev/null +++ b/tests/Covery/BuildMediaStorageTest.php @@ -0,0 +1,24 @@ +build(); + + $request = new \Covery\Client\Requests\MediaStorage($mediaStorage); + + self::assertEquals($request->getMethod(), 'POST'); + self::assertContains($request->getUri()->getPath(), '/api/mediaStorage'); + } +} From 05dc8f602b4d4997f038a42fbcee41273d5c462a Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Thu, 8 Jun 2023 18:16:15 +0300 Subject: [PATCH 02/28] PSPD-12317 [PHP Client] Add new media methods and field --- src/Facade.php | 5 + src/MediaConnection/Builder.php | 88 ++++++++++++++++ src/MediaConnection/MediaConnection.php | 118 ++++++++++++++++++++++ src/MediaConnectionInterface.php | 28 +++++ src/MediaConnectionResult.php | 19 ++++ src/PublicAPIClient.php | 16 +++ src/Requests/MediaConnection.php | 31 ++++++ tests/Covery/BuildMediaConnectionTest.php | 19 ++++ tests/Covery/BuildMediaStorageTest.php | 2 +- 9 files changed, 325 insertions(+), 1 deletion(-) create mode 100644 src/MediaConnection/Builder.php create mode 100644 src/MediaConnection/MediaConnection.php create mode 100644 src/MediaConnectionInterface.php create mode 100644 src/MediaConnectionResult.php create mode 100644 src/Requests/MediaConnection.php create mode 100644 tests/Covery/BuildMediaConnectionTest.php diff --git a/src/Facade.php b/src/Facade.php index 1db2604..5412936 100644 --- a/src/Facade.php +++ b/src/Facade.php @@ -162,4 +162,9 @@ public static function sendMediaStorage(MediaStorageInterface $mediaStorage) { return self::getClient()->sendMediaStorage($mediaStorage); } + + public static function sendMediaConnection(MediaConnectionInterface $mediaConnection, $method = 'PUT') + { + return self::getClient()->sendMediaConnection($mediaConnection, $method); + } } diff --git a/src/MediaConnection/Builder.php b/src/MediaConnection/Builder.php new file mode 100644 index 0000000..15c5ec6 --- /dev/null +++ b/src/MediaConnection/Builder.php @@ -0,0 +1,88 @@ +addConnectionData($requestId, $mediaId); + } + + /** + * Provides MediaConnection value + * + * @param $requestId + * @param $mediaId + * @return Builder + */ + public function addConnectionData($requestId, $mediaId) + { + if (!is_int($requestId)) { + throw new \InvalidArgumentException('Request Id must be integer'); + } + if (!is_array($mediaId)) { + throw new \InvalidArgumentException('Media Id must be array'); + } + + $this->requestId = $requestId; + $this->mediaId = $mediaId; + + $this->replace('request_id', $requestId); + $this->replace('media_id', $mediaId); + + return $this; + } + + /** + * Returns built MediaConnection + * + * @return MediaConnection + */ + public function build() + { + return new MediaConnection( + $this->requestId, + $this->mediaId, + array_filter($this->data, function ($data) { + return $data !== null; + }) + ); + } + + /** + * Replaces value in internal array if provided value not empty + * + * @param string $key + * @param string|int|float|bool|array|null $value + */ + private function replace($key, $value) + { + if ($value !== null && $value !== '' && $value !== 0 && $value !== 0.0) { + $this->data[$key] = $value; + } + } +} diff --git a/src/MediaConnection/MediaConnection.php b/src/MediaConnection/MediaConnection.php new file mode 100644 index 0000000..ebb7fb9 --- /dev/null +++ b/src/MediaConnection/MediaConnection.php @@ -0,0 +1,118 @@ +requestId = $requestId; + $this->mediaId = $mediaId; + $this->data = $data; + } + + /** + * @return array + */ + public function toArray() + { + return $this->data; + } + + /** + * @return int + */ + public function count() + { + return count($this->data); + } + + /** + * @inheritDoc + */ + public function offsetExists($offset) + { + return array_key_exists($offset, $this->data); + } + + /** + * @inheritDoc + */ + public function offsetGet($offset) + { + if (!$this->offsetExists($offset)) { + throw new \OutOfBoundsException("No offset {$offset}"); + } + + return $this->data[$offset]; + } + + /** + * @inheritDoc + */ + public function offsetSet($offset, $value) + { + $this->data[$offset] = $value; + } + + /** + * @inheritDoc + */ + public function offsetUnset($offset) + { + if ($this->offsetExists($offset)) { + unset($this->data[$offset]); + } + } + + /** + * @inheritDoc + */ + public function getIterator() + { + return new \ArrayIterator($this->data); + } + + /** + * @return int + */ + public function getRequestId() + { + return $this->requestId; + } + + /** + * @return array + */ + public function getMediaId() + { + return $this->mediaId; + } +} diff --git a/src/MediaConnectionInterface.php b/src/MediaConnectionInterface.php new file mode 100644 index 0000000..c671b3f --- /dev/null +++ b/src/MediaConnectionInterface.php @@ -0,0 +1,28 @@ +getStatusCode(); + $this->statusCode = $code; $this->logger->debug('Received status code ' . $code); if ($code >= 400) { @@ -359,4 +365,14 @@ public function sendMediaStorage(MediaStorageInterface $media) $data[MediaStorageResultBaseField::CREATED_AT] ); } + + public function sendMediaConnection(MediaConnectionInterface $mediaConnection, $method) + { + $this->readJson($this->send(new \Covery\Client\Requests\MediaConnection($mediaConnection, $method))); + if ($this->statusCode >= 300) { + throw new Exception("Malformed response"); + } + + return new MediaConnectionResult(); + } } diff --git a/src/Requests/MediaConnection.php b/src/Requests/MediaConnection.php new file mode 100644 index 0000000..a9ecc59 --- /dev/null +++ b/src/Requests/MediaConnection.php @@ -0,0 +1,31 @@ +toArray()) + ); + } +} diff --git a/tests/Covery/BuildMediaConnectionTest.php b/tests/Covery/BuildMediaConnectionTest.php new file mode 100644 index 0000000..cccc721 --- /dev/null +++ b/tests/Covery/BuildMediaConnectionTest.php @@ -0,0 +1,19 @@ +build(); + + $request = new \Covery\Client\Requests\MediaConnection($mediaConnection); + self::assertEquals('PUT', $request->getMethod()); + self::assertContains($request->getUri()->getPath(), '/api/mediaConnection'); + } +} diff --git a/tests/Covery/BuildMediaStorageTest.php b/tests/Covery/BuildMediaStorageTest.php index aac1db1..6c6bca9 100644 --- a/tests/Covery/BuildMediaStorageTest.php +++ b/tests/Covery/BuildMediaStorageTest.php @@ -18,7 +18,7 @@ public function testBuild() $request = new \Covery\Client\Requests\MediaStorage($mediaStorage); - self::assertEquals($request->getMethod(), 'POST'); + self::assertEquals('POST', $request->getMethod()); self::assertContains($request->getUri()->getPath(), '/api/mediaStorage'); } } From 37abf607d252c698a61070fa6e0b0eba61e23ea9 Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Fri, 9 Jun 2023 17:18:23 +0300 Subject: [PATCH 03/28] PSPD-12317 [PHP Client] Add new media methods and field --- README.md | 17 +++++++++ src/Facade.php | 34 +++++++++++++++++ src/MediaConnectionResult.php | 19 ---------- src/MediaFileUploader.php | 54 +++++++++++++++++++++++++++ src/PublicAPIClient.php | 26 +++++++++++-- src/Requests/MediaFileUploader.php | 33 ++++++++++++++++ tests/Covery/UploadFileByLinkTest.php | 0 7 files changed, 160 insertions(+), 23 deletions(-) delete mode 100644 src/MediaConnectionResult.php create mode 100644 src/MediaFileUploader.php create mode 100644 src/Requests/MediaFileUploader.php create mode 100644 tests/Covery/UploadFileByLinkTest.php diff --git a/README.md b/README.md index 8203ed8..3089279 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,22 @@ $event = Builder::mediaStorageEvent('image/jpeg', 'personal_photo', '', false)-> $result = Facade::sendMediaStorage($event); ``` +Media Connection event example: +```php +use Covery\Client\MediaConnection\Builder; +use Covery\Client\Facade; + +$event = Builder::mediaConnectionEvent(1, 1)->build(); +$result = Facade::sendMediaConnection($event); +``` + +Media file upload example: +```php +use Covery\Client\Facade; + +$statusCode = \Covery\Client\Facade::uploadMediaFile($mediaUrl, $filePath); +``` + # Tech Details @@ -200,6 +216,7 @@ You may provide the following as envelopes: ## Changelog +* `1.3.15` Added MediaConnection method. Added UploadMediaFile method * `1.3.14` Added MediaStorage method * `1.3.13` Added StaleDataException exception * `1.3.12` Added sendCardId method diff --git a/src/Facade.php b/src/Facade.php index 5412936..3b2261c 100644 --- a/src/Facade.php +++ b/src/Facade.php @@ -158,13 +158,47 @@ public static function sendCardId(CardIdInterface $cardId) return self::getClient()->sendCardId($cardId); } + /** + * Send Media Storage data and return upload URL + * + * @param MediaStorageInterface $mediaStorage + * @return MediaStorageResult + * @throws Exception + * @throws IoException + */ public static function sendMediaStorage(MediaStorageInterface $mediaStorage) { return self::getClient()->sendMediaStorage($mediaStorage); } + /** + * Send Media Connection and return status code + * + * @param MediaConnectionInterface $mediaConnection + * @param $method + * @return int + * @throws Exception + * @throws IoException + */ public static function sendMediaConnection(MediaConnectionInterface $mediaConnection, $method = 'PUT') { return self::getClient()->sendMediaConnection($mediaConnection, $method); } + + /** + * Upload Media file and returns status code + * + * @param $url + * @param $filePath + * @return int + * @throws Exception + * @throws IoException + * @throws TimeoutException + */ + public static function uploadMediaFile($url, $filePath) + { + $mediaFileUploader = new MediaFileUploader($url, $filePath); + + return $mediaFileUploader->upload(); + } } diff --git a/src/MediaConnectionResult.php b/src/MediaConnectionResult.php deleted file mode 100644 index 11bb3e6..0000000 --- a/src/MediaConnectionResult.php +++ /dev/null @@ -1,19 +0,0 @@ -url = $url; + $this->filePath = $filePath; + } + + /** + * Upload media file + * + * @return int + * @throws Exception + * @throws IoException + * @throws TimeoutException + */ + public function upload() + { + $connectionTimeout = 60; + $transport = new Curl($connectionTimeout); + $response = $transport->send(new MediaFileUploaderRequest($this->url, $this->filePath)); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 300) { + $response = json_decode($response->getBody()->getContents()); + throw new Exception($response->message, $response->code); + } + + return $statusCode; + } +} diff --git a/src/PublicAPIClient.php b/src/PublicAPIClient.php index 01650c6..c26af41 100644 --- a/src/PublicAPIClient.php +++ b/src/PublicAPIClient.php @@ -10,6 +10,7 @@ use Covery\Client\Requests\MediaStorage; use Covery\Client\Requests\Ping; use Covery\Client\Requests\Postback; +use Covery\Client\Transport\Curl; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Psr\Log\LoggerInterface; @@ -40,7 +41,7 @@ class PublicAPIClient /** * @var int */ - private $statusCode; + private $responseStatusCode; /** * Client constructor. @@ -80,7 +81,7 @@ public function send(RequestInterface $request) throw new IoException('Error sending request', 0, $inner); } $code = $response->getStatusCode(); - $this->statusCode = $code; + $this->responseStatusCode = $code; $this->logger->debug('Received status code ' . $code); if ($code >= 400) { @@ -351,6 +352,14 @@ public function sendCardId(CardIdInterface $cardId) ); } + /** + * Send Media Storage data and return upload URL + * + * @param MediaStorageInterface $media + * @return MediaStorageResult + * @throws Exception + * @throws IoException + */ public function sendMediaStorage(MediaStorageInterface $media) { $data = $this->readJson($this->send(new MediaStorage($media))); @@ -366,13 +375,22 @@ public function sendMediaStorage(MediaStorageInterface $media) ); } + /** + * Send Media Connection and return status code + * + * @param MediaConnectionInterface $mediaConnection + * @param $method + * @return int + * @throws Exception + * @throws IoException + */ public function sendMediaConnection(MediaConnectionInterface $mediaConnection, $method) { $this->readJson($this->send(new \Covery\Client\Requests\MediaConnection($mediaConnection, $method))); - if ($this->statusCode >= 300) { + if ($this->responseStatusCode >= 300) { throw new Exception("Malformed response"); } - return new MediaConnectionResult(); + return $this->responseStatusCode; } } diff --git a/src/Requests/MediaFileUploader.php b/src/Requests/MediaFileUploader.php new file mode 100644 index 0000000..aa7ef96 --- /dev/null +++ b/src/Requests/MediaFileUploader.php @@ -0,0 +1,33 @@ + 'application/octet-stream', + ], + $resourceFileText + ); + } +} diff --git a/tests/Covery/UploadFileByLinkTest.php b/tests/Covery/UploadFileByLinkTest.php new file mode 100644 index 0000000..e69de29 From 549c463fa075af243859b743b62a01de90bbcc23 Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Mon, 12 Jun 2023 21:45:34 +0300 Subject: [PATCH 04/28] PSPD-12317 [PHP Client] Add new media methods and field --- README.md | 9 +- src/AccountConfigurationStatusResult.php | 294 ++++++++++++++++++ ...ountConfigurationStatusResultBaseField.php | 26 ++ src/Envelopes/Builder.php | 140 +++++++-- src/Envelopes/ValidatorV1.php | 34 +- src/Facade.php | 12 + src/MediaFileUploader.php | 12 +- src/PublicAPIClient.php | 37 ++- src/Requests/AccountConfigurationStatus.php | 25 ++ src/Requests/MediaFileUploader.php | 8 +- .../BuildAccountConfigurationStatusTest.php | 12 + .../Covery/BuildConfirmationEnvelopeTest.php | 6 +- tests/Covery/BuildInstallEventTest.php | 6 +- tests/Covery/BuildKYCProfileEnvelopeTest.php | 14 +- tests/Covery/BuildKYCSubmitEnvelopeTest.php | 14 +- tests/Covery/BuildLoginEnvelopeTest.php | 6 +- tests/Covery/BuildOrderItemEnvelopeTest.php | 6 +- tests/Covery/BuildOrderSubmitEnvelopeTest.php | 6 +- tests/Covery/BuildPayoutEventTest.php | 6 +- tests/Covery/BuildProfileUpdateEventTest.php | 6 +- tests/Covery/BuildRefundEventTest.php | 6 +- tests/Covery/BuildRegistrationEventTest.php | 6 +- tests/Covery/BuildTransactionEventTest.php | 6 +- tests/Covery/BuildTransferEventTest.php | 6 +- 24 files changed, 630 insertions(+), 73 deletions(-) create mode 100644 src/AccountConfigurationStatusResult.php create mode 100644 src/AccountConfigurationStatusResultBaseField.php create mode 100644 src/Requests/AccountConfigurationStatus.php create mode 100644 tests/Covery/BuildAccountConfigurationStatusTest.php diff --git a/README.md b/README.md index 3089279..4904e8a 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,13 @@ use Covery\Client\Facade; $statusCode = \Covery\Client\Facade::uploadMediaFile($mediaUrl, $filePath); ``` +Account Configuration Status event example: +```php +use Covery\Client\Facade; + +$accountConfigurationStatus = Facade::getAccountConfigurationStatus(); +``` + # Tech Details @@ -216,7 +223,7 @@ You may provide the following as envelopes: ## Changelog -* `1.3.15` Added MediaConnection method. Added UploadMediaFile method +* `1.3.15` Added MediaConnection method. Added UploadMediaFile method. Added optional `media_id` field for install, registration event * `1.3.14` Added MediaStorage method * `1.3.13` Added StaleDataException exception * `1.3.12` Added sendCardId method diff --git a/src/AccountConfigurationStatusResult.php b/src/AccountConfigurationStatusResult.php new file mode 100644 index 0000000..6c567f2 --- /dev/null +++ b/src/AccountConfigurationStatusResult.php @@ -0,0 +1,294 @@ +actualEventTypes = $actualEventTypes; + $this->baseCurrency = $baseCurrency; + $this->decisionCallbackUrl = $decisionCallbackUrl; + $this->manualDecisionCallbackUrl = $manualDecisionCallbackUrl; + $this->ongoingMonitoringWebhookUrl = $ongoingMonitoringWebhookUrl; + $this->mediaStorageWebhookUrl = $mediaStorageWebhookUrl; + $this->fraudAlertCallbackUrl = $fraudAlertCallbackUrl; + $this->cardIdGeneration = $cardIdGeneration; + $this->deviceFingerprintGeneration = $deviceFingerprintGeneration; + $this->sequenceIdGeneration = $sequenceIdGeneration; + $this->sequenceIdGenerationMethod = $sequenceIdGenerationMethod; + $this->amlService = $amlService; + $this->amlServiceStatus = $amlServiceStatus; + $this->dowJonesDataBaseDate = $dowJonesDataBaseDate; + $this->kycProvider = $kycProvider; + } + + /** + * @return string + */ + public function getActualEventTypes() + { + return $this->actualEventTypes; + } + + /** + * @return string + */ + public function getBaseCurrency() + { + return $this->baseCurrency; + } + + /** + * @return string + */ + public function getDecisionCallbackUrl() + { + return $this->decisionCallbackUrl; + } + + /** + * @return string + */ + public function getManualDecisionCallbackUrl() + { + return $this->manualDecisionCallbackUrl; + } + + /** + * @return string + */ + public function getOngoingMonitoringWebhookUrl() + { + return $this->ongoingMonitoringWebhookUrl; + } + + /** + * @return string + */ + public function getMediaStorageWebhookUrl() + { + return $this->mediaStorageWebhookUrl; + } + + /** + * @return string + */ + public function getFraudAlertCallbackUrl() + { + return $this->fraudAlertCallbackUrl; + } + + /** + * @return bool + */ + public function isCardIdGeneration() + { + return $this->cardIdGeneration; + } + + /** + * @return bool + */ + public function isDeviceFingerprintGeneration() + { + return $this->deviceFingerprintGeneration; + } + + /** + * @return bool + */ + public function isSequenceIdGeneration() + { + return $this->sequenceIdGeneration; + } + + /** + * @return string + */ + public function getSequenceIdGenerationMethod() + { + return $this->sequenceIdGenerationMethod; + } + + /** + * @return string + */ + public function getAmlService() + { + return $this->amlService; + } + + /** + * @return bool + */ + public function isAmlServiceStatus() + { + return $this->amlServiceStatus; + } + + /** + * @return string + */ + public function getDowJonesDataBaseDate() + { + return $this->dowJonesDataBaseDate; + } + + /** + * @return string + */ + public function getKycProvider() + { + return $this->kycProvider; + } +} diff --git a/src/AccountConfigurationStatusResultBaseField.php b/src/AccountConfigurationStatusResultBaseField.php new file mode 100644 index 0000000..ead7a98 --- /dev/null +++ b/src/AccountConfigurationStatusResultBaseField.php @@ -0,0 +1,26 @@ +addGroupId($groupId); + ) + ->addGroupId($groupId) + ->addMediaId($mediaId); } /** @@ -103,7 +106,8 @@ public static function loginEvent( $affiliateId = null, $password = null, $campaign = null, - $groupId = null + $groupId = null, + $mediaId = null ) { $builder = new self('login', $sequenceId); if ($timestamp === null) { @@ -134,7 +138,10 @@ public static function loginEvent( null, null, $password - )->addWebsiteData(null, $trafficSource, $affiliateId, $campaign)->addGroupId($groupId); + ) + ->addWebsiteData(null, $trafficSource, $affiliateId, $campaign) + ->addGroupId($groupId) + ->addMediaId($mediaId); } /** @@ -179,7 +186,8 @@ public static function registrationEvent( $affiliateId = null, $password = null, $campaign = null, - $groupId = null + $groupId = null, + $mediaId = null ) { $builder = new self('registration', $sequenceId); if ($timestamp === null) { @@ -215,7 +223,9 @@ public static function registrationEvent( null, null, $password - )-> addGroupId($groupId); + ) + ->addGroupId($groupId) + ->addMediaId($mediaId); } /** @@ -270,7 +280,8 @@ public static function payoutEvent( $cardExpirationMonth = null, $cardExpirationYear = null, $groupId = null, - $linksToDocuments = null + $linksToDocuments = null, + $mediaId = null ) { $builder = new self('payout', $sequenceId); if ($payoutTimestamp === null) { @@ -295,7 +306,8 @@ public static function payoutEvent( ) ->addShortUserData($email, $userId, $phone, $firstName, $lastName, $country) ->addGroupId($groupId) - ->addLinksToDocuments($linksToDocuments); + ->addLinksToDocuments($linksToDocuments) + ->addMediaId($mediaId); } /** @@ -398,7 +410,8 @@ public static function transactionEvent( $mcc = null, $acquirerMerchantId = null, $groupId = null, - $linksToDocuments = null + $linksToDocuments = null, + $mediaId = null ) { $builder = new self('transaction', $sequenceId); if ($transactionTimestamp === null) { @@ -449,7 +462,8 @@ public static function transactionEvent( ->addWebsiteData($websiteUrl, null, $affiliateId, $campaign) ->addIpData(null, null, $merchantIp) ->addGroupId($groupId) - ->addLinksToDocuments($linksToDocuments); + ->addLinksToDocuments($linksToDocuments) + ->addMediaId($mediaId); } @@ -465,6 +479,7 @@ public static function transactionEvent( * @param string|null $affiliateId * @param string|null $campaign * @param string|null $groupId + * @param array|null $mediaId * @return Builder */ public static function installEvent( @@ -476,7 +491,8 @@ public static function installEvent( $trafficSource = null, $affiliateId = null, $campaign = null, - $groupId = null + $groupId = null, + $mediaId = null ) { $builder = new self('install', $sequenceId); if ($installTimestamp === null) { @@ -487,7 +503,8 @@ public static function installEvent( $installTimestamp )->addWebsiteData($websiteUrl, $trafficSource, $affiliateId, $campaign) ->addShortUserData(null, $userId, null, null, null, $country) - ->addGroupId($groupId); + ->addGroupId($groupId) + ->addMediaId($mediaId); } /** @@ -534,7 +551,8 @@ public static function refundEvent( $phone = null, $userId = null, $groupId = null, - $linksToDocuments = null + $linksToDocuments = null, + $mediaId = null ) { $builder = new self('refund', $sequenceId); if ($refundTimestamp === null) { @@ -559,7 +577,8 @@ public static function refundEvent( ) ->addUserData($email, $userId, $phone) ->addGroupId($groupId) - ->addLinksToDocuments($linksToDocuments); + ->addLinksToDocuments($linksToDocuments) + ->addMediaId($mediaId); } /** @@ -660,7 +679,8 @@ public static function transferEvent( $source = null, $groupId = null, $secondUserMerchantId = null, - $linksToDocuments = null + $linksToDocuments = null, + $mediaId = null ) { $builder = new self('transfer', $sequenceId); if ($eventTimestamp === null) { @@ -724,7 +744,8 @@ public static function transferEvent( ) ->addProductData($productQuantity, $productName, $productDescription) ->addGroupId($groupId) - ->addLinksToDocuments($linksToDocuments); + ->addLinksToDocuments($linksToDocuments) + ->addMediaId($mediaId); } /** @@ -832,7 +853,10 @@ public static function kycProfileEvent( $issueDate = null, $expiryDate = null, $gender = null, - $linksToDocuments = null + $linksToDocuments = null, + $mediaId = null, + $addressConfirmed = false, + $secondAddressConfirmed = false ) { $builder = new self('kyc_profile', $sequenceId); if ($eventTimestamp === null) { @@ -899,7 +923,10 @@ public static function kycProfileEvent( null ) ->addWebsiteData($websiteUrl) - ->addLinksToDocuments($linksToDocuments); + ->addLinksToDocuments($linksToDocuments) + ->addMediaId($mediaId) + ->addAddressConfirmed($addressConfirmed) + ->addSecondAddressConfirmed($secondAddressConfirmed); } /** @@ -998,6 +1025,7 @@ public static function kycProfileEvent( * @param null $refererUrl * @param null $originUrl * @param string|null $linksToDocuments + * @param null $mediaId * @return static */ public static function profileUpdateEvent( @@ -1095,7 +1123,8 @@ public static function profileUpdateEvent( $plugins = null, $refererUrl = null, $originUrl = null, - $linksToDocuments = null + $linksToDocuments = null, + $mediaId = null ) { $builder = new self(self::EVENT_PROFILE_UPDATE, $sequenceId); @@ -1195,7 +1224,8 @@ public static function profileUpdateEvent( $refererUrl, $originUrl ) - ->addLinksToDocuments($linksToDocuments); + ->addLinksToDocuments($linksToDocuments) + ->addMediaId($mediaId); } @@ -1289,7 +1319,10 @@ public static function kycSubmitEvent( $userAgent = null, $plugins = null, $refererUrl = null, - $originUrl = null + $originUrl = null, + $mediaId = null, + $addressConfirmed = false, + $secondAddressConfirmed = false ) { $builder = new self('kyc_submit', $sequenceId); if ($eventTimestamp === null) { @@ -1371,7 +1404,10 @@ public static function kycSubmitEvent( null, $userId ) - ->addLinksToDocuments($linksToDocuments); + ->addLinksToDocuments($linksToDocuments) + ->addMediaId($mediaId) + ->addAddressConfirmed($addressConfirmed) + ->addSecondAddressConfirmed($secondAddressConfirmed); } /** @@ -1625,7 +1661,8 @@ public static function orderItemEvent( $userMerchantId = null, $websiteUrl = null, $productUrl = null, - $productImageUrl = null + $productImageUrl = null, + $mediaId = null ) { $envelopeType = 'order_item'; $builder = new self($envelopeType, $sequenceId); @@ -1694,7 +1731,8 @@ public static function orderItemEvent( $websiteUrl, null, $affiliateId - ); + ) + ->addMediaId($mediaId); } /** @@ -1792,7 +1830,8 @@ public static function orderSubmitEvent( $userMerchantId = null, $websiteUrl = null, $productUrl = null, - $productImageUrl = null + $productImageUrl = null, + $mediaId = null ) { $envelopeType = 'order_submit'; $builder = new self($envelopeType, $sequenceId); @@ -1856,7 +1895,8 @@ public static function orderSubmitEvent( $websiteUrl, null, $affiliateId - ); + ) + ->addMediaId($mediaId); } /** @@ -3607,6 +3647,54 @@ public function addGroupId($groupId = null) return $this; } + /** + * Provides media id value to envelope + * + * @param array|null $mediaId + * @return $this + */ + public function addMediaId($mediaId = null) + { + if ($mediaId !== null && !is_array($mediaId)) { + throw new \InvalidArgumentException('Media id must be string'); + } + $this->replace('media_id', $mediaId); + + return $this; + } + + /** + * Provides address confirmed value to envelope + * + * @param bool $addressConfirmed + * @return $this + */ + public function addAddressConfirmed($addressConfirmed = false) + { + if (!is_bool($addressConfirmed)) { + throw new \InvalidArgumentException('Address Confirmed must be bool'); + } + $this->replace('address_confirmed', $addressConfirmed); + + return $this; + } + + /** + * Provides address confirmed value to envelope + * + * @param bool $secondAddressConfirmed + * @return $this + */ + public function addSecondAddressConfirmed($secondAddressConfirmed = false) + { + if (!is_bool($secondAddressConfirmed)) { + throw new \InvalidArgumentException('Second Address Confirmed must be bool'); + } + $this->replace('second_address_confirmed', $secondAddressConfirmed); + + return $this; + } + /** * Add links to documents * diff --git a/src/Envelopes/ValidatorV1.php b/src/Envelopes/ValidatorV1.php index dfef3c8..e960ec7 100644 --- a/src/Envelopes/ValidatorV1.php +++ b/src/Envelopes/ValidatorV1.php @@ -241,6 +241,7 @@ class ValidatorV1 'active_features' => 'string(1024)', 'promotions' => 'string(1024)', 'links_to_documents' => 'string(2048)', + 'media_id' => 'array', ); private static $sharedOptional = array( @@ -272,7 +273,7 @@ class ValidatorV1 private static $types = array( 'confirmation' => array( 'mandatory' => array('confirmation_timestamp', 'user_merchant_id'), - 'optional' => array('email_confirmed', 'phone_confirmed', 'email', 'phone', "group_id"), + 'optional' => array('email_confirmed', 'phone_confirmed', 'email', 'phone', "group_id", "media_id"), ), 'login' => array( 'mandatory' => array('login_timestamp', 'user_merchant_id'), @@ -285,7 +286,8 @@ class ValidatorV1 'affiliate_id', 'password', 'campaign', - "group_id" + "group_id", + "media_id", ) ), 'registration' => array( @@ -305,7 +307,8 @@ class ValidatorV1 'affiliate_id', 'password', 'campaign', - "group_id" + "group_id", + "media_id", ), ), 'transaction' => array( @@ -358,6 +361,7 @@ class ValidatorV1 'acquirer_merchant_id', 'group_id', 'links_to_documents', + 'media_id', ) ), 'payout' => array( @@ -386,6 +390,7 @@ class ValidatorV1 'payout_expiration_year', 'group_id', 'links_to_documents', + 'media_id', ) ), 'install' => array( @@ -399,7 +404,8 @@ class ValidatorV1 'traffic_source', 'affiliate_id', 'campaign', - "group_id" + "group_id", + "media_id", ) ), 'refund' => array( @@ -424,6 +430,7 @@ class ValidatorV1 'user_merchant_id', 'group_id', 'links_to_documents', + 'media_id', ) ), 'transfer' => array( @@ -475,6 +482,7 @@ class ValidatorV1 'account_id', 'second_account_id', 'links_to_documents', + 'media_id', ) ), 'postback' => array( @@ -547,6 +555,9 @@ class ValidatorV1 'expiry_date', 'gender', 'links_to_documents', + 'media_id', + 'address_confirmed', + 'second_address_confirmed', ) ), 'kyc_submit' => array( @@ -624,6 +635,9 @@ class ValidatorV1 'plugins', 'referer_url', 'origin_url', + 'media_id', + 'address_confirmed', + 'second_address_confirmed', ) ), 'kyc_start' => array( @@ -713,6 +727,7 @@ class ValidatorV1 "product_image_url", "carrier_url", "carrier_phone", + 'media_id', ) ), 'order_submit' => array( @@ -763,6 +778,7 @@ class ValidatorV1 "product_image_url", "carrier_url", "carrier_phone", + 'media_id', ) ), 'profile_update' => array( @@ -864,6 +880,7 @@ class ValidatorV1 "referer_url", "origin_url", "links_to_documents", + "media_id", ) ), ); @@ -1021,6 +1038,15 @@ public function analyzeFieldTypes(EnvelopeInterface $envelope) ); } break; + case 'array': + if (!is_array($value)) { + $details[] = sprintf( + 'Field "%s" must be array, but %s provided', + $key, + $value === null ? 'null' : gettype($value) + ); + } + break; default: $details[] = sprintf('Unknown type for "%s"', $key); } diff --git a/src/Facade.php b/src/Facade.php index 3b2261c..0038d9b 100644 --- a/src/Facade.php +++ b/src/Facade.php @@ -201,4 +201,16 @@ public static function uploadMediaFile($url, $filePath) return $mediaFileUploader->upload(); } + + /** + * Get account configuration status and return result object + * + * @return AccountConfigurationStatusResult + * @throws Exception + * @throws IoException + */ + public static function getAccountConfigurationStatus() + { + return self::getClient()->getAccountConfigurationStatus(); + } } diff --git a/src/MediaFileUploader.php b/src/MediaFileUploader.php index f6d43d8..f858d6b 100644 --- a/src/MediaFileUploader.php +++ b/src/MediaFileUploader.php @@ -14,20 +14,20 @@ class MediaFileUploader /** * @var string */ - private $filePath; + private $file; - public function __construct($url, $filePath) + public function __construct($url, $file) { if (!is_string($url)) { throw new \InvalidArgumentException('Url must be string'); } - if (!is_string($filePath)) { - throw new \InvalidArgumentException('File path must be string'); + if (!is_resource($file)) { + throw new \InvalidArgumentException('File must be resource'); } $this->url = $url; - $this->filePath = $filePath; + $this->file = $file; } /** @@ -42,7 +42,7 @@ public function upload() { $connectionTimeout = 60; $transport = new Curl($connectionTimeout); - $response = $transport->send(new MediaFileUploaderRequest($this->url, $this->filePath)); + $response = $transport->send(new MediaFileUploaderRequest($this->url, $this->file)); $statusCode = $response->getStatusCode(); if ($statusCode >= 300) { $response = json_decode($response->getBody()->getContents()); diff --git a/src/PublicAPIClient.php b/src/PublicAPIClient.php index c26af41..b4e6d79 100644 --- a/src/PublicAPIClient.php +++ b/src/PublicAPIClient.php @@ -10,12 +10,10 @@ use Covery\Client\Requests\MediaStorage; use Covery\Client\Requests\Ping; use Covery\Client\Requests\Postback; -use Covery\Client\Transport\Curl; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; -use Covery\Client\Requests\MediaConnection; class PublicAPIClient { @@ -393,4 +391,39 @@ public function sendMediaConnection(MediaConnectionInterface $mediaConnection, $ return $this->responseStatusCode; } + + /** + * Get Account configuration status object from Covery + * + * @return AccountConfigurationStatusResult + * @throws Exception + * @throws IoException + */ + public function getAccountConfigurationStatus() + { + // Sending + $data = $this->readJson($this->send(new \Covery\Client\Requests\AccountConfigurationStatus())); + + if (!is_array($data)) { + throw new Exception("Malformed response"); + } + + return new AccountConfigurationStatusResult( + $data[AccountConfigurationStatusResultBaseField::ACTUAL_EVENT_TYPES], + $data[AccountConfigurationStatusResultBaseField::BASE_CURRENCY], + $data[AccountConfigurationStatusResultBaseField::DECISION_CALLBACK_URL], + $data[AccountConfigurationStatusResultBaseField::MANUAL_DECISION_CALLBACK_URL], + $data[AccountConfigurationStatusResultBaseField::ONGOING_MONITORING_WEBHOOK_URL], + $data[AccountConfigurationStatusResultBaseField::MEDIA_STORAGE_WEBHOOK_URL], + $data[AccountConfigurationStatusResultBaseField::FRAUD_ALERT_CALLBACK_URL], + $data[AccountConfigurationStatusResultBaseField::CARD_ID_GENERATION], + $data[AccountConfigurationStatusResultBaseField::DEVICE_FINGERPRINT_GENERATION], + $data[AccountConfigurationStatusResultBaseField::SEQUENCE_ID_GENERATION], + $data[AccountConfigurationStatusResultBaseField::SEQUENCE_ID_GENERATION_METHOD], + $data[AccountConfigurationStatusResultBaseField::AML_SERVICE], + $data[AccountConfigurationStatusResultBaseField::AML_SERVICE_STATUS], + $data[AccountConfigurationStatusResultBaseField::DOW_JONES_DATA_BASE_DATE], + $data[AccountConfigurationStatusResultBaseField::KYC_PROVIDER] + ); + } } diff --git a/src/Requests/AccountConfigurationStatus.php b/src/Requests/AccountConfigurationStatus.php new file mode 100644 index 0000000..ee4b646 --- /dev/null +++ b/src/Requests/AccountConfigurationStatus.php @@ -0,0 +1,25 @@ + 'application/octet-stream', ], - $resourceFileText + $resourceBinary ); } } diff --git a/tests/Covery/BuildAccountConfigurationStatusTest.php b/tests/Covery/BuildAccountConfigurationStatusTest.php new file mode 100644 index 0000000..3b06fb1 --- /dev/null +++ b/tests/Covery/BuildAccountConfigurationStatusTest.php @@ -0,0 +1,12 @@ +getMethod()); + self::assertContains($request->getUri()->getPath(), '/api/accountConfigurationStatus'); + } +} \ No newline at end of file diff --git a/tests/Covery/BuildConfirmationEnvelopeTest.php b/tests/Covery/BuildConfirmationEnvelopeTest.php index 3d429ba..1f7bf4e 100644 --- a/tests/Covery/BuildConfirmationEnvelopeTest.php +++ b/tests/Covery/BuildConfirmationEnvelopeTest.php @@ -15,13 +15,14 @@ public function testBuild() false, null, null, - "group id value" + "group id value", + [1, 2] )->addIdentity(new \Covery\Client\Identities\Stub())->build(); self::assertSame('confirmation', $result->getType()); self::assertCount(1, $result->getIdentities()); self::assertSame('sequenceIdSome', $result->getSequenceId()); - self::assertCount(5, $result); + self::assertCount(6, $result); self::assertSame('ababagalamaga', $result['user_merchant_id']); self::assertSame(42342352, $result['confirmation_timestamp']); self::assertTrue($result['email_confirmed']); @@ -29,6 +30,7 @@ public function testBuild() self::assertArrayNotHasKey('email', $result); self::assertArrayNotHasKey('phone', $result); self::assertSame('group id value', $result['group_id']); + self::assertSame([1, 2], $result['media_id']); $validator->validate($result); // Minimal data diff --git a/tests/Covery/BuildInstallEventTest.php b/tests/Covery/BuildInstallEventTest.php index 34148e8..5ec0254 100644 --- a/tests/Covery/BuildInstallEventTest.php +++ b/tests/Covery/BuildInstallEventTest.php @@ -16,13 +16,14 @@ public function testBuild() 'source', 'affId12345', 'email campaign', - "group id value" + "group id value", + [1, 2] )->addBrowserData('88889', 'Test curl')->addIdentity(new \Covery\Client\Identities\Stub())->build(); self::assertSame('install', $result->getType()); self::assertCount(1, $result->getIdentities()); self::assertSame('someSequenceId', $result->getSequenceId()); - self::assertCount(10, $result); + self::assertCount(11, $result); self::assertSame('fooUserId', $result['user_merchant_id']); self::assertSame(123456, $result['install_timestamp']); self::assertSame('ukr', $result['country']); @@ -31,6 +32,7 @@ public function testBuild() self::assertSame('affId12345', $result['affiliate_id']); self::assertSame('email campaign', $result['campaign']); self::assertSame('group id value', $result['group_id']); + self::assertSame([1, 2], $result['media_id']); $validator->validate($result); // Minimal data diff --git a/tests/Covery/BuildKYCProfileEnvelopeTest.php b/tests/Covery/BuildKYCProfileEnvelopeTest.php index 4642e1e..411844e 100644 --- a/tests/Covery/BuildKYCProfileEnvelopeTest.php +++ b/tests/Covery/BuildKYCProfileEnvelopeTest.php @@ -57,12 +57,15 @@ public function testBuild() 999, 888, "male", - 'linksToDocuments' + 'linksToDocuments', + [1, 2], + true, + true )->addIdentity(new \Covery\Client\Identities\Stub())->build(); self::assertSame('kyc_profile', $result->getType()); self::assertSame('kycProfileSequenceIdSome', $result->getSequenceId()); - self::assertCount(49, $result); + self::assertCount(52, $result); self::assertSame('kycProfileEventId', $result['event_id']); self::assertSame(123456, $result['event_timestamp']); self::assertSame('kycProfileUserMerchantId', $result['user_merchant_id']); @@ -112,6 +115,9 @@ public function testBuild() self::assertSame(888, $result['expiry_date']); self::assertSame('male', $result['gender']); self::assertSame('linksToDocuments', $result['links_to_documents']); + self::assertSame([1, 2], $result['media_id']); + self::assertTrue($result['address_confirmed']); + self::assertTrue($result['second_address_confirmed']); $validator->validate($result); @@ -127,7 +133,7 @@ public function testBuild() self::assertSame('kyc_profile', $result->getType()); self::assertSame('seqIdValue', $result->getSequenceId()); self::assertCount(1, $result->getIdentities()); - self::assertCount(3, $result); + self::assertCount(5, $result); self::assertSame('eventId', $result['event_id']); self::assertSame('userId', $result['user_merchant_id']); self::assertTrue($result['event_timestamp'] >= $current); @@ -148,7 +154,7 @@ public function testBuild() self::assertSame('kyc_profile', $result->getType()); self::assertSame('seqIdValue', $result->getSequenceId()); self::assertCount(0, $result->getIdentities()); - self::assertCount(6, $result); + self::assertCount(8, $result); self::assertSame('eventId', $result['event_id']); self::assertSame('userId', $result['user_merchant_id']); self::assertSame(333, $result['event_timestamp']); diff --git a/tests/Covery/BuildKYCSubmitEnvelopeTest.php b/tests/Covery/BuildKYCSubmitEnvelopeTest.php index 25be9ba..7ea769b 100644 --- a/tests/Covery/BuildKYCSubmitEnvelopeTest.php +++ b/tests/Covery/BuildKYCSubmitEnvelopeTest.php @@ -79,13 +79,16 @@ public function testBuild() 'KycSubmitUserAgent', 'KycSubmitPlugins', 'KycSubmitRefererUrl', - 'KycSubmitOriginUrl' + 'KycSubmitOriginUrl', + [1, 2], + true, + true )->addIdentity(new \Covery\Client\Identities\Stub())->build(); self::assertSame('kyc_submit', $result->getType()); self::assertSame('kycSubmitSequenceIdSome', $result->getSequenceId()); - self::assertCount(71, $result); + self::assertCount(74, $result); self::assertSame('kycSubmitEventId', $result['event_id']); self::assertSame(1234568, $result['event_timestamp']); self::assertSame('kycSubmitUserMerchantId', $result['user_merchant_id']); @@ -157,6 +160,9 @@ public function testBuild() self::assertSame('KycSubmitPlugins', $result['plugins']); self::assertSame('KycSubmitRefererUrl', $result['referer_url']); self::assertSame('KycSubmitOriginUrl', $result['origin_url']); + self::assertSame([1, 2], $result['media_id']); + self::assertTrue($result['address_confirmed']); + self::assertTrue($result['second_address_confirmed']); $validator->validate($result); @@ -174,7 +180,7 @@ public function testBuild() self::assertSame('kyc_submit', $result->getType()); self::assertSame('seqIdValue', $result->getSequenceId()); self::assertCount(1, $result->getIdentities()); - self::assertCount(3, $result); + self::assertCount(5, $result); self::assertSame('eventId', $result['event_id']); self::assertSame('userId', $result['user_merchant_id']); self::assertTrue($result['event_timestamp'] >= $current); @@ -195,7 +201,7 @@ public function testBuild() self::assertSame('kyc_submit', $result->getType()); self::assertSame('seqIdValue', $result->getSequenceId()); self::assertCount(0, $result->getIdentities()); - self::assertCount(6, $result); + self::assertCount(8, $result); self::assertSame('eventId', $result['event_id']); self::assertSame('userId', $result['user_merchant_id']); self::assertSame(333, $result['event_timestamp']); diff --git a/tests/Covery/BuildLoginEnvelopeTest.php b/tests/Covery/BuildLoginEnvelopeTest.php index b4d3472..6386537 100644 --- a/tests/Covery/BuildLoginEnvelopeTest.php +++ b/tests/Covery/BuildLoginEnvelopeTest.php @@ -18,13 +18,14 @@ public function testBuild() 'someAffiliateId', "somePassword", "email campaign", - "group id value" + "group id value", + [1, 2] )->addIdentity(new \Covery\Client\Identities\Stub())->build(); self::assertSame('login', $result->getType()); self::assertCount(1, $result->getIdentities()); self::assertSame('someSequenceId', $result->getSequenceId()); - self::assertCount(10, $result); + self::assertCount(11, $result); self::assertSame('someUserId', $result['user_merchant_id']); self::assertSame(123456, $result['login_timestamp']); self::assertSame('foo@bar.com', $result['email']); @@ -34,6 +35,7 @@ public function testBuild() self::assertSame('somePassword', $result['password']); self::assertSame('email campaign', $result['campaign']); self::assertSame('group id value', $result['group_id']); + self::assertSame([1, 2], $result['media_id']); self::assertTrue($result['login_failed']); $validator->validate($result); diff --git a/tests/Covery/BuildOrderItemEnvelopeTest.php b/tests/Covery/BuildOrderItemEnvelopeTest.php index 6dfcad3..6d6a7ee 100644 --- a/tests/Covery/BuildOrderItemEnvelopeTest.php +++ b/tests/Covery/BuildOrderItemEnvelopeTest.php @@ -54,7 +54,8 @@ public function testBuild() "userMerchantId", "websiteUrl", "productUrl", - "productImageUrl" + "productImageUrl", + [1, 2] )->addIdentity(new \Covery\Client\Identities\Stub() )->addBrowserData( "deviceFingerprint", @@ -81,7 +82,7 @@ public function testBuild() )->build(); self::assertSame('order_item', $result->getType()); - self::assertCount(68, $result); + self::assertCount(69, $result); self::assertCount(1, $result->getIdentities()); self::assertSame('sequenceId', $result->getSequenceId()); self::assertSame(123.456, $result["amount"]); @@ -152,6 +153,7 @@ public function testBuild() self::assertSame(true, $result["cookie_enabled"]); self::assertSame(false, $result["do_not_track"]); self::assertSame(true, $result["ajax_validation"]); + self::assertSame([1, 2], $result["media_id"]); $validator->validate($result); diff --git a/tests/Covery/BuildOrderSubmitEnvelopeTest.php b/tests/Covery/BuildOrderSubmitEnvelopeTest.php index c568978..0a0a2ed 100644 --- a/tests/Covery/BuildOrderSubmitEnvelopeTest.php +++ b/tests/Covery/BuildOrderSubmitEnvelopeTest.php @@ -51,7 +51,8 @@ public function testBuild() "userMerchantId", "websiteUrl", "productUrl", - "productImageUrl" + "productImageUrl", + [1, 2] )->addIdentity(new \Covery\Client\Identities\Stub() )->addBrowserData( "deviceFingerprint", @@ -78,7 +79,7 @@ public function testBuild() )->build(); self::assertSame('order_submit', $result->getType()); - self::assertCount(65, $result); + self::assertCount(66, $result); self::assertCount(1, $result->getIdentities()); self::assertSame('sequenceId', $result->getSequenceId()); self::assertSame(123.456, $result["amount"]); @@ -146,6 +147,7 @@ public function testBuild() self::assertSame(true, $result["cookie_enabled"]); self::assertSame(false, $result["do_not_track"]); self::assertSame(true, $result["ajax_validation"]); + self::assertSame([1, 2], $result["media_id"]); $validator->validate($result); diff --git a/tests/Covery/BuildPayoutEventTest.php b/tests/Covery/BuildPayoutEventTest.php index 5b97178..c51223c 100644 --- a/tests/Covery/BuildPayoutEventTest.php +++ b/tests/Covery/BuildPayoutEventTest.php @@ -30,13 +30,14 @@ public function testBuild() 11, 22, "group id value", - 'links to documents' + 'links to documents', + [1, 2] )->addBrowserData('88889', 'Test curl')->addIdentity(new \Covery\Client\Identities\Stub())->build(); self::assertSame('payout', $result->getType()); self::assertCount(1, $result->getIdentities()); self::assertSame('someSequenceId', $result->getSequenceId()); - self::assertCount(24, $result); + self::assertCount(25, $result); self::assertSame('fooUserId', $result['user_merchant_id']); self::assertSame(5566, $result['payout_timestamp']); self::assertSame('payoutLargeId', $result['payout_id']); @@ -62,6 +63,7 @@ public function testBuild() self::assertSame('Test curl', $result['user_agent']); self::assertSame('group id value', $result['group_id']); self::assertSame('links to documents', $result['links_to_documents']); + self::assertSame([1, 2], $result['media_id']); $validator->validate($result); // Minimal data diff --git a/tests/Covery/BuildProfileUpdateEventTest.php b/tests/Covery/BuildProfileUpdateEventTest.php index a356b52..7e08e93 100644 --- a/tests/Covery/BuildProfileUpdateEventTest.php +++ b/tests/Covery/BuildProfileUpdateEventTest.php @@ -105,11 +105,12 @@ public function testBuild() "profileUpdatePlugins", "profileUpdateRefererUrl", "profileUpdateOriginUrl", - "linksToDocuments" + "linksToDocuments", + [1, 2] )->build(); - self::assertCount(94, $result); + self::assertCount(95, $result); self::assertSame(Builder::EVENT_PROFILE_UPDATE, $result->getType()); self::assertSame('profileUpdateSequenceId', $result->getSequenceId()); self::assertSame('profileUpdateEventId', $result['event_id']); @@ -208,6 +209,7 @@ public function testBuild() self::assertSame("profileUpdateRefererUrl", $result['referer_url']); self::assertSame("profileUpdateOriginUrl", $result['origin_url']); self::assertSame("linksToDocuments", $result['links_to_documents']); + self::assertSame([1, 2], $result['media_id']); $validator->validate($result); diff --git a/tests/Covery/BuildRefundEventTest.php b/tests/Covery/BuildRefundEventTest.php index 48a1010..822fb37 100644 --- a/tests/Covery/BuildRefundEventTest.php +++ b/tests/Covery/BuildRefundEventTest.php @@ -26,7 +26,8 @@ public function testBuild() 'somePhone', 'someUid', "group id value", - 'links to documents' + 'links to documents', + [1, 2] )->addBrowserData( '88889', 'Test curl', @@ -54,7 +55,7 @@ public function testBuild() self::assertSame('refund', $result->getType()); self::assertCount(1, $result->getIdentities()); self::assertSame('someSequenceId', $result->getSequenceId()); - self::assertCount(39, $result); + self::assertCount(40, $result); self::assertSame('refundLargeId', $result['refund_id']); self::assertSame(0.12, $result['refund_amount']); self::assertSame('GBP', $result['refund_currency']); @@ -93,6 +94,7 @@ public function testBuild() self::assertSame('clientResolution', $result['client_resolution']); self::assertSame('group id value', $result['group_id']); self::assertSame('links to documents', $result['links_to_documents']); + self::assertSame([1, 2], $result['media_id']); $validator->validate($result); // Minimal data diff --git a/tests/Covery/BuildRegistrationEventTest.php b/tests/Covery/BuildRegistrationEventTest.php index 7e5b967..f752957 100644 --- a/tests/Covery/BuildRegistrationEventTest.php +++ b/tests/Covery/BuildRegistrationEventTest.php @@ -25,13 +25,14 @@ public function testBuild() '8965asd-2', 'somePassword', 'email campaign', - "group id value" + "group id value", + [1, 2] )->addIdentity(new \Covery\Client\Identities\Stub())->build(); self::assertSame('registration', $result->getType()); self::assertCount(1, $result->getIdentities()); self::assertSame('someLongString', $result->getSequenceId()); - self::assertCount(17, $result); + self::assertCount(18, $result); self::assertSame('thisisuser', $result['user_merchant_id']); self::assertSame(320746, $result['registration_timestamp']); self::assertSame('user@site.net', $result['email']); @@ -49,6 +50,7 @@ public function testBuild() self::assertSame('somePassword', $result['password']); self::assertSame('email campaign', $result['campaign']); self::assertSame('group id value', $result['group_id']); + self::assertCount(2, $result['media_id']); $validator->validate($result); // Minimal data diff --git a/tests/Covery/BuildTransactionEventTest.php b/tests/Covery/BuildTransactionEventTest.php index d7d209c..8bbd961 100644 --- a/tests/Covery/BuildTransactionEventTest.php +++ b/tests/Covery/BuildTransactionEventTest.php @@ -54,7 +54,8 @@ public function testBuild() "mcc value", "acquirer merchant id value", "group id value", - 'links to documents' + 'links to documents', + [1, 2] ) ->addBrowserData('88889', 'Test curl') ->addIdentity(new \Covery\Client\Identities\Stub()) @@ -64,7 +65,7 @@ public function testBuild() self::assertSame('transaction', $result->getType()); self::assertCount(1, $result->getIdentities()); self::assertSame('someSequenceId', $result->getSequenceId()); - self::assertCount(49, $result); + self::assertCount(50, $result); self::assertSame('fooUserId', $result['user_merchant_id']); self::assertSame('transactionId', $result['transaction_id']); self::assertSame(0.12, $result['transaction_amount']); @@ -112,6 +113,7 @@ public function testBuild() self::assertSame('acquirer merchant id value', $result['acquirer_merchant_id']); self::assertSame('group id value', $result['group_id']); self::assertSame('links to documents', $result['links_to_documents']); + self::assertSame([1, 2], $result['media_id']); $validator->validate($result); diff --git a/tests/Covery/BuildTransferEventTest.php b/tests/Covery/BuildTransferEventTest.php index 7113591..4f1e257 100644 --- a/tests/Covery/BuildTransferEventTest.php +++ b/tests/Covery/BuildTransferEventTest.php @@ -53,7 +53,8 @@ public function testBuild() 'source value', "group id value", "second user merchant id value", - 'links to documents' + 'links to documents', + [1, 2] ) ->addBrowserData('88889', 'Test curl') ->addIdentity(new \Covery\Client\Identities\Stub()) @@ -63,7 +64,7 @@ public function testBuild() self::assertSame('transfer', $result->getType()); self::assertCount(1, $result->getIdentities()); self::assertSame('someSequenceId', $result->getSequenceId()); - self::assertCount(48, $result); + self::assertCount(49, $result); self::assertSame('someEventId', $result['event_id']); self::assertSame(0.42, $result['amount']); @@ -110,6 +111,7 @@ public function testBuild() self::assertSame('group id value', $result['group_id']); self::assertSame('second user merchant id value', $result['second_user_merchant_id']); self::assertSame('links to documents', $result['links_to_documents']); + self::assertSame([1, 2], $result['media_id']); $validator->validate($result); From 1a408ff497bce90fecb6cf982699c8a3ec248157 Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Tue, 13 Jun 2023 10:38:52 +0300 Subject: [PATCH 05/28] PSPD-12317 [PHP Client] Add new media methods and field --- src/AccountConfigurationStatusResult.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/AccountConfigurationStatusResult.php b/src/AccountConfigurationStatusResult.php index 6c567f2..bf37a3e 100644 --- a/src/AccountConfigurationStatusResult.php +++ b/src/AccountConfigurationStatusResult.php @@ -108,8 +108,8 @@ public function __construct( $dowJonesDataBaseDate, $kycProvider ) { - if (!is_string($actualEventTypes)) { - throw new \InvalidArgumentException("Actual Event Types must be string"); + if (!is_array($actualEventTypes)) { + throw new \InvalidArgumentException("Actual Event Types must be array"); } if (!is_string($baseCurrency)) { throw new \InvalidArgumentException("Base Currency must be string"); @@ -147,14 +147,13 @@ public function __construct( if (!is_bool($amlServiceStatus)) { throw new \InvalidArgumentException("Aml Service Status must be string"); } - if (!is_string($dowJonesDataBaseDate)) { - throw new \InvalidArgumentException("Dow Jones Data Base Date must be string"); + if (!is_int($dowJonesDataBaseDate)) { + throw new \InvalidArgumentException("Dow Jones Data Base Date must be integer"); } if (!is_string($kycProvider)) { throw new \InvalidArgumentException("Kyc Provider must be string"); } - $this->actualEventTypes = $actualEventTypes; $this->baseCurrency = $baseCurrency; $this->decisionCallbackUrl = $decisionCallbackUrl; @@ -173,7 +172,7 @@ public function __construct( } /** - * @return string + * @return array */ public function getActualEventTypes() { @@ -277,7 +276,7 @@ public function isAmlServiceStatus() } /** - * @return string + * @return int */ public function getDowJonesDataBaseDate() { From c493025e2975372020294ed495083a9ee010a957 Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Tue, 13 Jun 2023 14:24:32 +0300 Subject: [PATCH 06/28] PSPD-12317 [PHP Client] Add new media methods and field --- README.md | 23 ++++++++--------------- src/Facade.php | 22 +++------------------- src/PublicAPIClient.php | 22 ---------------------- src/Requests/Ping.php | 20 -------------------- tests/Covery/Psr7RequestsTest.php | 9 --------- tests/Covery/UploadFileByLinkTest.php | 0 tests/Covery/WithCustomHostTest.php | 21 --------------------- 7 files changed, 11 insertions(+), 106 deletions(-) delete mode 100644 src/Requests/Ping.php delete mode 100644 tests/Covery/UploadFileByLinkTest.php delete mode 100644 tests/Covery/WithCustomHostTest.php diff --git a/README.md b/README.md index 4904e8a..0645a06 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,6 @@ Official PHP Covery Client * [Facade](#facade) * [PSR-3 logging](#psr) [PSR-4 autoloading](#psr) and [PSR-7 HTTP messages](#psr) * [Transports](#transports) - * [Health check](#ping) * [Envelopes](#envelopes) * [Results](#results) * [Exceptions](#exceptions) @@ -55,7 +54,6 @@ Facade::setLogger(new FileLogger($filePath)); That's all! Having completed this procedure, you can now query Covery using `Facade::sendEvent`, `Facade::sendPostback`, `Facade::makeDecision`. -You can test connectivity problems and token/secret validity using `Facade::ping` request. Login event example: @@ -124,7 +122,7 @@ Media file upload example: ```php use Covery\Client\Facade; -$statusCode = \Covery\Client\Facade::uploadMediaFile($mediaUrl, $filePath); +$statusCode = \Covery\Client\Facade::uploadMediaFile($mediaUrl, $file); ``` Account Configuration Status event example: @@ -157,13 +155,6 @@ Covery client may use any class that satisfies `Covery\Client\TransportInterface 1. `Covery\Client\Transport\Curl` - simple PHP curl implementation 2. `Covery\Client\Transport\OverGuzzle` - adapter over [Guzzle](https://github.com/guzzle/guzzle) HTTP client - -## Health Check - -To perform network accessibility and token validity tests, run `ping()` method inside `Facade` -or `PublicAPIClient`. It will throw an exception on any problems or return your token access level on success. -In most cases it will return `"DECISION"` as your token level. - ## Envelopes @@ -197,9 +188,8 @@ You may provide the following as envelopes: ## Results -1. `ping` will return `string` containing current token access level on success. -2. `sendEvent` will return `integer` (may be x64) containing ID of a stored entity on Covery side. You should log it. -3. `makeDecision` will return `Covery\Client\Result` object: +1. `sendEvent` will return `integer` (may be x64) containing ID of a stored entity on Covery side. You should log it. +2. `makeDecision` will return `Covery\Client\Result` object: * Call `getScore()` to obtain score in range [-100, 100] * Method `isAccept()` will return `true` if Covery did not found fraud in incoming envelope data * Method `isReject()` will return `true` if Covery found fraud in incoming envelope data @@ -223,8 +213,11 @@ You may provide the following as envelopes: ## Changelog -* `1.3.15` Added MediaConnection method. Added UploadMediaFile method. Added optional `media_id` field for install, registration event -* `1.3.14` Added MediaStorage method +* `1.3.14` Added MediaStorage method. Added MediaConnection method. Added UploadMediaFile method. + * Added optional `media_id` field for events: install, registration, confirmation, login, order-item, order-submit, transaction, refund, payout, transfer, profile-update, kyc-profile, kyc-submit. + * Added address_confirmed, second_address_confirmed fields for KYC profile and KYC submit events. + * Added AccountConfigurationStatus method. + * Removed Health check method. * `1.3.13` Added StaleDataException exception * `1.3.12` Added sendCardId method * `1.3.11` Added VarDumpLogger and FileLogger diff --git a/src/Facade.php b/src/Facade.php index 0038d9b..5e86a40 100644 --- a/src/Facade.php +++ b/src/Facade.php @@ -81,22 +81,6 @@ private static function getClient() return self::$client; } - /** - * Sends request to Covery and returns access level, associated with - * used credentials - * - * This method can be used for Covery health check and availability - * On any problem (network, credentials, server side) this method - * will throw an exception - * - * @return mixed - * @throws Exception - */ - public static function ping() - { - return self::getClient()->ping(); - } - /** * Sends envelope to Covery and returns it's ID on Covery side * Before sending, validation is performed @@ -189,15 +173,15 @@ public static function sendMediaConnection(MediaConnectionInterface $mediaConnec * Upload Media file and returns status code * * @param $url - * @param $filePath + * @param $file * @return int * @throws Exception * @throws IoException * @throws TimeoutException */ - public static function uploadMediaFile($url, $filePath) + public static function uploadMediaFile($url, $file) { - $mediaFileUploader = new MediaFileUploader($url, $filePath); + $mediaFileUploader = new MediaFileUploader($url, $file); return $mediaFileUploader->upload(); } diff --git a/src/PublicAPIClient.php b/src/PublicAPIClient.php index b4e6d79..ea5f8bb 100644 --- a/src/PublicAPIClient.php +++ b/src/PublicAPIClient.php @@ -8,7 +8,6 @@ use Covery\Client\Requests\Event; use Covery\Client\Requests\KycProof; use Covery\Client\Requests\MediaStorage; -use Covery\Client\Requests\Ping; use Covery\Client\Requests\Postback; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -180,27 +179,6 @@ private function readJson($string) return $data; } - /** - * Sends request to Covery and returns access level, associated with - * used credentials - * - * This method can be used for Covery health check and availability - * On any problem (network, credentials, server side) this method - * will throw an exception - * - * @return string - * @throws Exception - */ - public function ping() - { - $data = $this->readJson($this->send(new Ping())); - if (!is_array($data) || !isset($data['level'])) { - throw new Exception("Malformed response"); - } - - return $data['level']; - } - /** * Sends envelope to Covery and returns it's ID on Covery side * Before sending, validation is performed diff --git a/src/Requests/Ping.php b/src/Requests/Ping.php deleted file mode 100644 index c20d26e..0000000 --- a/src/Requests/Ping.php +++ /dev/null @@ -1,20 +0,0 @@ -getBody()->getContents()); - self::assertSame('POST', $req->getMethod()); - self::assertSame('/api/ping', strval($req->getUri())); - } - public function testEvent() { $noIdentities = new \Covery\Client\Envelopes\Builder('foo', 'bar'); diff --git a/tests/Covery/UploadFileByLinkTest.php b/tests/Covery/UploadFileByLinkTest.php deleted file mode 100644 index e69de29..0000000 diff --git a/tests/Covery/WithCustomHostTest.php b/tests/Covery/WithCustomHostTest.php deleted file mode 100644 index 4c22143..0000000 --- a/tests/Covery/WithCustomHostTest.php +++ /dev/null @@ -1,21 +0,0 @@ -getMock(); - $mock->expects(self::exactly(1))->method('send')->with(self::callback(function(\Psr\Http\Message\RequestInterface $req) { - return strval($req->getUri()) == 'ftp://localhost/api/ping'; - })); - $custom = new \Covery\Client\Transport\WithCustomHost($mock, 'localhost', 'ftp'); - $custom->send(new \Covery\Client\Requests\Ping()); - - $mock = self::getMockBuilder('Covery\\Client\\TransportInterface')->getMock(); - $mock->expects(self::exactly(1))->method('send')->with(self::callback(function(\Psr\Http\Message\RequestInterface $req) { - return strval($req->getUri()) == 'https://test.local:8083/api/ping'; - })); - $custom = new \Covery\Client\Transport\WithCustomHost($mock, 'test.local:8083', 'https'); - $custom->send(new \Covery\Client\Requests\Ping()); - } -} From 9947cb7d90c46f8867ce29b4d19fe101d0345d2b Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Tue, 13 Jun 2023 15:35:41 +0300 Subject: [PATCH 07/28] PSPD-12317 [PHP Client] Add new media methods and field --- src/AccountConfigurationStatusResult.php | 2 +- src/Envelopes/Builder.php | 2 +- src/Requests/MediaConnection.php | 2 +- src/Requests/MediaFileUploader.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/AccountConfigurationStatusResult.php b/src/AccountConfigurationStatusResult.php index bf37a3e..8d1c68b 100644 --- a/src/AccountConfigurationStatusResult.php +++ b/src/AccountConfigurationStatusResult.php @@ -12,7 +12,7 @@ class AccountConfigurationStatusResult { /** - * @var string + * @var array */ private $actualEventTypes; /** diff --git a/src/Envelopes/Builder.php b/src/Envelopes/Builder.php index 99a5629..53fd9fb 100644 --- a/src/Envelopes/Builder.php +++ b/src/Envelopes/Builder.php @@ -1025,7 +1025,7 @@ public static function kycProfileEvent( * @param null $refererUrl * @param null $originUrl * @param string|null $linksToDocuments - * @param null $mediaId + * @param array|null $mediaId * @return static */ public static function profileUpdateEvent( diff --git a/src/Requests/MediaConnection.php b/src/Requests/MediaConnection.php index a9ecc59..6011010 100644 --- a/src/Requests/MediaConnection.php +++ b/src/Requests/MediaConnection.php @@ -24,7 +24,7 @@ public function __construct(MediaConnectionInterface $media, $method = 'PUT') parent::__construct( $method, '/api/mediaConnection', - array(), + [], json_encode($media->toArray()) ); } diff --git a/src/Requests/MediaFileUploader.php b/src/Requests/MediaFileUploader.php index 9758c49..865272f 100644 --- a/src/Requests/MediaFileUploader.php +++ b/src/Requests/MediaFileUploader.php @@ -5,7 +5,7 @@ use GuzzleHttp\Psr7\Request; /** - * Class MediaFileUploaderRequest + * Class MediaFileUploader * * Upload Media file * From 1739c3a20accf7ab506e493ded1d397b33929090 Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Tue, 13 Jun 2023 15:39:13 +0300 Subject: [PATCH 08/28] PSPD-12317 [PHP Client] Add new media methods and field --- src/Requests/MediaStorage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Requests/MediaStorage.php b/src/Requests/MediaStorage.php index 8b79331..187d36c 100644 --- a/src/Requests/MediaStorage.php +++ b/src/Requests/MediaStorage.php @@ -23,7 +23,7 @@ public function __construct(MediaStorageInterface $media) parent::__construct( 'POST', '/api/mediaStorage', - array(), + [], json_encode($media->toArray()) ); } From 07940de99e4c7f70a9ef56263eaecb358f2ed5de Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Tue, 13 Jun 2023 15:41:03 +0300 Subject: [PATCH 09/28] PSPD-12317 [PHP Client] Add new media methods and field --- src/MediaConnection/Builder.php | 2 +- src/MediaStorage/Builder.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MediaConnection/Builder.php b/src/MediaConnection/Builder.php index 15c5ec6..ebd514b 100644 --- a/src/MediaConnection/Builder.php +++ b/src/MediaConnection/Builder.php @@ -7,7 +7,7 @@ class Builder /** * @var array */ - private $data = array(); + private $data = []; /** * @var int */ diff --git a/src/MediaStorage/Builder.php b/src/MediaStorage/Builder.php index 8221bff..4d2bd36 100644 --- a/src/MediaStorage/Builder.php +++ b/src/MediaStorage/Builder.php @@ -8,7 +8,7 @@ class Builder /** * @var array */ - private $data = array(); + private $data = []; /** * @var string */ From cf60ca0ecca07d5ccd07ab338f5a3e38d9bd657a Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Tue, 13 Jun 2023 17:38:29 +0300 Subject: [PATCH 10/28] PSPD-12317 [PHP Client] Add new media methods and field --- src/MediaFileUploader.php | 8 +++++--- src/Requests/MediaFileUploader.php | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/MediaFileUploader.php b/src/MediaFileUploader.php index f858d6b..07f626c 100644 --- a/src/MediaFileUploader.php +++ b/src/MediaFileUploader.php @@ -4,6 +4,7 @@ use Covery\Client\Transport\Curl; use Covery\Client\Requests\MediaFileUploader as MediaFileUploaderRequest; +use Psr\Http\Message\StreamInterface; class MediaFileUploader { @@ -11,8 +12,9 @@ class MediaFileUploader * @var string */ private $url; + /** - * @var string + * @var StreamInterface */ private $file; @@ -22,8 +24,8 @@ public function __construct($url, $file) throw new \InvalidArgumentException('Url must be string'); } - if (!is_resource($file)) { - throw new \InvalidArgumentException('File must be resource'); + if (!($file instanceof StreamInterface)) { + throw new \InvalidArgumentException('File must be instance of StreamInterface'); } $this->url = $url; diff --git a/src/Requests/MediaFileUploader.php b/src/Requests/MediaFileUploader.php index 865272f..304adc1 100644 --- a/src/Requests/MediaFileUploader.php +++ b/src/Requests/MediaFileUploader.php @@ -19,7 +19,6 @@ class MediaFileUploader extends Request */ public function __construct($url, $file) { - $resourceBinary = stream_get_contents($file); parent::__construct( 'PUT', @@ -27,7 +26,7 @@ public function __construct($url, $file) [ 'Content-Type' => 'application/octet-stream', ], - $resourceBinary + $file ); } } From a92d445eac4ae9a3dc698b7ffbbc2c20d7b4c014 Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Wed, 14 Jun 2023 13:52:52 +0300 Subject: [PATCH 11/28] PSPD-12317 [PHP Client] Add new media methods and field --- README.md | 2 +- src/ContentDescription.php | 19 ++++ src/ContentType.php | 19 ++++ src/MediaConnection/Builder.php | 13 --- src/MediaConnection/MediaConnection.php | 45 +--------- src/MediaConnectionInterface.php | 12 +-- src/MediaStorage/Builder.php | 63 +++++++------ src/MediaStorage/MediaStorage.php | 103 +--------------------- src/MediaStorageInterface.php | 22 +---- tests/Covery/BuildMediaConnectionTest.php | 21 ++++- tests/Covery/BuildMediaStorageTest.php | 39 +++++++- 11 files changed, 127 insertions(+), 231 deletions(-) create mode 100644 src/ContentDescription.php create mode 100644 src/ContentType.php diff --git a/README.md b/README.md index 0645a06..98e138c 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ Media Storage event example: use Covery\Client\MediaStorage\Builder; use Covery\Client\Facade; -$event = Builder::mediaStorageEvent('image/jpeg', 'personal_photo', '', false)->build(); +$event = Builder::mediaStorageEvent(\Covery\Client\ContentType::JPEG, \Covery\Client\ContentDescription::GENERAL_DOCUMENT, null, false)->build(); $result = Facade::sendMediaStorage($event); ``` diff --git a/src/ContentDescription.php b/src/ContentDescription.php new file mode 100644 index 0000000..2f877bd --- /dev/null +++ b/src/ContentDescription.php @@ -0,0 +1,19 @@ +requestId = $requestId; - $this->mediaId = $mediaId; - $this->replace('request_id', $requestId); $this->replace('media_id', $mediaId); @@ -65,8 +54,6 @@ public function addConnectionData($requestId, $mediaId) public function build() { return new MediaConnection( - $this->requestId, - $this->mediaId, array_filter($this->data, function ($data) { return $data !== null; }) diff --git a/src/MediaConnection/MediaConnection.php b/src/MediaConnection/MediaConnection.php index ebb7fb9..4166691 100644 --- a/src/MediaConnection/MediaConnection.php +++ b/src/MediaConnection/MediaConnection.php @@ -6,16 +6,6 @@ class MediaConnection implements MediaConnectionInterface { - /** - * @var int - */ - private $requestId; - - /** - * @var array - */ - private $mediaId; - /** * @var array */ @@ -24,17 +14,8 @@ class MediaConnection implements MediaConnectionInterface /** * MediaConnection constructor. */ - public function __construct($requestId, $mediaId = [], $data = []) + public function __construct($data = []) { - if (!is_int($requestId)) { - throw new \InvalidArgumentException('Request Id must be string'); - } - if (!is_array($mediaId)) { - throw new \InvalidArgumentException('Media Id must be array'); - } - - $this->requestId = $requestId; - $this->mediaId = $mediaId; $this->data = $data; } @@ -91,28 +72,4 @@ public function offsetUnset($offset) unset($this->data[$offset]); } } - - /** - * @inheritDoc - */ - public function getIterator() - { - return new \ArrayIterator($this->data); - } - - /** - * @return int - */ - public function getRequestId() - { - return $this->requestId; - } - - /** - * @return array - */ - public function getMediaId() - { - return $this->mediaId; - } } diff --git a/src/MediaConnectionInterface.php b/src/MediaConnectionInterface.php index c671b3f..76a3c6b 100644 --- a/src/MediaConnectionInterface.php +++ b/src/MediaConnectionInterface.php @@ -9,18 +9,8 @@ * * @package Covery\Client */ -interface MediaConnectionInterface extends \IteratorAggregate, \ArrayAccess, \Countable +interface MediaConnectionInterface extends \ArrayAccess, \Countable { - /** - * @return string - */ - public function getRequestId(); - - /** - * @return array - */ - public function getMediaId(); - /** * @return array */ diff --git a/src/MediaStorage/Builder.php b/src/MediaStorage/Builder.php index 4d2bd36..17385ab 100644 --- a/src/MediaStorage/Builder.php +++ b/src/MediaStorage/Builder.php @@ -2,6 +2,8 @@ namespace Covery\Client\MediaStorage; +use Covery\Client\ContentDescription; +use Covery\Client\ContentType; class Builder { @@ -9,22 +11,6 @@ class Builder * @var array */ private $data = []; - /** - * @var string - */ - private $contentType; - /** - * @var string - */ - private $contentDescription; - /** - * @var string - */ - private $fileName; - /** - * @var bool - */ - private $ocr; /** * Returns builder for media request @@ -35,7 +21,7 @@ class Builder * @param $ocr * @return Builder */ - public static function mediaStorageEvent($contentType, $contentDescription, $fileName = '', $ocr = false) + public static function mediaStorageEvent($contentType, $contentDescription, $fileName = null, $ocr = false) { $builder = new self(); @@ -52,26 +38,41 @@ public static function mediaStorageEvent($contentType, $contentDescription, $fil * @param $ocr * @return Builder */ - public function addMediaStorageData($contentType, $contentDescription, $fileName = '', $ocr = false) + public function addMediaStorageData($contentType, $contentDescription, $fileName = null, $ocr = false) { - if (!is_string($contentType)) { - throw new \InvalidArgumentException('Content type must be string'); + if (!is_string($contentType) || strlen($contentType) > 255) { + throw new \InvalidArgumentException( + 'Content type must be string and contain no more than 255 characters' + ); + } + if (!in_array($contentType, ContentType::getAll())) { + throw new \InvalidArgumentException('Content type must be one of the types: ' . implode( + ', ', + ContentType::getAll() + ) + ); } - if (!is_string($contentDescription)) { - throw new \InvalidArgumentException('Content Description must be string'); + if (!is_string($contentDescription) || strlen($contentDescription) > 255) { + throw new \InvalidArgumentException( + 'Content Description must be string and contain no more than 255 characters' + ); } - if (!is_string($fileName)) { - throw new \InvalidArgumentException('File name must be string'); + if (!in_array($contentDescription, ContentDescription::getAll())) { + throw new \InvalidArgumentException('Content type must be one of the types: ' . implode( + ', ', + ContentType::getAll() + ) + ); + } + if ($fileName && !is_string($fileName) || strlen($fileName) > 255) { + throw new \InvalidArgumentException( + 'File name must be string and contain no more than 255 characters' + ); } if (!is_bool($ocr)) { throw new \InvalidArgumentException('Ocr must be bool'); } - $this->contentType = $contentType; - $this->contentDescription = $contentDescription; - $this->fileName = $fileName; - $this->ocr = $ocr; - $this->replace('content_type', $contentType); $this->replace('content_description', $contentDescription); $this->replace('file_name', $fileName); @@ -88,10 +89,6 @@ public function addMediaStorageData($contentType, $contentDescription, $fileName public function build() { return new MediaStorage( - $this->contentType, - $this->contentDescription, - $this->fileName, - $this->ocr, array_filter($this->data, function ($data) { return $data !== null; }) diff --git a/src/MediaStorage/MediaStorage.php b/src/MediaStorage/MediaStorage.php index 73e40f2..e3e27c6 100644 --- a/src/MediaStorage/MediaStorage.php +++ b/src/MediaStorage/MediaStorage.php @@ -6,26 +6,6 @@ class MediaStorage implements MediaStorageInterface { - /** - * @var bool - */ - private $ocr; - - /** - * @var string - */ - private $fileName; - - /** - * @var string - */ - private $contentType; - - /** - * @var string - */ - private $contentDescription; - /** * @var array */ @@ -34,49 +14,8 @@ class MediaStorage implements MediaStorageInterface /** * MediaStorage constructor. */ - public function __construct($contentType, $contentDescription, $fileName = '', $ocr = false, $data = []) + public function __construct($data = []) { - $contentTypes = [ - 'image/jpeg', - 'image/png', - 'image/gif', - ]; - $contentDescriptions = [ - 'personal_photo', - 'linked_document', - 'general_document', - ]; - if (!is_string($contentType)) { - throw new \InvalidArgumentException('Content type must be string'); - } - if (!in_array($contentType, $contentTypes)) { - throw new \InvalidArgumentException('Content type must be one of the types: ' . implode( - ', ', - $contentTypes - ) - ); - } - if (!is_string($contentDescription)) { - throw new \InvalidArgumentException('Content description must be string'); - } - if (!in_array($contentDescription, $contentDescriptions)) { - throw new \InvalidArgumentException('Content type must be one of the types: ' . implode( - ', ', - $contentDescriptions - ) - ); - } - if (!is_string($fileName)) { - throw new \InvalidArgumentException('File name must be string'); - } - if (!is_bool($ocr)) { - throw new \InvalidArgumentException('OCR must be bool'); - } - - $this->contentType = $contentType; - $this->contentDescription = $contentDescription; - $this->fileName = $fileName; - $this->ocr = $ocr; $this->data = $data; } @@ -133,44 +72,4 @@ public function offsetUnset($offset) unset($this->data[$offset]); } } - - /** - * @inheritDoc - */ - public function getIterator() - { - return new \ArrayIterator($this->data); - } - - /** - * @return string - */ - public function getOcr() - { - return $this->ocr; - } - - /** - * @return string - */ - public function getFileName() - { - return $this->fileName; - } - - /** - * @return string - */ - public function getContentType() - { - return $this->contentType; - } - - /** - * @return string - */ - public function getContentDescription() - { - return $this->contentDescription; - } } diff --git a/src/MediaStorageInterface.php b/src/MediaStorageInterface.php index 2fca150..d35d6fc 100644 --- a/src/MediaStorageInterface.php +++ b/src/MediaStorageInterface.php @@ -9,28 +9,8 @@ * * @package Covery\Client */ -interface MediaStorageInterface extends \IteratorAggregate, \ArrayAccess, \Countable +interface MediaStorageInterface extends \ArrayAccess, \Countable { - /** - * @return string - */ - public function getContentType(); - - /** - * @return string - */ - public function getContentDescription(); - - /** - * @return @sting - */ - public function getFileName(); - - /** - * @return @bool - */ - public function getOCR(); - /** * @return array */ diff --git a/tests/Covery/BuildMediaConnectionTest.php b/tests/Covery/BuildMediaConnectionTest.php index cccc721..78d177e 100644 --- a/tests/Covery/BuildMediaConnectionTest.php +++ b/tests/Covery/BuildMediaConnectionTest.php @@ -7,13 +7,30 @@ public function testBuild() $requestId = 51876931; $mediaId = [119961]; - $mediaConnection = \Covery\Client\MediaConnection\Builder::mediaConnectionEvent( + $mediaConnectionResult = \Covery\Client\MediaConnection\Builder::mediaConnectionEvent( $requestId, $mediaId )->build(); - $request = new \Covery\Client\Requests\MediaConnection($mediaConnection); + $request = new \Covery\Client\Requests\MediaConnection($mediaConnectionResult); self::assertEquals('PUT', $request->getMethod()); self::assertContains($request->getUri()->getPath(), '/api/mediaConnection'); + self::assertInstanceOf('Psr\Http\Message\RequestInterface', $request); + self::assertCount(2, $mediaConnectionResult); + self::assertSame($mediaId, $mediaConnectionResult['media_id']); + self::assertSame($requestId, $mediaConnectionResult['request_id']); + self::assertJson($request->getBody()->getContents()); + } + + public function testEventExpectsInvalidArgumentException() + { + $requestId = 'text'; + $mediaId = 1; + + self::setExpectedException('InvalidArgumentException'); + $mediaConnection = \Covery\Client\MediaConnection\Builder::mediaConnectionEvent( + $requestId, + $mediaId + )->build(); } } diff --git a/tests/Covery/BuildMediaStorageTest.php b/tests/Covery/BuildMediaStorageTest.php index 6c6bca9..de61f92 100644 --- a/tests/Covery/BuildMediaStorageTest.php +++ b/tests/Covery/BuildMediaStorageTest.php @@ -4,21 +4,52 @@ class BuildMediaStorageTest extends \PHPUnit_Framework_TestCase { public function testBuild() { - $contentType = 'image/jpeg'; - $contentDescription = 'personal_photo'; + $contentType = \Covery\Client\ContentType::PNG; + $contentDescription = \Covery\Client\ContentDescription::PERSONAL_PHOTO; $fileName = 'passport.jpeg'; $ocr = false; - $mediaStorage = \Covery\Client\MediaStorage\Builder::mediaStorageEvent( + $mediaStorageResult = \Covery\Client\MediaStorage\Builder::mediaStorageEvent( $contentType, $contentDescription, $fileName, $ocr )->build(); - $request = new \Covery\Client\Requests\MediaStorage($mediaStorage); + $request = new \Covery\Client\Requests\MediaStorage($mediaStorageResult); self::assertEquals('POST', $request->getMethod()); self::assertContains($request->getUri()->getPath(), '/api/mediaStorage'); + self::assertInstanceOf('Psr\Http\Message\RequestInterface', $request); + self::assertCount(4, $mediaStorageResult); + self::assertSame($contentType, $mediaStorageResult['content_type']); + self::assertSame($contentDescription, $mediaStorageResult['content_description']); + self::assertSame($fileName, $mediaStorageResult['file_name']); + self::assertSame($ocr, $mediaStorageResult['ocr']); + self::assertJson($request->getBody()->getContents()); + } + + public function testBuildFileLengthException() + { + $fileNameWith256Symbols = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque consectetur doloremque ducimus est eum hic illum incidunt, labore, minus optio reiciendis totam velit vero. Animi asperiores autem consequuntur cupiditate deleniti dignissimos dolor dolore doloribus eaque esse, et, eum facere facilis id illo impedit iusto laborum magni molestias nemo nihil nobis nulla, omnis perferendis quam quasi qui quia sint sit suscipit tempora tempore ullam veniam veritatis vitae voluptatem voluptates. A aliquid aspernatur autem blanditiis consequatur cum dolores, eligendi inventore ipsa libero necessitatibus nisi, odit praesentium repellat repellendus unde voluptatum? Beatae est facilis magni odio optio. Ab accusamus asperiores autem consequuntur debitis dolor dolorum, ducimus est eum excepturi fugiat fugit neque nihil nobis, non obcaecati perferendis quaerat quasi quo reiciendis sapiente similique sint tempore tenetur ullam veniam vitae! Adipisci atque aut consequuntur ea eligendi illo impedit incidunt ipsa, laborum laudantium modi odit officiis pariatur porro quaerat qui similique suscipit tempora tempore temporibus. Aperiam at cupiditate dolorum eius et explicabo fuga ipsum libero maxime minus necessitatibus neque pariatur reiciendis, rem sint sit unde velit voluptates? Consequatur dolor dolores doloribus eaque earum et excepturi incidunt inventore iste laboriosam minima mollitia nobis odio, officiis perspiciatis quia recusandae rerum saepe sed soluta tempora totam voluptatibus. Ad aperiam commodi expedita facere ipsam iste laboriosam obcaecati perferendis, quam quidem repellendus rerum totam voluptate. Ab aliquam amet atque autem, fugiat maxime mollitia odit, praesentium quibusdam, ratione repellendus suscipit. Asperiores consequatur exercitationem iusto nesciunt nulla? Dolorum earum ipsum, nostrum provident totam ullam voluptatibus. Ad animi, asperiores atque delectus dolore dolorem facere harum ipsam maiores natus nihil non officiis, perferendis repellendus repudiandae sed similique tempore vero vitae?'; + + self::setExpectedException('InvalidArgumentException'); + $mediaStorage = \Covery\Client\MediaStorage\Builder::mediaStorageEvent( + \Covery\Client\ContentType::PNG, + \Covery\Client\ContentDescription::GENERAL_DOCUMENT, + $fileNameWith256Symbols, + false + )->build(); + } + + public function testEventExpectsInvalidArgumentException() + { + self::setExpectedException('InvalidArgumentException'); + $mediaStorage = \Covery\Client\MediaStorage\Builder::mediaStorageEvent( + 'Unique content type', + 'Unique content description', + null, + false + )->build(); } } From e320d1d896845531f16a504d1c43d1b3fda15077 Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Wed, 14 Jun 2023 14:20:09 +0300 Subject: [PATCH 12/28] PSPD-12317 [PHP Client] Add new media methods and field --- src/Requests/MediaFileUploader.php | 1 - tests/Covery/BuildMediaStorageTest.php | 22 ++++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Requests/MediaFileUploader.php b/src/Requests/MediaFileUploader.php index 304adc1..8abfb33 100644 --- a/src/Requests/MediaFileUploader.php +++ b/src/Requests/MediaFileUploader.php @@ -19,7 +19,6 @@ class MediaFileUploader extends Request */ public function __construct($url, $file) { - parent::__construct( 'PUT', $url, diff --git a/tests/Covery/BuildMediaStorageTest.php b/tests/Covery/BuildMediaStorageTest.php index de61f92..86dedcc 100644 --- a/tests/Covery/BuildMediaStorageTest.php +++ b/tests/Covery/BuildMediaStorageTest.php @@ -29,15 +29,13 @@ public function testBuild() self::assertJson($request->getBody()->getContents()); } - public function testBuildFileLengthException() + public function testBuildExpectsInvalidArgumentFileName() { - $fileNameWith256Symbols = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque consectetur doloremque ducimus est eum hic illum incidunt, labore, minus optio reiciendis totam velit vero. Animi asperiores autem consequuntur cupiditate deleniti dignissimos dolor dolore doloribus eaque esse, et, eum facere facilis id illo impedit iusto laborum magni molestias nemo nihil nobis nulla, omnis perferendis quam quasi qui quia sint sit suscipit tempora tempore ullam veniam veritatis vitae voluptatem voluptates. A aliquid aspernatur autem blanditiis consequatur cum dolores, eligendi inventore ipsa libero necessitatibus nisi, odit praesentium repellat repellendus unde voluptatum? Beatae est facilis magni odio optio. Ab accusamus asperiores autem consequuntur debitis dolor dolorum, ducimus est eum excepturi fugiat fugit neque nihil nobis, non obcaecati perferendis quaerat quasi quo reiciendis sapiente similique sint tempore tenetur ullam veniam vitae! Adipisci atque aut consequuntur ea eligendi illo impedit incidunt ipsa, laborum laudantium modi odit officiis pariatur porro quaerat qui similique suscipit tempora tempore temporibus. Aperiam at cupiditate dolorum eius et explicabo fuga ipsum libero maxime minus necessitatibus neque pariatur reiciendis, rem sint sit unde velit voluptates? Consequatur dolor dolores doloribus eaque earum et excepturi incidunt inventore iste laboriosam minima mollitia nobis odio, officiis perspiciatis quia recusandae rerum saepe sed soluta tempora totam voluptatibus. Ad aperiam commodi expedita facere ipsam iste laboriosam obcaecati perferendis, quam quidem repellendus rerum totam voluptate. Ab aliquam amet atque autem, fugiat maxime mollitia odit, praesentium quibusdam, ratione repellendus suscipit. Asperiores consequatur exercitationem iusto nesciunt nulla? Dolorum earum ipsum, nostrum provident totam ullam voluptatibus. Ad animi, asperiores atque delectus dolore dolorem facere harum ipsam maiores natus nihil non officiis, perferendis repellendus repudiandae sed similique tempore vero vitae?'; - self::setExpectedException('InvalidArgumentException'); $mediaStorage = \Covery\Client\MediaStorage\Builder::mediaStorageEvent( \Covery\Client\ContentType::PNG, \Covery\Client\ContentDescription::GENERAL_DOCUMENT, - $fileNameWith256Symbols, + $this->generateRandomString(256), false )->build(); } @@ -52,4 +50,20 @@ public function testEventExpectsInvalidArgumentException() false )->build(); } + + /** + * @param int $length + * @return string + */ + private function generateRandomString($length) + { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + + return $randomString; + } } From 9ad3ca64b105d957b101bdd847ae7f3381406360 Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Thu, 15 Jun 2023 13:47:45 +0300 Subject: [PATCH 13/28] PSPD-12317 [PHP Client] Add new media methods and field --- README.md | 18 +++++++++++ src/ContentType.php | 9 ++++++ src/Facade.php | 20 +++++++++--- src/MediaConnection/Builder.php | 22 ++++++++++++-- src/MediaStorage/Builder.php | 37 ++++++++++++++--------- src/PublicAPIClient.php | 26 ++++++++++++++-- tests/Covery/BuildMediaConnectionTest.php | 4 +-- 7 files changed, 111 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 98e138c..a9ebf77 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,24 @@ $event = Builder::mediaConnectionEvent(1, 1)->build(); $result = Facade::sendMediaConnection($event); ``` +Attach media connection event example: +```php +use Covery\Client\MediaConnection\Builder; +use Covery\Client\Facade; + +$event = Builder::mediaConnectionEvent(1, [1])->build(); +$result = Facade::attachMediaConnection($event); +``` + +Detach media connection event example: +```php +use Covery\Client\MediaConnection\Builder; +use Covery\Client\Facade; + +$event = Builder::mediaConnectionEvent(1, [1])->build(); +$result = Facade::detachMediaConnection($event); +``` + Media file upload example: ```php use Covery\Client\Facade; diff --git a/src/ContentType.php b/src/ContentType.php index edaf501..18a1913 100644 --- a/src/ContentType.php +++ b/src/ContentType.php @@ -16,4 +16,13 @@ public static function getAll() self::GIF, ]; } + + public static function getOCRAllowed() + { + return [ + self::JPEG, + self::PNG, + self::GIF, + ]; + } } \ No newline at end of file diff --git a/src/Facade.php b/src/Facade.php index 5e86a40..44d5f4d 100644 --- a/src/Facade.php +++ b/src/Facade.php @@ -156,17 +156,29 @@ public static function sendMediaStorage(MediaStorageInterface $mediaStorage) } /** - * Send Media Connection and return status code + * Attach media connection and return status code * * @param MediaConnectionInterface $mediaConnection - * @param $method * @return int * @throws Exception * @throws IoException */ - public static function sendMediaConnection(MediaConnectionInterface $mediaConnection, $method = 'PUT') + public static function attachMediaConnection(MediaConnectionInterface $mediaConnection) { - return self::getClient()->sendMediaConnection($mediaConnection, $method); + return self::getClient()->attachMediaConnection($mediaConnection); + } + + /** + * Detach media connection and return status code + * + * @param MediaConnectionInterface $mediaConnection + * @return int + * @throws Exception + * @throws IoException + */ + public static function detachMediaConnection(MediaConnectionInterface $mediaConnection) + { + return self::getClient()->detachMediaConnection($mediaConnection); } /** diff --git a/src/MediaConnection/Builder.php b/src/MediaConnection/Builder.php index 8592b5f..c83112c 100644 --- a/src/MediaConnection/Builder.php +++ b/src/MediaConnection/Builder.php @@ -33,12 +33,15 @@ public static function mediaConnectionEvent($requestId, $mediaId) */ public function addConnectionData($requestId, $mediaId) { - if (!is_int($requestId)) { - throw new \InvalidArgumentException('Request Id must be integer'); + if (!is_int($requestId) && $requestId > 0) { + throw new \InvalidArgumentException('Request Id must be positive integer'); } if (!is_array($mediaId)) { throw new \InvalidArgumentException('Media Id must be array'); } + if (!$this->isListOfPositiveInt($mediaId)) { + throw new \InvalidArgumentException('Media Id must be list of positive int'); + } $this->replace('request_id', $requestId); $this->replace('media_id', $mediaId); @@ -72,4 +75,19 @@ private function replace($key, $value) $this->data[$key] = $value; } } + + /** + * @param array $ids + * @return bool + */ + private function isListOfPositiveInt(array $ids) + { + foreach ($ids as $id) { + if (!is_int($id) || $id < 0) { + return false; + } + } + + return true; + } } diff --git a/src/MediaStorage/Builder.php b/src/MediaStorage/Builder.php index 17385ab..b578005 100644 --- a/src/MediaStorage/Builder.php +++ b/src/MediaStorage/Builder.php @@ -40,10 +40,8 @@ public static function mediaStorageEvent($contentType, $contentDescription, $fil */ public function addMediaStorageData($contentType, $contentDescription, $fileName = null, $ocr = false) { - if (!is_string($contentType) || strlen($contentType) > 255) { - throw new \InvalidArgumentException( - 'Content type must be string and contain no more than 255 characters' - ); + if (!is_string($contentType) || empty($contentType)) { + throw new \InvalidArgumentException('Content type is empty'); } if (!in_array($contentType, ContentType::getAll())) { throw new \InvalidArgumentException('Content type must be one of the types: ' . implode( @@ -52,25 +50,34 @@ public function addMediaStorageData($contentType, $contentDescription, $fileName ) ); } - if (!is_string($contentDescription) || strlen($contentDescription) > 255) { - throw new \InvalidArgumentException( - 'Content Description must be string and contain no more than 255 characters' - ); + + if (!is_string($contentDescription) || empty($contentDescription)) { + throw new \InvalidArgumentException('Content description must be string'); } if (!in_array($contentDescription, ContentDescription::getAll())) { - throw new \InvalidArgumentException('Content type must be one of the types: ' . implode( + throw new \InvalidArgumentException('Content description must be one of the types: ' . implode( ', ', - ContentType::getAll() + ContentDescription::getAll() ) ); } - if ($fileName && !is_string($fileName) || strlen($fileName) > 255) { - throw new \InvalidArgumentException( - 'File name must be string and contain no more than 255 characters' - ); + + if (!is_string($fileName) || empty($fileName)) { + throw new \InvalidArgumentException('File name is empty'); } + if (strlen($fileName) > 255) { + throw new \InvalidArgumentException('File name must contain no more than 255 characters'); + } + if (!is_bool($ocr)) { - throw new \InvalidArgumentException('Ocr must be bool'); + throw new \InvalidArgumentException('OCR must be boolean'); + } + if ($ocr && !in_array($contentType, ContentType::getOCRAllowed())) { + throw new \InvalidArgumentException('Allowed Content type for OCR: ' . implode( + ', ', + ContentType::getOCRAllowed() + ) + ); } $this->replace('content_type', $contentType); diff --git a/src/PublicAPIClient.php b/src/PublicAPIClient.php index ea5f8bb..d468e84 100644 --- a/src/PublicAPIClient.php +++ b/src/PublicAPIClient.php @@ -352,7 +352,29 @@ public function sendMediaStorage(MediaStorageInterface $media) } /** - * Send Media Connection and return status code + * @param MediaConnectionInterface $mediaConnection + * @return int + * @throws Exception + * @throws IoException + */ + public function attachMediaConnection(MediaConnectionInterface $mediaConnection) + { + return $this->sendMediaConnection($mediaConnection, 'PUT'); + } + + /** + * @param MediaConnectionInterface $mediaConnection + * @return int + * @throws Exception + * @throws IoException + */ + public function detachMediaConnection(MediaConnectionInterface $mediaConnection) + { + return $this->sendMediaConnection($mediaConnection, 'DELETE'); + } + + /** + * Send media connection and return status code * * @param MediaConnectionInterface $mediaConnection * @param $method @@ -360,7 +382,7 @@ public function sendMediaStorage(MediaStorageInterface $media) * @throws Exception * @throws IoException */ - public function sendMediaConnection(MediaConnectionInterface $mediaConnection, $method) + private function sendMediaConnection(MediaConnectionInterface $mediaConnection, $method) { $this->readJson($this->send(new \Covery\Client\Requests\MediaConnection($mediaConnection, $method))); if ($this->responseStatusCode >= 300) { diff --git a/tests/Covery/BuildMediaConnectionTest.php b/tests/Covery/BuildMediaConnectionTest.php index 78d177e..4f77b0e 100644 --- a/tests/Covery/BuildMediaConnectionTest.php +++ b/tests/Covery/BuildMediaConnectionTest.php @@ -25,10 +25,10 @@ public function testBuild() public function testEventExpectsInvalidArgumentException() { $requestId = 'text'; - $mediaId = 1; + $mediaId = -1; self::setExpectedException('InvalidArgumentException'); - $mediaConnection = \Covery\Client\MediaConnection\Builder::mediaConnectionEvent( + \Covery\Client\MediaConnection\Builder::mediaConnectionEvent( $requestId, $mediaId )->build(); From 296754cf58c4c5f642e20d1eceb66f45f0500715 Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Thu, 15 Jun 2023 14:30:13 +0300 Subject: [PATCH 14/28] PSPD-12317 [PHP Client] Add new media methods and field --- README.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/README.md b/README.md index a9ebf77..eefa221 100644 --- a/README.md +++ b/README.md @@ -109,15 +109,6 @@ $event = Builder::mediaStorageEvent(\Covery\Client\ContentType::JPEG, \Covery\Cl $result = Facade::sendMediaStorage($event); ``` -Media Connection event example: -```php -use Covery\Client\MediaConnection\Builder; -use Covery\Client\Facade; - -$event = Builder::mediaConnectionEvent(1, 1)->build(); -$result = Facade::sendMediaConnection($event); -``` - Attach media connection event example: ```php use Covery\Client\MediaConnection\Builder; From 3061dc8557e3d441743d6ca0dfe7a81b5528804e Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Thu, 15 Jun 2023 14:40:54 +0300 Subject: [PATCH 15/28] PSPD-12317 [PHP Client] Add new media methods and field --- src/MediaStorage/Builder.php | 4 ++-- tests/Covery/BuildMediaStorageTest.php | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/MediaStorage/Builder.php b/src/MediaStorage/Builder.php index b578005..fa5b938 100644 --- a/src/MediaStorage/Builder.php +++ b/src/MediaStorage/Builder.php @@ -62,10 +62,10 @@ public function addMediaStorageData($contentType, $contentDescription, $fileName ); } - if (!is_string($fileName) || empty($fileName)) { + if (!empty($fileName) && !is_string($fileName)) { throw new \InvalidArgumentException('File name is empty'); } - if (strlen($fileName) > 255) { + if (!empty($fileName) && strlen($fileName) > 255) { throw new \InvalidArgumentException('File name must contain no more than 255 characters'); } diff --git a/tests/Covery/BuildMediaStorageTest.php b/tests/Covery/BuildMediaStorageTest.php index 86dedcc..e644971 100644 --- a/tests/Covery/BuildMediaStorageTest.php +++ b/tests/Covery/BuildMediaStorageTest.php @@ -50,6 +50,15 @@ public function testEventExpectsInvalidArgumentException() false )->build(); } + public function testEmptyFileNameIsValidString() + { + $mediaStorage = \Covery\Client\MediaStorage\Builder::mediaStorageEvent( + \Covery\Client\ContentType::PNG, + \Covery\Client\ContentDescription::GENERAL_DOCUMENT, + null, + false + )->build(); + } /** * @param int $length From cee224c0fdb2d41e2f70e8abf0bfe6088b735008 Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Thu, 15 Jun 2023 14:43:48 +0300 Subject: [PATCH 16/28] PSPD-12317 [PHP Client] Add new media methods and field --- tests/Covery/BuildMediaStorageTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Covery/BuildMediaStorageTest.php b/tests/Covery/BuildMediaStorageTest.php index e644971..c326a4a 100644 --- a/tests/Covery/BuildMediaStorageTest.php +++ b/tests/Covery/BuildMediaStorageTest.php @@ -58,6 +58,8 @@ public function testEmptyFileNameIsValidString() null, false )->build(); + + self::assertSame($mediaStorage['content_type'], \Covery\Client\ContentType::PNG); } /** From 6ea7b8a0e9d3ae0e17be46d5272ce5dd4a4fcbe7 Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Thu, 15 Jun 2023 15:09:29 +0300 Subject: [PATCH 17/28] PSPD-12317 [PHP Client] Add new media methods and field --- src/MediaConnection/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MediaConnection/Builder.php b/src/MediaConnection/Builder.php index c83112c..b8b4c00 100644 --- a/src/MediaConnection/Builder.php +++ b/src/MediaConnection/Builder.php @@ -33,7 +33,7 @@ public static function mediaConnectionEvent($requestId, $mediaId) */ public function addConnectionData($requestId, $mediaId) { - if (!is_int($requestId) && $requestId > 0) { + if (!is_int($requestId) && $requestId < 0) { throw new \InvalidArgumentException('Request Id must be positive integer'); } if (!is_array($mediaId)) { From b0b38d78ec4c573108d10810d34b83b7e9be4361 Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Thu, 15 Jun 2023 15:10:47 +0300 Subject: [PATCH 18/28] PSPD-12317 [PHP Client] Add new media methods and field --- tests/Covery/BuildMediaConnectionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Covery/BuildMediaConnectionTest.php b/tests/Covery/BuildMediaConnectionTest.php index 4f77b0e..197c4dd 100644 --- a/tests/Covery/BuildMediaConnectionTest.php +++ b/tests/Covery/BuildMediaConnectionTest.php @@ -24,7 +24,7 @@ public function testBuild() public function testEventExpectsInvalidArgumentException() { - $requestId = 'text'; + $requestId = -1; $mediaId = -1; self::setExpectedException('InvalidArgumentException'); From 7d36f99969ae56b486b732cfb96d53173f7759a3 Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Thu, 15 Jun 2023 15:18:22 +0300 Subject: [PATCH 19/28] PSPD-12317 [PHP Client] Add new media methods and field --- src/MediaConnection/Builder.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/MediaConnection/Builder.php b/src/MediaConnection/Builder.php index b8b4c00..95bea58 100644 --- a/src/MediaConnection/Builder.php +++ b/src/MediaConnection/Builder.php @@ -33,7 +33,10 @@ public static function mediaConnectionEvent($requestId, $mediaId) */ public function addConnectionData($requestId, $mediaId) { - if (!is_int($requestId) && $requestId < 0) { + if (!is_int($requestId)) { + throw new \InvalidArgumentException('Request Id must be integer'); + } + if ($requestId <= 0) { throw new \InvalidArgumentException('Request Id must be positive integer'); } if (!is_array($mediaId)) { @@ -83,7 +86,7 @@ private function replace($key, $value) private function isListOfPositiveInt(array $ids) { foreach ($ids as $id) { - if (!is_int($id) || $id < 0) { + if (!is_int($id) || $id <= 0) { return false; } } From 5eddd5d02ba10e9250124c64e4a79f461058ebd2 Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Thu, 15 Jun 2023 15:30:00 +0300 Subject: [PATCH 20/28] PSPD-12317 [PHP Client] Add new media methods and field --- src/MediaStorage/Builder.php | 12 ++++++++++-- tests/Covery/BuildMediaConnectionTest.php | 11 +++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/MediaStorage/Builder.php b/src/MediaStorage/Builder.php index fa5b938..f401f79 100644 --- a/src/MediaStorage/Builder.php +++ b/src/MediaStorage/Builder.php @@ -40,7 +40,10 @@ public static function mediaStorageEvent($contentType, $contentDescription, $fil */ public function addMediaStorageData($contentType, $contentDescription, $fileName = null, $ocr = false) { - if (!is_string($contentType) || empty($contentType)) { + if (!is_string($contentType)) { + throw new \InvalidArgumentException('Content type must be a string'); + } + if (empty($contentType)) { throw new \InvalidArgumentException('Content type is empty'); } if (!in_array($contentType, ContentType::getAll())) { @@ -51,9 +54,12 @@ public function addMediaStorageData($contentType, $contentDescription, $fileName ); } - if (!is_string($contentDescription) || empty($contentDescription)) { + if (!is_string($contentDescription)) { throw new \InvalidArgumentException('Content description must be string'); } + if (empty($contentDescription)) { + throw new \InvalidArgumentException('Content description is empty'); + } if (!in_array($contentDescription, ContentDescription::getAll())) { throw new \InvalidArgumentException('Content description must be one of the types: ' . implode( ', ', @@ -62,6 +68,7 @@ public function addMediaStorageData($contentType, $contentDescription, $fileName ); } + //fileName is optional field if (!empty($fileName) && !is_string($fileName)) { throw new \InvalidArgumentException('File name is empty'); } @@ -72,6 +79,7 @@ public function addMediaStorageData($contentType, $contentDescription, $fileName if (!is_bool($ocr)) { throw new \InvalidArgumentException('OCR must be boolean'); } + //ocr is optional field if ($ocr && !in_array($contentType, ContentType::getOCRAllowed())) { throw new \InvalidArgumentException('Allowed Content type for OCR: ' . implode( ', ', diff --git a/tests/Covery/BuildMediaConnectionTest.php b/tests/Covery/BuildMediaConnectionTest.php index 197c4dd..fe9c787 100644 --- a/tests/Covery/BuildMediaConnectionTest.php +++ b/tests/Covery/BuildMediaConnectionTest.php @@ -27,6 +27,17 @@ public function testEventExpectsInvalidArgumentException() $requestId = -1; $mediaId = -1; + self::setExpectedException('InvalidArgumentException'); + \Covery\Client\MediaConnection\Builder::mediaConnectionEvent( + $requestId, + $mediaId + )->build(); + } + public function testEventExpectsInvalidArgumentExceptionCheckZeroFields() + { + $requestId = 0; + $mediaId = [1, 0, -1]; + self::setExpectedException('InvalidArgumentException'); \Covery\Client\MediaConnection\Builder::mediaConnectionEvent( $requestId, From 4f3b6e14b43933bc2f0d3bda1a5555f7d3cc178e Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Thu, 15 Jun 2023 15:37:46 +0300 Subject: [PATCH 21/28] PSPD-12317 [PHP Client] Add new media methods and field --- src/MediaStorage/Builder.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/MediaStorage/Builder.php b/src/MediaStorage/Builder.php index f401f79..7135c31 100644 --- a/src/MediaStorage/Builder.php +++ b/src/MediaStorage/Builder.php @@ -68,18 +68,18 @@ public function addMediaStorageData($contentType, $contentDescription, $fileName ); } - //fileName is optional field - if (!empty($fileName) && !is_string($fileName)) { - throw new \InvalidArgumentException('File name is empty'); - } - if (!empty($fileName) && strlen($fileName) > 255) { - throw new \InvalidArgumentException('File name must contain no more than 255 characters'); + if (!empty($fileName)) { + if (!is_string($fileName)) { + throw new \InvalidArgumentException('File name is empty'); + } + if(strlen($fileName) > 255) { + throw new \InvalidArgumentException('File name must contain no more than 255 characters'); + } } if (!is_bool($ocr)) { throw new \InvalidArgumentException('OCR must be boolean'); } - //ocr is optional field if ($ocr && !in_array($contentType, ContentType::getOCRAllowed())) { throw new \InvalidArgumentException('Allowed Content type for OCR: ' . implode( ', ', From 6261f66c3a7c1b509e319d2e96932653b10c5e24 Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Thu, 15 Jun 2023 15:47:14 +0300 Subject: [PATCH 22/28] PSPD-12317 [PHP Client] Add new media methods and field --- src/MediaStorage/Builder.php | 2 +- tests/Covery/BuildMediaConnectionTest.php | 1 + tests/Covery/BuildMediaStorageTest.php | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/MediaStorage/Builder.php b/src/MediaStorage/Builder.php index 7135c31..1416694 100644 --- a/src/MediaStorage/Builder.php +++ b/src/MediaStorage/Builder.php @@ -72,7 +72,7 @@ public function addMediaStorageData($contentType, $contentDescription, $fileName if (!is_string($fileName)) { throw new \InvalidArgumentException('File name is empty'); } - if(strlen($fileName) > 255) { + if (strlen($fileName) > 255) { throw new \InvalidArgumentException('File name must contain no more than 255 characters'); } } diff --git a/tests/Covery/BuildMediaConnectionTest.php b/tests/Covery/BuildMediaConnectionTest.php index fe9c787..a3319f2 100644 --- a/tests/Covery/BuildMediaConnectionTest.php +++ b/tests/Covery/BuildMediaConnectionTest.php @@ -33,6 +33,7 @@ public function testEventExpectsInvalidArgumentException() $mediaId )->build(); } + public function testEventExpectsInvalidArgumentExceptionCheckZeroFields() { $requestId = 0; diff --git a/tests/Covery/BuildMediaStorageTest.php b/tests/Covery/BuildMediaStorageTest.php index c326a4a..d692b92 100644 --- a/tests/Covery/BuildMediaStorageTest.php +++ b/tests/Covery/BuildMediaStorageTest.php @@ -50,6 +50,7 @@ public function testEventExpectsInvalidArgumentException() false )->build(); } + public function testEmptyFileNameIsValidString() { $mediaStorage = \Covery\Client\MediaStorage\Builder::mediaStorageEvent( From bae0e462e3a9fded538139b8a37644f51826cebe Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Thu, 15 Jun 2023 19:43:39 +0300 Subject: [PATCH 23/28] PSPD-12317 [PHP Client] Add new media methods and field --- src/Facade.php | 10 +-- src/MediaFileUploader.php | 56 -------------- src/MediaFileUploader/Builder.php | 81 +++++++++++++++++++++ src/MediaFileUploader/MediaFileUploader.php | 75 +++++++++++++++++++ src/MediaFileUploaderInterface.php | 18 +++++ src/PublicAPIClient.php | 20 +++++ src/Requests/MediaFileUploader.php | 10 +-- tests/Covery/BuildMediaFileUploaderTest.php | 0 8 files changed, 202 insertions(+), 68 deletions(-) delete mode 100644 src/MediaFileUploader.php create mode 100644 src/MediaFileUploader/Builder.php create mode 100644 src/MediaFileUploader/MediaFileUploader.php create mode 100644 src/MediaFileUploaderInterface.php create mode 100644 tests/Covery/BuildMediaFileUploaderTest.php diff --git a/src/Facade.php b/src/Facade.php index 44d5f4d..e3a67b6 100644 --- a/src/Facade.php +++ b/src/Facade.php @@ -184,18 +184,14 @@ public static function detachMediaConnection(MediaConnectionInterface $mediaConn /** * Upload Media file and returns status code * - * @param $url - * @param $file + * @param MediaFileUploaderInterface $mediaFileUploader * @return int * @throws Exception * @throws IoException - * @throws TimeoutException */ - public static function uploadMediaFile($url, $file) + public static function uploadMediaFile(MediaFileUploaderInterface $mediaFileUploader) { - $mediaFileUploader = new MediaFileUploader($url, $file); - - return $mediaFileUploader->upload(); + return self::getClient()->uploadMediaFile($mediaFileUploader); } /** diff --git a/src/MediaFileUploader.php b/src/MediaFileUploader.php deleted file mode 100644 index 07f626c..0000000 --- a/src/MediaFileUploader.php +++ /dev/null @@ -1,56 +0,0 @@ -url = $url; - $this->file = $file; - } - - /** - * Upload media file - * - * @return int - * @throws Exception - * @throws IoException - * @throws TimeoutException - */ - public function upload() - { - $connectionTimeout = 60; - $transport = new Curl($connectionTimeout); - $response = $transport->send(new MediaFileUploaderRequest($this->url, $this->file)); - $statusCode = $response->getStatusCode(); - if ($statusCode >= 300) { - $response = json_decode($response->getBody()->getContents()); - throw new Exception($response->message, $response->code); - } - - return $statusCode; - } -} diff --git a/src/MediaFileUploader/Builder.php b/src/MediaFileUploader/Builder.php new file mode 100644 index 0000000..69ca689 --- /dev/null +++ b/src/MediaFileUploader/Builder.php @@ -0,0 +1,81 @@ +addMediaFileUploaderData($url, $file); + } + + /** + * Provides Upload data value + * + * @param $url + * @param $file + * @return Builder + */ + public function addMediaFileUploaderData($url, $file) + { + if (!is_string($url)) { + throw new \InvalidArgumentException('Url must be string'); + } + if (empty($url)) { + throw new \InvalidArgumentException('URL is empty'); + } + + if (!($file instanceof StreamInterface)) { + throw new \InvalidArgumentException('File must be instance of StreamInterface'); + } + + $this->replace('url', $url); + $this->replace('file', $file); + + return $this; + } + + /** + * Returns built MediaFileUploader + * + * @return MediaFileUploader + */ + public function build() + { + return new MediaFileUploader( + array_filter($this->data, function ($data) { + return $data !== null; + }) + ); + } + + /** + * Replaces value in internal array if provided value not empty + * + * @param string $key + * @param string|int|float|bool|array|null $value + */ + private function replace($key, $value) + { + if ($value !== null && $value !== '' && $value !== 0 && $value !== 0.0) { + $this->data[$key] = $value; + } + } +} diff --git a/src/MediaFileUploader/MediaFileUploader.php b/src/MediaFileUploader/MediaFileUploader.php new file mode 100644 index 0000000..1fe0c5e --- /dev/null +++ b/src/MediaFileUploader/MediaFileUploader.php @@ -0,0 +1,75 @@ +data = $data; + } + + /** + * @return array + */ + public function toArray() + { + return $this->data; + } + + /** + * @return int + */ + public function count() + { + return count($this->data); + } + + /** + * @inheritDoc + */ + public function offsetExists($offset) + { + return array_key_exists($offset, $this->data); + } + + /** + * @inheritDoc + */ + public function offsetGet($offset) + { + if (!$this->offsetExists($offset)) { + throw new \OutOfBoundsException("No offset {$offset}"); + } + + return $this->data[$offset]; + } + + /** + * @inheritDoc + */ + public function offsetSet($offset, $value) + { + $this->data[$offset] = $value; + } + + /** + * @inheritDoc + */ + public function offsetUnset($offset) + { + if ($this->offsetExists($offset)) { + unset($this->data[$offset]); + } + } +} diff --git a/src/MediaFileUploaderInterface.php b/src/MediaFileUploaderInterface.php new file mode 100644 index 0000000..477b354 --- /dev/null +++ b/src/MediaFileUploaderInterface.php @@ -0,0 +1,18 @@ +sendMediaConnection($mediaConnection, 'DELETE'); } + /** + * Upload Media file and returns status code + * + * @param MediaFileUploaderInterface $mediaFileUploader + * @return int + * @throws Exception + * @throws IoException + */ + public function uploadMediaFile(MediaFileUploaderInterface $mediaFileUploader) + { + $this->send(new MediaFileUploaderRequest($mediaFileUploader)); + + if ($this->responseStatusCode >= 300) { + throw new Exception("Malformed response"); + } + + return $this->responseStatusCode; + } + /** * Send media connection and return status code * diff --git a/src/Requests/MediaFileUploader.php b/src/Requests/MediaFileUploader.php index 8abfb33..d871341 100644 --- a/src/Requests/MediaFileUploader.php +++ b/src/Requests/MediaFileUploader.php @@ -2,6 +2,7 @@ namespace Covery\Client\Requests; +use Covery\Client\MediaFileUploaderInterface; use GuzzleHttp\Psr7\Request; /** @@ -14,18 +15,17 @@ class MediaFileUploader extends Request { /** - * @param $url - * @param $file + * @param MediaFileUploaderInterface $mediaFileUploader */ - public function __construct($url, $file) + public function __construct(MediaFileUploaderInterface $mediaFileUploader) { parent::__construct( 'PUT', - $url, + $mediaFileUploader['url'], [ 'Content-Type' => 'application/octet-stream', ], - $file + $mediaFileUploader['file'] ); } } diff --git a/tests/Covery/BuildMediaFileUploaderTest.php b/tests/Covery/BuildMediaFileUploaderTest.php new file mode 100644 index 0000000..e69de29 From 40c5a1ec38647cde0c0da8fb3a412f1ab61eb789 Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Tue, 20 Jun 2023 01:28:11 +0300 Subject: [PATCH 24/28] PSPD-12317 [PHP Client] Add new media methods and field --- src/AccountConfigurationStatusResult.php | 62 ++++----- src/Envelopes/Builder.php | 138 +++++++++++-------- src/Envelopes/ValidatorV1.php | 16 ++- src/PublicAPIClient.php | 17 ++- tests/Covery/BuildKYCProfileEnvelopeTest.php | 4 +- tests/Covery/BuildKYCStartEnvelopeTest.php | 10 +- tests/Covery/BuildKYCSubmitEnvelopeTest.php | 4 +- tests/Covery/BuildMediaFileUploaderTest.php | 0 8 files changed, 145 insertions(+), 106 deletions(-) delete mode 100644 tests/Covery/BuildMediaFileUploaderTest.php diff --git a/src/AccountConfigurationStatusResult.php b/src/AccountConfigurationStatusResult.php index 8d1c68b..0ee8b5f 100644 --- a/src/AccountConfigurationStatusResult.php +++ b/src/AccountConfigurationStatusResult.php @@ -12,68 +12,68 @@ class AccountConfigurationStatusResult { /** - * @var array + * @var array|null */ private $actualEventTypes; /** - * @var string + * @var string|null */ private $baseCurrency; /** - * @var string + * @var string|null */ private $decisionCallbackUrl; /** - * @var string + * @var string|null */ private $manualDecisionCallbackUrl; /** - * @var string + * @var string|null */ private $ongoingMonitoringWebhookUrl; /** - * @var string + * @var string|null */ private $mediaStorageWebhookUrl; /** - * @var string + * @var string|null */ private $fraudAlertCallbackUrl; /** - * @var bool + * @var bool|null */ private $cardIdGeneration; /** - * @var bool + * @var bool|null */ private $deviceFingerprintGeneration; /** - * @var bool + * @var bool|null */ private $sequenceIdGeneration; /** - * @var string + * @var string|null */ private $sequenceIdGenerationMethod; /** - * @var string + * @var string|null */ private $amlService; /** - * @var bool + * @var bool|null */ private $amlServiceStatus; /** - * @var string + * @var string|null */ private $dowJonesDataBaseDate; /** - * @var string + * @var string|null */ private $kycProvider; /** - * CardIdResult constructor. + * AccountConfigurationStatusResult constructor. * * @param $actualEventTypes * @param $baseCurrency @@ -108,49 +108,49 @@ public function __construct( $dowJonesDataBaseDate, $kycProvider ) { - if (!is_array($actualEventTypes)) { + if (!empty($actualEventTypes) && !is_array($actualEventTypes)) { throw new \InvalidArgumentException("Actual Event Types must be array"); } - if (!is_string($baseCurrency)) { + if (!empty($baseCurrency) && !is_string($baseCurrency)) { throw new \InvalidArgumentException("Base Currency must be string"); } - if (!is_string($decisionCallbackUrl)) { + if (!empty($decisionCallbackUrl) && !is_string($decisionCallbackUrl)) { throw new \InvalidArgumentException("Decision Callback Url must be string"); } - if (!is_string($manualDecisionCallbackUrl)) { + if (!empty($manualDecisionCallbackUrl) && !is_string($manualDecisionCallbackUrl)) { throw new \InvalidArgumentException("Manual Decision Callback Url must be string"); } - if (!is_string($ongoingMonitoringWebhookUrl)) { + if (!empty($ongoingMonitoringWebhookUrl) && !is_string($ongoingMonitoringWebhookUrl)) { throw new \InvalidArgumentException("Ongoing Monitoring Webhook Url must be string"); } - if (!is_string($mediaStorageWebhookUrl)) { + if (!empty($mediaStorageWebhookUrl) && !is_string($mediaStorageWebhookUrl)) { throw new \InvalidArgumentException("Media Storage Webhook Url Url must be string"); } - if (!is_string($fraudAlertCallbackUrl)) { + if (!empty($fraudAlertCallbackUrl) && !is_string($fraudAlertCallbackUrl)) { throw new \InvalidArgumentException("Fraud Alert Callback Url must be string"); } - if (!is_bool($cardIdGeneration)) { + if (!empty($cardIdGeneration) && !is_bool($cardIdGeneration)) { throw new \InvalidArgumentException("Card Id Generation must be string"); } - if (!is_bool($deviceFingerprintGeneration)) { + if (!empty($deviceFingerprintGeneration) && !is_bool($deviceFingerprintGeneration)) { throw new \InvalidArgumentException("Device Fingerprint Generation must be string"); } - if (!is_bool($sequenceIdGeneration)) { + if (!empty($sequenceIdGeneration) && !is_bool($sequenceIdGeneration)) { throw new \InvalidArgumentException("Sequence Id Generation must be string"); } - if (!is_string($sequenceIdGenerationMethod)) { + if (!empty($sequenceIdGenerationMethod) && !is_string($sequenceIdGenerationMethod)) { throw new \InvalidArgumentException("Sequence Id Generation Method must be string"); } - if (!is_string($amlService)) { + if (!empty($amlService) && !is_string($amlService)) { throw new \InvalidArgumentException("Aml Service must be string"); } - if (!is_bool($amlServiceStatus)) { + if (!empty($amlServiceStatus) && !is_bool($amlServiceStatus)) { throw new \InvalidArgumentException("Aml Service Status must be string"); } - if (!is_int($dowJonesDataBaseDate)) { + if (!empty($dowJonesDataBaseDate) && !is_int($dowJonesDataBaseDate)) { throw new \InvalidArgumentException("Dow Jones Data Base Date must be integer"); } - if (!is_string($kycProvider)) { + if (!empty($kycProvider) && !is_string($kycProvider)) { throw new \InvalidArgumentException("Kyc Provider must be string"); } diff --git a/src/Envelopes/Builder.php b/src/Envelopes/Builder.php index 53fd9fb..2918008 100644 --- a/src/Envelopes/Builder.php +++ b/src/Envelopes/Builder.php @@ -75,7 +75,7 @@ public static function confirmationEvent( null ) ->addGroupId($groupId) - ->addMediaId($mediaId); + ->addMediaData($mediaId); } /** @@ -141,7 +141,7 @@ public static function loginEvent( ) ->addWebsiteData(null, $trafficSource, $affiliateId, $campaign) ->addGroupId($groupId) - ->addMediaId($mediaId); + ->addMediaData($mediaId); } /** @@ -225,7 +225,7 @@ public static function registrationEvent( $password ) ->addGroupId($groupId) - ->addMediaId($mediaId); + ->addMediaData($mediaId); } /** @@ -307,7 +307,7 @@ public static function payoutEvent( ->addShortUserData($email, $userId, $phone, $firstName, $lastName, $country) ->addGroupId($groupId) ->addLinksToDocuments($linksToDocuments) - ->addMediaId($mediaId); + ->addMediaData($mediaId); } /** @@ -463,7 +463,7 @@ public static function transactionEvent( ->addIpData(null, null, $merchantIp) ->addGroupId($groupId) ->addLinksToDocuments($linksToDocuments) - ->addMediaId($mediaId); + ->addMediaData($mediaId); } @@ -504,7 +504,7 @@ public static function installEvent( )->addWebsiteData($websiteUrl, $trafficSource, $affiliateId, $campaign) ->addShortUserData(null, $userId, null, null, null, $country) ->addGroupId($groupId) - ->addMediaId($mediaId); + ->addMediaData($mediaId); } /** @@ -578,7 +578,7 @@ public static function refundEvent( ->addUserData($email, $userId, $phone) ->addGroupId($groupId) ->addLinksToDocuments($linksToDocuments) - ->addMediaId($mediaId); + ->addMediaData($mediaId); } /** @@ -745,7 +745,7 @@ public static function transferEvent( ->addProductData($productQuantity, $productName, $productDescription) ->addGroupId($groupId) ->addLinksToDocuments($linksToDocuments) - ->addMediaId($mediaId); + ->addMediaData($mediaId); } /** @@ -801,6 +801,9 @@ public static function transferEvent( * @param int|null $expiryDate * @param string|null $gender * @param string|null $linksToDocuments + * @param array|null $mediaId + * @param bool|null $addressConfirmed + * @param bool|null $secondAddressConfirmed * @return Builder */ public static function kycProfileEvent( @@ -855,8 +858,8 @@ public static function kycProfileEvent( $gender = null, $linksToDocuments = null, $mediaId = null, - $addressConfirmed = false, - $secondAddressConfirmed = false + $addressConfirmed = null, + $secondAddressConfirmed = null ) { $builder = new self('kyc_profile', $sequenceId); if ($eventTimestamp === null) { @@ -895,7 +898,19 @@ public static function kycProfileEvent( $employmentStatus, $sourceOfFunds, $issueDate, - $expiryDate + $expiryDate, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + $addressConfirmed, + $secondAddressConfirmed ) ->addUserData( $email, @@ -924,9 +939,7 @@ public static function kycProfileEvent( ) ->addWebsiteData($websiteUrl) ->addLinksToDocuments($linksToDocuments) - ->addMediaId($mediaId) - ->addAddressConfirmed($addressConfirmed) - ->addSecondAddressConfirmed($secondAddressConfirmed); + ->addMediaData($mediaId); } /** @@ -1225,7 +1238,7 @@ public static function profileUpdateEvent( $originUrl ) ->addLinksToDocuments($linksToDocuments) - ->addMediaId($mediaId); + ->addMediaData($mediaId); } @@ -1321,8 +1334,8 @@ public static function kycSubmitEvent( $refererUrl = null, $originUrl = null, $mediaId = null, - $addressConfirmed = false, - $secondAddressConfirmed = false + $addressConfirmed = null, + $secondAddressConfirmed = null ) { $builder = new self('kyc_submit', $sequenceId); if ($eventTimestamp === null) { @@ -1398,16 +1411,16 @@ public static function kycSubmitEvent( $userAgent, $plugins, $refererUrl, - $originUrl + $originUrl, + $addressConfirmed, + $secondAddressConfirmed ) ->addUserData( null, $userId ) ->addLinksToDocuments($linksToDocuments) - ->addMediaId($mediaId) - ->addAddressConfirmed($addressConfirmed) - ->addSecondAddressConfirmed($secondAddressConfirmed); + ->addMediaData($mediaId); } /** @@ -1419,6 +1432,7 @@ public static function kycSubmitEvent( * @param string $verificationMode * @param string $verificationSource * @param bool $consent + * @param array $mediaId * @param null|int $eventTimestamp * @param bool|null $allowNaOcrInputs * @param bool|null $declineOnSingleStep @@ -1447,6 +1461,7 @@ public static function kycStartEvent( $verificationMode, $verificationSource, $consent, + $mediaId, $eventTimestamp = null, $allowNaOcrInputs = null, $declineOnSingleStep = null, @@ -1515,8 +1530,11 @@ public static function kycStartEvent( $kycLanguage, $redirectUrl, $numberOfDocuments, - $allowedDocumentFormat + $allowedDocumentFormat, + null, + null ) + ->addMediaData($mediaId) ->addUserData( $email, $userMerchantId, @@ -1732,7 +1750,7 @@ public static function orderItemEvent( null, $affiliateId ) - ->addMediaId($mediaId); + ->addMediaData($mediaId); } /** @@ -1896,7 +1914,7 @@ public static function orderSubmitEvent( null, $affiliateId ) - ->addMediaId($mediaId); + ->addMediaData($mediaId); } /** @@ -3059,6 +3077,8 @@ public function addTransferData( * @param string|null $redirectUrl * @param int|null $numberOfDocuments * @param string|null $allowedDocumentFormat + * @param bool|null $addressConfirmed + * @param bool|null $secondAddressConfirmed * @return $this */ public function addKycData( @@ -3103,7 +3123,9 @@ public function addKycData( $kycLanguage = null, $redirectUrl = null, $numberOfDocuments = null, - $allowedDocumentFormat = null + $allowedDocumentFormat = null, + $addressConfirmed = null, + $secondAddressConfirmed = null ) { if (!is_string($eventId)) { throw new \InvalidArgumentException('Event ID must be string'); @@ -3231,6 +3253,12 @@ public function addKycData( if ($allowedDocumentFormat !== null && !is_string($allowedDocumentFormat)) { throw new \InvalidArgumentException('Allowed document format must be string'); } + if ($addressConfirmed !== null && !is_bool($addressConfirmed)) { + throw new \InvalidArgumentException('Address confirmed must be boolean'); + } + if ($secondAddressConfirmed !== null && !is_bool($secondAddressConfirmed)) { + throw new \InvalidArgumentException('Second address confirmed must be boolean'); + } $this->replace('event_id', $eventId); $this->replace('event_timestamp', $eventTimestamp); @@ -3274,6 +3302,8 @@ public function addKycData( $this->replace('redirect_url', $redirectUrl); $this->replace('number_of_documents', $numberOfDocuments); $this->replace('allowed_document_format', $allowedDocumentFormat); + $this->replace('address_confirmed', $addressConfirmed); + $this->replace('second_address_confirmed', $secondAddressConfirmed); return $this; } @@ -3653,44 +3683,20 @@ public function addGroupId($groupId = null) * @param array|null $mediaId * @return $this */ - public function addMediaId($mediaId = null) + public function addMediaData($mediaId = null) { - if ($mediaId !== null && !is_array($mediaId)) { - throw new \InvalidArgumentException('Media id must be string'); - } - $this->replace('media_id', $mediaId); - - return $this; - } - - /** - * Provides address confirmed value to envelope - * - * @param bool $addressConfirmed - * @return $this - */ - public function addAddressConfirmed($addressConfirmed = false) - { - if (!is_bool($addressConfirmed)) { - throw new \InvalidArgumentException('Address Confirmed must be bool'); - } - $this->replace('address_confirmed', $addressConfirmed); - - return $this; - } + if ($mediaId !== null) { + if (!is_array($mediaId)) { + throw new \InvalidArgumentException('Media id must be array'); + } - /** - * Provides address confirmed value to envelope - * - * @param bool $secondAddressConfirmed - * @return $this - */ - public function addSecondAddressConfirmed($secondAddressConfirmed = false) - { - if (!is_bool($secondAddressConfirmed)) { - throw new \InvalidArgumentException('Second Address Confirmed must be bool'); + foreach ($mediaId as $id) { + if (!is_int($id) || $id <= 0) { + throw new \InvalidArgumentException('Media id must be list of int'); + } + } } - $this->replace('second_address_confirmed', $secondAddressConfirmed); + $this->replace('media_id', $mediaId); return $this; } @@ -4433,7 +4439,9 @@ public function addKycSubmitData( $userAgent = null, $plugins = null, $refererUrl = null, - $originUrl = null + $originUrl = null, + $addressConfirmed = null, + $secondAddressConfirmed = null ) { if (!is_string($eventId)) { throw new \InvalidArgumentException('Event ID must be string'); @@ -4642,6 +4650,12 @@ public function addKycSubmitData( if ($originUrl !== null && !is_string($originUrl)) { throw new \InvalidArgumentException('Origin Url must be string'); } + if ($addressConfirmed !== null && !is_bool($addressConfirmed)) { + throw new \InvalidArgumentException('Address confirmed must be boolean'); + } + if ($secondAddressConfirmed !== null && !is_bool($secondAddressConfirmed)) { + throw new \InvalidArgumentException('Second address confirmed must be boolean'); + } $this->replace('event_id', $eventId); $this->replace('event_timestamp', $eventTimestamp); @@ -4712,6 +4726,8 @@ public function addKycSubmitData( $this->replace('plugins', $plugins); $this->replace('referer_url', $refererUrl); $this->replace('origin_url', $originUrl); + $this->replace('address_confirmed', $addressConfirmed); + $this->replace('second_address_confirmed', $secondAddressConfirmed); return $this; } diff --git a/src/Envelopes/ValidatorV1.php b/src/Envelopes/ValidatorV1.php index e960ec7..1f88fa0 100644 --- a/src/Envelopes/ValidatorV1.php +++ b/src/Envelopes/ValidatorV1.php @@ -241,7 +241,7 @@ class ValidatorV1 'active_features' => 'string(1024)', 'promotions' => 'string(1024)', 'links_to_documents' => 'string(2048)', - 'media_id' => 'array', + 'media_id' => 'array_int', ); private static $sharedOptional = array( @@ -648,6 +648,7 @@ class ValidatorV1 'verification_mode', 'verification_source', 'consent', + 'media_id', ), 'optional' => array( 'allow_na_ocr_inputs', @@ -1038,7 +1039,7 @@ public function analyzeFieldTypes(EnvelopeInterface $envelope) ); } break; - case 'array': + case 'array_int': if (!is_array($value)) { $details[] = sprintf( 'Field "%s" must be array, but %s provided', @@ -1046,6 +1047,17 @@ public function analyzeFieldTypes(EnvelopeInterface $envelope) $value === null ? 'null' : gettype($value) ); } + if (is_array($value)) { + foreach ($value as $id) { + if (!is_int($id) || $id <= 0) { + $details[] = sprintf( + 'ID: "%s" must be int, but %s provided', + $id, + $id === null ? 'null' : gettype($id) + ); + } + } + } break; default: $details[] = sprintf('Unknown type for "%s"', $key); diff --git a/src/PublicAPIClient.php b/src/PublicAPIClient.php index 52dd13a..ed17091 100644 --- a/src/PublicAPIClient.php +++ b/src/PublicAPIClient.php @@ -62,16 +62,23 @@ public function __construct( * Sends PSR-7 compatible request to Covery and returns * * @param RequestInterface $request + * @param bool $sign * @return string + * @throws Exception * @throws IoException */ - public function send(RequestInterface $request) + public function send(RequestInterface $request, $sign = true) { - $request = $this->prepareRequest($request); + $requestPrepared = $this->prepareRequest($request); + if ($sign) { + $requestSigned = $this->credentials->signRequest($requestPrepared); + } else { + $requestSigned = $requestPrepared; + } try { $this->logger->info('Sending request to ' . $request->getUri()); $before = microtime(true); - $response = $this->transport->send($request); + $response = $this->transport->send($requestSigned); $this->logger->info(sprintf('Request done in %.2f', microtime(true) - $before)); } catch (\Exception $inner) { $this->logger->error($inner->getMessage(), ['exception' => $inner]); @@ -105,7 +112,7 @@ private function prepareRequest(RequestInterface $request) ); } - return $this->credentials->signRequest($request); + return $request; } /** @@ -384,7 +391,7 @@ public function detachMediaConnection(MediaConnectionInterface $mediaConnection) */ public function uploadMediaFile(MediaFileUploaderInterface $mediaFileUploader) { - $this->send(new MediaFileUploaderRequest($mediaFileUploader)); + $this->send(new MediaFileUploaderRequest($mediaFileUploader), false); if ($this->responseStatusCode >= 300) { throw new Exception("Malformed response"); diff --git a/tests/Covery/BuildKYCProfileEnvelopeTest.php b/tests/Covery/BuildKYCProfileEnvelopeTest.php index 411844e..b56963d 100644 --- a/tests/Covery/BuildKYCProfileEnvelopeTest.php +++ b/tests/Covery/BuildKYCProfileEnvelopeTest.php @@ -133,7 +133,7 @@ public function testBuild() self::assertSame('kyc_profile', $result->getType()); self::assertSame('seqIdValue', $result->getSequenceId()); self::assertCount(1, $result->getIdentities()); - self::assertCount(5, $result); + self::assertCount(3, $result); self::assertSame('eventId', $result['event_id']); self::assertSame('userId', $result['user_merchant_id']); self::assertTrue($result['event_timestamp'] >= $current); @@ -154,7 +154,7 @@ public function testBuild() self::assertSame('kyc_profile', $result->getType()); self::assertSame('seqIdValue', $result->getSequenceId()); self::assertCount(0, $result->getIdentities()); - self::assertCount(8, $result); + self::assertCount(6, $result); self::assertSame('eventId', $result['event_id']); self::assertSame('userId', $result['user_merchant_id']); self::assertSame(333, $result['event_timestamp']); diff --git a/tests/Covery/BuildKYCStartEnvelopeTest.php b/tests/Covery/BuildKYCStartEnvelopeTest.php index c297743..e8d874a 100644 --- a/tests/Covery/BuildKYCStartEnvelopeTest.php +++ b/tests/Covery/BuildKYCStartEnvelopeTest.php @@ -14,6 +14,7 @@ public function testBuild() "kycStartVerificationMode", "kycStartVerificationSource", true, + [1, 2], 444, false, true, @@ -37,13 +38,14 @@ public function testBuild() self::assertSame('kyc_start', $result->getType()); self::assertSame('kycStartSequenceId', $result->getSequenceId()); - self::assertCount(24, $result); + self::assertCount(25, $result); self::assertSame('kycStartEventId', $result['event_id']); self::assertSame('kycStartUserMerchantId', $result['user_merchant_id']); self::assertSame('kycStartVerificationMode', $result['verification_mode']); self::assertSame('kycStartVerificationSource', $result['verification_source']); self::assertSame(true, $result['consent']); self::assertSame(444, $result['event_timestamp']); + self::assertSame([1, 2], $result['media_id']); self::assertSame(false, $result['allow_na_ocr_inputs']); self::assertSame(true, $result['decline_on_single_step']); self::assertSame(false, $result['backside_proof']); @@ -74,12 +76,13 @@ public function testBuild() "kycStartVerificationMode", "kycStartVerificationSource", true, + [1, 2], 555 )->build(); self::assertSame('kyc_start', $result->getType()); self::assertSame('kycStartSequenceId', $result->getSequenceId()); - self::assertCount(6, $result); + self::assertCount(7, $result); self::assertSame('kycStartEventId', $result['event_id']); self::assertSame('kycStartUserMerchantId', $result['user_merchant_id']); self::assertSame('kycStartVerificationMode', $result['verification_mode']); @@ -97,6 +100,7 @@ public function testBuild() "kycStartVerificationMode", "kycStartVerificationSource", true, + [1, 2], 555 )->addBrowserData( "deviceFingerprint", @@ -105,7 +109,7 @@ public function testBuild() )->build(); self::assertSame('kyc_start', $result->getType()); self::assertSame('kycStartSequenceId', $result->getSequenceId()); - self::assertCount(9, $result); + self::assertCount(10, $result); self::assertSame('kycStartEventId', $result['event_id']); self::assertSame('kycStartUserMerchantId', $result['user_merchant_id']); self::assertSame('kycStartVerificationMode', $result['verification_mode']); diff --git a/tests/Covery/BuildKYCSubmitEnvelopeTest.php b/tests/Covery/BuildKYCSubmitEnvelopeTest.php index 7ea769b..79991a4 100644 --- a/tests/Covery/BuildKYCSubmitEnvelopeTest.php +++ b/tests/Covery/BuildKYCSubmitEnvelopeTest.php @@ -180,7 +180,7 @@ public function testBuild() self::assertSame('kyc_submit', $result->getType()); self::assertSame('seqIdValue', $result->getSequenceId()); self::assertCount(1, $result->getIdentities()); - self::assertCount(5, $result); + self::assertCount(3, $result); self::assertSame('eventId', $result['event_id']); self::assertSame('userId', $result['user_merchant_id']); self::assertTrue($result['event_timestamp'] >= $current); @@ -201,7 +201,7 @@ public function testBuild() self::assertSame('kyc_submit', $result->getType()); self::assertSame('seqIdValue', $result->getSequenceId()); self::assertCount(0, $result->getIdentities()); - self::assertCount(8, $result); + self::assertCount(6, $result); self::assertSame('eventId', $result['event_id']); self::assertSame('userId', $result['user_merchant_id']); self::assertSame(333, $result['event_timestamp']); diff --git a/tests/Covery/BuildMediaFileUploaderTest.php b/tests/Covery/BuildMediaFileUploaderTest.php deleted file mode 100644 index e69de29..0000000 From 31021ed9a052137f615ad942a98eb9ccb975bb96 Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Tue, 20 Jun 2023 02:08:29 +0300 Subject: [PATCH 25/28] PSPD-12317 [PHP Client] Add new media methods and field --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eefa221..57d3a35 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,7 @@ You may provide the following as envelopes: ## Changelog * `1.3.14` Added MediaStorage method. Added MediaConnection method. Added UploadMediaFile method. * Added optional `media_id` field for events: install, registration, confirmation, login, order-item, order-submit, transaction, refund, payout, transfer, profile-update, kyc-profile, kyc-submit. - * Added address_confirmed, second_address_confirmed fields for KYC profile and KYC submit events. + * Added optional address_confirmed, second_address_confirmed fields for KYC profile and KYC submit events. * Added AccountConfigurationStatus method. * Removed Health check method. * `1.3.13` Added StaleDataException exception From da133efe8b0b13fede6ef759653fef30ab9f8ace Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Tue, 20 Jun 2023 14:40:05 +0300 Subject: [PATCH 26/28] PSPD-12317 [PHP Client] Add new media methods and field --- README.md | 14 ++++++++++++- src/Envelopes/Builder.php | 15 +++++++++++--- src/Envelopes/ValidatorV1.php | 1 - src/PublicAPIClient.php | 2 +- tests/Covery/BuildKYCStartEnvelopeTest.php | 10 +++------ tests/Covery/BuildMediaFileUploaderTest.php | 21 +++++++++++++++++++ tests/Covery/WithCustomHostTest.php | 23 +++++++++++++++++++++ 7 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 tests/Covery/BuildMediaFileUploaderTest.php create mode 100644 tests/Covery/WithCustomHostTest.php diff --git a/README.md b/README.md index 57d3a35..4d5e1e9 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,19 @@ Media file upload example: ```php use Covery\Client\Facade; -$statusCode = \Covery\Client\Facade::uploadMediaFile($mediaUrl, $file); +$base64EncodedFile = 'base64'; +$stream = fopen('php://temp', 'r+'); +fwrite($stream, $base64EncodedFile); +rewind($stream); +$fileStream = new \GuzzleHttp\Psr7\Stream($stream); + +$mediaUrl = 'UPLOAD_URL'; //URL from Covery +$mediaFileUploader = \Covery\Client\MediaFileUploader\Builder::mediaFileUploaderEvent( + $mediaUrl, + $fileStream +)->build(); + +$result = \Covery\Client\Facade::uploadMediaFile($mediaFileUploader); ``` Account Configuration Status event example: diff --git a/src/Envelopes/Builder.php b/src/Envelopes/Builder.php index 2918008..41b6638 100644 --- a/src/Envelopes/Builder.php +++ b/src/Envelopes/Builder.php @@ -37,6 +37,7 @@ class Builder * @param string|null $email * @param string|null $phone * @param string|null $groupId + * @param array|null $mediaId * * @return Builder */ @@ -92,6 +93,7 @@ public static function confirmationEvent( * @param string|null $password * @param string|null $campaign * @param string|null $groupId + * @param array|null $mediaId * * @return Builder */ @@ -165,6 +167,7 @@ public static function loginEvent( * @param string|null $password * @param string|null $campaign * @param string|null $groupId + * @param array|null $mediaId * * @return Builder */ @@ -254,6 +257,7 @@ public static function registrationEvent( * @param int|null $cardExpirationYear * @param string|null $groupId * @param string|null $linksToDocuments + * @param array|null $mediaId * * @return Builder */ @@ -360,6 +364,7 @@ public static function payoutEvent( * @param string|null $acquirerMerchantId * @param string|null $groupId * @param string|null $linksToDocuments + * @param array|null $mediaId * * @return Builder */ @@ -529,6 +534,7 @@ public static function installEvent( * @param string|null $userId * @param string|null $groupId * @param string|null $linksToDocuments + * @param array|null $mediaId * * @return Builder */ @@ -630,6 +636,7 @@ public static function refundEvent( * @param string|null $groupId * @param string|null $secondUserMerchantId * @param string|null $linksToDocuments + * @param array|null $mediaId * * @return Builder */ @@ -1257,6 +1264,9 @@ public static function profileUpdateEvent( * @param string|null $providerCode * @param string|null $providerReason * @param string|null $linksToDocuments + * @param array|null $mediaId + * @param bool|null $addressConfirmed + * @param bool|null $secondAddressConfirmed * * @return Builder */ @@ -1432,7 +1442,6 @@ public static function kycSubmitEvent( * @param string $verificationMode * @param string $verificationSource * @param bool $consent - * @param array $mediaId * @param null|int $eventTimestamp * @param bool|null $allowNaOcrInputs * @param bool|null $declineOnSingleStep @@ -1461,7 +1470,6 @@ public static function kycStartEvent( $verificationMode, $verificationSource, $consent, - $mediaId, $eventTimestamp = null, $allowNaOcrInputs = null, $declineOnSingleStep = null, @@ -1534,7 +1542,6 @@ public static function kycStartEvent( null, null ) - ->addMediaData($mediaId) ->addUserData( $email, $userMerchantId, @@ -1629,6 +1636,7 @@ public static function kycProofEvent($kycStartId) * @param string|null $websiteUrl * @param string|null $productUrl * @param string|null $productImageUrl + * @param array|null $mediaId * @return Builder */ public static function orderItemEvent( @@ -1801,6 +1809,7 @@ public static function orderItemEvent( * @param string|null $websiteUrl * @param string|null $productUrl * @param string|null $productImageUrl + * @param array|null $mediaId * @return Builder */ public static function orderSubmitEvent( diff --git a/src/Envelopes/ValidatorV1.php b/src/Envelopes/ValidatorV1.php index 1f88fa0..aa2c156 100644 --- a/src/Envelopes/ValidatorV1.php +++ b/src/Envelopes/ValidatorV1.php @@ -648,7 +648,6 @@ class ValidatorV1 'verification_mode', 'verification_source', 'consent', - 'media_id', ), 'optional' => array( 'allow_na_ocr_inputs', diff --git a/src/PublicAPIClient.php b/src/PublicAPIClient.php index ed17091..bf0749d 100644 --- a/src/PublicAPIClient.php +++ b/src/PublicAPIClient.php @@ -76,7 +76,7 @@ public function send(RequestInterface $request, $sign = true) $requestSigned = $requestPrepared; } try { - $this->logger->info('Sending request to ' . $request->getUri()); + $this->logger->info('Sending request to ' . $requestSigned->getUri()); $before = microtime(true); $response = $this->transport->send($requestSigned); $this->logger->info(sprintf('Request done in %.2f', microtime(true) - $before)); diff --git a/tests/Covery/BuildKYCStartEnvelopeTest.php b/tests/Covery/BuildKYCStartEnvelopeTest.php index e8d874a..c297743 100644 --- a/tests/Covery/BuildKYCStartEnvelopeTest.php +++ b/tests/Covery/BuildKYCStartEnvelopeTest.php @@ -14,7 +14,6 @@ public function testBuild() "kycStartVerificationMode", "kycStartVerificationSource", true, - [1, 2], 444, false, true, @@ -38,14 +37,13 @@ public function testBuild() self::assertSame('kyc_start', $result->getType()); self::assertSame('kycStartSequenceId', $result->getSequenceId()); - self::assertCount(25, $result); + self::assertCount(24, $result); self::assertSame('kycStartEventId', $result['event_id']); self::assertSame('kycStartUserMerchantId', $result['user_merchant_id']); self::assertSame('kycStartVerificationMode', $result['verification_mode']); self::assertSame('kycStartVerificationSource', $result['verification_source']); self::assertSame(true, $result['consent']); self::assertSame(444, $result['event_timestamp']); - self::assertSame([1, 2], $result['media_id']); self::assertSame(false, $result['allow_na_ocr_inputs']); self::assertSame(true, $result['decline_on_single_step']); self::assertSame(false, $result['backside_proof']); @@ -76,13 +74,12 @@ public function testBuild() "kycStartVerificationMode", "kycStartVerificationSource", true, - [1, 2], 555 )->build(); self::assertSame('kyc_start', $result->getType()); self::assertSame('kycStartSequenceId', $result->getSequenceId()); - self::assertCount(7, $result); + self::assertCount(6, $result); self::assertSame('kycStartEventId', $result['event_id']); self::assertSame('kycStartUserMerchantId', $result['user_merchant_id']); self::assertSame('kycStartVerificationMode', $result['verification_mode']); @@ -100,7 +97,6 @@ public function testBuild() "kycStartVerificationMode", "kycStartVerificationSource", true, - [1, 2], 555 )->addBrowserData( "deviceFingerprint", @@ -109,7 +105,7 @@ public function testBuild() )->build(); self::assertSame('kyc_start', $result->getType()); self::assertSame('kycStartSequenceId', $result->getSequenceId()); - self::assertCount(10, $result); + self::assertCount(9, $result); self::assertSame('kycStartEventId', $result['event_id']); self::assertSame('kycStartUserMerchantId', $result['user_merchant_id']); self::assertSame('kycStartVerificationMode', $result['verification_mode']); diff --git a/tests/Covery/BuildMediaFileUploaderTest.php b/tests/Covery/BuildMediaFileUploaderTest.php new file mode 100644 index 0000000..98cbb4f --- /dev/null +++ b/tests/Covery/BuildMediaFileUploaderTest.php @@ -0,0 +1,21 @@ +build(); + self::assertSame($mediaUrl, $mediaStorageResult['url']); + self::assertInstanceOf('Psr\Http\Message\StreamInterface', $mediaStorageResult['file']); + } +} diff --git a/tests/Covery/WithCustomHostTest.php b/tests/Covery/WithCustomHostTest.php new file mode 100644 index 0000000..004dfb1 --- /dev/null +++ b/tests/Covery/WithCustomHostTest.php @@ -0,0 +1,23 @@ +build(); + + $mock = self::getMockBuilder('Covery\\Client\\TransportInterface')->getMock(); + $mock->expects(self::exactly(1))->method('send')->with(self::callback(function(\Psr\Http\Message\RequestInterface $req) { + return strval($req->getUri()) == 'ftp://localhost/api/postback'; + })); + $custom = new \Covery\Client\Transport\WithCustomHost($mock, 'localhost', 'ftp'); + $custom->send(new \Covery\Client\Requests\Postback($result)); + + $mock = self::getMockBuilder('Covery\\Client\\TransportInterface')->getMock(); + $mock->expects(self::exactly(1))->method('send')->with(self::callback(function(\Psr\Http\Message\RequestInterface $req) { + return strval($req->getUri()) == 'https://test.local:8083/api/postback'; + })); + $custom = new \Covery\Client\Transport\WithCustomHost($mock, 'test.local:8083', 'https'); + $custom->send(new \Covery\Client\Requests\Postback($result)); + } +} From b1ab67adfdf81e98f723ff538c136dfdad2e1785 Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Tue, 20 Jun 2023 16:31:43 +0300 Subject: [PATCH 27/28] PSPD-12317 [PHP Client] Add new media methods and field --- README.md | 7 +------ tests/Covery/BuildMediaFileUploaderTest.php | 10 +++++----- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 4d5e1e9..62b525a 100644 --- a/README.md +++ b/README.md @@ -131,12 +131,7 @@ Media file upload example: ```php use Covery\Client\Facade; -$base64EncodedFile = 'base64'; -$stream = fopen('php://temp', 'r+'); -fwrite($stream, $base64EncodedFile); -rewind($stream); -$fileStream = new \GuzzleHttp\Psr7\Stream($stream); - +$stream = fopen('PATH_TO_FILE', 'r'); $mediaUrl = 'UPLOAD_URL'; //URL from Covery $mediaFileUploader = \Covery\Client\MediaFileUploader\Builder::mediaFileUploaderEvent( $mediaUrl, diff --git a/tests/Covery/BuildMediaFileUploaderTest.php b/tests/Covery/BuildMediaFileUploaderTest.php index 98cbb4f..66ff4e8 100644 --- a/tests/Covery/BuildMediaFileUploaderTest.php +++ b/tests/Covery/BuildMediaFileUploaderTest.php @@ -4,18 +4,18 @@ class BuildMediaFileUploaderTest extends \PHPUnit_Framework_TestCase { public function testBuild() { - $base64EncodedFile = 'iVBORw0KGgoAAAANSUhEUgAAAGcAAAAZCAYAAAAsaTBIAAAABHNCSVQICAgIfAhkiAAAABl0RVh0U29mdHdhcmUAZ25vbWUtc2NyZWVuc2hvdO8Dvz4AAAAtdEVYdENyZWF0aW9uIFRpbWUAVHVlIDIwIEp1biAyMDIzIDEyOjQzOjIxIFBNICswM6SysjgAAAfHSURBVGiB1Vp7iF7FFf/N3FljHppkNZutbdYsoja6QUWoEFPbbmlrFfHR1kQwRtYHqHu/rI+0DSaxEKnQWut+325CNbFCC9YHWKGNQRGkiBoDSov4QMUHosE+jG50k+zce/rHzJ07c2fm2+/b3Yge+Mjvnpk55/zmdc69G8Z7TyUQAAYl08HN5Kvk40viT4CYaiCtYQBI926GQTBjPQyAaW9ECjOth8aAHtMqZpOTYwHcDqd2+VU5tc2v4BTmJ4wzlEoDpowLogE8ZbtkHv1Ym+AZ49SE34xw8vlxHBZhLeCvmrTCaWb58ak5ZtazhZl1nzCmn8nVT9VfcU0yxDECeLr8itgZ+fz8u3NqnCL8hNJUjqi5u62jxghYuBjJ+deCLewC8gzZM38F/fNpy4Q1NmQTADvxTCTf/Rkwazbw+Rjkzu3Ah++49zlg3eEVDDS/MmPYjivGL4St2ON2rNhbwS3yY7y3j5wkF8D84kHwnpPLeIrNozGN7UP2x83unFSStbjqdmDO0WCsnE8b0953kD10F4pdKWp1s0EJAH36P2T3/8o1WmACxMDtwFHz9bwyECPI4RQdtYYXbwznz+9E/sIuAASRNswBLGoaa94AANkTfwK9tgfgDGJw2OMkGzVrIRUR3r8KyfKzNQMVAAGQ9dTjxEGko9SeK1jURsCXfFM7YcE8xuYtgEjrOir9IzLPIq0Dc46ukGMOZt1LIWqNMraxT8o+xMCO6tSmybgwGADmLTD7igDQ3ne1KWbFHsMlJ9tm4cKo7d0NIPnhGrWJ8hzZUw94/ERatyaLAHEEeN9Kw4mIQATI4TTIiVvTXK6aXh9RK4wT/H4BOeY471o1E+5J6Aoi0z+7b6Pnl5/zk6Cl5MLrPHvZg3d6tuN4epJcfivolWdB4/udGACAXzRoNOL6Oz2/sl6L2hVBLQH84jTctO8jZH/5LVjvciQ/usLo5Y5NwGf7XONpbGEA+cjvIX56Y7CNX3gd8se2guQhMHFEqT/9O8j/8UgZpBZ2/CmugTyL+x0ZCrQ7ySM8rl7OB//B5eDLzipHd3YDBGT3bvA2I+85Gfn8RUiu2BSOJZonY4sDIFlykhM3TRyC3Haz0dHreyBf3wORDkM+8Bt/YWoNhyoBkPf8AjjwuU94YRfEmk3GHT9+GXIA2dab/ZPX3QvsfVvHwcDP6C9gedePlotupj00/15yJ6P3lslykD/5ZyTLzjLm7CmV9dRwL/Qdazc7qZgA5M/9LbyJLD88WBZ3dgNW3AAgt91SthMzWDaGgP98ULZBJXOPHOXAgXGnn/l9/G/j3cix3zAaWy8uvanUEMBXXmQwAGB8zOQS17/9r8/Dx9X4rXGBuOw2NVfw+ph0P74f+Z4nLI21BlbsohxdmknOu6rkwgD65L9lF6ruFxeLG34Hk2QtkY11rqJatsGtnpJzLkH2aANyZAgivVt1K3Ll7LnAgf3AsV8vORWbaPutMJ9DrDgK22Lwbi98OawrJYufl4nmHwPwBOyE05CsuMBtz3PLIICJg5Av7ELyrXONXzuGbPsGmFJQtQQwK6o198c6F8NeyeyxbTAVmDEADyfX3gEkHVabsiHrKZJV612yoXcVvWMJDKxridLnGZCrNipO5jV3qIm+7Jd69+iFyKRVzRHKjVRWZi62w4/xUyLW3gaxZiOSFRf4/EbWef3p+b+DDo67p5CYusqrlVkQU+TzTZY5ASbfvyzYzZZkYAvYkXOrIULWU7Dl3wZb3DOpDfvuobGPjVY2arAiV0rGKzpCNhoqMA5TlZbnyB7f4RQKnud3X6n4ac+nKggqxzzbdT+S8682ndhxJzQ1wn88ADZvgaeX9RSYvwjJ9y5tHkVgbP7iU+UDC+zkdNhVEHk8QnMhR4f05mtT5CHAqhzBOeiNl9q3U0jsRivaqHjPMclQYXrrX54t3r/KslJaT1avR3LiGY6WoXzj7Vi72bSplzI/CYqBLX4R9epu2NeQ3LExVLoYkSPrIgk+VCCH0rSLq1q59RbPr3pViEXFmljWVysFsBU7jwVHEwcdOrxvJZIrb4P54CeEKhm7esoFZyqRTtRrUJ9gGrqMZUUHiGt+7fgpSmV7k+d55k/PZ5/qVMHK/uabSu7EGivUAAALu4HOxaoi7azg2XPNBFU5gamiprgYGVMFRHmC/XlsfqFFNogN+dJToxdh/O0+LnL0RiCT6oFz882pKvTh22Bf6w3biN3jXT0Qq9ejen/JxmD0Om+HQ757J/LdjwfHFTGxvhVI+t0cTAfHkf3h5549fu6V4CedGbTTijT9e44cHWrZkOpvLQwA5DnkvRuCfaMLE0zqWj56T4PKnpxmbm9JikP68rNANuE2zZoN3r96xl1y27HBxXOe6UppcpEj69TCVG2N7295t8hGWi5u5NTLh+9yx9g7NpZK2pXQWPu9aPQmr5n3na2+Xljjm4bQQqz6WmuhzJk1B2JgC9BhVSxEkI82gPffrIzXbIrv/UXbgkXqMw0ro6FDB5DdswGgzH0pjeKI7VbKn2b8PKmMsV5QPdt2m8GT8ZiEHwDGl/ZN7VII8Y3NT6vzMVW/zfB0/cRO0UxyCvlF8R88mnSI4lApEitPvoicMJm0u6iTvat+AZzCBcGXeZJbiS0U51THFcJCR+gwiBXD/wFy/RlTkleVwQAAAABJRU5ErkJggg=='; - $stream = fopen('php://temp', 'r+'); - fwrite($stream, $base64EncodedFile); - rewind($stream); - + $testString = 'Test file content'; + $stream = fopen('data://text/plain,' . $testString, 'r'); $mediaUrl = 'https://covery.devafenv.net/media/v1/1/1'; $fileStream = new \GuzzleHttp\Psr7\Stream($stream); $mediaStorageResult = \Covery\Client\MediaFileUploader\Builder::mediaFileUploaderEvent( $mediaUrl, $fileStream )->build(); + self::assertSame($mediaUrl, $mediaStorageResult['url']); self::assertInstanceOf('Psr\Http\Message\StreamInterface', $mediaStorageResult['file']); + self::assertEquals($fileStream, $mediaStorageResult['file']); + self::assertSame($testString, (string)$fileStream); } } From 8dd271c422490adfd4adcc2248d9f81980dcde52 Mon Sep 17 00:00:00 2001 From: Andrii Kozar Date: Tue, 20 Jun 2023 16:33:57 +0300 Subject: [PATCH 28/28] PSPD-12317 [PHP Client] Add new media methods and field --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 62b525a..965f283 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ $stream = fopen('PATH_TO_FILE', 'r'); $mediaUrl = 'UPLOAD_URL'; //URL from Covery $mediaFileUploader = \Covery\Client\MediaFileUploader\Builder::mediaFileUploaderEvent( $mediaUrl, - $fileStream + $stream )->build(); $result = \Covery\Client\Facade::uploadMediaFile($mediaFileUploader);