Skip to content

Commit

Permalink
Merge pull request #450 from stripe/ob-error-code
Browse files Browse the repository at this point in the history
Add support for code attribute on all Stripe exceptions
  • Loading branch information
ob-stripe authored Feb 23, 2018
2 parents 4d5d96a + 6791706 commit 54c9fac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
9 changes: 9 additions & 0 deletions lib/Error/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@ public function __construct(
$this->httpHeaders = $httpHeaders;
$this->requestId = null;

// TODO: make this a proper constructor argument in the next major
// release.
$this->stripeCode = isset($jsonBody["error"]["code"]) ? $jsonBody["error"]["code"] : null;

if ($httpHeaders && isset($httpHeaders['Request-Id'])) {
$this->requestId = $httpHeaders['Request-Id'];
}
}

public function getStripeCode()
{
return $this->stripeCode;
}

public function getHttpStatus()
{
return $this->httpStatus;
Expand Down
13 changes: 6 additions & 7 deletions lib/Error/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ public function __construct(
) {
parent::__construct($message, $httpStatus, $httpBody, $jsonBody, $httpHeaders);
$this->stripeParam = $stripeParam;

// TODO: once Error\Base accepts the error code as an argument, pass it
// in the call to parent::__construct() and stop setting it here.
$this->stripeCode = $stripeCode;

// This one is not like the others because it was added later and we're
// trying to do our best not to change the public interface of this class'
// constructor. We should consider changing its implementation on the
// next major version bump of this library.
// constructor.
// TODO: make this a proper constructor argument in the next major
// release.
$this->declineCode = isset($jsonBody["error"]["decline_code"]) ? $jsonBody["error"]["decline_code"] : null;
}

Expand All @@ -29,11 +33,6 @@ public function getDeclineCode()
return $this->declineCode;
}

public function getStripeCode()
{
return $this->stripeCode;
}

public function getStripeParam()
{
return $this->stripeParam;
Expand Down

0 comments on commit 54c9fac

Please sign in to comment.