Skip to content
This repository has been archived by the owner on Oct 30, 2020. It is now read-only.

Response success logic #4

Merged
merged 3 commits into from
Dec 28, 2016
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
8 changes: 8 additions & 0 deletions src/Receipt.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public function __construct($data)
]);
}

public function successful() {
$complete = $this->read('complete');
$valid_code = $this->read('code') !== 'null';
$code = (int)$this->read('code');

return $complete && $valid_code && $code >= 0 && $code < 50;
}

/**
* Read an item from the receipt.
*
Expand Down
12 changes: 3 additions & 9 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,10 @@ public function validate()
return $this;
}

$code = (int)$receipt->read('code');
$this->successful = $receipt->successful();

if ($code >= 50 || $code === 0) {
if (!$this->successful) {
$this->status = $this->convertReceiptCodeToStatus($receipt);
$this->successful = false;

return $this;
}

Expand Down Expand Up @@ -176,23 +174,19 @@ public function validate()
}

$this->failedAvs = true;
$this->successful = false;

return $this;
}

$code = !is_null($receipt->read('cvd_result')) ? $receipt->read('cvd_result') : null;

if ($gateway->avs && !is_null($code) && $code !== 'null' && !in_array($code{1}, $gateway->cvdCodes)) {
if ($gateway->cvd && !is_null($code) && $code !== 'null' && !in_array($code{1}, $gateway->cvdCodes)) {
$this->status = self::CVD;
$this->failedCvd = true;
$this->successful = false;

return $this;
}

$this->successful = true;

return $this;
}

Expand Down