diff --git a/README.md b/README.md index 965f283..cc51d04 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ Postback event example: use Covery\Client\Envelopes\Builder; use Covery\Client\Facade; -$event = Builder::postbackEvent($requestId, null, 'code', 'reason')->build(); //postbcak for event with id $requestId +$event = Builder::postbackEvent($requestId, null, 'code', 'reason')->build(); //postback for event with id $requestId $postbackRequestId = Facade::sendPostback($event); ``` @@ -100,45 +100,45 @@ $event = Builder::cardIdEvent('curdNumber')->build(); $result = Facade::sendCardId($event); ``` -Media Storage event example: +Document Storage event example: ```php -use Covery\Client\MediaStorage\Builder; +use Covery\Client\DocumentStorage\Builder; use Covery\Client\Facade; -$event = Builder::mediaStorageEvent(\Covery\Client\ContentType::JPEG, \Covery\Client\ContentDescription::GENERAL_DOCUMENT, null, false)->build(); -$result = Facade::sendMediaStorage($event); +$event = Builder::documentStorageEvent(\Covery\Client\ContentType::JPEG, \Covery\Client\ContentDescription::GENERAL_DOCUMENT, null, false)->build(); +$result = Facade::sendDocumentStorage($event); ``` -Attach media connection event example: +Attach document connection event example: ```php -use Covery\Client\MediaConnection\Builder; +use Covery\Client\DocumentConnection\Builder; use Covery\Client\Facade; -$event = Builder::mediaConnectionEvent(1, [1])->build(); -$result = Facade::attachMediaConnection($event); +$event = Builder::documentConnectionEvent(1, [1])->build(); +$result = Facade::attachDocumentConnection($event); ``` -Detach media connection event example: +Detach document connection event example: ```php -use Covery\Client\MediaConnection\Builder; +use Covery\Client\DocumentConnection\Builder; use Covery\Client\Facade; -$event = Builder::mediaConnectionEvent(1, [1])->build(); -$result = Facade::detachMediaConnection($event); +$event = Builder::documentConnectionEvent(1, [1])->build(); +$result = Facade::detachDocumentConnection($event); ``` -Media file upload example: +Document file upload example: ```php use Covery\Client\Facade; $stream = fopen('PATH_TO_FILE', 'r'); -$mediaUrl = 'UPLOAD_URL'; //URL from Covery -$mediaFileUploader = \Covery\Client\MediaFileUploader\Builder::mediaFileUploaderEvent( - $mediaUrl, +$documentUrl = 'UPLOAD_URL'; //URL from Covery +$documentFileUploader = \Covery\Client\DocumentFileUploader\Builder::documentFileUploaderEvent( + $documentUrl, $stream )->build(); -$result = \Covery\Client\Facade::uploadMediaFile($mediaFileUploader); +$result = \Covery\Client\Facade::uploadDocumentFile($documentFileUploader); ``` Account Configuration Status event example: @@ -192,6 +192,7 @@ Methods `sendEvent` and `makeDecision` require envelope as argument. Envelope is * `kyc_submit` - kyc submit event * `order_item` - order item event * `order_submit` - order submit event + * `document` - document event Envelope specifications are bundled in `Covery\Client\EnvelopeInterface`. @@ -229,6 +230,17 @@ You may provide the following as envelopes: ## Changelog +* `1.4.0` + * **Removed transaction_id field from postback event** + * Renamed MediaStorage method to DocumentMethod + * Renamed MediaConnection method to DocumentConnection + * Renamed UploadMediaFile method to DocumentMediaFile. + * Renamed `media_id` field to `document_id` + * Added optional `merchant_advice_code` and `merchant_advice_text` fields for postback event + * Added optional `anonymous` field for kyc_submit, profile_update events + * Changed length field `plugins` to `8192` + * New `document` event introduced + * Old tests modified * `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 optional address_confirmed, second_address_confirmed fields for KYC profile and KYC submit events. diff --git a/src/AccountConfigurationStatusResult.php b/src/AccountConfigurationStatusResult.php index 0ee8b5f..8a09836 100644 --- a/src/AccountConfigurationStatusResult.php +++ b/src/AccountConfigurationStatusResult.php @@ -34,7 +34,7 @@ class AccountConfigurationStatusResult /** * @var string|null */ - private $mediaStorageWebhookUrl; + private $documentStorageWebhookUrl; /** * @var string|null */ @@ -80,7 +80,7 @@ class AccountConfigurationStatusResult * @param $decisionCallbackUrl * @param $manualDecisionCallbackUrl * @param $ongoingMonitoringWebhookUrl - * @param $mediaStorageWebhookUrl + * @param $documentStorageWebhookUrl * @param $fraudAlertCallbackUrl * @param $cardIdGeneration * @param $deviceFingerprintGeneration @@ -97,7 +97,7 @@ public function __construct( $decisionCallbackUrl, $manualDecisionCallbackUrl, $ongoingMonitoringWebhookUrl, - $mediaStorageWebhookUrl, + $documentStorageWebhookUrl, $fraudAlertCallbackUrl, $cardIdGeneration, $deviceFingerprintGeneration, @@ -123,8 +123,8 @@ public function __construct( if (!empty($ongoingMonitoringWebhookUrl) && !is_string($ongoingMonitoringWebhookUrl)) { throw new \InvalidArgumentException("Ongoing Monitoring Webhook Url must be string"); } - if (!empty($mediaStorageWebhookUrl) && !is_string($mediaStorageWebhookUrl)) { - throw new \InvalidArgumentException("Media Storage Webhook Url Url must be string"); + if (!empty($documentStorageWebhookUrl) && !is_string($documentStorageWebhookUrl)) { + throw new \InvalidArgumentException("Document Storage Webhook Url Url must be string"); } if (!empty($fraudAlertCallbackUrl) && !is_string($fraudAlertCallbackUrl)) { throw new \InvalidArgumentException("Fraud Alert Callback Url must be string"); @@ -159,7 +159,7 @@ public function __construct( $this->decisionCallbackUrl = $decisionCallbackUrl; $this->manualDecisionCallbackUrl = $manualDecisionCallbackUrl; $this->ongoingMonitoringWebhookUrl = $ongoingMonitoringWebhookUrl; - $this->mediaStorageWebhookUrl = $mediaStorageWebhookUrl; + $this->documentStorageWebhookUrl = $documentStorageWebhookUrl; $this->fraudAlertCallbackUrl = $fraudAlertCallbackUrl; $this->cardIdGeneration = $cardIdGeneration; $this->deviceFingerprintGeneration = $deviceFingerprintGeneration; @@ -214,9 +214,9 @@ public function getOngoingMonitoringWebhookUrl() /** * @return string */ - public function getMediaStorageWebhookUrl() + public function getDocumentStorageWebhookUrl() { - return $this->mediaStorageWebhookUrl; + return $this->documentStorageWebhookUrl; } /** diff --git a/src/AccountConfigurationStatusResultBaseField.php b/src/AccountConfigurationStatusResultBaseField.php index ead7a98..bf30d9e 100644 --- a/src/AccountConfigurationStatusResultBaseField.php +++ b/src/AccountConfigurationStatusResultBaseField.php @@ -13,7 +13,7 @@ class AccountConfigurationStatusResultBaseField const DECISION_CALLBACK_URL = 'decisionCallbackUrl'; const MANUAL_DECISION_CALLBACK_URL = 'manualDecisionCallbackUrl'; const ONGOING_MONITORING_WEBHOOK_URL = 'ongoingMonitoringWebhookUrl'; - const MEDIA_STORAGE_WEBHOOK_URL = 'mediaStorageWebhookUrl'; + const DOCUMENT_STORAGE_WEBHOOK_URL = 'documentStorageWebhookUrl'; const FRAUD_ALERT_CALLBACK_URL = 'fraudAlertCallbackUrl'; const CARD_ID_GENERATION = 'cardIdGeneration'; const DEVICE_FINGERPRINT_GENERATION = 'deviceFingerprintGeneration'; diff --git a/src/ContentDescription.php b/src/ContentDescription.php deleted file mode 100644 index 2f877bd..0000000 --- a/src/ContentDescription.php +++ /dev/null @@ -1,19 +0,0 @@ -addConnectionData($requestId, $mediaId); + ->addConnectionData($requestId, $documentId); } /** - * Provides MediaConnection value + * Provides DocumentConnection value * * @param $requestId - * @param $mediaId + * @param $documentId * @return Builder */ - public function addConnectionData($requestId, $mediaId) + public function addConnectionData($requestId, $documentId) { if (!is_int($requestId)) { throw new \InvalidArgumentException('Request Id must be integer'); @@ -39,27 +39,27 @@ public function addConnectionData($requestId, $mediaId) if ($requestId <= 0) { throw new \InvalidArgumentException('Request Id must be positive integer'); } - if (!is_array($mediaId)) { - throw new \InvalidArgumentException('Media Id must be array'); + if (!is_array($documentId)) { + throw new \InvalidArgumentException('Document Id must be array'); } - if (!$this->isListOfPositiveInt($mediaId)) { - throw new \InvalidArgumentException('Media Id must be list of positive int'); + if (!$this->isListOfPositiveInt($documentId)) { + throw new \InvalidArgumentException('Document Id must be list of positive int'); } $this->replace('request_id', $requestId); - $this->replace('media_id', $mediaId); + $this->replace('document_id', $documentId); return $this; } /** - * Returns built MediaConnection + * Returns built DocumentConnection * - * @return MediaConnection + * @return DocumentConnection */ public function build() { - return new MediaConnection( + return new DocumentConnection( array_filter($this->data, function ($data) { return $data !== null; }) diff --git a/src/MediaConnection/MediaConnection.php b/src/DocumentConnection/DocumentConnection.php similarity index 84% rename from src/MediaConnection/MediaConnection.php rename to src/DocumentConnection/DocumentConnection.php index 4166691..3f921f5 100644 --- a/src/MediaConnection/MediaConnection.php +++ b/src/DocumentConnection/DocumentConnection.php @@ -1,10 +1,10 @@ addMediaFileUploaderData($url, $file); + ->addDocumentFileUploaderData($url, $file); } /** @@ -33,7 +33,7 @@ public static function mediaFileUploaderEvent($url, $file) * @param $file * @return Builder */ - public function addMediaFileUploaderData($url, $file) + public function addDocumentFileUploaderData($url, $file) { if (!is_string($url)) { throw new \InvalidArgumentException('Url must be string'); @@ -53,13 +53,13 @@ public function addMediaFileUploaderData($url, $file) } /** - * Returns built MediaFileUploader + * Returns built DocumentFileUploader * - * @return MediaFileUploader + * @return DocumentFileUploader */ public function build() { - return new MediaFileUploader( + return new DocumentFileUploader( array_filter($this->data, function ($data) { return $data !== null; }) diff --git a/src/MediaFileUploader/MediaFileUploader.php b/src/DocumentFileUploader/DocumentFileUploader.php similarity index 84% rename from src/MediaFileUploader/MediaFileUploader.php rename to src/DocumentFileUploader/DocumentFileUploader.php index 1fe0c5e..b0bbf2b 100644 --- a/src/MediaFileUploader/MediaFileUploader.php +++ b/src/DocumentFileUploader/DocumentFileUploader.php @@ -1,10 +1,10 @@ addDocumentStorageData( + $userId, + $documentType, + $documentCountry, + $sequenceId, + $groupId, + $fileName, + $ocr, + $numberOfPages, + $translatedFrom, + $translatedTo + ); + } + + /** + * Provides DocumentStorage value + * + * @param string $userId + * @param string $documentType + * @param string|null $documentCountry + * @param string|null $sequenceId + * @param string|null $groupId + * @param string|null $fileName + * @param bool|null $ocr + * @param int|null $numberOfPages + * @param string|null $translatedFrom + * @param string|null $translatedTo + * + * @return Builder + */ + public function addDocumentStorageData( + $userMerchantId, + $documentType, + $documentCountry = null, + $sequenceId = null, + $groupId = null, + $fileName = null, + $ocr = false, + $numberOfPages = 1, + $translatedFrom = null, + $translatedTo = null + ) { + if (!is_string($userMerchantId)) { + throw new \InvalidArgumentException('User Merchant Id must be string'); + } + if (empty($userMerchantId)) { + throw new \InvalidArgumentException('User Merchant Id type is empty'); + } + + if (!is_string($documentType)) { + throw new \InvalidArgumentException('Document Type must be a string'); + } + if (empty($documentType)) { + throw new \InvalidArgumentException('Document Type is empty'); + } + if (!in_array($documentType, DocumentType::getAll())) { + throw new \InvalidArgumentException('Document Type must be one of the types: ' . implode( + ', ', + DocumentType::getAll() + ) + ); + } + + if ($documentCountry !== null && !is_string($documentCountry)) { + throw new \InvalidArgumentException('Document Country Id must be string'); + } + + if ($sequenceId !== null && !is_string($sequenceId)) { + throw new \InvalidArgumentException('Sequence Id must be string'); + } + + if ($groupId !== null && !is_string($groupId)) { + throw new \InvalidArgumentException('Group Id must be string'); + } + + 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'); + } + + if (!is_int($numberOfPages)) { + throw new \InvalidArgumentException('Number Of Pages must be int'); + } + + if ($translatedFrom !== null && !is_string($translatedFrom)) { + throw new \InvalidArgumentException('Translated From must be string'); + } + + if ($translatedTo !== null && !is_string($translatedTo)) { + throw new \InvalidArgumentException('Translated To must be string'); + } + + $this->replace('user_merchant_id', $userMerchantId); + $this->replace('document_type', $documentType); + $this->replace('document_country', $documentCountry); + $this->replace('sequence_id', $sequenceId); + $this->replace('group_id', $groupId); + $this->replace('file_name', $fileName); + $this->replace('ocr', $ocr); + $this->replace('number_of_pages', $numberOfPages); + $this->replace('translated_from', $translatedFrom); + $this->replace('translated_to', $translatedTo); + + return $this; + } + + /** + * Returns built DocumentStorage + * + * @return DocumentStorage + */ + public function build() + { + return new DocumentStorage( + 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/DocumentStorage/DocumentStorage.php similarity index 85% rename from src/MediaStorage/MediaStorage.php rename to src/DocumentStorage/DocumentStorage.php index e3e27c6..5cb9408 100644 --- a/src/MediaStorage/MediaStorage.php +++ b/src/DocumentStorage/DocumentStorage.php @@ -1,10 +1,10 @@ uploadUrl = $uploadUrl; + $this->documentId = $documentId; + $this->createdAt = $createdAt; + } + + + /** + * @return string[] + */ + public function getUploadUrl() + { + return $this->uploadUrl; + } + + /** + * @return int + */ + public function getDocumentId() + { + return $this->documentId; + } + + /** + * @return float + */ + public function getCreatedAt() + { + return $this->createdAt; + } +} diff --git a/src/MediaStorageResultBaseField.php b/src/DocumentStorageResultBaseField.php similarity index 69% rename from src/MediaStorageResultBaseField.php rename to src/DocumentStorageResultBaseField.php index 60f4090..3cc0862 100644 --- a/src/MediaStorageResultBaseField.php +++ b/src/DocumentStorageResultBaseField.php @@ -6,9 +6,9 @@ * Class CardIdResultBaseField * @package Covery\Client */ -class MediaStorageResultBaseField +class DocumentStorageResultBaseField { const UPLOAD_URL = 'uploadUrl'; - const MEDIA_ID = 'mediaId'; + const DOCUMENT_ID = 'documentId'; const CREATED_AT = 'createdAt'; } diff --git a/src/DocumentType.php b/src/DocumentType.php new file mode 100644 index 0000000..ef5941e --- /dev/null +++ b/src/DocumentType.php @@ -0,0 +1,47 @@ +addGroupId($groupId) - ->addMediaData($mediaId); + ->addDocumentData($documentId); } /** @@ -93,7 +107,7 @@ public static function confirmationEvent( * @param string|null $password * @param string|null $campaign * @param string|null $groupId - * @param array|null $mediaId + * @param array|null $documentId * * @return Builder */ @@ -109,7 +123,7 @@ public static function loginEvent( $password = null, $campaign = null, $groupId = null, - $mediaId = null + $documentId = null ) { $builder = new self('login', $sequenceId); if ($timestamp === null) { @@ -143,7 +157,7 @@ public static function loginEvent( ) ->addWebsiteData(null, $trafficSource, $affiliateId, $campaign) ->addGroupId($groupId) - ->addMediaData($mediaId); + ->addDocumentData($documentId); } /** @@ -167,7 +181,7 @@ public static function loginEvent( * @param string|null $password * @param string|null $campaign * @param string|null $groupId - * @param array|null $mediaId + * @param array|null $documentId * * @return Builder */ @@ -190,7 +204,7 @@ public static function registrationEvent( $password = null, $campaign = null, $groupId = null, - $mediaId = null + $documentId = null ) { $builder = new self('registration', $sequenceId); if ($timestamp === null) { @@ -228,7 +242,7 @@ public static function registrationEvent( $password ) ->addGroupId($groupId) - ->addMediaData($mediaId); + ->addDocumentData($documentId); } /** @@ -257,7 +271,7 @@ public static function registrationEvent( * @param int|null $cardExpirationYear * @param string|null $groupId * @param string|null $linksToDocuments - * @param array|null $mediaId + * @param array|null $documentId * * @return Builder */ @@ -285,7 +299,7 @@ public static function payoutEvent( $cardExpirationYear = null, $groupId = null, $linksToDocuments = null, - $mediaId = null + $documentId = null ) { $builder = new self('payout', $sequenceId); if ($payoutTimestamp === null) { @@ -311,7 +325,7 @@ public static function payoutEvent( ->addShortUserData($email, $userId, $phone, $firstName, $lastName, $country) ->addGroupId($groupId) ->addLinksToDocuments($linksToDocuments) - ->addMediaData($mediaId); + ->addDocumentData($documentId); } /** @@ -364,7 +378,7 @@ public static function payoutEvent( * @param string|null $acquirerMerchantId * @param string|null $groupId * @param string|null $linksToDocuments - * @param array|null $mediaId + * @param array|null $documentId * * @return Builder */ @@ -416,7 +430,7 @@ public static function transactionEvent( $acquirerMerchantId = null, $groupId = null, $linksToDocuments = null, - $mediaId = null + $documentId = null ) { $builder = new self('transaction', $sequenceId); if ($transactionTimestamp === null) { @@ -468,7 +482,7 @@ public static function transactionEvent( ->addIpData(null, null, $merchantIp) ->addGroupId($groupId) ->addLinksToDocuments($linksToDocuments) - ->addMediaData($mediaId); + ->addDocumentData($documentId); } @@ -484,7 +498,7 @@ public static function transactionEvent( * @param string|null $affiliateId * @param string|null $campaign * @param string|null $groupId - * @param array|null $mediaId + * @param array|null $documentId * @return Builder */ public static function installEvent( @@ -497,7 +511,7 @@ public static function installEvent( $affiliateId = null, $campaign = null, $groupId = null, - $mediaId = null + $documentId = null ) { $builder = new self('install', $sequenceId); if ($installTimestamp === null) { @@ -509,7 +523,7 @@ public static function installEvent( )->addWebsiteData($websiteUrl, $trafficSource, $affiliateId, $campaign) ->addShortUserData(null, $userId, null, null, null, $country) ->addGroupId($groupId) - ->addMediaData($mediaId); + ->addDocumentData($documentId); } /** @@ -534,7 +548,7 @@ public static function installEvent( * @param string|null $userId * @param string|null $groupId * @param string|null $linksToDocuments - * @param array|null $mediaId + * @param array|null $documentId * * @return Builder */ @@ -558,7 +572,7 @@ public static function refundEvent( $userId = null, $groupId = null, $linksToDocuments = null, - $mediaId = null + $documentId = null ) { $builder = new self('refund', $sequenceId); if ($refundTimestamp === null) { @@ -584,7 +598,7 @@ public static function refundEvent( ->addUserData($email, $userId, $phone) ->addGroupId($groupId) ->addLinksToDocuments($linksToDocuments) - ->addMediaData($mediaId); + ->addDocumentData($documentId); } /** @@ -636,7 +650,7 @@ public static function refundEvent( * @param string|null $groupId * @param string|null $secondUserMerchantId * @param string|null $linksToDocuments - * @param array|null $mediaId + * @param array|null $documentId * * @return Builder */ @@ -687,7 +701,7 @@ public static function transferEvent( $groupId = null, $secondUserMerchantId = null, $linksToDocuments = null, - $mediaId = null + $documentId = null ) { $builder = new self('transfer', $sequenceId); if ($eventTimestamp === null) { @@ -752,7 +766,7 @@ public static function transferEvent( ->addProductData($productQuantity, $productName, $productDescription) ->addGroupId($groupId) ->addLinksToDocuments($linksToDocuments) - ->addMediaData($mediaId); + ->addDocumentData($documentId); } /** @@ -808,7 +822,7 @@ public static function transferEvent( * @param int|null $expiryDate * @param string|null $gender * @param string|null $linksToDocuments - * @param array|null $mediaId + * @param array|null $documentId * @param bool|null $addressConfirmed * @param bool|null $secondAddressConfirmed * @return Builder @@ -864,7 +878,7 @@ public static function kycProfileEvent( $expiryDate = null, $gender = null, $linksToDocuments = null, - $mediaId = null, + $documentId = null, $addressConfirmed = null, $secondAddressConfirmed = null ) { @@ -946,7 +960,7 @@ public static function kycProfileEvent( ) ->addWebsiteData($websiteUrl) ->addLinksToDocuments($linksToDocuments) - ->addMediaData($mediaId); + ->addDocumentData($documentId); } /** @@ -1045,7 +1059,8 @@ public static function kycProfileEvent( * @param null $refererUrl * @param null $originUrl * @param string|null $linksToDocuments - * @param array|null $mediaId + * @param array|null $documentId + * @param null $anonymous * @return static */ public static function profileUpdateEvent( @@ -1144,7 +1159,8 @@ public static function profileUpdateEvent( $refererUrl = null, $originUrl = null, $linksToDocuments = null, - $mediaId = null + $documentId = null, + $anonymous = null ) { $builder = new self(self::EVENT_PROFILE_UPDATE, $sequenceId); @@ -1242,10 +1258,11 @@ public static function profileUpdateEvent( $userAgent, $plugins, $refererUrl, - $originUrl + $originUrl, + $anonymous ) ->addLinksToDocuments($linksToDocuments) - ->addMediaData($mediaId); + ->addDocumentData($documentId); } @@ -1264,7 +1281,7 @@ public static function profileUpdateEvent( * @param string|null $providerCode * @param string|null $providerReason * @param string|null $linksToDocuments - * @param array|null $mediaId + * @param array|null $documentId * @param bool|null $addressConfirmed * @param bool|null $secondAddressConfirmed * @@ -1343,9 +1360,10 @@ public static function kycSubmitEvent( $plugins = null, $refererUrl = null, $originUrl = null, - $mediaId = null, + $documentId = null, $addressConfirmed = null, - $secondAddressConfirmed = null + $secondAddressConfirmed = null, + $anonymous = null ) { $builder = new self('kyc_submit', $sequenceId); if ($eventTimestamp === null) { @@ -1423,14 +1441,15 @@ public static function kycSubmitEvent( $refererUrl, $originUrl, $addressConfirmed, - $secondAddressConfirmed + $secondAddressConfirmed, + $anonymous ) ->addUserData( null, $userId ) ->addLinksToDocuments($linksToDocuments) - ->addMediaData($mediaId); + ->addDocumentData($documentId); } /** @@ -1576,10 +1595,9 @@ public static function kycStartEvent( */ public static function kycProofEvent($kycStartId) { - $envelopeType = 'kyc_proof'; $sequenceId = ''; - $builder = new self($envelopeType, $sequenceId); + $builder = new self(self::EVENT_KYC_PROOF, $sequenceId); return $builder ->addKycProofData($kycStartId); @@ -1636,7 +1654,7 @@ public static function kycProofEvent($kycStartId) * @param string|null $websiteUrl * @param string|null $productUrl * @param string|null $productImageUrl - * @param array|null $mediaId + * @param array|null $documentId * @return Builder */ public static function orderItemEvent( @@ -1688,7 +1706,7 @@ public static function orderItemEvent( $websiteUrl = null, $productUrl = null, $productImageUrl = null, - $mediaId = null + $documentId = null ) { $envelopeType = 'order_item'; $builder = new self($envelopeType, $sequenceId); @@ -1758,7 +1776,7 @@ public static function orderItemEvent( null, $affiliateId ) - ->addMediaData($mediaId); + ->addDocumentData($documentId); } /** @@ -1809,7 +1827,7 @@ public static function orderItemEvent( * @param string|null $websiteUrl * @param string|null $productUrl * @param string|null $productImageUrl - * @param array|null $mediaId + * @param array|null $documentId * @return Builder */ public static function orderSubmitEvent( @@ -1858,7 +1876,7 @@ public static function orderSubmitEvent( $websiteUrl = null, $productUrl = null, $productImageUrl = null, - $mediaId = null + $documentId = null ) { $envelopeType = 'order_submit'; $builder = new self($envelopeType, $sequenceId); @@ -1923,14 +1941,13 @@ public static function orderSubmitEvent( null, $affiliateId ) - ->addMediaData($mediaId); + ->addDocumentData($documentId); } /** * Returns builder for postback request * - * @param int|null $requestId - * @param string|null $transactionId + * @param int $requestId * @param string|null $transactionStatus * @param string|null $code * @param string|null $reason @@ -1939,13 +1956,14 @@ public static function orderSubmitEvent( * @param string|null $cvvResult * @param string|null $pspCode * @param string|null $pspReason + * @param string|null $merchantAdviceCode + * @param string|null $merchantAdviceText * @param string|null $arn * @param string|null $paymentAccountId * @return Builder */ public static function postBackEvent( - $requestId = null, - $transactionId = null, + $requestId, $transactionStatus = null, $code = null, $reason = null, @@ -1955,12 +1973,13 @@ public static function postBackEvent( $pspCode = null, $pspReason = null, $arn = null, - $paymentAccountId = null + $paymentAccountId = null, + $merchantAdviceCode = null, + $merchantAdviceText = null ) { - $builder = new self('postback', ''); + $builder = new self(self::EVENT_POSTBACK, ''); return $builder->addPostBackData( $requestId, - $transactionId, $transactionStatus, $code, $reason, @@ -1970,10 +1989,191 @@ public static function postBackEvent( $pspCode, $pspReason, $arn, - $paymentAccountId + $paymentAccountId, + $merchantAdviceCode, + $merchantAdviceText ); } + /** + * Returns builder for document request + * + * @param string $eventId + * @param int $eventTimestamp + * @param string $userId + * @param string $documentType + * @param string|null $sequenceId + * @param string|null $groupId + * @param string|null $documentCountry + * @param string|null $documentNumber + * @param string|null $fileName + * @param string|null $email + * @param string|null $firstname + * @param string|null $lastname + * @param string|null $fullname + * @param int|null $birthDate + * @param int|null $age + * @param string|null $gender + * @param string|null $nationality + * @param string|null $country + * @param string|null $city + * @param string|null $zip + * @param string|null $address + * @param int|null $issueDate + * @param int|null $expiryDate + * @param string|null $authority + * @param string|null $recordNumber + * @param string|null $personalNumber + * @param string|null $description + * @param float|null $productQuantity + * @param string|null $paymentMethod + * @param float|null $amount + * @param float|null $amountConverted + * @param string|null $currency + * @param string|null $mrzDocumentType + * @param string|null $mrzCountry + * @param string|null $mrzLastname + * @param string|null $mrzFirstname + * @param string|null $mrzFullname + * @param string|null $mrzDocumentNumber + * @param string|null $mrzNationality + * @param string|null $mrzPersonalNumber + * @param int|null $mrzBirthDate + * @param string|null $mrzGender + * @param int|null $mrzExpiryDate + * @param string|null $mrzRecordNumber + * @param bool|null $mrzCheckDigitsValidation + * @param string|null $extractedTest + * @param array|null $textLanguageDetails + * @param string|null $translatedExtractedText + * @param string|null $translatedFrom + * @param string|null $translatedTo + * + * @return Builder + */ + public static function documentEvent( + $eventId, + $eventTimestamp, + $userId, + $documentType, + $sequenceId = null, + $groupId = null, + $documentCountry = null, + $documentNumber = null, + $fileName = null, + $email = null, + $firstname = null, + $lastname = null, + $fullname = null, + $birthDate = null, + $age = null, + $gender = null, + $nationality = null, + $country = null, + $city = null, + $zip = null, + $address = null, + $issueDate = null, + $expiryDate = null, + $authority = null, + $recordNumber = null, + $personalNumber = null, + $description = null, + $productQuantity = null, + $paymentMethod = null, + $amount = null, + $amountConverted = null, + $currency = null, + $mrzDocumentType = null, + $mrzCountry = null, + $mrzLastname = null, + $mrzFirstname = null, + $mrzFullname = null, + $mrzDocumentNumber = null, + $mrzNationality = null, + $mrzPersonalNumber = null, + $mrzBirthDate = null, + $mrzGender = null, + $mrzExpiryDate = null, + $mrzRecordNumber = null, + $mrzCheckDigitsValidation = null, + $extractedTest = null, + $textLanguageDetails = null, + $translatedExtractedText = null, + $translatedFrom = null, + $translatedTo = null + ) { + $sequenceId = $sequenceId ?? ''; + $builder = new self(self::EVENT_DOCUMENT, $sequenceId); + if ($eventTimestamp === null) { + $eventTimestamp = time(); + } + return $builder + ->addDocumentEventData( + $eventId, + $eventTimestamp, + $documentType, + $groupId, + $documentCountry, + $documentNumber, + $fileName, + $nationality, + $issueDate, + $expiryDate, + $authority, + $recordNumber, + $personalNumber, + $description, + $productQuantity, + $paymentMethod, + $amount, + $amountConverted, + $currency, + $mrzDocumentType, + $mrzCountry, + $mrzLastname, + $mrzFirstname, + $mrzFullname, + $mrzDocumentNumber, + $mrzNationality, + $mrzPersonalNumber, + $mrzBirthDate, + $mrzGender, + $mrzExpiryDate, + $mrzRecordNumber, + $mrzCheckDigitsValidation, + $extractedTest, + $textLanguageDetails, + $translatedExtractedText, + $translatedFrom, + $translatedTo + ) + ->addUserData( + $email, + $userId, + null, + null, + $firstname, + $lastname, + $gender, + $age, + $country, + null, + null, + null, + null, + null, + null, + null, + $birthDate, + $fullname, + null, + $city, + $address, + $zip + ); + } + /** * Builder constructor. * @@ -1986,7 +2186,7 @@ public function __construct($envelopeType, $sequenceId) throw new \InvalidArgumentException('Envelope type must be string'); } - if ($envelopeType == self::EVENT_PROFILE_UPDATE) { + if ($envelopeType == self::EVENT_PROFILE_UPDATE || $envelopeType == self::EVENT_DOCUMENT) { if (!is_null($sequenceId) && !is_string($sequenceId)) { throw new \InvalidArgumentException('Sequence ID must be string or null'); } @@ -2127,6 +2327,7 @@ public function addIpData($ip = '', $realIp = '', $merchantIp = '') * @param string|null $refererUrl * @param string|null $originUrl * @param string|null $clientResolution + * @param bool|null $anonymous * @return $this */ public function addBrowserData( @@ -2150,7 +2351,8 @@ public function addBrowserData( $plugins = null, $refererUrl = null, $originUrl = null, - $clientResolution = null + $clientResolution = null, + $anonymous = null ) { if ($deviceFingerprint !== null && !is_string($deviceFingerprint)) { throw new \InvalidArgumentException('Device fingerprint must be string'); @@ -2194,6 +2396,9 @@ public function addBrowserData( if ($doNotTrack !== null && !is_bool($doNotTrack)) { throw new \InvalidArgumentException('DNT flag must be boolean'); } + if ($anonymous !== null && !is_bool($anonymous)) { + throw new \InvalidArgumentException('Anonymous flag must be boolean'); + } if ($ajaxValidation !== null && !is_bool($ajaxValidation)) { throw new \InvalidArgumentException('AJAX validation flag must be boolean'); } @@ -2230,6 +2435,7 @@ public function addBrowserData( $this->replace('language_user', $languageUser); $this->replace('cookie_enabled', $cookieEnabled); $this->replace('do_not_track', $doNotTrack); + $this->replace('anonymous', $anonymous); $this->replace('ajax_validation', $ajaxValidation); $this->replace('device_id', $deviceId); $this->replace('local_ip_list', $ipList); @@ -3561,8 +3767,7 @@ public function addOrderData( /** * Provides postback information to envelope * - * @param int|null $requestId - * @param string|null $transactionId + * @param int $requestId * @param string|null $transactionStatus * @param string|null $code * @param string|null $reason @@ -3573,11 +3778,12 @@ public function addOrderData( * @param string|null $pspReason * @param string|null $arn * @param string|null $paymentAccountId + * @param string|null $merchantAdviceCode + * @param string|null $merchantAdviceText * @return $this */ public function addPostbackData( - $requestId = null, - $transactionId = null, + $requestId, $transactionStatus = null, $code = null, $reason = null, @@ -3587,16 +3793,12 @@ public function addPostbackData( $pspCode = null, $pspReason = null, $arn = null, - $paymentAccountId = null + $paymentAccountId = null, + $merchantAdviceCode = null, + $merchantAdviceText = null ) { - if ($requestId === null && $transactionId === null) { - throw new \InvalidArgumentException('request_id or transaction_id should be provided'); - } - if ($transactionId !== null && !is_string($transactionId)) { - throw new \InvalidArgumentException('TransactionId must be string'); - } - if ($requestId !== null && !is_int($requestId)) { - throw new \InvalidArgumentException('RequestId must be int'); + if (!is_int($requestId)) { + throw new \InvalidArgumentException('Request ID must be integer'); } if ($transactionStatus !== null && !is_string($transactionStatus)) { throw new \InvalidArgumentException('Transaction status must be string'); @@ -3622,6 +3824,12 @@ public function addPostbackData( if ($pspReason !== null && !is_string($pspReason)) { throw new \InvalidArgumentException('PspReason must be string'); } + if ($merchantAdviceCode !== null && !is_string($merchantAdviceCode)) { + throw new \InvalidArgumentException('Merchant advice code must be string'); + } + if ($merchantAdviceText !== null && !is_string($merchantAdviceText)) { + throw new \InvalidArgumentException('Merchant advice text must be string'); + } if ($arn !== null && !is_string($arn)) { throw new \InvalidArgumentException('Arn must be string'); } @@ -3630,7 +3838,6 @@ public function addPostbackData( } $this->replace('request_id', $requestId); - $this->replace('transaction_id', $transactionId); $this->replace('transaction_status', $transactionStatus); $this->replace('code', $code); $this->replace('reason', $reason); @@ -3641,6 +3848,8 @@ public function addPostbackData( $this->replace('psp_reason', $pspReason); $this->replace('arn', $arn); $this->replace('payment_account_id', $paymentAccountId); + $this->replace('merchant_advice_code', $merchantAdviceCode); + $this->replace('merchant_advice_text', $merchantAdviceText); return $this; } @@ -3687,25 +3896,25 @@ public function addGroupId($groupId = null) } /** - * Provides media id value to envelope + * Provides document id value to envelope * - * @param array|null $mediaId + * @param array|null $documentId * @return $this */ - public function addMediaData($mediaId = null) + public function addDocumentData($documentId = null) { - if ($mediaId !== null) { - if (!is_array($mediaId)) { - throw new \InvalidArgumentException('Media id must be array'); + if ($documentId !== null) { + if (!is_array($documentId)) { + throw new \InvalidArgumentException('Document id must be array'); } - foreach ($mediaId as $id) { + foreach ($documentId as $id) { if (!is_int($id) || $id <= 0) { - throw new \InvalidArgumentException('Media id must be list of int'); + throw new \InvalidArgumentException('Document id must be list of int'); } } } - $this->replace('media_id', $mediaId); + $this->replace('document_id', $documentId); return $this; } @@ -3735,7 +3944,7 @@ public function addLinksToDocuments($linksToDocuments = null) public function addKycProofData($kycStartId) { if (!is_int($kycStartId)) { - throw new \InvalidArgumentException('KycStartId must be integer'); + throw new \InvalidArgumentException('Kyc start ID must be integer'); } $this->replace('kyc_start_id', $kycStartId); @@ -3836,7 +4045,8 @@ public function addProfileData( $userAgent = null, $plugins = null, $refererUrl = null, - $originUrl = null + $originUrl = null, + $anonymous = null ) { if (!is_string($eventId)) { throw new \InvalidArgumentException('Event ID must be string'); @@ -4142,6 +4352,10 @@ public function addProfileData( throw new \InvalidArgumentException('Do Not Track must be boolean'); } + if ($anonymous !== null && !is_bool($anonymous)) { + throw new \InvalidArgumentException('Anonymous flag must be boolean'); + } + if ($ip !== null && !is_string($ip)) { throw new \InvalidArgumentException('IP must be string'); } @@ -4286,6 +4500,7 @@ public function addProfileData( $this->replace('device_fingerprint', $deviceFingerprint); $this->replace('device_id', $deviceId); $this->replace('do_not_track', $doNotTrack); + $this->replace('anonymous', $anonymous); $this->replace('ip', $ip); $this->replace('real_ip', $realIp); $this->replace('local_ip_list', $localIpList); @@ -4377,6 +4592,7 @@ public function addProfileData( * @param string|null $plugins * @param string|null $refererUrl * @param string|null $originUrl + * @param bool|null $anonymous * @return $this */ public function addKycSubmitData( @@ -4450,7 +4666,8 @@ public function addKycSubmitData( $refererUrl = null, $originUrl = null, $addressConfirmed = null, - $secondAddressConfirmed = null + $secondAddressConfirmed = null, + $anonymous = null ) { if (!is_string($eventId)) { throw new \InvalidArgumentException('Event ID must be string'); @@ -4608,6 +4825,9 @@ public function addKycSubmitData( if ($doNotTrack !== null && !is_bool($doNotTrack)) { throw new \InvalidArgumentException('Do Not Track must be boolean'); } + if ($anonymous !== null && !is_bool($anonymous)) { + throw new \InvalidArgumentException('Anonymous flag must be boolean'); + } if ($ip !== null && !is_string($ip)) { throw new \InvalidArgumentException('IP must be string'); } @@ -4718,6 +4938,7 @@ public function addKycSubmitData( $this->replace('device_fingerprint', $deviceFingerprint); $this->replace('device_id', $deviceId); $this->replace('do_not_track', $doNotTrack); + $this->replace('anonymous', $anonymous); $this->replace('ip', $ip); $this->replace('real_ip', $realIp); $this->replace('local_ip_list', $localIpList); @@ -4740,4 +4961,253 @@ public function addKycSubmitData( return $this; } + + /** + * Provides document information to envelope + * + * @param string $eventId + * @param int $eventTimestamp + * @param string $documentType + * @param string|null $groupId + * @param string|null $documentCountry + * @param string|null $documentNumber + * @param string|null $fileName + * @param string|null $nationality + * @param int|null $issueDate + * @param int|null $expiryDate + * @param string|null $authority + * @param string|null $recordNumber + * @param string|null $personalNumber + * @param string|null $description + * @param float|null $productQuantity + * @param string|null $paymentMethod + * @param float|null $amount + * @param float|null $amountConverted + * @param string|null $currency + * @param string|null $mrzDocumentType + * @param string|null $mrzCountry + * @param string|null $mrzLastname + * @param string|null $mrzFirstname + * @param string|null $mrzFullname + * @param string|null $mrzDocumentNumber + * @param string|null $mrzNationality + * @param string|null $mrzPersonalNumber + * @param int|null $mrzBirthDate + * @param string|null $mrzGender + * @param int|null $mrzExpiryDate + * @param string|null $mrzRecordNumber + * @param bool|null $mrzCheckDigitsValidation + * @param string|null $extractedTest + * @param array|null $textLanguageDetails + * @param string|null $translatedExtractedText + * @param string|null $translatedFrom + * @param string|null $translatedTo + * @return Builder + */ + public function addDocumentEventData( + $eventId, + $eventTimestamp, + $documentType, + $groupId = null, + $documentCountry = null, + $documentNumber = null, + $fileName = null, + $nationality = null, + $issueDate = null, + $expiryDate = null, + $authority = null, + $recordNumber = null, + $personalNumber = null, + $description = null, + $productQuantity = null, + $paymentMethod = null, + $amount = null, + $amountConverted = null, + $currency = null, + $mrzDocumentType = null, + $mrzCountry = null, + $mrzLastname = null, + $mrzFirstname = null, + $mrzFullname = null, + $mrzDocumentNumber = null, + $mrzNationality = null, + $mrzPersonalNumber = null, + $mrzBirthDate = null, + $mrzGender = null, + $mrzExpiryDate = null, + $mrzRecordNumber = null, + $mrzCheckDigitsValidation = null, + $extractedTest = null, + $textLanguageDetails = null, + $translatedExtractedText = null, + $translatedFrom = null, + $translatedTo = null + ) { + if (!is_string($eventId)) { + throw new \InvalidArgumentException('Event ID must be string'); + } + if (!is_int($eventTimestamp)) { + throw new \InvalidArgumentException('Event timestamp must be int'); + } + if (empty($documentType)) { + throw new \InvalidArgumentException('Document Type is empty'); + } + if (!in_array($documentType, DocumentType::getShortList())) { + throw new \InvalidArgumentException('Document Type must be one of the types: ' . implode( + ', ', + DocumentType::getShortList() + ) + ); + } + if ($groupId !== null && !is_string($groupId)) { + throw new \InvalidArgumentException('Group ID must be string'); + } + if ($documentCountry !== null && !is_string($documentCountry)) { + throw new \InvalidArgumentException('Document Country must be string'); + } + if ($documentNumber !== null && !is_string($documentNumber)) { + throw new \InvalidArgumentException('Document Number must be string'); + } + if ($fileName !== null && !is_string($fileName)) { + throw new \InvalidArgumentException('File Name must be string'); + } + if ($nationality !== null && !is_string($nationality)) { + throw new \InvalidArgumentException('Nationality must be string'); + } + if ($issueDate !== null && !is_int($issueDate)) { + throw new \InvalidArgumentException('Issue Date must be int'); + } + if ($expiryDate !== null && !is_int($expiryDate)) { + throw new \InvalidArgumentException('Expiry Date must be int'); + } + if ($authority !== null && !is_string($authority)) { + throw new \InvalidArgumentException('Authority must be string'); + } + if ($recordNumber !== null && !is_string($recordNumber)) { + throw new \InvalidArgumentException('Record Number must be string'); + } + if ($personalNumber !== null && !is_string($personalNumber)) { + throw new \InvalidArgumentException('Personal Number must be string'); + } + if ($description !== null && !is_string($description)) { + throw new \InvalidArgumentException('Description must be string'); + } + if ($productQuantity !== null && !is_float($productQuantity)) { + throw new \InvalidArgumentException('Product Quantity must be float'); + } + if ($paymentMethod !== null && !is_string($paymentMethod)) { + throw new \InvalidArgumentException('Payment Method must be string'); + } + if ($amount !== null && !is_float($amount)) { + throw new \InvalidArgumentException('Amount must be must be float'); + } + if ($amountConverted !== null && !is_int($amountConverted) && !is_float($amountConverted)) { + throw new \InvalidArgumentException('Amount Converted must be number'); + } + if ($currency !== null && !is_string($currency)) { + throw new \InvalidArgumentException('Currency must be string'); + } + if ($mrzDocumentType !== null && !is_string($mrzDocumentType)) { + throw new \InvalidArgumentException('Mrz Document Type must be string'); + } + if ($mrzCountry !== null && !is_string($mrzCountry)) { + throw new \InvalidArgumentException('Mrz Country must be string'); + } + if ($mrzLastname !== null && !is_string($mrzLastname)) { + throw new \InvalidArgumentException('Mrz Lastname must be string'); + } + if ($mrzFirstname !== null && !is_string($mrzFirstname)) { + throw new \InvalidArgumentException('Mrz Firstname must be string'); + } + if ($mrzFullname !== null && !is_string($mrzFullname)) { + throw new \InvalidArgumentException('Mrz Fullname must be string'); + } + if ($mrzDocumentNumber !== null && !is_string($mrzDocumentNumber)) { + throw new \InvalidArgumentException('Mrz Document Number must be string'); + } + if ($mrzNationality !== null && !is_string($mrzNationality)) { + throw new \InvalidArgumentException('Mrz Nationality must be string'); + } + if ($mrzPersonalNumber !== null && !is_string($mrzPersonalNumber)) { + throw new \InvalidArgumentException('Mrz Personal Number must be string'); + } + if ($mrzBirthDate !== null && !is_int($mrzBirthDate)) { + throw new \InvalidArgumentException('Mrz Birth Date must be int'); + } + if ($mrzGender !== null && !is_string($mrzGender)) { + throw new \InvalidArgumentException('Mrz Gender must be string'); + } + if ($mrzExpiryDate !== null && !is_int($mrzExpiryDate)) { + throw new \InvalidArgumentException('Mrz Expiry Date must be int'); + } + if ($mrzRecordNumber !== null && !is_string($mrzRecordNumber)) { + throw new \InvalidArgumentException('Mrz Record Number must be string'); + } + if ($mrzCheckDigitsValidation !== null && !is_bool($mrzCheckDigitsValidation)) { + throw new \InvalidArgumentException('Mrz Check Digits Validation enabled flag must be boolean'); + } + if ($extractedTest !== null && !is_string($extractedTest)) { + throw new \InvalidArgumentException('Extracted Test must be string'); + } + if ($textLanguageDetails !== null) { + if (!is_array($textLanguageDetails)) { + throw new \InvalidArgumentException('Text Language Details must be array'); + } + + foreach ($textLanguageDetails as $detail) { + if (!is_string($detail)) { + throw new \InvalidArgumentException('Text Language Details must be list of string'); + } + } + } + if ($translatedExtractedText !== null && !is_string($translatedExtractedText)) { + throw new \InvalidArgumentException('Translated Extracted Text must be string'); + } + if ($translatedFrom !== null && !is_string($translatedFrom)) { + throw new \InvalidArgumentException('Translated From must be string'); + } + if ($translatedTo !== null && !is_string($translatedTo)) { + throw new \InvalidArgumentException('Translated To must be string'); + } + + $this->replace('event_id', $eventId); + $this->replace('event_timestamp', $eventTimestamp); + $this->replace('document_type', $documentType); + $this->replace('group_id', $groupId); + $this->replace('document_country', $documentCountry); + $this->replace('document_number', $documentNumber); + $this->replace('file_name', $fileName); + $this->replace('nationality', $nationality); + $this->replace('issue_date', $issueDate); + $this->replace('expiry_date', $expiryDate); + $this->replace('authority', $authority); + $this->replace('record_number', $recordNumber); + $this->replace('personal_number', $personalNumber); + $this->replace('description', $description); + $this->replace('product_quantity', $productQuantity); + $this->replace('payment_method', $paymentMethod); + $this->replace('amount', $amount); + $this->replace('amount_converted', $amountConverted); + $this->replace('currency', $currency); + $this->replace('mrz_document_type', $mrzDocumentType); + $this->replace('mrz_country', $mrzCountry); + $this->replace('mrz_lastname', $mrzLastname); + $this->replace('mrz_firstname', $mrzFirstname); + $this->replace('mrz_fullname', $mrzFullname); + $this->replace('mrz_document_number', $mrzDocumentNumber); + $this->replace('mrz_nationality', $mrzNationality); + $this->replace('mrz_personal_number', $mrzPersonalNumber); + $this->replace('mrz_birth_date', $mrzBirthDate); + $this->replace('mrz_gender', $mrzGender); + $this->replace('mrz_expiry_date', $mrzExpiryDate); + $this->replace('mrz_record_number', $mrzRecordNumber); + $this->replace('mrz_check_digits_validation', $mrzCheckDigitsValidation); + $this->replace('extracted_text', $extractedTest); + $this->replace('text_language_details', $textLanguageDetails); + $this->replace('translated_extracted_text', $translatedExtractedText); + $this->replace('translated_from', $translatedFrom); + $this->replace('translated_to', $translatedTo); + + return $this; + } } diff --git a/src/Envelopes/Envelope.php b/src/Envelopes/Envelope.php index b5173d1..dc1afa2 100644 --- a/src/Envelopes/Envelope.php +++ b/src/Envelopes/Envelope.php @@ -37,7 +37,7 @@ public function __construct($type, $sequenceId, array $inodes, array $values) throw new \InvalidArgumentException('Envelope type must be string'); } - if ($type == Builder::EVENT_PROFILE_UPDATE) { + if ($type == Builder::EVENT_PROFILE_UPDATE || $type == Builder::EVENT_DOCUMENT) { if (!is_null($sequenceId) && !is_string($sequenceId)) { throw new \InvalidArgumentException('Sequence ID must be string or null'); } diff --git a/src/Envelopes/ValidatorV1.php b/src/Envelopes/ValidatorV1.php index aa2c156..9491e54 100644 --- a/src/Envelopes/ValidatorV1.php +++ b/src/Envelopes/ValidatorV1.php @@ -53,7 +53,7 @@ class ValidatorV1 'transaction_type' => 'string(255)', 'user_agent' => 'string(2048)', 'local_ip_list' => 'string(1024)', - 'plugins' => 'string(1024)', + 'plugins' => 'string(8192)', 'referer_url' => 'string(2048)', 'origin_url' => 'string(2048)', 'client_resolution' => 'string(255)', @@ -81,6 +81,7 @@ class ValidatorV1 'ajax_validation' => 'bool', 'cookie_enabled' => 'bool', 'do_not_track' => 'bool', + 'anonymous' => 'bool', 'email_confirmed' => 'bool', 'login_failed' => 'bool', 'phone_confirmed' => 'bool', @@ -144,6 +145,8 @@ class ValidatorV1 'cvv_result' => 'string(255)', 'psp_code' => 'string(255)', 'psp_reason' => 'string(255)', + 'merchant_advice_code' => 'string(255)', + 'merchant_advice_text' => 'string(255)', 'arn' => 'string(255)', 'password' => 'string(255)', 'iban' => 'string(255)', @@ -241,7 +244,32 @@ class ValidatorV1 'active_features' => 'string(1024)', 'promotions' => 'string(1024)', 'links_to_documents' => 'string(2048)', - 'media_id' => 'array_int', + 'type' => 'string(255)', + 'document_id' => 'array_int', + 'document_type' => 'string(225)', + 'document_number' => 'string(225)', + 'file_name' => 'string(225)', + 'authority' => 'string(225)', + 'record_number' => 'string(225)', + 'personal_number' => 'string(225)', + 'mrz_document_type' => 'string(225)', + 'mrz_country' => 'string(225)', + 'mrz_lastname' => 'string(225)', + 'mrz_firstname' => 'string(225)', + 'mrz_fullname' => 'string(225)', + 'mrz_document_number' => 'string(225)', + 'mrz_nationality' => 'string(225)', + 'mrz_personal_number' => 'string(225)', + 'mrz_birth_date' => 'int', + 'mrz_gender' => 'string(225)', + 'mrz_expiry_date' => 'int', + 'mrz_record_number' => 'string(225)', + 'mrz_check_digits_validation' => 'bool', + 'extracted_text' => 'string(225)', + 'text_language_details' => 'array_string', + 'translated_extracted_text' => 'string(225)', + 'translated_from' => 'string(225)', + 'translated_to' => 'string(225)' ); private static $sharedOptional = array( @@ -251,6 +279,7 @@ class ValidatorV1 'device_fingerprint', 'device_id', 'do_not_track', + 'anonymous', 'ip', 'language', 'language_browser', @@ -273,7 +302,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", "media_id"), + 'optional' => array('email_confirmed', 'phone_confirmed', 'email', 'phone', "group_id", "document_id"), ), 'login' => array( 'mandatory' => array('login_timestamp', 'user_merchant_id'), @@ -287,7 +316,7 @@ class ValidatorV1 'password', 'campaign', "group_id", - "media_id", + "document_id", ) ), 'registration' => array( @@ -308,7 +337,7 @@ class ValidatorV1 'password', 'campaign', "group_id", - "media_id", + "document_id", ), ), 'transaction' => array( @@ -361,7 +390,7 @@ class ValidatorV1 'acquirer_merchant_id', 'group_id', 'links_to_documents', - 'media_id', + 'document_id', ) ), 'payout' => array( @@ -390,7 +419,7 @@ class ValidatorV1 'payout_expiration_year', 'group_id', 'links_to_documents', - 'media_id', + 'document_id', ) ), 'install' => array( @@ -405,7 +434,7 @@ class ValidatorV1 'affiliate_id', 'campaign', "group_id", - "media_id", + "document_id", ) ), 'refund' => array( @@ -430,7 +459,7 @@ class ValidatorV1 'user_merchant_id', 'group_id', 'links_to_documents', - 'media_id', + 'document_id', ) ), 'transfer' => array( @@ -482,14 +511,13 @@ class ValidatorV1 'account_id', 'second_account_id', 'links_to_documents', - 'media_id', + 'document_id', ) ), 'postback' => array( 'mandatory' => array(), 'optional' => array( 'request_id', - 'transaction_id', 'transaction_status', 'code', 'reason', @@ -498,6 +526,8 @@ class ValidatorV1 'cvv_result', 'psp_code', 'psp_reason', + 'merchant_advice_code', + 'merchant_advice_text', 'arn', 'payment_account_id', ) @@ -555,7 +585,7 @@ class ValidatorV1 'expiry_date', 'gender', 'links_to_documents', - 'media_id', + 'document_id', 'address_confirmed', 'second_address_confirmed', ) @@ -618,6 +648,7 @@ class ValidatorV1 'device_fingerprint', 'device_id', 'do_not_track', + 'anonymous', 'ip', 'real_ip', 'local_ip_list', @@ -635,7 +666,7 @@ class ValidatorV1 'plugins', 'referer_url', 'origin_url', - 'media_id', + 'document_id', 'address_confirmed', 'second_address_confirmed', ) @@ -727,7 +758,7 @@ class ValidatorV1 "product_image_url", "carrier_url", "carrier_phone", - 'media_id', + 'document_id', ) ), 'order_submit' => array( @@ -778,7 +809,7 @@ class ValidatorV1 "product_image_url", "carrier_url", "carrier_phone", - 'media_id', + 'document_id', ) ), 'profile_update' => array( @@ -862,6 +893,7 @@ class ValidatorV1 "device_fingerprint", "device_id", "do_not_track", + "anonymous", "ip", "real_ip", "local_ip_list", @@ -880,7 +912,65 @@ class ValidatorV1 "referer_url", "origin_url", "links_to_documents", - "media_id", + "document_id", + ) + ), + 'document' => array( + 'mandatory' => array( + "event_id", + "event_timestamp", + "user_merchant_id", + "document_type", + ), + 'optional' => array( + "sequence_id", + "group_id", + "operation", + "document_country", + "document_number", + "file_name", + "email", + "firstname", + "lastname", + "fullname", + "birth_date", + "age", + "gender", + "nationality", + "country", + "state", + "city", + "zip", + "address", + "issue_date", + "expiry_date", + "authority", + "record_number", + "personal_number", + "description", + "product_quantity", + "payment_method", + "amount", + "amount_converted", + "currency", + "mrz_document_type", + "mrz_country", + "mrz_lastname", + "mrz_firstname", + "mrz_fullname", + "mrz_document_number", + "mrz_nationality", + "mrz_personal_number", + "mrz_birth_date", + "mrz_gender", + "mrz_expiry_date", + "mrz_record_number", + "mrz_check_digits_validation", + "extracted_text", + "text_language_details", + "translated_extracted_text", + "translated_from", + "translated_to", ) ), ); @@ -1058,6 +1148,26 @@ public function analyzeFieldTypes(EnvelopeInterface $envelope) } } break; + case 'array_string': + if (!is_array($value)) { + $details[] = sprintf( + 'Field "%s" must be array, but %s provided', + $key, + $value === null ? 'null' : gettype($value) + ); + } + if (is_array($value)) { + foreach ($value as $id) { + if (!is_string($id)) { + $details[] = sprintf( + 'ID: "%s" must be string, but %s provided', + $id, + $id === null ? 'null' : gettype($id) + ); + } + } + } + break; default: $details[] = sprintf('Unknown type for "%s"', $key); } @@ -1081,17 +1191,7 @@ public function analyzeFieldTypes(EnvelopeInterface $envelope) */ public function validate(EnvelopeInterface $envelope) { - if ($envelope->getType() === 'postback') { - $details = array_merge( - $this->analyzeTypeAndMandatoryFields($envelope), - $this->analyzeFieldTypes($envelope) - ); - } elseif ($envelope->getType() === 'kyc_proof') { - $details = array_merge( - $this->analyzeTypeAndMandatoryFields($envelope), - $this->analyzeFieldTypes($envelope) - ); - } elseif ($envelope->getType() === Builder::EVENT_PROFILE_UPDATE) { + if (in_array($envelope->getType(), Builder::LIMITED_VALIDATION_EVENTS)) { $details = array_merge( $this->analyzeTypeAndMandatoryFields($envelope), $this->analyzeFieldTypes($envelope) diff --git a/src/Facade.php b/src/Facade.php index e3a67b6..e93053c 100644 --- a/src/Facade.php +++ b/src/Facade.php @@ -143,55 +143,55 @@ public static function sendCardId(CardIdInterface $cardId) } /** - * Send Media Storage data and return upload URL + * Send Document Storage data and return upload URL * - * @param MediaStorageInterface $mediaStorage - * @return MediaStorageResult + * @param DocumentStorageInterface $documentStorage + * @return DocumentStorageResult * @throws Exception * @throws IoException */ - public static function sendMediaStorage(MediaStorageInterface $mediaStorage) + public static function sendDocumentStorage(DocumentStorageInterface $documentStorage) { - return self::getClient()->sendMediaStorage($mediaStorage); + return self::getClient()->sendDocumentStorage($documentStorage); } /** - * Attach media connection and return status code + * Attach document connection and return status code * - * @param MediaConnectionInterface $mediaConnection + * @param DocumentConnectionInterface $documentConnection * @return int * @throws Exception * @throws IoException */ - public static function attachMediaConnection(MediaConnectionInterface $mediaConnection) + public static function attachDocumentConnection(DocumentConnectionInterface $documentConnection) { - return self::getClient()->attachMediaConnection($mediaConnection); + return self::getClient()->attachDocumentConnection($documentConnection); } /** - * Detach media connection and return status code + * Detach document connection and return status code * - * @param MediaConnectionInterface $mediaConnection + * @param DocumentConnectionInterface $documentConnection * @return int * @throws Exception * @throws IoException */ - public static function detachMediaConnection(MediaConnectionInterface $mediaConnection) + public static function detachDocumentConnection(DocumentConnectionInterface $documentConnection) { - return self::getClient()->detachMediaConnection($mediaConnection); + return self::getClient()->detachDocumentConnection($documentConnection); } /** - * Upload Media file and returns status code + * Upload Document file and returns status code * - * @param MediaFileUploaderInterface $mediaFileUploader + * @param DocumentFileUploaderInterface $documentFileUploader * @return int * @throws Exception * @throws IoException */ - public static function uploadMediaFile(MediaFileUploaderInterface $mediaFileUploader) + public static function uploadDocumentFile(DocumentFileUploaderInterface $documentFileUploader) { - return self::getClient()->uploadMediaFile($mediaFileUploader); + return self::getClient()->uploadDocumentFile($documentFileUploader); } /** diff --git a/src/MediaConnectionInterface.php b/src/MediaConnectionInterface.php deleted file mode 100644 index 76a3c6b..0000000 --- a/src/MediaConnectionInterface.php +++ /dev/null @@ -1,18 +0,0 @@ -addMediaStorageData($contentType, $contentDescription, $fileName, $ocr); - } - - /** - * Provides MediaStorage value - * - * @param $contentType - * @param $contentDescription - * @param $fileName - * @param $ocr - * @return Builder - */ - public function addMediaStorageData($contentType, $contentDescription, $fileName = null, $ocr = false) - { - 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())) { - 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 (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( - ', ', - ContentDescription::getAll() - ) - ); - } - - 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'); - } - if ($ocr && !in_array($contentType, ContentType::getOCRAllowed())) { - throw new \InvalidArgumentException('Allowed Content type for OCR: ' . implode( - ', ', - ContentType::getOCRAllowed() - ) - ); - } - - $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( - 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/MediaStorageInterface.php b/src/MediaStorageInterface.php deleted file mode 100644 index d35d6fc..0000000 --- a/src/MediaStorageInterface.php +++ /dev/null @@ -1,18 +0,0 @@ -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/PublicAPIClient.php b/src/PublicAPIClient.php index bf0749d..06c62f8 100644 --- a/src/PublicAPIClient.php +++ b/src/PublicAPIClient.php @@ -7,13 +7,13 @@ use Covery\Client\Requests\Decision; use Covery\Client\Requests\Event; use Covery\Client\Requests\KycProof; -use Covery\Client\Requests\MediaStorage; +use Covery\Client\Requests\DocumentStorage; use Covery\Client\Requests\Postback; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; -use Covery\Client\Requests\MediaFileUploader as MediaFileUploaderRequest; +use Covery\Client\Requests\DocumentFileUploader as DocumentFileUploaderRequest; class PublicAPIClient { @@ -337,61 +337,61 @@ public function sendCardId(CardIdInterface $cardId) } /** - * Send Media Storage data and return upload URL + * Send Document Storage data and return upload URL * - * @param MediaStorageInterface $media - * @return MediaStorageResult + * @param DocumentStorageInterface $document + * @return DocumentStorageResult * @throws Exception * @throws IoException */ - public function sendMediaStorage(MediaStorageInterface $media) + public function sendDocumentStorage(DocumentStorageInterface $document) { - $data = $this->readJson($this->send(new MediaStorage($media))); + $data = $this->readJson($this->send(new DocumentStorage($document))); if (!is_array($data)) { throw new Exception("Malformed response"); } - return new MediaStorageResult( - $data[MediaStorageResultBaseField::UPLOAD_URL], - $data[MediaStorageResultBaseField::MEDIA_ID], - $data[MediaStorageResultBaseField::CREATED_AT] + return new DocumentStorageResult( + $data[DocumentStorageResultBaseField::UPLOAD_URL], + $data[DocumentStorageResultBaseField::DOCUMENT_ID], + $data[DocumentStorageResultBaseField::CREATED_AT] ); } /** - * @param MediaConnectionInterface $mediaConnection + * @param DocumentConnectionInterface $documentConnection * @return int * @throws Exception * @throws IoException */ - public function attachMediaConnection(MediaConnectionInterface $mediaConnection) + public function attachDocumentConnection(DocumentConnectionInterface $documentConnection) { - return $this->sendMediaConnection($mediaConnection, 'PUT'); + return $this->sendDocumentConnection($documentConnection, 'PUT'); } /** - * @param MediaConnectionInterface $mediaConnection + * @param DocumentConnectionInterface $documentConnection * @return int * @throws Exception * @throws IoException */ - public function detachMediaConnection(MediaConnectionInterface $mediaConnection) + public function detachDocumentConnection(DocumentConnectionInterface $documentConnection) { - return $this->sendMediaConnection($mediaConnection, 'DELETE'); + return $this->sendDocumentConnection($documentConnection, 'DELETE'); } /** - * Upload Media file and returns status code + * Upload Document file and returns status code * - * @param MediaFileUploaderInterface $mediaFileUploader + * @param DocumentFileUploaderInterface $documentFileUploader * @return int * @throws Exception * @throws IoException */ - public function uploadMediaFile(MediaFileUploaderInterface $mediaFileUploader) + public function uploadDocumentFile(DocumentFileUploaderInterface $documentFileUploader) { - $this->send(new MediaFileUploaderRequest($mediaFileUploader), false); + $this->send(new DocumentFileUploaderRequest($documentFileUploader), false); if ($this->responseStatusCode >= 300) { throw new Exception("Malformed response"); @@ -401,17 +401,17 @@ public function uploadMediaFile(MediaFileUploaderInterface $mediaFileUploader) } /** - * Send media connection and return status code + * Send document connection and return status code * - * @param MediaConnectionInterface $mediaConnection + * @param DocumentConnectionInterface $documentConnection * @param $method * @return int * @throws Exception * @throws IoException */ - private function sendMediaConnection(MediaConnectionInterface $mediaConnection, $method) + private function sendDocumentConnection(DocumentConnectionInterface $documentConnection, $method) { - $this->readJson($this->send(new \Covery\Client\Requests\MediaConnection($mediaConnection, $method))); + $this->readJson($this->send(new \Covery\Client\Requests\DocumentConnection($documentConnection, $method))); if ($this->responseStatusCode >= 300) { throw new Exception("Malformed response"); } @@ -441,7 +441,7 @@ public function getAccountConfigurationStatus() $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::DOCUMENT_STORAGE_WEBHOOK_URL], $data[AccountConfigurationStatusResultBaseField::FRAUD_ALERT_CALLBACK_URL], $data[AccountConfigurationStatusResultBaseField::CARD_ID_GENERATION], $data[AccountConfigurationStatusResultBaseField::DEVICE_FINGERPRINT_GENERATION], diff --git a/src/Requests/DocumentConnection.php b/src/Requests/DocumentConnection.php new file mode 100644 index 0000000..1c38409 --- /dev/null +++ b/src/Requests/DocumentConnection.php @@ -0,0 +1,31 @@ +toArray()) + ); + } +} diff --git a/src/Requests/DocumentFileUploader.php b/src/Requests/DocumentFileUploader.php new file mode 100644 index 0000000..74ef6e7 --- /dev/null +++ b/src/Requests/DocumentFileUploader.php @@ -0,0 +1,31 @@ + 'application/octet-stream', + ], + $documentFileUploader['file'] + ); + } +} diff --git a/src/Requests/DocumentStorage.php b/src/Requests/DocumentStorage.php new file mode 100644 index 0000000..6b4e771 --- /dev/null +++ b/src/Requests/DocumentStorage.php @@ -0,0 +1,30 @@ +toArray()) + ); + } +} diff --git a/src/Requests/MediaConnection.php b/src/Requests/MediaConnection.php deleted file mode 100644 index 6011010..0000000 --- a/src/Requests/MediaConnection.php +++ /dev/null @@ -1,31 +0,0 @@ -toArray()) - ); - } -} diff --git a/src/Requests/MediaFileUploader.php b/src/Requests/MediaFileUploader.php deleted file mode 100644 index d871341..0000000 --- a/src/Requests/MediaFileUploader.php +++ /dev/null @@ -1,31 +0,0 @@ - 'application/octet-stream', - ], - $mediaFileUploader['file'] - ); - } -} diff --git a/src/Requests/MediaStorage.php b/src/Requests/MediaStorage.php deleted file mode 100644 index 187d36c..0000000 --- a/src/Requests/MediaStorage.php +++ /dev/null @@ -1,30 +0,0 @@ -toArray()) - ); - } -} diff --git a/tests/Covery/BuildConfirmationEnvelopeTest.php b/tests/Covery/BuildConfirmationEnvelopeTest.php index 1f7bf4e..e6f3ecf 100644 --- a/tests/Covery/BuildConfirmationEnvelopeTest.php +++ b/tests/Covery/BuildConfirmationEnvelopeTest.php @@ -30,7 +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']); + self::assertSame([1, 2], $result['document_id']); $validator->validate($result); // Minimal data diff --git a/tests/Covery/BuildMediaConnectionTest.php b/tests/Covery/BuildDocumentConnectionTest.php similarity index 50% rename from tests/Covery/BuildMediaConnectionTest.php rename to tests/Covery/BuildDocumentConnectionTest.php index a3319f2..4e1e411 100644 --- a/tests/Covery/BuildMediaConnectionTest.php +++ b/tests/Covery/BuildDocumentConnectionTest.php @@ -1,48 +1,48 @@ build(); - $request = new \Covery\Client\Requests\MediaConnection($mediaConnectionResult); + $request = new \Covery\Client\Requests\DocumentConnection($documentConnectionResult); self::assertEquals('PUT', $request->getMethod()); - self::assertContains($request->getUri()->getPath(), '/api/mediaConnection'); + self::assertContains($request->getUri()->getPath(), '/api/documentConnection'); self::assertInstanceOf('Psr\Http\Message\RequestInterface', $request); - self::assertCount(2, $mediaConnectionResult); - self::assertSame($mediaId, $mediaConnectionResult['media_id']); - self::assertSame($requestId, $mediaConnectionResult['request_id']); + self::assertCount(2, $documentConnectionResult); + self::assertSame($documentId, $documentConnectionResult['document_id']); + self::assertSame($requestId, $documentConnectionResult['request_id']); self::assertJson($request->getBody()->getContents()); } public function testEventExpectsInvalidArgumentException() { $requestId = -1; - $mediaId = -1; + $documentId = -1; self::setExpectedException('InvalidArgumentException'); - \Covery\Client\MediaConnection\Builder::mediaConnectionEvent( + \Covery\Client\DocumentConnection\Builder::documentConnectionEvent( $requestId, - $mediaId + $documentId )->build(); } public function testEventExpectsInvalidArgumentExceptionCheckZeroFields() { $requestId = 0; - $mediaId = [1, 0, -1]; + $documentId = [1, 0, -1]; self::setExpectedException('InvalidArgumentException'); - \Covery\Client\MediaConnection\Builder::mediaConnectionEvent( + \Covery\Client\DocumentConnection\Builder::documentConnectionEvent( $requestId, - $mediaId + $documentId )->build(); } } diff --git a/tests/Covery/BuildDocumentEventTest.php b/tests/Covery/BuildDocumentEventTest.php new file mode 100644 index 0000000..c380d11 --- /dev/null +++ b/tests/Covery/BuildDocumentEventTest.php @@ -0,0 +1,138 @@ +build(); + + self::assertCount(49, $result); + self::assertSame(Builder::EVENT_DOCUMENT, $result->getType()); + self::assertSame('tempSequenceId', $result->getSequenceId()); + self::assertSame('tempEventId', $result['event_id']); + self::assertSame(123456, $result['event_timestamp']); + self::assertSame('tempUserId', $result['user_merchant_id']); + self::assertSame(\Covery\Client\DocumentType::INTERNATIONAL_PASSPORT, $result['document_type']); + self::assertSame('tempGroupId', $result['group_id']); + self::assertSame("tempDocumentCountry", $result['document_country']); + self::assertSame("tempDocumentNumber", $result['document_number']); + self::assertSame("tempFileName", $result['file_name']); + self::assertSame("tempEmail", $result['email']); + self::assertSame("tempFirstName", $result['firstname']); + self::assertSame("tempLastName", $result['lastname']); + self::assertSame("tempFullname", $result['fullname']); + self::assertSame(123456, $result['birth_date']); + self::assertSame(18, $result['age']); + self::assertSame("tempGender", $result['gender']); + self::assertSame("tempNationality", $result['nationality']); + self::assertSame("tempCountry", $result['country']); + self::assertSame("tempCity", $result['city']); + self::assertSame("tempZip", $result['zip']); + self::assertSame("tempAddress", $result['address']); + self::assertSame(123456, $result['issue_date']); + self::assertSame(123456, $result['expiry_date']); + self::assertSame("tempAuthority", $result['authority']); + self::assertSame("testRecordNumber", $result['record_number']); + self::assertSame("testPersonalNumber", $result['personal_number']); + self::assertSame("testDescription", $result['description']); + self::assertSame(10.4, $result['product_quantity']); + self::assertSame("testPaymentMethod", $result['payment_method']); + self::assertSame(23.6, $result['amount']); + self::assertSame(34.5, $result['amount_converted']); + self::assertSame("testCurrency", $result['currency']); + self::assertSame("testMrzDocumentType", $result['mrz_document_type']); + self::assertSame("testMrzCountry", $result['mrz_country']); + self::assertSame("testMrzLastname", $result['mrz_lastname']); + self::assertSame("testMrzFirstname", $result['mrz_firstname']); + self::assertSame("testMrzFullname", $result['mrz_fullname']); + self::assertSame("testMrzDocumentNumber", $result['mrz_document_number']); + self::assertSame("testMrzNationality", $result['mrz_nationality']); + self::assertSame("testMrzPersonalNumber", $result['mrz_personal_number']); + self::assertSame(123456, $result['mrz_birth_date']); + self::assertSame("testMrzGender", $result['mrz_gender']); + self::assertSame(123456, $result['mrz_expiry_date']); + self::assertSame("testMrzRecordNumber", $result['mrz_record_number']); + self::assertSame(false, $result['mrz_check_digits_validation']); + self::assertSame("testExtractedText", $result['extracted_text']); + self::assertSame(['en'], $result['text_language_details']); + self::assertSame("testTranslatedExtractedText", $result['translated_extracted_text']); + self::assertSame("testTranslatedFrom", $result['translated_from']); + self::assertSame("testTranslatedTo", $result['translated_to']); + + $validator->validate($result); + + // Minimal data + $result = Builder::documentEvent( + 'tempEventId', + 123456789, + 'tempUserId', + \Covery\Client\DocumentType::INTERNATIONAL_PASSPORT, + )->build(); + + self::assertCount(4, $result); + self::assertSame(Builder::EVENT_DOCUMENT, $result->getType()); + self::assertSame('tempEventId', $result['event_id']); + self::assertSame(123456789, $result['event_timestamp']); + self::assertSame('tempUserId', $result['user_merchant_id']); + self::assertSame(\Covery\Client\DocumentType::INTERNATIONAL_PASSPORT, $result['document_type']); + + $validator->validate($result); + } +} diff --git a/tests/Covery/BuildDocumentFileUploaderTest.php b/tests/Covery/BuildDocumentFileUploaderTest.php new file mode 100644 index 0000000..a3fb086 --- /dev/null +++ b/tests/Covery/BuildDocumentFileUploaderTest.php @@ -0,0 +1,21 @@ +build(); + + self::assertSame($documentUrl, $documentStorageResult['url']); + self::assertInstanceOf('Psr\Http\Message\StreamInterface', $documentStorageResult['file']); + self::assertEquals($fileStream, $documentStorageResult['file']); + self::assertSame($testString, (string)$fileStream); + } +} diff --git a/tests/Covery/BuildDocumentStorageTest.php b/tests/Covery/BuildDocumentStorageTest.php new file mode 100644 index 0000000..ea4aea4 --- /dev/null +++ b/tests/Covery/BuildDocumentStorageTest.php @@ -0,0 +1,88 @@ +build(); + + $request = new \Covery\Client\Requests\DocumentStorage($documentStorageResult); + + self::assertEquals('POST', $request->getMethod()); + self::assertContains($request->getUri()->getPath(), '/api/documentStorage'); + self::assertInstanceOf('Psr\Http\Message\RequestInterface', $request); + self::assertCount(10, $documentStorageResult); + self::assertSame("documentStorageUserMerchantId", $documentStorageResult['user_merchant_id']); + self::assertSame(\Covery\Client\DocumentType::INTERNATIONAL_PASSPORT, $documentStorageResult['document_type']); + self::assertSame("documentStorageCountry", $documentStorageResult['document_country']); + self::assertSame("documentStorageSequenceIdSome", $documentStorageResult['sequence_id']); + self::assertSame("documentStorageGroupIdSome", $documentStorageResult['group_id']); + self::assertSame("passport.jpeg", $documentStorageResult['file_name']); + self::assertSame(false, $documentStorageResult['ocr']); + self::assertSame(2, $documentStorageResult['number_of_pages']); + self::assertSame("documentStorageTranslatedFrom", $documentStorageResult['translated_from']); + self::assertSame("documentStorageTranslatedTo", $documentStorageResult['translated_to']); + self::assertJson($request->getBody()->getContents()); + } + + public function testEventExpectsInvalidArgumentException() + { + self::setExpectedException('InvalidArgumentException'); + $documentStorage = \Covery\Client\DocumentStorage\Builder::documentStorageEvent( + "documentStorageUserMerchantId", + null, + "documentStorageCountry", + "documentStorageSequenceIdSome", + "documentStorageGroupIdSome", + "passport.jpeg", + false, + 2, + "documentStorageTranslatedFrom", + "documentStorageTranslatedTo" + )->build(); + } + + public function testEventExpectsInvalidDocumentType() + { + self::setExpectedException('InvalidArgumentException'); + $documentStorage = \Covery\Client\DocumentStorage\Builder::documentStorageEvent( + "documentStorageUserMerchantId", + "regional_password", + "documentStorageCountry", + "documentStorageSequenceIdSome", + "documentStorageGroupIdSome", + "passport.jpeg", + false, + 2, + "documentStorageTranslatedFrom", + "documentStorageTranslatedTo" + )->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; + } +} diff --git a/tests/Covery/BuildInstallEventTest.php b/tests/Covery/BuildInstallEventTest.php index 5ec0254..1a7647a 100644 --- a/tests/Covery/BuildInstallEventTest.php +++ b/tests/Covery/BuildInstallEventTest.php @@ -32,7 +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']); + self::assertSame([1, 2], $result['document_id']); $validator->validate($result); // Minimal data diff --git a/tests/Covery/BuildKYCProfileEnvelopeTest.php b/tests/Covery/BuildKYCProfileEnvelopeTest.php index b56963d..3f64e60 100644 --- a/tests/Covery/BuildKYCProfileEnvelopeTest.php +++ b/tests/Covery/BuildKYCProfileEnvelopeTest.php @@ -115,7 +115,7 @@ 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::assertSame([1, 2], $result['document_id']); self::assertTrue($result['address_confirmed']); self::assertTrue($result['second_address_confirmed']); diff --git a/tests/Covery/BuildKYCSubmitEnvelopeTest.php b/tests/Covery/BuildKYCSubmitEnvelopeTest.php index 79991a4..950146e 100644 --- a/tests/Covery/BuildKYCSubmitEnvelopeTest.php +++ b/tests/Covery/BuildKYCSubmitEnvelopeTest.php @@ -82,13 +82,14 @@ public function testBuild() 'KycSubmitOriginUrl', [1, 2], true, + true, true )->addIdentity(new \Covery\Client\Identities\Stub())->build(); self::assertSame('kyc_submit', $result->getType()); self::assertSame('kycSubmitSequenceIdSome', $result->getSequenceId()); - self::assertCount(74, $result); + self::assertCount(75, $result); self::assertSame('kycSubmitEventId', $result['event_id']); self::assertSame(1234568, $result['event_timestamp']); self::assertSame('kycSubmitUserMerchantId', $result['user_merchant_id']); @@ -143,6 +144,7 @@ public function testBuild() self::assertSame('KycSubmitDeviceFingerPrint', $result['device_fingerprint']); self::assertSame('KycSubmitDeviceId', $result['device_id']); self::assertSame(false, $result['do_not_track']); + self::assertSame(true, $result['anonymous']); self::assertSame('KycSubmitIp', $result['ip']); self::assertSame('KycSubmitRealIp', $result['real_ip']); self::assertSame('KycSubmitLocalIpList', $result['local_ip_list']); @@ -160,7 +162,7 @@ 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::assertSame([1, 2], $result['document_id']); self::assertTrue($result['address_confirmed']); self::assertTrue($result['second_address_confirmed']); diff --git a/tests/Covery/BuildKycProofEventTest.php b/tests/Covery/BuildKycProofEventTest.php index f5cc7bd..cd06a9d 100644 --- a/tests/Covery/BuildKycProofEventTest.php +++ b/tests/Covery/BuildKycProofEventTest.php @@ -1,15 +1,18 @@ build(); + $result = Builder::kycProofEvent($kycStartId)->build(); - self::assertSame('kyc_proof', $result->getType()); + self::assertSame(Builder::EVENT_KYC_PROOF, $result->getType()); self::assertCount(1, $result); self::assertSame($kycStartId, $result['kyc_start_id']); $validator->validate($result); diff --git a/tests/Covery/BuildLoginEnvelopeTest.php b/tests/Covery/BuildLoginEnvelopeTest.php index 6386537..86a264d 100644 --- a/tests/Covery/BuildLoginEnvelopeTest.php +++ b/tests/Covery/BuildLoginEnvelopeTest.php @@ -35,7 +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::assertSame([1, 2], $result['document_id']); self::assertTrue($result['login_failed']); $validator->validate($result); diff --git a/tests/Covery/BuildMediaFileUploaderTest.php b/tests/Covery/BuildMediaFileUploaderTest.php deleted file mode 100644 index 66ff4e8..0000000 --- a/tests/Covery/BuildMediaFileUploaderTest.php +++ /dev/null @@ -1,21 +0,0 @@ -build(); - - self::assertSame($mediaUrl, $mediaStorageResult['url']); - self::assertInstanceOf('Psr\Http\Message\StreamInterface', $mediaStorageResult['file']); - self::assertEquals($fileStream, $mediaStorageResult['file']); - self::assertSame($testString, (string)$fileStream); - } -} diff --git a/tests/Covery/BuildMediaStorageTest.php b/tests/Covery/BuildMediaStorageTest.php deleted file mode 100644 index d692b92..0000000 --- a/tests/Covery/BuildMediaStorageTest.php +++ /dev/null @@ -1,81 +0,0 @@ -build(); - - $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 testBuildExpectsInvalidArgumentFileName() - { - self::setExpectedException('InvalidArgumentException'); - $mediaStorage = \Covery\Client\MediaStorage\Builder::mediaStorageEvent( - \Covery\Client\ContentType::PNG, - \Covery\Client\ContentDescription::GENERAL_DOCUMENT, - $this->generateRandomString(256), - false - )->build(); - } - - public function testEventExpectsInvalidArgumentException() - { - self::setExpectedException('InvalidArgumentException'); - $mediaStorage = \Covery\Client\MediaStorage\Builder::mediaStorageEvent( - 'Unique content type', - 'Unique content description', - null, - false - )->build(); - } - - public function testEmptyFileNameIsValidString() - { - $mediaStorage = \Covery\Client\MediaStorage\Builder::mediaStorageEvent( - \Covery\Client\ContentType::PNG, - \Covery\Client\ContentDescription::GENERAL_DOCUMENT, - null, - false - )->build(); - - self::assertSame($mediaStorage['content_type'], \Covery\Client\ContentType::PNG); - } - - /** - * @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; - } -} diff --git a/tests/Covery/BuildOrderItemEnvelopeTest.php b/tests/Covery/BuildOrderItemEnvelopeTest.php index 6d6a7ee..7a60026 100644 --- a/tests/Covery/BuildOrderItemEnvelopeTest.php +++ b/tests/Covery/BuildOrderItemEnvelopeTest.php @@ -78,11 +78,12 @@ public function testBuild() "plugins", "refererUrl", "originUrl", - "clientResolution" + "clientResolution", + true )->build(); self::assertSame('order_item', $result->getType()); - self::assertCount(69, $result); + self::assertCount(70, $result); self::assertCount(1, $result->getIdentities()); self::assertSame('sequenceId', $result->getSequenceId()); self::assertSame(123.456, $result["amount"]); @@ -152,8 +153,9 @@ public function testBuild() self::assertSame("clientResolution", $result["client_resolution"]); self::assertSame(true, $result["cookie_enabled"]); self::assertSame(false, $result["do_not_track"]); + self::assertSame(true, $result['anonymous']); self::assertSame(true, $result["ajax_validation"]); - self::assertSame([1, 2], $result["media_id"]); + self::assertSame([1, 2], $result["document_id"]); $validator->validate($result); diff --git a/tests/Covery/BuildOrderSubmitEnvelopeTest.php b/tests/Covery/BuildOrderSubmitEnvelopeTest.php index 0a0a2ed..36d84c3 100644 --- a/tests/Covery/BuildOrderSubmitEnvelopeTest.php +++ b/tests/Covery/BuildOrderSubmitEnvelopeTest.php @@ -75,11 +75,12 @@ public function testBuild() "plugins", "refererUrl", "originUrl", - "clientResolution" + "clientResolution", + true )->build(); self::assertSame('order_submit', $result->getType()); - self::assertCount(66, $result); + self::assertCount(67, $result); self::assertCount(1, $result->getIdentities()); self::assertSame('sequenceId', $result->getSequenceId()); self::assertSame(123.456, $result["amount"]); @@ -146,8 +147,9 @@ public function testBuild() self::assertSame("clientResolution", $result["client_resolution"]); self::assertSame(true, $result["cookie_enabled"]); self::assertSame(false, $result["do_not_track"]); + self::assertSame(true, $result['anonymous']); self::assertSame(true, $result["ajax_validation"]); - self::assertSame([1, 2], $result["media_id"]); + self::assertSame([1, 2], $result["document_id"]); $validator->validate($result); diff --git a/tests/Covery/BuildPayoutEventTest.php b/tests/Covery/BuildPayoutEventTest.php index c51223c..32fa10c 100644 --- a/tests/Covery/BuildPayoutEventTest.php +++ b/tests/Covery/BuildPayoutEventTest.php @@ -63,7 +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']); + self::assertSame([1, 2], $result['document_id']); $validator->validate($result); // Minimal data diff --git a/tests/Covery/BuildPostbackEventTest.php b/tests/Covery/BuildPostbackEventTest.php index 29edb7d..2e6de8b 100644 --- a/tests/Covery/BuildPostbackEventTest.php +++ b/tests/Covery/BuildPostbackEventTest.php @@ -1,15 +1,17 @@ addIdentity(new \Covery\Client\Identities\Stub())->build(); - self::assertSame('postback', $result->getType()); + self::assertSame(Builder::EVENT_POSTBACK, $result->getType()); self::assertCount(1, $result->getIdentities()); - self::assertSame('', $result->getSequenceId()); - self::assertCount(11, $result); + self::assertSame('someTransactionStatus', $result['transaction_status']); + self::assertSame('someCode', $result['code']); + self::assertSame('someReason', $result['reason']); + self::assertSame('someSecure3d', $result['secure3d']); + self::assertSame('someAvsResult', $result['avs_result']); + self::assertSame('someCvvResult', $result['cvv_result']); + self::assertSame('somePspCode', $result['psp_code']); + self::assertSame('somePspReason', $result['psp_reason']); + self::assertSame('someArn', $result['arn']); + self::assertSame('z1234fcdfd23', $result['payment_account_id']); + self::assertSame('someMerchantAdviceCode', $result['merchant_advice_code']); + self::assertSame('someMerchantAdviceText', $result['merchant_advice_text']); + self::assertCount(13, $result); $validator->validate($result); - // Minimal data with request id - $result = \Covery\Client\Envelopes\Builder::postBackEvent(22222)->build(); - self::assertSame('postback', $result->getType()); + $result = Builder::postBackEvent(22222)->build(); + self::assertSame(Builder::EVENT_POSTBACK, $result->getType()); self::assertCount(0, $result->getIdentities()); self::assertSame('', $result->getSequenceId()); self::assertCount(1, $result); $validator->validate($result); - - // Minimal data with transaction id - $result = \Covery\Client\Envelopes\Builder::postBackEvent(null, "transactionId")->build(); - self::assertSame('postback', $result->getType()); - self::assertCount(0, $result->getIdentities()); - self::assertSame('', $result->getSequenceId()); - self::assertCount(1, $result); - $validator->validate($result); - } } \ No newline at end of file diff --git a/tests/Covery/BuildProfileUpdateEventTest.php b/tests/Covery/BuildProfileUpdateEventTest.php index 7e08e93..0284421 100644 --- a/tests/Covery/BuildProfileUpdateEventTest.php +++ b/tests/Covery/BuildProfileUpdateEventTest.php @@ -106,11 +106,12 @@ public function testBuild() "profileUpdateRefererUrl", "profileUpdateOriginUrl", "linksToDocuments", - [1, 2] + [1, 2], + false )->build(); - self::assertCount(95, $result); + self::assertCount(96, $result); self::assertSame(Builder::EVENT_PROFILE_UPDATE, $result->getType()); self::assertSame('profileUpdateSequenceId', $result->getSequenceId()); self::assertSame('profileUpdateEventId', $result['event_id']); @@ -191,6 +192,7 @@ public function testBuild() self::assertSame("profileUpdateDeviceFingerprint", $result['device_fingerprint']); self::assertSame("profileUpdateDeviceId", $result['device_id']); self::assertSame(true, $result['do_not_track']); + self::assertSame(false, $result['anonymous']); self::assertSame("profileUpdateIp", $result['ip']); self::assertSame("profileUpdateRealIp", $result['real_ip']); self::assertSame("profileUpdateLocalIpList", $result['local_ip_list']); @@ -209,7 +211,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']); + self::assertSame([1, 2], $result['document_id']); $validator->validate($result); diff --git a/tests/Covery/BuildRefundEventTest.php b/tests/Covery/BuildRefundEventTest.php index 822fb37..0e9175e 100644 --- a/tests/Covery/BuildRefundEventTest.php +++ b/tests/Covery/BuildRefundEventTest.php @@ -49,13 +49,14 @@ public function testBuild() "plugins", "refUrl", "originUrl", - "clientResolution" + "clientResolution", + false )->addIdentity(new \Covery\Client\Identities\Stub())->build(); self::assertSame('refund', $result->getType()); self::assertCount(1, $result->getIdentities()); self::assertSame('someSequenceId', $result->getSequenceId()); - self::assertCount(40, $result); + self::assertCount(41, $result); self::assertSame('refundLargeId', $result['refund_id']); self::assertSame(0.12, $result['refund_amount']); self::assertSame('GBP', $result['refund_currency']); @@ -77,6 +78,7 @@ public function testBuild() self::assertSame('88889', $result['device_fingerprint']); self::assertSame('id', $result['device_id']); self::assertSame(true, $result['do_not_track']); + self::assertSame(false, $result['anonymous']); self::assertSame('lang', $result['language']); self::assertSame('langBrowser', $result['language_browser']); self::assertSame('langSystem', $result['language_system']); @@ -94,7 +96,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']); + self::assertSame([1, 2], $result['document_id']); $validator->validate($result); // Minimal data diff --git a/tests/Covery/BuildRegistrationEventTest.php b/tests/Covery/BuildRegistrationEventTest.php index f752957..5264dda 100644 --- a/tests/Covery/BuildRegistrationEventTest.php +++ b/tests/Covery/BuildRegistrationEventTest.php @@ -50,7 +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']); + self::assertCount(2, $result['document_id']); $validator->validate($result); // Minimal data diff --git a/tests/Covery/BuildTransactionEventTest.php b/tests/Covery/BuildTransactionEventTest.php index 8bbd961..117fd8e 100644 --- a/tests/Covery/BuildTransactionEventTest.php +++ b/tests/Covery/BuildTransactionEventTest.php @@ -113,7 +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']); + self::assertSame([1, 2], $result['document_id']); $validator->validate($result); diff --git a/tests/Covery/BuildTransferEventTest.php b/tests/Covery/BuildTransferEventTest.php index 4f1e257..12d2d53 100644 --- a/tests/Covery/BuildTransferEventTest.php +++ b/tests/Covery/BuildTransferEventTest.php @@ -111,7 +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']); + self::assertSame([1, 2], $result['document_id']); $validator->validate($result);