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

yii\base\ErrorException: Undefined array key "billing" #294

Closed
Saboteur777 opened this issue Mar 25, 2024 · 5 comments
Closed

yii\base\ErrorException: Undefined array key "billing" #294

Saboteur777 opened this issue Mar 25, 2024 · 5 comments

Comments

@Saboteur777
Copy link

Description

When a Stripe webhook is sent, I get this error message.

Steps to reproduce

  1. Set up Stripe payment gateway as usual.
  2. Enable these events for the webhook:
payment_method.updated
payment_method.automatically_updated
payment_method.detached
plan.updated
plan.deleted
customer.subscription.updated
customer.subscription.deleted
invoice.payment_succeeded
invoice.payment_failed
invoice.created
  1. Check the logs after an invoice has been created.

Additional info

  • Craft CMS version: Craft Pro 3.9.12
  • Stripe for Craft Commerce version: 2.4.4.1 *
  • PHP version: 8.1.27
  • Database driver & version: MariaDB 11.3.2
  • Stripe API version: 2020-08-27
  • This part of the code is unchanged, should still be present in current versions.
Copy link

linear bot commented Mar 25, 2024

Saboteur777 added a commit to Saboteur777/commerce-stripe that referenced this issue Mar 25, 2024
@nfourtythree
Copy link
Contributor

Hi @Saboteur777

Thank you for bringing this to our attention, we have created a fix for the issue and published the following versions of the Stripe plugin:

  • 5.0.1
  • 4.1.2.2
  • 3.1.2
  • 2.4.5

Thanks!

@Saboteur777
Copy link
Author

Thank you, Nathaniel! It's awesome that you backported it to older versions. 👏

Just out of curiosity: why did you go with

$stripeInvoiceBilling = isset($stripeInvoice['billing']) && $stripeInvoice['billing'] ? $stripeInvoice['billing'] : null;

instead of using the null coalescing operator?

@nfourtythree
Copy link
Contributor

No problem @Saboteur777

As for the code, just for a little bit more verbosity and creates a bit of self-documenting code.

Yes, null coalescing is shorter/tidier but it doesn't really tell the story as to why, as it captures both if the value is null but also if the key doesn't exist.

In the future, it will be more obvious if there is a possibility to remove this code if Stripe is no longer passing the key for example.

Could have certainly gone with either method.

Thanks!

@Saboteur777
Copy link
Author

Thanks for the explanation – it is always interesting to understand how other developers decides which solution to use and why.

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

No branches or pull requests

2 participants