diff --git a/README.md b/README.md
index 650683c..965f283 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,6 @@ Official PHP Covery Client
* [Facade](#facade)
* [PSR-3 logging](#psr) [PSR-4 autoloading](#psr) and [PSR-7 HTTP messages](#psr)
* [Transports](#transports)
- * [Health check](#ping)
* [Envelopes](#envelopes)
* [Results](#results)
* [Exceptions](#exceptions)
@@ -55,7 +54,6 @@ Facade::setLogger(new FileLogger($filePath));
That's all!
Having completed this procedure, you can now query Covery using `Facade::sendEvent`, `Facade::sendPostback`, `Facade::makeDecision`.
-You can test connectivity problems and token/secret validity using `Facade::ping` request.
Login event example:
@@ -102,6 +100,54 @@ $event = Builder::cardIdEvent('curdNumber')->build();
$result = Facade::sendCardId($event);
```
+Media Storage event example:
+```php
+use Covery\Client\MediaStorage\Builder;
+use Covery\Client\Facade;
+
+$event = Builder::mediaStorageEvent(\Covery\Client\ContentType::JPEG, \Covery\Client\ContentDescription::GENERAL_DOCUMENT, null, false)->build();
+$result = Facade::sendMediaStorage($event);
+```
+
+Attach media connection event example:
+```php
+use Covery\Client\MediaConnection\Builder;
+use Covery\Client\Facade;
+
+$event = Builder::mediaConnectionEvent(1, [1])->build();
+$result = Facade::attachMediaConnection($event);
+```
+
+Detach media connection event example:
+```php
+use Covery\Client\MediaConnection\Builder;
+use Covery\Client\Facade;
+
+$event = Builder::mediaConnectionEvent(1, [1])->build();
+$result = Facade::detachMediaConnection($event);
+```
+
+Media file upload example:
+```php
+use Covery\Client\Facade;
+
+$stream = fopen('PATH_TO_FILE', 'r');
+$mediaUrl = 'UPLOAD_URL'; //URL from Covery
+$mediaFileUploader = \Covery\Client\MediaFileUploader\Builder::mediaFileUploaderEvent(
+ $mediaUrl,
+ $stream
+)->build();
+
+$result = \Covery\Client\Facade::uploadMediaFile($mediaFileUploader);
+```
+
+Account Configuration Status event example:
+```php
+use Covery\Client\Facade;
+
+$accountConfigurationStatus = Facade::getAccountConfigurationStatus();
+```
+
# Tech Details
@@ -125,13 +171,6 @@ Covery client may use any class that satisfies `Covery\Client\TransportInterface
1. `Covery\Client\Transport\Curl` - simple PHP curl implementation
2. `Covery\Client\Transport\OverGuzzle` - adapter over [Guzzle](https://github.com/guzzle/guzzle) HTTP client
-
-## Health Check
-
-To perform network accessibility and token validity tests, run `ping()` method inside `Facade`
-or `PublicAPIClient`. It will throw an exception on any problems or return your token access level on success.
-In most cases it will return `"DECISION"` as your token level.
-
## Envelopes
@@ -165,9 +204,8 @@ You may provide the following as envelopes:
## Results
-1. `ping` will return `string` containing current token access level on success.
-2. `sendEvent` will return `integer` (may be x64) containing ID of a stored entity on Covery side. You should log it.
-3. `makeDecision` will return `Covery\Client\Result` object:
+1. `sendEvent` will return `integer` (may be x64) containing ID of a stored entity on Covery side. You should log it.
+2. `makeDecision` will return `Covery\Client\Result` object:
* Call `getScore()` to obtain score in range [-100, 100]
* Method `isAccept()` will return `true` if Covery did not found fraud in incoming envelope data
* Method `isReject()` will return `true` if Covery found fraud in incoming envelope data
@@ -191,6 +229,11 @@ You may provide the following as envelopes:
## Changelog
+* `1.3.14` Added MediaStorage method. Added MediaConnection method. Added UploadMediaFile method.
+ * Added optional `media_id` field for events: install, registration, confirmation, login, order-item, order-submit, transaction, refund, payout, transfer, profile-update, kyc-profile, kyc-submit.
+ * Added optional address_confirmed, second_address_confirmed fields for KYC profile and KYC submit events.
+ * Added AccountConfigurationStatus method.
+ * Removed Health check method.
* `1.3.13` Added StaleDataException exception
* `1.3.12` Added sendCardId method
* `1.3.11` Added VarDumpLogger and FileLogger
diff --git a/src/AccountConfigurationStatusResult.php b/src/AccountConfigurationStatusResult.php
new file mode 100644
index 0000000..0ee8b5f
--- /dev/null
+++ b/src/AccountConfigurationStatusResult.php
@@ -0,0 +1,293 @@
+actualEventTypes = $actualEventTypes;
+ $this->baseCurrency = $baseCurrency;
+ $this->decisionCallbackUrl = $decisionCallbackUrl;
+ $this->manualDecisionCallbackUrl = $manualDecisionCallbackUrl;
+ $this->ongoingMonitoringWebhookUrl = $ongoingMonitoringWebhookUrl;
+ $this->mediaStorageWebhookUrl = $mediaStorageWebhookUrl;
+ $this->fraudAlertCallbackUrl = $fraudAlertCallbackUrl;
+ $this->cardIdGeneration = $cardIdGeneration;
+ $this->deviceFingerprintGeneration = $deviceFingerprintGeneration;
+ $this->sequenceIdGeneration = $sequenceIdGeneration;
+ $this->sequenceIdGenerationMethod = $sequenceIdGenerationMethod;
+ $this->amlService = $amlService;
+ $this->amlServiceStatus = $amlServiceStatus;
+ $this->dowJonesDataBaseDate = $dowJonesDataBaseDate;
+ $this->kycProvider = $kycProvider;
+ }
+
+ /**
+ * @return array
+ */
+ public function getActualEventTypes()
+ {
+ return $this->actualEventTypes;
+ }
+
+ /**
+ * @return string
+ */
+ public function getBaseCurrency()
+ {
+ return $this->baseCurrency;
+ }
+
+ /**
+ * @return string
+ */
+ public function getDecisionCallbackUrl()
+ {
+ return $this->decisionCallbackUrl;
+ }
+
+ /**
+ * @return string
+ */
+ public function getManualDecisionCallbackUrl()
+ {
+ return $this->manualDecisionCallbackUrl;
+ }
+
+ /**
+ * @return string
+ */
+ public function getOngoingMonitoringWebhookUrl()
+ {
+ return $this->ongoingMonitoringWebhookUrl;
+ }
+
+ /**
+ * @return string
+ */
+ public function getMediaStorageWebhookUrl()
+ {
+ return $this->mediaStorageWebhookUrl;
+ }
+
+ /**
+ * @return string
+ */
+ public function getFraudAlertCallbackUrl()
+ {
+ return $this->fraudAlertCallbackUrl;
+ }
+
+ /**
+ * @return bool
+ */
+ public function isCardIdGeneration()
+ {
+ return $this->cardIdGeneration;
+ }
+
+ /**
+ * @return bool
+ */
+ public function isDeviceFingerprintGeneration()
+ {
+ return $this->deviceFingerprintGeneration;
+ }
+
+ /**
+ * @return bool
+ */
+ public function isSequenceIdGeneration()
+ {
+ return $this->sequenceIdGeneration;
+ }
+
+ /**
+ * @return string
+ */
+ public function getSequenceIdGenerationMethod()
+ {
+ return $this->sequenceIdGenerationMethod;
+ }
+
+ /**
+ * @return string
+ */
+ public function getAmlService()
+ {
+ return $this->amlService;
+ }
+
+ /**
+ * @return bool
+ */
+ public function isAmlServiceStatus()
+ {
+ return $this->amlServiceStatus;
+ }
+
+ /**
+ * @return int
+ */
+ public function getDowJonesDataBaseDate()
+ {
+ return $this->dowJonesDataBaseDate;
+ }
+
+ /**
+ * @return string
+ */
+ public function getKycProvider()
+ {
+ return $this->kycProvider;
+ }
+}
diff --git a/src/AccountConfigurationStatusResultBaseField.php b/src/AccountConfigurationStatusResultBaseField.php
new file mode 100644
index 0000000..ead7a98
--- /dev/null
+++ b/src/AccountConfigurationStatusResultBaseField.php
@@ -0,0 +1,26 @@
+addGroupId($groupId);
+ )
+ ->addGroupId($groupId)
+ ->addMediaData($mediaId);
}
/**
@@ -89,6 +93,7 @@ public static function confirmationEvent(
* @param string|null $password
* @param string|null $campaign
* @param string|null $groupId
+ * @param array|null $mediaId
*
* @return Builder
*/
@@ -103,7 +108,8 @@ public static function loginEvent(
$affiliateId = null,
$password = null,
$campaign = null,
- $groupId = null
+ $groupId = null,
+ $mediaId = null
) {
$builder = new self('login', $sequenceId);
if ($timestamp === null) {
@@ -134,7 +140,10 @@ public static function loginEvent(
null,
null,
$password
- )->addWebsiteData(null, $trafficSource, $affiliateId, $campaign)->addGroupId($groupId);
+ )
+ ->addWebsiteData(null, $trafficSource, $affiliateId, $campaign)
+ ->addGroupId($groupId)
+ ->addMediaData($mediaId);
}
/**
@@ -158,6 +167,7 @@ public static function loginEvent(
* @param string|null $password
* @param string|null $campaign
* @param string|null $groupId
+ * @param array|null $mediaId
*
* @return Builder
*/
@@ -179,7 +189,8 @@ public static function registrationEvent(
$affiliateId = null,
$password = null,
$campaign = null,
- $groupId = null
+ $groupId = null,
+ $mediaId = null
) {
$builder = new self('registration', $sequenceId);
if ($timestamp === null) {
@@ -215,7 +226,9 @@ public static function registrationEvent(
null,
null,
$password
- )-> addGroupId($groupId);
+ )
+ ->addGroupId($groupId)
+ ->addMediaData($mediaId);
}
/**
@@ -244,6 +257,7 @@ public static function registrationEvent(
* @param int|null $cardExpirationYear
* @param string|null $groupId
* @param string|null $linksToDocuments
+ * @param array|null $mediaId
*
* @return Builder
*/
@@ -270,7 +284,8 @@ public static function payoutEvent(
$cardExpirationMonth = null,
$cardExpirationYear = null,
$groupId = null,
- $linksToDocuments = null
+ $linksToDocuments = null,
+ $mediaId = null
) {
$builder = new self('payout', $sequenceId);
if ($payoutTimestamp === null) {
@@ -295,7 +310,8 @@ public static function payoutEvent(
)
->addShortUserData($email, $userId, $phone, $firstName, $lastName, $country)
->addGroupId($groupId)
- ->addLinksToDocuments($linksToDocuments);
+ ->addLinksToDocuments($linksToDocuments)
+ ->addMediaData($mediaId);
}
/**
@@ -348,6 +364,7 @@ public static function payoutEvent(
* @param string|null $acquirerMerchantId
* @param string|null $groupId
* @param string|null $linksToDocuments
+ * @param array|null $mediaId
*
* @return Builder
*/
@@ -398,7 +415,8 @@ public static function transactionEvent(
$mcc = null,
$acquirerMerchantId = null,
$groupId = null,
- $linksToDocuments = null
+ $linksToDocuments = null,
+ $mediaId = null
) {
$builder = new self('transaction', $sequenceId);
if ($transactionTimestamp === null) {
@@ -449,7 +467,8 @@ public static function transactionEvent(
->addWebsiteData($websiteUrl, null, $affiliateId, $campaign)
->addIpData(null, null, $merchantIp)
->addGroupId($groupId)
- ->addLinksToDocuments($linksToDocuments);
+ ->addLinksToDocuments($linksToDocuments)
+ ->addMediaData($mediaId);
}
@@ -465,6 +484,7 @@ public static function transactionEvent(
* @param string|null $affiliateId
* @param string|null $campaign
* @param string|null $groupId
+ * @param array|null $mediaId
* @return Builder
*/
public static function installEvent(
@@ -476,7 +496,8 @@ public static function installEvent(
$trafficSource = null,
$affiliateId = null,
$campaign = null,
- $groupId = null
+ $groupId = null,
+ $mediaId = null
) {
$builder = new self('install', $sequenceId);
if ($installTimestamp === null) {
@@ -487,7 +508,8 @@ public static function installEvent(
$installTimestamp
)->addWebsiteData($websiteUrl, $trafficSource, $affiliateId, $campaign)
->addShortUserData(null, $userId, null, null, null, $country)
- ->addGroupId($groupId);
+ ->addGroupId($groupId)
+ ->addMediaData($mediaId);
}
/**
@@ -512,6 +534,7 @@ public static function installEvent(
* @param string|null $userId
* @param string|null $groupId
* @param string|null $linksToDocuments
+ * @param array|null $mediaId
*
* @return Builder
*/
@@ -534,7 +557,8 @@ public static function refundEvent(
$phone = null,
$userId = null,
$groupId = null,
- $linksToDocuments = null
+ $linksToDocuments = null,
+ $mediaId = null
) {
$builder = new self('refund', $sequenceId);
if ($refundTimestamp === null) {
@@ -559,7 +583,8 @@ public static function refundEvent(
)
->addUserData($email, $userId, $phone)
->addGroupId($groupId)
- ->addLinksToDocuments($linksToDocuments);
+ ->addLinksToDocuments($linksToDocuments)
+ ->addMediaData($mediaId);
}
/**
@@ -611,6 +636,7 @@ public static function refundEvent(
* @param string|null $groupId
* @param string|null $secondUserMerchantId
* @param string|null $linksToDocuments
+ * @param array|null $mediaId
*
* @return Builder
*/
@@ -660,7 +686,8 @@ public static function transferEvent(
$source = null,
$groupId = null,
$secondUserMerchantId = null,
- $linksToDocuments = null
+ $linksToDocuments = null,
+ $mediaId = null
) {
$builder = new self('transfer', $sequenceId);
if ($eventTimestamp === null) {
@@ -724,7 +751,8 @@ public static function transferEvent(
)
->addProductData($productQuantity, $productName, $productDescription)
->addGroupId($groupId)
- ->addLinksToDocuments($linksToDocuments);
+ ->addLinksToDocuments($linksToDocuments)
+ ->addMediaData($mediaId);
}
/**
@@ -780,6 +808,9 @@ public static function transferEvent(
* @param int|null $expiryDate
* @param string|null $gender
* @param string|null $linksToDocuments
+ * @param array|null $mediaId
+ * @param bool|null $addressConfirmed
+ * @param bool|null $secondAddressConfirmed
* @return Builder
*/
public static function kycProfileEvent(
@@ -832,7 +863,10 @@ public static function kycProfileEvent(
$issueDate = null,
$expiryDate = null,
$gender = null,
- $linksToDocuments = null
+ $linksToDocuments = null,
+ $mediaId = null,
+ $addressConfirmed = null,
+ $secondAddressConfirmed = null
) {
$builder = new self('kyc_profile', $sequenceId);
if ($eventTimestamp === null) {
@@ -871,7 +905,19 @@ public static function kycProfileEvent(
$employmentStatus,
$sourceOfFunds,
$issueDate,
- $expiryDate
+ $expiryDate,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ $addressConfirmed,
+ $secondAddressConfirmed
)
->addUserData(
$email,
@@ -899,7 +945,8 @@ public static function kycProfileEvent(
null
)
->addWebsiteData($websiteUrl)
- ->addLinksToDocuments($linksToDocuments);
+ ->addLinksToDocuments($linksToDocuments)
+ ->addMediaData($mediaId);
}
/**
@@ -998,6 +1045,7 @@ public static function kycProfileEvent(
* @param null $refererUrl
* @param null $originUrl
* @param string|null $linksToDocuments
+ * @param array|null $mediaId
* @return static
*/
public static function profileUpdateEvent(
@@ -1095,7 +1143,8 @@ public static function profileUpdateEvent(
$plugins = null,
$refererUrl = null,
$originUrl = null,
- $linksToDocuments = null
+ $linksToDocuments = null,
+ $mediaId = null
) {
$builder = new self(self::EVENT_PROFILE_UPDATE, $sequenceId);
@@ -1195,7 +1244,8 @@ public static function profileUpdateEvent(
$refererUrl,
$originUrl
)
- ->addLinksToDocuments($linksToDocuments);
+ ->addLinksToDocuments($linksToDocuments)
+ ->addMediaData($mediaId);
}
@@ -1214,6 +1264,9 @@ public static function profileUpdateEvent(
* @param string|null $providerCode
* @param string|null $providerReason
* @param string|null $linksToDocuments
+ * @param array|null $mediaId
+ * @param bool|null $addressConfirmed
+ * @param bool|null $secondAddressConfirmed
*
* @return Builder
*/
@@ -1289,7 +1342,10 @@ public static function kycSubmitEvent(
$userAgent = null,
$plugins = null,
$refererUrl = null,
- $originUrl = null
+ $originUrl = null,
+ $mediaId = null,
+ $addressConfirmed = null,
+ $secondAddressConfirmed = null
) {
$builder = new self('kyc_submit', $sequenceId);
if ($eventTimestamp === null) {
@@ -1365,13 +1421,16 @@ public static function kycSubmitEvent(
$userAgent,
$plugins,
$refererUrl,
- $originUrl
+ $originUrl,
+ $addressConfirmed,
+ $secondAddressConfirmed
)
->addUserData(
null,
$userId
)
- ->addLinksToDocuments($linksToDocuments);
+ ->addLinksToDocuments($linksToDocuments)
+ ->addMediaData($mediaId);
}
/**
@@ -1479,7 +1538,9 @@ public static function kycStartEvent(
$kycLanguage,
$redirectUrl,
$numberOfDocuments,
- $allowedDocumentFormat
+ $allowedDocumentFormat,
+ null,
+ null
)
->addUserData(
$email,
@@ -1575,6 +1636,7 @@ public static function kycProofEvent($kycStartId)
* @param string|null $websiteUrl
* @param string|null $productUrl
* @param string|null $productImageUrl
+ * @param array|null $mediaId
* @return Builder
*/
public static function orderItemEvent(
@@ -1625,7 +1687,8 @@ public static function orderItemEvent(
$userMerchantId = null,
$websiteUrl = null,
$productUrl = null,
- $productImageUrl = null
+ $productImageUrl = null,
+ $mediaId = null
) {
$envelopeType = 'order_item';
$builder = new self($envelopeType, $sequenceId);
@@ -1694,7 +1757,8 @@ public static function orderItemEvent(
$websiteUrl,
null,
$affiliateId
- );
+ )
+ ->addMediaData($mediaId);
}
/**
@@ -1745,6 +1809,7 @@ public static function orderItemEvent(
* @param string|null $websiteUrl
* @param string|null $productUrl
* @param string|null $productImageUrl
+ * @param array|null $mediaId
* @return Builder
*/
public static function orderSubmitEvent(
@@ -1792,7 +1857,8 @@ public static function orderSubmitEvent(
$userMerchantId = null,
$websiteUrl = null,
$productUrl = null,
- $productImageUrl = null
+ $productImageUrl = null,
+ $mediaId = null
) {
$envelopeType = 'order_submit';
$builder = new self($envelopeType, $sequenceId);
@@ -1856,7 +1922,8 @@ public static function orderSubmitEvent(
$websiteUrl,
null,
$affiliateId
- );
+ )
+ ->addMediaData($mediaId);
}
/**
@@ -3019,6 +3086,8 @@ public function addTransferData(
* @param string|null $redirectUrl
* @param int|null $numberOfDocuments
* @param string|null $allowedDocumentFormat
+ * @param bool|null $addressConfirmed
+ * @param bool|null $secondAddressConfirmed
* @return $this
*/
public function addKycData(
@@ -3063,7 +3132,9 @@ public function addKycData(
$kycLanguage = null,
$redirectUrl = null,
$numberOfDocuments = null,
- $allowedDocumentFormat = null
+ $allowedDocumentFormat = null,
+ $addressConfirmed = null,
+ $secondAddressConfirmed = null
) {
if (!is_string($eventId)) {
throw new \InvalidArgumentException('Event ID must be string');
@@ -3191,6 +3262,12 @@ public function addKycData(
if ($allowedDocumentFormat !== null && !is_string($allowedDocumentFormat)) {
throw new \InvalidArgumentException('Allowed document format must be string');
}
+ if ($addressConfirmed !== null && !is_bool($addressConfirmed)) {
+ throw new \InvalidArgumentException('Address confirmed must be boolean');
+ }
+ if ($secondAddressConfirmed !== null && !is_bool($secondAddressConfirmed)) {
+ throw new \InvalidArgumentException('Second address confirmed must be boolean');
+ }
$this->replace('event_id', $eventId);
$this->replace('event_timestamp', $eventTimestamp);
@@ -3234,6 +3311,8 @@ public function addKycData(
$this->replace('redirect_url', $redirectUrl);
$this->replace('number_of_documents', $numberOfDocuments);
$this->replace('allowed_document_format', $allowedDocumentFormat);
+ $this->replace('address_confirmed', $addressConfirmed);
+ $this->replace('second_address_confirmed', $secondAddressConfirmed);
return $this;
}
@@ -3607,6 +3686,30 @@ public function addGroupId($groupId = null)
return $this;
}
+ /**
+ * Provides media id value to envelope
+ *
+ * @param array|null $mediaId
+ * @return $this
+ */
+ public function addMediaData($mediaId = null)
+ {
+ if ($mediaId !== null) {
+ if (!is_array($mediaId)) {
+ throw new \InvalidArgumentException('Media id must be array');
+ }
+
+ foreach ($mediaId as $id) {
+ if (!is_int($id) || $id <= 0) {
+ throw new \InvalidArgumentException('Media id must be list of int');
+ }
+ }
+ }
+ $this->replace('media_id', $mediaId);
+
+ return $this;
+ }
+
/**
* Add links to documents
*
@@ -4345,7 +4448,9 @@ public function addKycSubmitData(
$userAgent = null,
$plugins = null,
$refererUrl = null,
- $originUrl = null
+ $originUrl = null,
+ $addressConfirmed = null,
+ $secondAddressConfirmed = null
) {
if (!is_string($eventId)) {
throw new \InvalidArgumentException('Event ID must be string');
@@ -4554,6 +4659,12 @@ public function addKycSubmitData(
if ($originUrl !== null && !is_string($originUrl)) {
throw new \InvalidArgumentException('Origin Url must be string');
}
+ if ($addressConfirmed !== null && !is_bool($addressConfirmed)) {
+ throw new \InvalidArgumentException('Address confirmed must be boolean');
+ }
+ if ($secondAddressConfirmed !== null && !is_bool($secondAddressConfirmed)) {
+ throw new \InvalidArgumentException('Second address confirmed must be boolean');
+ }
$this->replace('event_id', $eventId);
$this->replace('event_timestamp', $eventTimestamp);
@@ -4624,6 +4735,8 @@ public function addKycSubmitData(
$this->replace('plugins', $plugins);
$this->replace('referer_url', $refererUrl);
$this->replace('origin_url', $originUrl);
+ $this->replace('address_confirmed', $addressConfirmed);
+ $this->replace('second_address_confirmed', $secondAddressConfirmed);
return $this;
}
diff --git a/src/Envelopes/ValidatorV1.php b/src/Envelopes/ValidatorV1.php
index dfef3c8..aa2c156 100644
--- a/src/Envelopes/ValidatorV1.php
+++ b/src/Envelopes/ValidatorV1.php
@@ -241,6 +241,7 @@ class ValidatorV1
'active_features' => 'string(1024)',
'promotions' => 'string(1024)',
'links_to_documents' => 'string(2048)',
+ 'media_id' => 'array_int',
);
private static $sharedOptional = array(
@@ -272,7 +273,7 @@ class ValidatorV1
private static $types = array(
'confirmation' => array(
'mandatory' => array('confirmation_timestamp', 'user_merchant_id'),
- 'optional' => array('email_confirmed', 'phone_confirmed', 'email', 'phone', "group_id"),
+ 'optional' => array('email_confirmed', 'phone_confirmed', 'email', 'phone', "group_id", "media_id"),
),
'login' => array(
'mandatory' => array('login_timestamp', 'user_merchant_id'),
@@ -285,7 +286,8 @@ class ValidatorV1
'affiliate_id',
'password',
'campaign',
- "group_id"
+ "group_id",
+ "media_id",
)
),
'registration' => array(
@@ -305,7 +307,8 @@ class ValidatorV1
'affiliate_id',
'password',
'campaign',
- "group_id"
+ "group_id",
+ "media_id",
),
),
'transaction' => array(
@@ -358,6 +361,7 @@ class ValidatorV1
'acquirer_merchant_id',
'group_id',
'links_to_documents',
+ 'media_id',
)
),
'payout' => array(
@@ -386,6 +390,7 @@ class ValidatorV1
'payout_expiration_year',
'group_id',
'links_to_documents',
+ 'media_id',
)
),
'install' => array(
@@ -399,7 +404,8 @@ class ValidatorV1
'traffic_source',
'affiliate_id',
'campaign',
- "group_id"
+ "group_id",
+ "media_id",
)
),
'refund' => array(
@@ -424,6 +430,7 @@ class ValidatorV1
'user_merchant_id',
'group_id',
'links_to_documents',
+ 'media_id',
)
),
'transfer' => array(
@@ -475,6 +482,7 @@ class ValidatorV1
'account_id',
'second_account_id',
'links_to_documents',
+ 'media_id',
)
),
'postback' => array(
@@ -547,6 +555,9 @@ class ValidatorV1
'expiry_date',
'gender',
'links_to_documents',
+ 'media_id',
+ 'address_confirmed',
+ 'second_address_confirmed',
)
),
'kyc_submit' => array(
@@ -624,6 +635,9 @@ class ValidatorV1
'plugins',
'referer_url',
'origin_url',
+ 'media_id',
+ 'address_confirmed',
+ 'second_address_confirmed',
)
),
'kyc_start' => array(
@@ -713,6 +727,7 @@ class ValidatorV1
"product_image_url",
"carrier_url",
"carrier_phone",
+ 'media_id',
)
),
'order_submit' => array(
@@ -763,6 +778,7 @@ class ValidatorV1
"product_image_url",
"carrier_url",
"carrier_phone",
+ 'media_id',
)
),
'profile_update' => array(
@@ -864,6 +880,7 @@ class ValidatorV1
"referer_url",
"origin_url",
"links_to_documents",
+ "media_id",
)
),
);
@@ -1021,6 +1038,26 @@ public function analyzeFieldTypes(EnvelopeInterface $envelope)
);
}
break;
+ case 'array_int':
+ 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_int($id) || $id <= 0) {
+ $details[] = sprintf(
+ 'ID: "%s" must be int, but %s provided',
+ $id,
+ $id === null ? 'null' : gettype($id)
+ );
+ }
+ }
+ }
+ break;
default:
$details[] = sprintf('Unknown type for "%s"', $key);
}
diff --git a/src/Facade.php b/src/Facade.php
index 5664899..e3a67b6 100644
--- a/src/Facade.php
+++ b/src/Facade.php
@@ -81,22 +81,6 @@ private static function getClient()
return self::$client;
}
- /**
- * Sends request to Covery and returns access level, associated with
- * used credentials
- *
- * This method can be used for Covery health check and availability
- * On any problem (network, credentials, server side) this method
- * will throw an exception
- *
- * @return mixed
- * @throws Exception
- */
- public static function ping()
- {
- return self::getClient()->ping();
- }
-
/**
* Sends envelope to Covery and returns it's ID on Covery side
* Before sending, validation is performed
@@ -157,4 +141,68 @@ public static function sendCardId(CardIdInterface $cardId)
{
return self::getClient()->sendCardId($cardId);
}
+
+ /**
+ * Send Media Storage data and return upload URL
+ *
+ * @param MediaStorageInterface $mediaStorage
+ * @return MediaStorageResult
+ * @throws Exception
+ * @throws IoException
+ */
+ public static function sendMediaStorage(MediaStorageInterface $mediaStorage)
+ {
+ return self::getClient()->sendMediaStorage($mediaStorage);
+ }
+
+ /**
+ * Attach media connection and return status code
+ *
+ * @param MediaConnectionInterface $mediaConnection
+ * @return int
+ * @throws Exception
+ * @throws IoException
+ */
+ public static function attachMediaConnection(MediaConnectionInterface $mediaConnection)
+ {
+ return self::getClient()->attachMediaConnection($mediaConnection);
+ }
+
+ /**
+ * Detach media connection and return status code
+ *
+ * @param MediaConnectionInterface $mediaConnection
+ * @return int
+ * @throws Exception
+ * @throws IoException
+ */
+ public static function detachMediaConnection(MediaConnectionInterface $mediaConnection)
+ {
+ return self::getClient()->detachMediaConnection($mediaConnection);
+ }
+
+ /**
+ * Upload Media file and returns status code
+ *
+ * @param MediaFileUploaderInterface $mediaFileUploader
+ * @return int
+ * @throws Exception
+ * @throws IoException
+ */
+ public static function uploadMediaFile(MediaFileUploaderInterface $mediaFileUploader)
+ {
+ return self::getClient()->uploadMediaFile($mediaFileUploader);
+ }
+
+ /**
+ * Get account configuration status and return result object
+ *
+ * @return AccountConfigurationStatusResult
+ * @throws Exception
+ * @throws IoException
+ */
+ public static function getAccountConfigurationStatus()
+ {
+ return self::getClient()->getAccountConfigurationStatus();
+ }
}
diff --git a/src/MediaConnection/Builder.php b/src/MediaConnection/Builder.php
new file mode 100644
index 0000000..95bea58
--- /dev/null
+++ b/src/MediaConnection/Builder.php
@@ -0,0 +1,96 @@
+addConnectionData($requestId, $mediaId);
+ }
+
+ /**
+ * Provides MediaConnection value
+ *
+ * @param $requestId
+ * @param $mediaId
+ * @return Builder
+ */
+ public function addConnectionData($requestId, $mediaId)
+ {
+ if (!is_int($requestId)) {
+ throw new \InvalidArgumentException('Request Id must be integer');
+ }
+ if ($requestId <= 0) {
+ throw new \InvalidArgumentException('Request Id must be positive integer');
+ }
+ if (!is_array($mediaId)) {
+ throw new \InvalidArgumentException('Media Id must be array');
+ }
+ if (!$this->isListOfPositiveInt($mediaId)) {
+ throw new \InvalidArgumentException('Media Id must be list of positive int');
+ }
+
+ $this->replace('request_id', $requestId);
+ $this->replace('media_id', $mediaId);
+
+ return $this;
+ }
+
+ /**
+ * Returns built MediaConnection
+ *
+ * @return MediaConnection
+ */
+ public function build()
+ {
+ return new MediaConnection(
+ array_filter($this->data, function ($data) {
+ return $data !== null;
+ })
+ );
+ }
+
+ /**
+ * Replaces value in internal array if provided value not empty
+ *
+ * @param string $key
+ * @param string|int|float|bool|array|null $value
+ */
+ private function replace($key, $value)
+ {
+ if ($value !== null && $value !== '' && $value !== 0 && $value !== 0.0) {
+ $this->data[$key] = $value;
+ }
+ }
+
+ /**
+ * @param array $ids
+ * @return bool
+ */
+ private function isListOfPositiveInt(array $ids)
+ {
+ foreach ($ids as $id) {
+ if (!is_int($id) || $id <= 0) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+}
diff --git a/src/MediaConnection/MediaConnection.php b/src/MediaConnection/MediaConnection.php
new file mode 100644
index 0000000..4166691
--- /dev/null
+++ b/src/MediaConnection/MediaConnection.php
@@ -0,0 +1,75 @@
+data = $data;
+ }
+
+ /**
+ * @return array
+ */
+ public function toArray()
+ {
+ return $this->data;
+ }
+
+ /**
+ * @return int
+ */
+ public function count()
+ {
+ return count($this->data);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function offsetExists($offset)
+ {
+ return array_key_exists($offset, $this->data);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function offsetGet($offset)
+ {
+ if (!$this->offsetExists($offset)) {
+ throw new \OutOfBoundsException("No offset {$offset}");
+ }
+
+ return $this->data[$offset];
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function offsetSet($offset, $value)
+ {
+ $this->data[$offset] = $value;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function offsetUnset($offset)
+ {
+ if ($this->offsetExists($offset)) {
+ unset($this->data[$offset]);
+ }
+ }
+}
diff --git a/src/MediaConnectionInterface.php b/src/MediaConnectionInterface.php
new file mode 100644
index 0000000..76a3c6b
--- /dev/null
+++ b/src/MediaConnectionInterface.php
@@ -0,0 +1,18 @@
+addMediaFileUploaderData($url, $file);
+ }
+
+ /**
+ * Provides Upload data value
+ *
+ * @param $url
+ * @param $file
+ * @return Builder
+ */
+ public function addMediaFileUploaderData($url, $file)
+ {
+ if (!is_string($url)) {
+ throw new \InvalidArgumentException('Url must be string');
+ }
+ if (empty($url)) {
+ throw new \InvalidArgumentException('URL is empty');
+ }
+
+ if (!($file instanceof StreamInterface)) {
+ throw new \InvalidArgumentException('File must be instance of StreamInterface');
+ }
+
+ $this->replace('url', $url);
+ $this->replace('file', $file);
+
+ return $this;
+ }
+
+ /**
+ * Returns built MediaFileUploader
+ *
+ * @return MediaFileUploader
+ */
+ public function build()
+ {
+ return new MediaFileUploader(
+ array_filter($this->data, function ($data) {
+ return $data !== null;
+ })
+ );
+ }
+
+ /**
+ * Replaces value in internal array if provided value not empty
+ *
+ * @param string $key
+ * @param string|int|float|bool|array|null $value
+ */
+ private function replace($key, $value)
+ {
+ if ($value !== null && $value !== '' && $value !== 0 && $value !== 0.0) {
+ $this->data[$key] = $value;
+ }
+ }
+}
diff --git a/src/MediaFileUploader/MediaFileUploader.php b/src/MediaFileUploader/MediaFileUploader.php
new file mode 100644
index 0000000..1fe0c5e
--- /dev/null
+++ b/src/MediaFileUploader/MediaFileUploader.php
@@ -0,0 +1,75 @@
+data = $data;
+ }
+
+ /**
+ * @return array
+ */
+ public function toArray()
+ {
+ return $this->data;
+ }
+
+ /**
+ * @return int
+ */
+ public function count()
+ {
+ return count($this->data);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function offsetExists($offset)
+ {
+ return array_key_exists($offset, $this->data);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function offsetGet($offset)
+ {
+ if (!$this->offsetExists($offset)) {
+ throw new \OutOfBoundsException("No offset {$offset}");
+ }
+
+ return $this->data[$offset];
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function offsetSet($offset, $value)
+ {
+ $this->data[$offset] = $value;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function offsetUnset($offset)
+ {
+ if ($this->offsetExists($offset)) {
+ unset($this->data[$offset]);
+ }
+ }
+}
diff --git a/src/MediaFileUploaderInterface.php b/src/MediaFileUploaderInterface.php
new file mode 100644
index 0000000..477b354
--- /dev/null
+++ b/src/MediaFileUploaderInterface.php
@@ -0,0 +1,18 @@
+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/MediaStorage/MediaStorage.php b/src/MediaStorage/MediaStorage.php
new file mode 100644
index 0000000..e3e27c6
--- /dev/null
+++ b/src/MediaStorage/MediaStorage.php
@@ -0,0 +1,75 @@
+data = $data;
+ }
+
+ /**
+ * @return array
+ */
+ public function toArray()
+ {
+ return $this->data;
+ }
+
+ /**
+ * @return int
+ */
+ public function count()
+ {
+ return count($this->data);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function offsetExists($offset)
+ {
+ return array_key_exists($offset, $this->data);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function offsetGet($offset)
+ {
+ if (!$this->offsetExists($offset)) {
+ throw new \OutOfBoundsException("No offset {$offset}");
+ }
+
+ return $this->data[$offset];
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function offsetSet($offset, $value)
+ {
+ $this->data[$offset] = $value;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function offsetUnset($offset)
+ {
+ if ($this->offsetExists($offset)) {
+ unset($this->data[$offset]);
+ }
+ }
+}
diff --git a/src/MediaStorageInterface.php b/src/MediaStorageInterface.php
new file mode 100644
index 0000000..d35d6fc
--- /dev/null
+++ b/src/MediaStorageInterface.php
@@ -0,0 +1,18 @@
+uploadUrl = $uploadUrl;
+ $this->mediaId = $mediaId;
+ $this->createdAt = $createdAt;
+ }
+
+
+ /**
+ * @return string
+ */
+ public function getUploadUrl()
+ {
+ return $this->uploadUrl;
+ }
+
+ /**
+ * @return int
+ */
+ public function getMediaId()
+ {
+ return $this->mediaId;
+ }
+
+ /**
+ * @return float
+ */
+ public function getCreatedAt()
+ {
+ return $this->createdAt;
+ }
+}
diff --git a/src/MediaStorageResultBaseField.php b/src/MediaStorageResultBaseField.php
new file mode 100644
index 0000000..60f4090
--- /dev/null
+++ b/src/MediaStorageResultBaseField.php
@@ -0,0 +1,14 @@
+prepareRequest($request);
+ $requestPrepared = $this->prepareRequest($request);
+ if ($sign) {
+ $requestSigned = $this->credentials->signRequest($requestPrepared);
+ } else {
+ $requestSigned = $requestPrepared;
+ }
try {
- $this->logger->info('Sending request to ' . $request->getUri());
+ $this->logger->info('Sending request to ' . $requestSigned->getUri());
$before = microtime(true);
- $response = $this->transport->send($request);
+ $response = $this->transport->send($requestSigned);
$this->logger->info(sprintf('Request done in %.2f', microtime(true) - $before));
} catch (\Exception $inner) {
$this->logger->error($inner->getMessage(), ['exception' => $inner]);
@@ -74,6 +86,7 @@ public function send(RequestInterface $request)
throw new IoException('Error sending request', 0, $inner);
}
$code = $response->getStatusCode();
+ $this->responseStatusCode = $code;
$this->logger->debug('Received status code ' . $code);
if ($code >= 400) {
@@ -99,7 +112,7 @@ private function prepareRequest(RequestInterface $request)
);
}
- return $this->credentials->signRequest($request);
+ return $request;
}
/**
@@ -174,27 +187,6 @@ private function readJson($string)
return $data;
}
- /**
- * Sends request to Covery and returns access level, associated with
- * used credentials
- *
- * This method can be used for Covery health check and availability
- * On any problem (network, credentials, server side) this method
- * will throw an exception
- *
- * @return string
- * @throws Exception
- */
- public function ping()
- {
- $data = $this->readJson($this->send(new Ping()));
- if (!is_array($data) || !isset($data['level'])) {
- throw new Exception("Malformed response");
- }
-
- return $data['level'];
- }
-
/**
* Sends envelope to Covery and returns it's ID on Covery side
* Before sending, validation is performed
@@ -343,4 +335,122 @@ public function sendCardId(CardIdInterface $cardId)
$data[CardIdResultBaseField::CREATED_AT]
);
}
+
+ /**
+ * Send Media Storage data and return upload URL
+ *
+ * @param MediaStorageInterface $media
+ * @return MediaStorageResult
+ * @throws Exception
+ * @throws IoException
+ */
+ public function sendMediaStorage(MediaStorageInterface $media)
+ {
+ $data = $this->readJson($this->send(new MediaStorage($media)));
+
+ if (!is_array($data)) {
+ throw new Exception("Malformed response");
+ }
+
+ return new MediaStorageResult(
+ $data[MediaStorageResultBaseField::UPLOAD_URL],
+ $data[MediaStorageResultBaseField::MEDIA_ID],
+ $data[MediaStorageResultBaseField::CREATED_AT]
+ );
+ }
+
+ /**
+ * @param MediaConnectionInterface $mediaConnection
+ * @return int
+ * @throws Exception
+ * @throws IoException
+ */
+ public function attachMediaConnection(MediaConnectionInterface $mediaConnection)
+ {
+ return $this->sendMediaConnection($mediaConnection, 'PUT');
+ }
+
+ /**
+ * @param MediaConnectionInterface $mediaConnection
+ * @return int
+ * @throws Exception
+ * @throws IoException
+ */
+ public function detachMediaConnection(MediaConnectionInterface $mediaConnection)
+ {
+ return $this->sendMediaConnection($mediaConnection, 'DELETE');
+ }
+
+ /**
+ * Upload Media file and returns status code
+ *
+ * @param MediaFileUploaderInterface $mediaFileUploader
+ * @return int
+ * @throws Exception
+ * @throws IoException
+ */
+ public function uploadMediaFile(MediaFileUploaderInterface $mediaFileUploader)
+ {
+ $this->send(new MediaFileUploaderRequest($mediaFileUploader), false);
+
+ if ($this->responseStatusCode >= 300) {
+ throw new Exception("Malformed response");
+ }
+
+ return $this->responseStatusCode;
+ }
+
+ /**
+ * Send media connection and return status code
+ *
+ * @param MediaConnectionInterface $mediaConnection
+ * @param $method
+ * @return int
+ * @throws Exception
+ * @throws IoException
+ */
+ private function sendMediaConnection(MediaConnectionInterface $mediaConnection, $method)
+ {
+ $this->readJson($this->send(new \Covery\Client\Requests\MediaConnection($mediaConnection, $method)));
+ if ($this->responseStatusCode >= 300) {
+ throw new Exception("Malformed response");
+ }
+
+ return $this->responseStatusCode;
+ }
+
+ /**
+ * Get Account configuration status object from Covery
+ *
+ * @return AccountConfigurationStatusResult
+ * @throws Exception
+ * @throws IoException
+ */
+ public function getAccountConfigurationStatus()
+ {
+ // Sending
+ $data = $this->readJson($this->send(new \Covery\Client\Requests\AccountConfigurationStatus()));
+
+ if (!is_array($data)) {
+ throw new Exception("Malformed response");
+ }
+
+ return new AccountConfigurationStatusResult(
+ $data[AccountConfigurationStatusResultBaseField::ACTUAL_EVENT_TYPES],
+ $data[AccountConfigurationStatusResultBaseField::BASE_CURRENCY],
+ $data[AccountConfigurationStatusResultBaseField::DECISION_CALLBACK_URL],
+ $data[AccountConfigurationStatusResultBaseField::MANUAL_DECISION_CALLBACK_URL],
+ $data[AccountConfigurationStatusResultBaseField::ONGOING_MONITORING_WEBHOOK_URL],
+ $data[AccountConfigurationStatusResultBaseField::MEDIA_STORAGE_WEBHOOK_URL],
+ $data[AccountConfigurationStatusResultBaseField::FRAUD_ALERT_CALLBACK_URL],
+ $data[AccountConfigurationStatusResultBaseField::CARD_ID_GENERATION],
+ $data[AccountConfigurationStatusResultBaseField::DEVICE_FINGERPRINT_GENERATION],
+ $data[AccountConfigurationStatusResultBaseField::SEQUENCE_ID_GENERATION],
+ $data[AccountConfigurationStatusResultBaseField::SEQUENCE_ID_GENERATION_METHOD],
+ $data[AccountConfigurationStatusResultBaseField::AML_SERVICE],
+ $data[AccountConfigurationStatusResultBaseField::AML_SERVICE_STATUS],
+ $data[AccountConfigurationStatusResultBaseField::DOW_JONES_DATA_BASE_DATE],
+ $data[AccountConfigurationStatusResultBaseField::KYC_PROVIDER]
+ );
+ }
}
diff --git a/src/Requests/AccountConfigurationStatus.php b/src/Requests/AccountConfigurationStatus.php
new file mode 100644
index 0000000..ee4b646
--- /dev/null
+++ b/src/Requests/AccountConfigurationStatus.php
@@ -0,0 +1,25 @@
+toArray())
+ );
+ }
+}
diff --git a/src/Requests/MediaFileUploader.php b/src/Requests/MediaFileUploader.php
new file mode 100644
index 0000000..d871341
--- /dev/null
+++ b/src/Requests/MediaFileUploader.php
@@ -0,0 +1,31 @@
+ 'application/octet-stream',
+ ],
+ $mediaFileUploader['file']
+ );
+ }
+}
diff --git a/src/Requests/MediaStorage.php b/src/Requests/MediaStorage.php
new file mode 100644
index 0000000..187d36c
--- /dev/null
+++ b/src/Requests/MediaStorage.php
@@ -0,0 +1,30 @@
+toArray())
+ );
+ }
+}
diff --git a/src/Requests/Ping.php b/src/Requests/Ping.php
deleted file mode 100644
index c20d26e..0000000
--- a/src/Requests/Ping.php
+++ /dev/null
@@ -1,20 +0,0 @@
-getMethod());
+ self::assertContains($request->getUri()->getPath(), '/api/accountConfigurationStatus');
+ }
+}
\ No newline at end of file
diff --git a/tests/Covery/BuildConfirmationEnvelopeTest.php b/tests/Covery/BuildConfirmationEnvelopeTest.php
index 3d429ba..1f7bf4e 100644
--- a/tests/Covery/BuildConfirmationEnvelopeTest.php
+++ b/tests/Covery/BuildConfirmationEnvelopeTest.php
@@ -15,13 +15,14 @@ public function testBuild()
false,
null,
null,
- "group id value"
+ "group id value",
+ [1, 2]
)->addIdentity(new \Covery\Client\Identities\Stub())->build();
self::assertSame('confirmation', $result->getType());
self::assertCount(1, $result->getIdentities());
self::assertSame('sequenceIdSome', $result->getSequenceId());
- self::assertCount(5, $result);
+ self::assertCount(6, $result);
self::assertSame('ababagalamaga', $result['user_merchant_id']);
self::assertSame(42342352, $result['confirmation_timestamp']);
self::assertTrue($result['email_confirmed']);
@@ -29,6 +30,7 @@ public function testBuild()
self::assertArrayNotHasKey('email', $result);
self::assertArrayNotHasKey('phone', $result);
self::assertSame('group id value', $result['group_id']);
+ self::assertSame([1, 2], $result['media_id']);
$validator->validate($result);
// Minimal data
diff --git a/tests/Covery/BuildInstallEventTest.php b/tests/Covery/BuildInstallEventTest.php
index 34148e8..5ec0254 100644
--- a/tests/Covery/BuildInstallEventTest.php
+++ b/tests/Covery/BuildInstallEventTest.php
@@ -16,13 +16,14 @@ public function testBuild()
'source',
'affId12345',
'email campaign',
- "group id value"
+ "group id value",
+ [1, 2]
)->addBrowserData('88889', 'Test curl')->addIdentity(new \Covery\Client\Identities\Stub())->build();
self::assertSame('install', $result->getType());
self::assertCount(1, $result->getIdentities());
self::assertSame('someSequenceId', $result->getSequenceId());
- self::assertCount(10, $result);
+ self::assertCount(11, $result);
self::assertSame('fooUserId', $result['user_merchant_id']);
self::assertSame(123456, $result['install_timestamp']);
self::assertSame('ukr', $result['country']);
@@ -31,6 +32,7 @@ public function testBuild()
self::assertSame('affId12345', $result['affiliate_id']);
self::assertSame('email campaign', $result['campaign']);
self::assertSame('group id value', $result['group_id']);
+ self::assertSame([1, 2], $result['media_id']);
$validator->validate($result);
// Minimal data
diff --git a/tests/Covery/BuildKYCProfileEnvelopeTest.php b/tests/Covery/BuildKYCProfileEnvelopeTest.php
index 4642e1e..b56963d 100644
--- a/tests/Covery/BuildKYCProfileEnvelopeTest.php
+++ b/tests/Covery/BuildKYCProfileEnvelopeTest.php
@@ -57,12 +57,15 @@ public function testBuild()
999,
888,
"male",
- 'linksToDocuments'
+ 'linksToDocuments',
+ [1, 2],
+ true,
+ true
)->addIdentity(new \Covery\Client\Identities\Stub())->build();
self::assertSame('kyc_profile', $result->getType());
self::assertSame('kycProfileSequenceIdSome', $result->getSequenceId());
- self::assertCount(49, $result);
+ self::assertCount(52, $result);
self::assertSame('kycProfileEventId', $result['event_id']);
self::assertSame(123456, $result['event_timestamp']);
self::assertSame('kycProfileUserMerchantId', $result['user_merchant_id']);
@@ -112,6 +115,9 @@ public function testBuild()
self::assertSame(888, $result['expiry_date']);
self::assertSame('male', $result['gender']);
self::assertSame('linksToDocuments', $result['links_to_documents']);
+ self::assertSame([1, 2], $result['media_id']);
+ self::assertTrue($result['address_confirmed']);
+ self::assertTrue($result['second_address_confirmed']);
$validator->validate($result);
diff --git a/tests/Covery/BuildKYCSubmitEnvelopeTest.php b/tests/Covery/BuildKYCSubmitEnvelopeTest.php
index 25be9ba..79991a4 100644
--- a/tests/Covery/BuildKYCSubmitEnvelopeTest.php
+++ b/tests/Covery/BuildKYCSubmitEnvelopeTest.php
@@ -79,13 +79,16 @@ public function testBuild()
'KycSubmitUserAgent',
'KycSubmitPlugins',
'KycSubmitRefererUrl',
- 'KycSubmitOriginUrl'
+ 'KycSubmitOriginUrl',
+ [1, 2],
+ true,
+ true
)->addIdentity(new \Covery\Client\Identities\Stub())->build();
self::assertSame('kyc_submit', $result->getType());
self::assertSame('kycSubmitSequenceIdSome', $result->getSequenceId());
- self::assertCount(71, $result);
+ self::assertCount(74, $result);
self::assertSame('kycSubmitEventId', $result['event_id']);
self::assertSame(1234568, $result['event_timestamp']);
self::assertSame('kycSubmitUserMerchantId', $result['user_merchant_id']);
@@ -157,6 +160,9 @@ public function testBuild()
self::assertSame('KycSubmitPlugins', $result['plugins']);
self::assertSame('KycSubmitRefererUrl', $result['referer_url']);
self::assertSame('KycSubmitOriginUrl', $result['origin_url']);
+ self::assertSame([1, 2], $result['media_id']);
+ self::assertTrue($result['address_confirmed']);
+ self::assertTrue($result['second_address_confirmed']);
$validator->validate($result);
diff --git a/tests/Covery/BuildLoginEnvelopeTest.php b/tests/Covery/BuildLoginEnvelopeTest.php
index b4d3472..6386537 100644
--- a/tests/Covery/BuildLoginEnvelopeTest.php
+++ b/tests/Covery/BuildLoginEnvelopeTest.php
@@ -18,13 +18,14 @@ public function testBuild()
'someAffiliateId',
"somePassword",
"email campaign",
- "group id value"
+ "group id value",
+ [1, 2]
)->addIdentity(new \Covery\Client\Identities\Stub())->build();
self::assertSame('login', $result->getType());
self::assertCount(1, $result->getIdentities());
self::assertSame('someSequenceId', $result->getSequenceId());
- self::assertCount(10, $result);
+ self::assertCount(11, $result);
self::assertSame('someUserId', $result['user_merchant_id']);
self::assertSame(123456, $result['login_timestamp']);
self::assertSame('foo@bar.com', $result['email']);
@@ -34,6 +35,7 @@ public function testBuild()
self::assertSame('somePassword', $result['password']);
self::assertSame('email campaign', $result['campaign']);
self::assertSame('group id value', $result['group_id']);
+ self::assertSame([1, 2], $result['media_id']);
self::assertTrue($result['login_failed']);
$validator->validate($result);
diff --git a/tests/Covery/BuildMediaConnectionTest.php b/tests/Covery/BuildMediaConnectionTest.php
new file mode 100644
index 0000000..a3319f2
--- /dev/null
+++ b/tests/Covery/BuildMediaConnectionTest.php
@@ -0,0 +1,48 @@
+build();
+
+ $request = new \Covery\Client\Requests\MediaConnection($mediaConnectionResult);
+ self::assertEquals('PUT', $request->getMethod());
+ self::assertContains($request->getUri()->getPath(), '/api/mediaConnection');
+ self::assertInstanceOf('Psr\Http\Message\RequestInterface', $request);
+ self::assertCount(2, $mediaConnectionResult);
+ self::assertSame($mediaId, $mediaConnectionResult['media_id']);
+ self::assertSame($requestId, $mediaConnectionResult['request_id']);
+ self::assertJson($request->getBody()->getContents());
+ }
+
+ public function testEventExpectsInvalidArgumentException()
+ {
+ $requestId = -1;
+ $mediaId = -1;
+
+ self::setExpectedException('InvalidArgumentException');
+ \Covery\Client\MediaConnection\Builder::mediaConnectionEvent(
+ $requestId,
+ $mediaId
+ )->build();
+ }
+
+ public function testEventExpectsInvalidArgumentExceptionCheckZeroFields()
+ {
+ $requestId = 0;
+ $mediaId = [1, 0, -1];
+
+ self::setExpectedException('InvalidArgumentException');
+ \Covery\Client\MediaConnection\Builder::mediaConnectionEvent(
+ $requestId,
+ $mediaId
+ )->build();
+ }
+}
diff --git a/tests/Covery/BuildMediaFileUploaderTest.php b/tests/Covery/BuildMediaFileUploaderTest.php
new file mode 100644
index 0000000..66ff4e8
--- /dev/null
+++ b/tests/Covery/BuildMediaFileUploaderTest.php
@@ -0,0 +1,21 @@
+build();
+
+ self::assertSame($mediaUrl, $mediaStorageResult['url']);
+ self::assertInstanceOf('Psr\Http\Message\StreamInterface', $mediaStorageResult['file']);
+ self::assertEquals($fileStream, $mediaStorageResult['file']);
+ self::assertSame($testString, (string)$fileStream);
+ }
+}
diff --git a/tests/Covery/BuildMediaStorageTest.php b/tests/Covery/BuildMediaStorageTest.php
new file mode 100644
index 0000000..d692b92
--- /dev/null
+++ b/tests/Covery/BuildMediaStorageTest.php
@@ -0,0 +1,81 @@
+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 6dfcad3..6d6a7ee 100644
--- a/tests/Covery/BuildOrderItemEnvelopeTest.php
+++ b/tests/Covery/BuildOrderItemEnvelopeTest.php
@@ -54,7 +54,8 @@ public function testBuild()
"userMerchantId",
"websiteUrl",
"productUrl",
- "productImageUrl"
+ "productImageUrl",
+ [1, 2]
)->addIdentity(new \Covery\Client\Identities\Stub()
)->addBrowserData(
"deviceFingerprint",
@@ -81,7 +82,7 @@ public function testBuild()
)->build();
self::assertSame('order_item', $result->getType());
- self::assertCount(68, $result);
+ self::assertCount(69, $result);
self::assertCount(1, $result->getIdentities());
self::assertSame('sequenceId', $result->getSequenceId());
self::assertSame(123.456, $result["amount"]);
@@ -152,6 +153,7 @@ public function testBuild()
self::assertSame(true, $result["cookie_enabled"]);
self::assertSame(false, $result["do_not_track"]);
self::assertSame(true, $result["ajax_validation"]);
+ self::assertSame([1, 2], $result["media_id"]);
$validator->validate($result);
diff --git a/tests/Covery/BuildOrderSubmitEnvelopeTest.php b/tests/Covery/BuildOrderSubmitEnvelopeTest.php
index c568978..0a0a2ed 100644
--- a/tests/Covery/BuildOrderSubmitEnvelopeTest.php
+++ b/tests/Covery/BuildOrderSubmitEnvelopeTest.php
@@ -51,7 +51,8 @@ public function testBuild()
"userMerchantId",
"websiteUrl",
"productUrl",
- "productImageUrl"
+ "productImageUrl",
+ [1, 2]
)->addIdentity(new \Covery\Client\Identities\Stub()
)->addBrowserData(
"deviceFingerprint",
@@ -78,7 +79,7 @@ public function testBuild()
)->build();
self::assertSame('order_submit', $result->getType());
- self::assertCount(65, $result);
+ self::assertCount(66, $result);
self::assertCount(1, $result->getIdentities());
self::assertSame('sequenceId', $result->getSequenceId());
self::assertSame(123.456, $result["amount"]);
@@ -146,6 +147,7 @@ public function testBuild()
self::assertSame(true, $result["cookie_enabled"]);
self::assertSame(false, $result["do_not_track"]);
self::assertSame(true, $result["ajax_validation"]);
+ self::assertSame([1, 2], $result["media_id"]);
$validator->validate($result);
diff --git a/tests/Covery/BuildPayoutEventTest.php b/tests/Covery/BuildPayoutEventTest.php
index 5b97178..c51223c 100644
--- a/tests/Covery/BuildPayoutEventTest.php
+++ b/tests/Covery/BuildPayoutEventTest.php
@@ -30,13 +30,14 @@ public function testBuild()
11,
22,
"group id value",
- 'links to documents'
+ 'links to documents',
+ [1, 2]
)->addBrowserData('88889', 'Test curl')->addIdentity(new \Covery\Client\Identities\Stub())->build();
self::assertSame('payout', $result->getType());
self::assertCount(1, $result->getIdentities());
self::assertSame('someSequenceId', $result->getSequenceId());
- self::assertCount(24, $result);
+ self::assertCount(25, $result);
self::assertSame('fooUserId', $result['user_merchant_id']);
self::assertSame(5566, $result['payout_timestamp']);
self::assertSame('payoutLargeId', $result['payout_id']);
@@ -62,6 +63,7 @@ public function testBuild()
self::assertSame('Test curl', $result['user_agent']);
self::assertSame('group id value', $result['group_id']);
self::assertSame('links to documents', $result['links_to_documents']);
+ self::assertSame([1, 2], $result['media_id']);
$validator->validate($result);
// Minimal data
diff --git a/tests/Covery/BuildProfileUpdateEventTest.php b/tests/Covery/BuildProfileUpdateEventTest.php
index a356b52..7e08e93 100644
--- a/tests/Covery/BuildProfileUpdateEventTest.php
+++ b/tests/Covery/BuildProfileUpdateEventTest.php
@@ -105,11 +105,12 @@ public function testBuild()
"profileUpdatePlugins",
"profileUpdateRefererUrl",
"profileUpdateOriginUrl",
- "linksToDocuments"
+ "linksToDocuments",
+ [1, 2]
)->build();
- self::assertCount(94, $result);
+ self::assertCount(95, $result);
self::assertSame(Builder::EVENT_PROFILE_UPDATE, $result->getType());
self::assertSame('profileUpdateSequenceId', $result->getSequenceId());
self::assertSame('profileUpdateEventId', $result['event_id']);
@@ -208,6 +209,7 @@ public function testBuild()
self::assertSame("profileUpdateRefererUrl", $result['referer_url']);
self::assertSame("profileUpdateOriginUrl", $result['origin_url']);
self::assertSame("linksToDocuments", $result['links_to_documents']);
+ self::assertSame([1, 2], $result['media_id']);
$validator->validate($result);
diff --git a/tests/Covery/BuildRefundEventTest.php b/tests/Covery/BuildRefundEventTest.php
index 48a1010..822fb37 100644
--- a/tests/Covery/BuildRefundEventTest.php
+++ b/tests/Covery/BuildRefundEventTest.php
@@ -26,7 +26,8 @@ public function testBuild()
'somePhone',
'someUid',
"group id value",
- 'links to documents'
+ 'links to documents',
+ [1, 2]
)->addBrowserData(
'88889',
'Test curl',
@@ -54,7 +55,7 @@ public function testBuild()
self::assertSame('refund', $result->getType());
self::assertCount(1, $result->getIdentities());
self::assertSame('someSequenceId', $result->getSequenceId());
- self::assertCount(39, $result);
+ self::assertCount(40, $result);
self::assertSame('refundLargeId', $result['refund_id']);
self::assertSame(0.12, $result['refund_amount']);
self::assertSame('GBP', $result['refund_currency']);
@@ -93,6 +94,7 @@ public function testBuild()
self::assertSame('clientResolution', $result['client_resolution']);
self::assertSame('group id value', $result['group_id']);
self::assertSame('links to documents', $result['links_to_documents']);
+ self::assertSame([1, 2], $result['media_id']);
$validator->validate($result);
// Minimal data
diff --git a/tests/Covery/BuildRegistrationEventTest.php b/tests/Covery/BuildRegistrationEventTest.php
index 7e5b967..f752957 100644
--- a/tests/Covery/BuildRegistrationEventTest.php
+++ b/tests/Covery/BuildRegistrationEventTest.php
@@ -25,13 +25,14 @@ public function testBuild()
'8965asd-2',
'somePassword',
'email campaign',
- "group id value"
+ "group id value",
+ [1, 2]
)->addIdentity(new \Covery\Client\Identities\Stub())->build();
self::assertSame('registration', $result->getType());
self::assertCount(1, $result->getIdentities());
self::assertSame('someLongString', $result->getSequenceId());
- self::assertCount(17, $result);
+ self::assertCount(18, $result);
self::assertSame('thisisuser', $result['user_merchant_id']);
self::assertSame(320746, $result['registration_timestamp']);
self::assertSame('user@site.net', $result['email']);
@@ -49,6 +50,7 @@ public function testBuild()
self::assertSame('somePassword', $result['password']);
self::assertSame('email campaign', $result['campaign']);
self::assertSame('group id value', $result['group_id']);
+ self::assertCount(2, $result['media_id']);
$validator->validate($result);
// Minimal data
diff --git a/tests/Covery/BuildTransactionEventTest.php b/tests/Covery/BuildTransactionEventTest.php
index d7d209c..8bbd961 100644
--- a/tests/Covery/BuildTransactionEventTest.php
+++ b/tests/Covery/BuildTransactionEventTest.php
@@ -54,7 +54,8 @@ public function testBuild()
"mcc value",
"acquirer merchant id value",
"group id value",
- 'links to documents'
+ 'links to documents',
+ [1, 2]
)
->addBrowserData('88889', 'Test curl')
->addIdentity(new \Covery\Client\Identities\Stub())
@@ -64,7 +65,7 @@ public function testBuild()
self::assertSame('transaction', $result->getType());
self::assertCount(1, $result->getIdentities());
self::assertSame('someSequenceId', $result->getSequenceId());
- self::assertCount(49, $result);
+ self::assertCount(50, $result);
self::assertSame('fooUserId', $result['user_merchant_id']);
self::assertSame('transactionId', $result['transaction_id']);
self::assertSame(0.12, $result['transaction_amount']);
@@ -112,6 +113,7 @@ public function testBuild()
self::assertSame('acquirer merchant id value', $result['acquirer_merchant_id']);
self::assertSame('group id value', $result['group_id']);
self::assertSame('links to documents', $result['links_to_documents']);
+ self::assertSame([1, 2], $result['media_id']);
$validator->validate($result);
diff --git a/tests/Covery/BuildTransferEventTest.php b/tests/Covery/BuildTransferEventTest.php
index 7113591..4f1e257 100644
--- a/tests/Covery/BuildTransferEventTest.php
+++ b/tests/Covery/BuildTransferEventTest.php
@@ -53,7 +53,8 @@ public function testBuild()
'source value',
"group id value",
"second user merchant id value",
- 'links to documents'
+ 'links to documents',
+ [1, 2]
)
->addBrowserData('88889', 'Test curl')
->addIdentity(new \Covery\Client\Identities\Stub())
@@ -63,7 +64,7 @@ public function testBuild()
self::assertSame('transfer', $result->getType());
self::assertCount(1, $result->getIdentities());
self::assertSame('someSequenceId', $result->getSequenceId());
- self::assertCount(48, $result);
+ self::assertCount(49, $result);
self::assertSame('someEventId', $result['event_id']);
self::assertSame(0.42, $result['amount']);
@@ -110,6 +111,7 @@ public function testBuild()
self::assertSame('group id value', $result['group_id']);
self::assertSame('second user merchant id value', $result['second_user_merchant_id']);
self::assertSame('links to documents', $result['links_to_documents']);
+ self::assertSame([1, 2], $result['media_id']);
$validator->validate($result);
diff --git a/tests/Covery/Psr7RequestsTest.php b/tests/Covery/Psr7RequestsTest.php
index 881cdc3..efce68d 100644
--- a/tests/Covery/Psr7RequestsTest.php
+++ b/tests/Covery/Psr7RequestsTest.php
@@ -2,15 +2,6 @@
class Psr7RequestsTest extends \PHPUnit_Framework_TestCase
{
- public function testPing()
- {
- $req = new \Covery\Client\Requests\Ping();
- self::assertInstanceOf('Psr\Http\Message\RequestInterface', $req);
- self::assertSame('', $req->getBody()->getContents());
- self::assertSame('POST', $req->getMethod());
- self::assertSame('/api/ping', strval($req->getUri()));
- }
-
public function testEvent()
{
$noIdentities = new \Covery\Client\Envelopes\Builder('foo', 'bar');
diff --git a/tests/Covery/WithCustomHostTest.php b/tests/Covery/WithCustomHostTest.php
index 4c22143..004dfb1 100644
--- a/tests/Covery/WithCustomHostTest.php
+++ b/tests/Covery/WithCustomHostTest.php
@@ -4,18 +4,20 @@ class WithCustomHostTest extends \PHPUnit_Framework_TestCase
{
public function testWithCustomUrl()
{
+ $result = \Covery\Client\Envelopes\Builder::postBackEvent(1)->build();
+
$mock = self::getMockBuilder('Covery\\Client\\TransportInterface')->getMock();
$mock->expects(self::exactly(1))->method('send')->with(self::callback(function(\Psr\Http\Message\RequestInterface $req) {
- return strval($req->getUri()) == 'ftp://localhost/api/ping';
+ return strval($req->getUri()) == 'ftp://localhost/api/postback';
}));
$custom = new \Covery\Client\Transport\WithCustomHost($mock, 'localhost', 'ftp');
- $custom->send(new \Covery\Client\Requests\Ping());
+ $custom->send(new \Covery\Client\Requests\Postback($result));
$mock = self::getMockBuilder('Covery\\Client\\TransportInterface')->getMock();
$mock->expects(self::exactly(1))->method('send')->with(self::callback(function(\Psr\Http\Message\RequestInterface $req) {
- return strval($req->getUri()) == 'https://test.local:8083/api/ping';
+ return strval($req->getUri()) == 'https://test.local:8083/api/postback';
}));
$custom = new \Covery\Client\Transport\WithCustomHost($mock, 'test.local:8083', 'https');
- $custom->send(new \Covery\Client\Requests\Ping());
+ $custom->send(new \Covery\Client\Requests\Postback($result));
}
}