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

Payment to manual invoice causes webhook error #317

Open
mikejpeters opened this issue Jan 15, 2025 · 1 comment
Open

Payment to manual invoice causes webhook error #317

mikejpeters opened this issue Jan 15, 2025 · 1 comment

Comments

@mikejpeters
Copy link

mikejpeters commented Jan 15, 2025

Description

If an invoice is created manually using Stripe dashboard and a customer pays that invoice, the invoice.payment_succeeded event is sent with a null subscription, e.g.:

{
  "object": {
    "id": "in_123abc",
    "object": "invoice",
    "billing_reason": "manual",
    "paid": true,
    "subscription": null
  }
}

In this case, this plugin attempts to find a subscription using a null reference, which errors with Stripe\Exception\InvalidArgumentException The resource ID cannot be null or whitespace.

$subscriptionReference = $stripeInvoice['subscription'];
$counter = 0;
$limit = 5;
do {
// Handle cases when Stripe sends us a webhook so soon that we haven't processed the subscription that triggered the webhook
sleep(1);
$subscription = Subscription::find()->status(null)->reference($subscriptionReference)->one();

I think it should ignore the event when the subscription property is null, because it's not applicable to Craft CMS.

(I think the existing behavior doesn't cause any serious problems in Craft, but having errors thrown for improperly handled situations makes it more difficult to determine when there are important errors that require more urgent attention.)

Steps to reproduce

  1. Manually invoice (using Stripe Dashboard) and pay

Additional info

  • Craft CMS version: 4.13.9
  • Stripe for Craft Commerce version: 4.1.5.1
  • PHP version: 8.0.30
  • Database driver & version:
  • Plugins & versions:
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

1 participant