Skip to content
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

PaymentIntent "last_payment_error" property is not an ErrorObject #1353

Closed
YonniRouelle opened this issue Aug 22, 2022 · 3 comments
Closed
Labels

Comments

@YonniRouelle
Copy link

Describe the bug

I'm retrieving some PaymentIntent with errors and I can't use Stripe\ErrorObject property because the last_payment_error property of a PaymentIntent is an instance of Stripe\StripeObject

To Reproduce

  1. Retrieve a PaymentIntent from Stripe which has a last_payment_error property defined
  2. Dump the PaymentIntent retrieved
  3. Check the last_payment_error property type
  4. The last_payment_error property is an instance of Stripe\StripeObject

Expected behavior

I expect the property to be an instance of Stripe\ErrorObject

Code snippets

$paymentIntent = $stripeClient->paymentIntents->retrieve('payment_intent_id');

dump($paymentIntent->last_payment_error instanceof Stripe\ErrorObject); // false

OS

Ubuntu 22.04.1 LTS

PHP version

PHP 8.1

Library version

stripe-php v9.0.0

API version

2022-08-01

Additional context

No response

@dcr-stripe
Copy link
Contributor

Thanks for the report @YonniRouelle - sorry you're experiencing issues here!

I believe this is because we aren't specifying the valid error types in https://github.com/stripe/stripe-php/blob/19218fbe/lib/Util/ObjectTypes.php#L12, and therefore these objects don't get transformed from a plain Stripe\StripeObject to a Stripe\ErrorObject.

@dcr-stripe
Copy link
Contributor

dcr-stripe commented Aug 25, 2022

Following up here - I submitted #1361 to actually fix the type hints to reflect reality. This will go out with the next release.

The team will investigate handling these fields more consistently across all SDKs to provide a better user experience.

Thanks for the patience!

@kissifrot
Copy link

Hello, a side effect of this change is we cannot use code such as $paymentIntent->last_payment_error->message anymore as static analysis tools such as phpstan will complain about missing message not being part of the class anymore.
However API docs sill mention those fields.

What is the workaround for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants