1. Setup
Documentation
  • Back to home
  • StripeKit
  • Installation
  • Getting Started
  • Choosing a Mode
  • Type Reference
  • Setup
    • Configuration
    • Timezones
    • Storage Adapter
    • Money and Currency
    • Error Handling
  • Stripe
    • Elements
  • Modules
    • Overview
    • Customers
      • Overview
      • List
      • Retrieve
      • Find or Create by Email
      • Create
      • Update
      • Sync
      • Delete
    • Payment Methods
      • Overview
      • Create Setup Intent
      • List
      • Attach
      • Detach
      • Set Default
      • Sync
    • Payments
      • Overview
      • Pay With Saved Method
      • Create
      • Retrieve
      • Confirm
      • Cancel
      • Sync
    • Checkout
      • Overview
      • Get
      • Create
      • Submit Fields
      • Apply Coupon
      • Mark Complete
    • Subscriptions
      • Overview
      • Create
      • Retrieve
      • Cancel
      • Resume
      • Toggle Collection Method
      • Update Fields
      • Apply Promotion Code
      • List By Customer
      • Find By Metadata
      • Sync
    • Invoices
      • Overview
      • Retrieve
      • List By Customer
      • List By Subscription
      • Pay With Saved Method
      • Void
      • Finalize
      • Sync
    • Coupons
      • Overview
      • Create
      • Validate
      • Apply To Subscription
      • List
      • Deactivate
    • Webhooks
      • Overview
      • Process
      • Events Reference
    • Sync
      • Overview
  1. Setup

Error Handling

Every module throws typed exceptions you can catch and branch on.

Exception hierarchy#

All StripeKit exceptions extend StripeKit\Exceptions\StripeKitError, itself an Exception, which exposes:
public readonly string $errorCode;
public readonly int $statusCode;
public readonly mixed $cause;
ClasserrorCodestatusCodeThrown when
ConfigurationErrorconfiguration_error500StripeKit::init() is called with missing or invalid options.
ValidationErrorvalidation_error422Input fails StripeKit's own validation before it reaches Stripe. Exposes an additional ?array $fieldErrors.
NotFoundErrornot_found404A requested object, such as a customer or subscription, cannot be found.
StripeOperationErrorstripe_operation_error422Stripe itself rejects the request. $cause holds the original Stripe exception.
WebhookVerificationErrorwebhook_verification_error400$kit->webhooks->process() cannot verify the signature or payload.
StripeOperationError also exposes a static factory, StripeOperationError::fromError($error, $fallbackMessage), used internally to wrap any underlying Stripe SDK exception while preserving its message and attaching it as $cause.

Catching broadly#

Since every StripeKit exception extends StripeKitError, you can catch all of them at once when you only need the normalized errorCode and statusCode, for example to return a consistent JSON error response from an API endpoint:
Previous
Money and Currency
Next
Elements
Built with