tuurbo/spreedly

setResponse doesn't set response status

oradwell opened this issue · 1 comments

I am trying to create a Spreedly client using:

// Retrieve transaction from POST data
$xmlText = file_get_contents('php://input', 'r');
$xml = new SimpleXMLElement($xmlText, LIBXML_NONET | LIBXML_NOCDATA);
// We expect only one transaction
$transactionXml = $xml->children()[0];

$client = new \Tuurbo\Spreedly\Client(new \GuzzleHttp\Client, []);
$client->setResponse($transactionXml);

Problem I have is that when response is set that way, status of the response does not get set on the client. Therefore the result of $client->success() and $client->fails() is always false.

I think it would be better if the code that sets the status:

if (isset($this->response['error']) || (isset($this->response['succeeded']) && $this->response['succeeded'] == 'false'))
{
    $this->status = 'error';

    return $this;
}

$this->status = 'success';

was inside setResponse method.

--- vendor/tuurbo/spreedly/src/Client.php    Tue Oct 20 17:53:03 2015
+++ vendor/tuurbo/spreedly/src/Client.php    Tue Oct 20 17:53:06 2015
@@ -58,15 +58,6 @@

        $this->setResponse($response);

-       if (isset($this->response['error']) || (isset($this->response['succeeded']) && $this->response['succeeded'] == 'false'))
-       {
-           $this->status = 'error';
-
-           return $this;
-       }
-
-       $this->status = 'success';
-
        return $this;
    }

@@ -93,6 +84,15 @@
        $response = json_decode(json_encode((array) $response), true);

        $this->response = $this->cleanArray($response);
+
+       if (isset($this->response['error']) || (isset($this->response['succeeded']) && $this->response['succeeded'] == 'false'))
+       {
+           $this->status = 'error';
+
+           return $this;
+       }
+
+       $this->status = 'success';
    }

    /**

@tuurbo Thanks