-
Notifications
You must be signed in to change notification settings - Fork 850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ErrorObject to Stripe exceptions #705
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace Stripe; | ||
|
||
/** | ||
* Class ErrorObject | ||
* | ||
* @property string $charge For card errors, the ID of the failed charge. | ||
* @property string $code For some errors that could be handled | ||
* programmatically, a short string indicating the error code reported. | ||
* @property string $decline_code For card errors resulting from a card issuer | ||
* decline, a short string indicating the card issuer's reason for the | ||
* decline if they provide one. | ||
* @property string $doc_url A URL to more information about the error code | ||
* reported. | ||
* @property string $message A human-readable message providing more details | ||
* about the error. For card errors, these messages can be shown to your | ||
* users. | ||
* @property string $param If the error is parameter-specific, the parameter | ||
* related to the error. For example, you can use this to display a message | ||
* near the correct form field. | ||
* @property PaymentIntent $payment_intent The PaymentIntent object for errors | ||
* returned on a request involving a PaymentIntent. | ||
* @property PaymentMethod $payment_method The PaymentMethod object for errors | ||
* returned on a request involving a PaymentMethod. | ||
* @property SetupIntent $setup_intent The SetupIntent object for errors | ||
* returned on a request involving a SetupIntent. | ||
* @property StripeObject $source The source object for errors returned on a | ||
* request involving a source. | ||
* @property string $type The type of error returned. One of | ||
* `api_connection_error`, `api_error`, `authentication_error`, | ||
* `card_error`, `idempotency_error`, `invalid_request_error`, or | ||
* `rate_limit_error`. | ||
* | ||
* @package Stripe | ||
*/ | ||
class ErrorObject extends StripeObject | ||
{ | ||
/** | ||
* Refreshes this object using the provided values. | ||
* | ||
* @param array $values | ||
* @param null|string|array|Util\RequestOptions $opts | ||
* @param boolean $partial Defaults to false. | ||
*/ | ||
public function refreshFrom($values, $opts, $partial = false) | ||
{ | ||
// Unlike most other API resources, the API will omit attributes in | ||
// error objects when they have a null value. We manually set default | ||
// values here to facilitate generic error handling. | ||
$values = array_merge([ | ||
'charge' => null, | ||
'code' => null, | ||
'decline_code' => null, | ||
'doc_url' => null, | ||
'message' => null, | ||
'param' => null, | ||
'payment_intent' => null, | ||
'payment_method' => null, | ||
'setup_intent' => null, | ||
'source' => null, | ||
'type' => null, | ||
], $values); | ||
parent::refreshFrom($values, $opts, $partial); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Stripe; | ||
|
||
/** | ||
* Class OAuthErrorObject | ||
* | ||
* @property string $error | ||
* @property string $error_description | ||
* | ||
* @package Stripe | ||
*/ | ||
class OAuthErrorObject extends StripeObject | ||
{ | ||
/** | ||
* Refreshes this object using the provided values. | ||
* | ||
* @param array $values | ||
* @param null|string|array|Util\RequestOptions $opts | ||
* @param boolean $partial Defaults to false. | ||
*/ | ||
public function refreshFrom($values, $opts, $partial = false) | ||
{ | ||
// Unlike most other API resources, the API will omit attributes in | ||
// error objects when they have a null value. We manually set default | ||
// values here to facilitate generic error handling. | ||
$values = array_merge([ | ||
'error' => null, | ||
'error_description' => null, | ||
], $values); | ||
parent::refreshFrom($values, $opts, $partial); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Stripe; | ||
|
||
class OAuthBaseTest extends TestCase | ||
{ | ||
public function createFixture() | ||
{ | ||
return $this->getMockForAbstractClass(\Stripe\Error\OAuth\OAuthBase::class, [ | ||
'code', | ||
'description', | ||
200, | ||
'{"error": "code", "error_description": "description"}', | ||
['error' => 'code', 'error_description' => 'description'], | ||
[ | ||
'Some-Header' => 'Some Value', | ||
'Request-Id' => 'req_test', | ||
], | ||
]); | ||
} | ||
|
||
public function testGetters() | ||
{ | ||
$e = $this->createFixture(); | ||
$this->assertSame(200, $e->getHttpStatus()); | ||
$this->assertSame('{"error": "code", "error_description": "description"}', $e->getHttpBody()); | ||
$this->assertSame(['error' => 'code', 'error_description' => 'description'], $e->getJsonBody()); | ||
$this->assertSame('Some Value', $e->getHttpHeaders()['Some-Header']); | ||
$this->assertSame('req_test', $e->getRequestId()); | ||
$this->assertNotNull($e->getError()); | ||
$this->assertSame('code', $e->getError()->error); | ||
$this->assertSame('description', $e->getError()->error_description); | ||
} | ||
|
||
public function testToString() | ||
{ | ||
$e = $this->createFixture(); | ||
$this->assertContains("(Request req_test)", (string)$e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Stripe; | ||
|
||
class ErrorObjectTest extends TestCase | ||
{ | ||
public function testDefaultValues() | ||
{ | ||
$error = ErrorObject::constructFrom([]); | ||
|
||
$this->assertNull($error->charge); | ||
$this->assertNull($error->code); | ||
$this->assertNull($error->decline_code); | ||
$this->assertNull($error->doc_url); | ||
$this->assertNull($error->message); | ||
$this->assertNull($error->param); | ||
$this->assertNull($error->payment_intent); | ||
$this->assertNull($error->payment_method); | ||
$this->assertNull($error->setup_intent); | ||
$this->assertNull($error->source); | ||
$this->assertNull($error->type); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Stripe; | ||
|
||
class OAuthErrorObjectTest extends TestCase | ||
{ | ||
public function testDefaultValues() | ||
{ | ||
$error = OAuthErrorObject::constructFrom([]); | ||
|
||
$this->assertNull($error->error); | ||
$this->assertNull($error->error_description); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea.