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

Commit

Permalink
Merge pull request #4 from tappleby/bugfix-payment-success
Browse files Browse the repository at this point in the history
Response success logic
  • Loading branch information
Craig Paul authored Dec 28, 2016
2 parents 262617c + bbd85b8 commit cb3b75e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
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

0 comments on commit cb3b75e

Please sign in to comment.