Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 30 additions & 31 deletions lib/ErrorObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,26 @@
/**
* 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 string $payment_method_type If the error is specific to the type
* of payment method, the payment method type that had a problem. This
* field is only populated for invoice-related errors.
* @property string $request_log_url A URL to the request log entry in your
* dashboard.
* @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_error`,
* `card_error`, `idempotency_error`, or `invalid_request_error`.
* // errorProperties: The beginning of the section generated from our OpenAPI spec
*
* @property null|string $advice_code For card errors resulting from a card issuer decline, a short string indicating [how to proceed with an error](https://docs.stripe.com/declines#retrying-issuer-declines) if they provide one.
* @property null|string $charge For card errors, the ID of the failed charge.
* @property null|string $code For some errors that could be handled programmatically, a short string indicating the [error code](https://docs.stripe.com/error-codes) reported.
* @property null|string $decline_code For card errors resulting from a card issuer decline, a short string indicating the [card issuer's reason for the decline](https://docs.stripe.com/declines#issuer-declines) if they provide one.
* @property null|string $doc_url A URL to more information about the [error code](https://docs.stripe.com/error-codes) reported.
* @property null|string $message A human-readable message providing more details about the error. For card errors, these messages can be shown to your users.
* @property null|string $network_advice_code For card errors resulting from a card issuer decline, a 2 digit code which indicates the advice given to merchant by the card network on how to proceed with an error.
* @property null|string $network_decline_code For payments declined by the network, an alphanumeric code which indicates the reason the payment failed.
* @property null|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 null|PaymentIntent $payment_intent The PaymentIntent object for errors returned on a request involving a PaymentIntent.
* @property null|PaymentMethod $payment_method The PaymentMethod object for errors returned on a request involving a PaymentMethod.
* @property null|string $payment_method_type If the error is specific to the type of payment method, the payment method type that had a problem. This field is only populated for invoice-related errors.
* @property null|string $request_log_url A URL to the request log entry in your dashboard.
* @property null|SetupIntent $setup_intent The SetupIntent object for errors returned on a request involving a SetupIntent.
* @property null|PaymentSource $source The PaymentSource object for errors returned on a request involving a PaymentSource.
* @property string $type The type of error returned. One of `api_error`, `card_error`, `idempotency_error`, or `invalid_request_error`
* @property null|string $user_message The user message associated with the error.
* // errorProperties: The end of the section generated from our OpenAPI spec
*/
class ErrorObject extends StripeObject
{
Expand All @@ -42,7 +33,7 @@ class ErrorObject extends StripeObject
*
* @see https://stripe.com/docs/error-codes
*/
// The beginning of the section generated from our OpenAPI spec
// errorCodes: The beginning of the section generated from our OpenAPI spec
const CODE_ACCOUNT_CLOSED = 'account_closed';
const CODE_ACCOUNT_COUNTRY_INVALID_ADDRESS = 'account_country_invalid_address';
const CODE_ACCOUNT_ERROR_COUNTRY_CHANGE_REQUIRES_ADDITIONAL_STEPS = 'account_error_country_change_requires_additional_steps';
Expand Down Expand Up @@ -238,7 +229,7 @@ class ErrorObject extends StripeObject
const CODE_TRANSFER_SOURCE_BALANCE_PARAMETERS_MISMATCH = 'transfer_source_balance_parameters_mismatch';
const CODE_TRANSFERS_NOT_ALLOWED = 'transfers_not_allowed';
const CODE_URL_INVALID = 'url_invalid';
// The end of the section generated from our OpenAPI spec
// errorCodes: The end of the section generated from our OpenAPI spec

/**
* Refreshes this object using the provided values.
Expand All @@ -254,17 +245,25 @@ public function refreshFrom($values, $opts, $partial = false, $apiMode = 'v1')
// error objects when they have a null value. We manually set default
// values here to facilitate generic error handling.
$values = \array_merge([
// errorRefreshFrom: The beginning of the section generated from our OpenAPI spec
'advice_code' => null,
'charge' => null,
'code' => null,
'decline_code' => null,
'doc_url' => null,
'message' => null,
'network_advice_code' => null,
'network_decline_code' => null,
'param' => null,
'payment_intent' => null,
'payment_method' => null,
'payment_method_type' => null,
'request_log_url' => null,
'setup_intent' => null,
'source' => null,
'type' => null,
'user_message' => null,
// errorRefreshFrom: The end of the section generated from our OpenAPI spec
], $values);
parent::refreshFrom($values, $opts, $partial);
}
Expand Down
10 changes: 10 additions & 0 deletions tests/Stripe/ErrorObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,14 @@ public function testDefaultValues()
self::assertNull($error->source);
self::assertNull($error->type);
}

public function testNetworkAdviceCode()
{
$error = ErrorObject::constructFrom([
'type' => 'card_error',
'network_advice_code' => '02',
]);

self::assertSame('02', $error->network_advice_code);
}
}
Loading