Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ You may provide the following as envelopes:

<a name="changelog"></a>
## Changelog
* `1.1.6`
* Added decision response fields: `type`, `createdAt`, `sequenceId`, `merchantUserId`, `reason`, `action` and custom response
* `1.1.5`
* Postback request_id change type to `int`
* `1.1.4`
Expand Down
19 changes: 14 additions & 5 deletions src/PublicAPIClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,20 @@ public function makeDecision(EnvelopeInterface $envelope)

try {
return new Result(
$data['requestId'],
$data['score'],
$data['accept'],
$data['reject'],
$data['manual']
$data[ResultBaseField::REQUEST_ID],
$data[ResultBaseField::TYPE],
$data[ResultBaseField::CREATED_AT],
$data[ResultBaseField::SEQUENCE_ID],
$data[ResultBaseField::MERCHANT_USER_ID],
$data[ResultBaseField::SCORE],
$data[ResultBaseField::ACCEPT],
$data[ResultBaseField::REJECT],
$data[ResultBaseField::MANUAL],
isset($data[ResultBaseField::REASON]) ? $data[ResultBaseField::REASON] : null,
isset($data[ResultBaseField::ACTION]) ? $data[ResultBaseField::ACTION] : null,
array_filter($data, function ($field) {
return !in_array($field, ResultBaseField::getAll());
}, ARRAY_FILTER_USE_KEY)
);
} catch (\Exception $error) {
throw new Exception('Malformed response', 0, $error);
Expand Down
136 changes: 133 additions & 3 deletions src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ class Result
* @var int
*/
private $requestId;
/**
* @var string
*/
private $type;
/**
* @var int
*/
private $createdAt;
/**
* @var string
*/
private $sequenceId;
/**
* @var string
*/
private $merchantUserId;
/**
* @var int
*/
Expand All @@ -31,21 +47,64 @@ class Result
* @var bool
*/
private $manual;
/**
* @var null|string
*/
private $reason;
/**
* @var null|string
*/
private $action;
/**
* @var null|array
*/
private $customResponse;

/**
* Result constructor.
*
* @param int $requestId
* @param string $type
* @param int $createdAt
* @param string $sequenceId
* @param string $merchantUserId
* @param int $score
* @param bool $accept
* @param bool $reject
* @param bool $manual
* @param null|string $reason
* @param null|string $action
* @param null|array $customResponse
*/
public function __construct($requestId, $score, $accept, $reject, $manual)
{
public function __construct(
$requestId,
$type,
$createdAt,
$sequenceId,
$merchantUserId,
$score,
$accept,
$reject,
$manual,
$reason = null,
$action = null,
$customResponse = null
) {
if (!is_int($requestId)) {
throw new \InvalidArgumentException('Request ID must be integer');
}
if (!is_string($type)) {
throw new \InvalidArgumentException('Type must be string');
}
if (!is_int($createdAt)) {
throw new \InvalidArgumentException('Created At must be integer');
}
if (!is_string($sequenceId)) {
throw new \InvalidArgumentException('Sequence Id must be string');
}
if (!is_string($merchantUserId)) {
throw new \InvalidArgumentException('Merchant User Id must be string');
}
if (!is_int($score)) {
throw new \InvalidArgumentException('Score must be integer');
}
Expand All @@ -58,12 +117,27 @@ public function __construct($requestId, $score, $accept, $reject, $manual)
if (!is_bool($manual)) {
throw new \InvalidArgumentException('Manual flag must be boolean');
}

if ($reason !== null && !is_string($reason)) {
throw new \InvalidArgumentException('Reason must be string');
}
if ($action !== null && !is_string($action)) {
throw new \InvalidArgumentException('Action must be string');
}
if ($customResponse !== null && !is_array($customResponse)) {
throw new \InvalidArgumentException('Custom Response must be array');
}
$this->requestId = $requestId;
$this->type = $type;
$this->createdAt = $createdAt;
$this->sequenceId = $sequenceId;
$this->merchantUserId = $merchantUserId;
$this->score = $score;
$this->accept = $accept;
$this->reject = $reject;
$this->manual = $manual;
$this->reason = $reason;
$this->action = $action;
$this->customResponse = $customResponse;
}

/**
Expand All @@ -74,6 +148,38 @@ public function getRequestId()
return $this->requestId;
}

/**
* @return string
*/
public function getType()
{
return $this->type;
}

/**
* @return int
*/
public function getCreatedAt()
{
return $this->createdAt;
}

/**
* @return string
*/
public function getSequenceId()
{
return $this->sequenceId;
}

/**
* @return string
*/
public function getMerchantUserId()
{
return $this->merchantUserId;
}

/**
* @return int
*/
Expand Down Expand Up @@ -105,4 +211,28 @@ public function isManual()
{
return $this->manual;
}

/**
* @return string|null
*/
public function getReason()
{
return $this->reason;
}

/**
* @return string|null
*/
public function getAction()
{
return $this->action;
}

/**
* @return array|null
*/
public function getCustomResponse()
{
return $this->customResponse;
}
}
37 changes: 37 additions & 0 deletions src/ResultBaseField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php


namespace Covery\Client;


class ResultBaseField
{
const REQUEST_ID = 'requestId';
const TYPE = 'type';
const CREATED_AT = 'createdAt';
const SEQUENCE_ID = 'sequenceId';
const MERCHANT_USER_ID = 'merchantUserId';
const SCORE = 'score';
const ACCEPT = 'accept';
const REJECT = 'reject';
const MANUAL = 'manual';
const REASON = 'reason';
const ACTION = 'action';

public static function getAll()
{
return [
self::REQUEST_ID,
self::TYPE,
self::CREATED_AT,
self::SEQUENCE_ID,
self::MERCHANT_USER_ID,
self::SCORE,
self::ACCEPT,
self::REJECT,
self::MANUAL,
self::REASON,
self::ACTION
];
}
}