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

Commit

Permalink
Update successful payment logic, AVS + CVD can fail but the transacti…
Browse files Browse the repository at this point in the history
…on will still be successful.
  • Loading branch information
tappleby committed Dec 9, 2016
1 parent 0f4f659 commit bbd85b8
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 bbd85b8

Please sign in to comment.