laravel / cashier-paddle

Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services.
https://laravel.com/docs/cashier-paddle
MIT License
238 stars 57 forks source link

[2.x] Add the ability to get the paddle error #248

Closed bensherred closed 6 months ago

bensherred commented 6 months ago

The aim of this pull request to make it easier to get the paddle error response. The Cashier currently throws an exception when Paddle returns an error, but it only provides the error.detail.

There is also a $message variable which is set but never used. I've therefore updated the PaddleException to use that custom $message variable and added a method for getting the Paddle error response.

One of the main use cases behind this PR, is being able to get the validation messages and formatting them into a readable format for the user.

driesvints commented 6 months ago

Heya, thanks for your PR. Could you show a before/after example of this? Maybe through a screenshot of the Ignition error page?

bensherred commented 6 months ago

Yeah sure thing

Before

A general exception with an invalid key:

image

An exception due to validation:

image

After

A general exception with an invalid key:

image

An exception due to validation:

image

By catching the exception and calling ->getError(), we can get the error response from Paddle like so:

image image