From bbd85b80635f75c39bcf4524fa10d0b494ead579 Mon Sep 17 00:00:00 2001 From: Terry Appleby Date: Thu, 8 Dec 2016 20:29:58 -0500 Subject: [PATCH] Update successful payment logic, AVS + CVD can fail but the transaction will still be successful. --- src/Receipt.php | 8 ++++++++ src/Response.php | 12 +++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Receipt.php b/src/Receipt.php index 8ec6fe3..0f662bf 100644 --- a/src/Receipt.php +++ b/src/Receipt.php @@ -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. * diff --git a/src/Response.php b/src/Response.php index 0c01ddf..352b422 100644 --- a/src/Response.php +++ b/src/Response.php @@ -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; } @@ -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; }