From d0b5e4e6cf8eaef3ae96279ed171ecd0de8044f4 Mon Sep 17 00:00:00 2001 From: Del Date: Sat, 19 Mar 2016 16:16:47 +0800 Subject: [PATCH] Implement getCode method in Response class --- src/Message/Response.php | 46 +++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/src/Message/Response.php b/src/Message/Response.php index a83974f6..6f75896d 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -40,7 +40,7 @@ public function getTransactionReference() return $this->data['error']['charge']; } - return; + return null; } /** @@ -79,7 +79,7 @@ public function getCustomerReference() } } - return; + return null; } /** @@ -110,7 +110,7 @@ public function getCardReference() } } - return; + return null; } /** @@ -124,7 +124,7 @@ public function getToken() return $this->data['id']; } - return; + return null; } /** @@ -138,7 +138,7 @@ public function getCard() return $this->data['card']; } - return; + return null; } /** @@ -150,9 +150,9 @@ public function getSource() { if (isset($this->data['source']) && $this->data['source']['object'] == 'card') { return $this->data['source']; - } else { - return; } + + return null; } /** @@ -166,7 +166,7 @@ public function getSubscriptionReference() return $this->data['id']; } - return; + return null; } /** @@ -180,7 +180,7 @@ public function getEventReference() return $this->data['id']; } - return; + return null; } /** @@ -194,7 +194,7 @@ public function getInvoiceReference() return $this->data['id']; } - return; + return null; } /** @@ -208,7 +208,7 @@ public function getList() return $this->data['data']; } - return; + return null; } /** @@ -224,7 +224,7 @@ public function getPlan() return $this->data; } - return; + return null; } /** @@ -239,7 +239,7 @@ public function getPlanId() return $plan['id']; } - return; + return null; } /** @@ -253,7 +253,7 @@ public function getInvoiceItemReference() return $this->data['id']; } - return; + return null; } /** @@ -269,6 +269,22 @@ public function getMessage() return $this->data['error']['message']; } - return; + return null; + } + + /** + * Get the error message from the response. + * + * Returns null if the request was successful. + * + * @return string|null + */ + public function getCode() + { + if (!$this->isSuccessful()) { + return $this->data['error']['code']; + } + + return null; } }