Skip to content

Issue with Webhook Handling: invoice.created Event Fails Due to Null dueDate #4

@kavicastelo

Description

@kavicastelo

Description

I am encountering an issue in my Spring Boot application while handling Stripe webhooks for payment processing. Specifically, the invoice.created event fails with the following error:

Webhook error: Cannot invoke "java.lang.Long.longValue()" because the return value of "com.stripe.model.Invoice.getDueDate()" is null

This occurs even though the event payload from Stripe contains valid data. Additionally, other events, like customer.subscription.created, sometimes save incorrect data (e.g., customer_id instead of company_id from the metadata field). These problems make the webhook integration unreliable.

Steps to Reproduce

  • follow the step by step guide provided from README

Observed Behavior

  • The invoice.created event processing fails with a NullPointerException because Invoice.getDueDate() returns null.
  • Other events like customer.subscription.created also exhibit inconsistent data handling:
    • The company_id from the metadata is not saved.
    • The planName field is missing.

Expected Behavior

  • The invoice.created event should process successfully without errors.
  • All required data fields should be extracted correctly and saved.

Environment

  • Spring Boot Version: 3.3.1
  • Java Version: 17

Additional Details

  • Logs from the application:
    Webhook error: Cannot invoke "java.lang.Long.longValue()" because the return value of "com.stripe.model.Invoice.getDueDate()" is null
    
  • Stripe Dashboard shows that all webhook events are successfully delivered.
  • Backend recieved all events.
    Received event: invoice.created
    Received event: invoice.payment_failed
    Received event: invoice.updated
    Received event: invoice.created
    Received event: checkout.session.completed
    Received event: customer.subscription.updated
    Received event: invoice.payment_succeeded
    Received event: invoice.updated
    

Event

{
  "object": {
    "id": "in_1QcTDzA9kBiWDgfZ8ytFsgjm",
    "object": "invoice",
    "account_country": "FI",
    "account_name": "Talent Boozt",
    "account_tax_ids": null,
    "amount_due": 990,
    "amount_paid": 0,
    "amount_remaining": 990,
    "amount_shipping": 0,
    "application": null,
    "application_fee_amount": null,
    "attempt_count": 0,
    "attempted": false,
    "auto_advance": false,
    "automatic_tax": {
      "disabled_reason": null,
      "enabled": false,
      "liability": null,
      "status": null
    },
    "automatically_finalizes_at": null,
    "billing_reason": "subscription_create",
    "charge": null,
    "collection_method": "charge_automatically",
    "created": 1735742923,
    "currency": "usd",
    "custom_fields": null,
    "customer": "cus_RVUCfVXJqK0On0",
    "customer_address": {
      "city": null,
      "country": "FI",
      "line1": null,
      "line2": null,
      "postal_code": null,
      "state": null
    },
    "customer_email": "email@gmail.com",
    "customer_name": "Customer Name",
    "customer_phone": null,
    "customer_shipping": null,
    "customer_tax_exempt": "none",
    "customer_tax_ids": [],
    "default_payment_method": null,
    "default_source": null,
    "default_tax_rates": [],
    "description": null,
    "discount": null,
    "discounts": [],
    "due_date": null,
    "effective_at": 1735742923,
    "ending_balance": 0,
    "footer": null,
    "from_invoice": null,
    "hosted_invoice_url": "https://invoice.stripe.com/i/acct_1QaJdqA9kBiWDgfZ/live_YWNjdF8xUWFKZHFBOWtCaVdEZ2ZaLF9SVlVDazhhb1hWeXl5eDh2VUdnaWpjWUt5RVZyZkU3LDEyNjI4MzcyNg0200AuNUpbeo?s=ap",
    "invoice_pdf": "https://pay.stripe.com/invoice/acct_1QaJdqA9kBiWDgfZ/live_YWNjdF8xUWFKZHFBOWtCaVdEZ2ZaLF9SVlVDazhhb1hWeXl5eDh2VUdnaWpjWUt5RVZyZkU3LDEyNjI4MzcyNg0200AuNUpbeo/pdf?s=ap",
    "issuer": {
      "type": "self"
    },
    "last_finalization_error": null,
    "latest_revision": null,
    "lines": {
      "object": "list",
      "data": [
        {
          "id": "il_1QcTDzA9kBiWDgfZXYoSQyvL",
          "object": "line_item",
          "amount": 990,
          "amount_excluding_tax": 990,
          "currency": "usd",
          "description": "1 × Talent Boozt Pro (at $9.90 / month)",
          "discount_amounts": [],
          "discountable": true,
          "discounts": [],
          "invoice": "in_1QcTDzA9kBiWDgfZ8ytFsgjm",
          "livemode": true,
          "metadata": {
            "company_id": "673b3a81c3a2b76a3ff6cbd2"
          },
          "period": {
            "end": 1738421323,
            "start": 1735742923
          },
          "plan": {
            "id": "price_1QahtiA9kBiWDgfZlVjhGnJ0",
            "object": "plan",
            "active": true,
            "aggregate_usage": null,
            "amount": 990,
            "amount_decimal": "990",
            "billing_scheme": "per_unit",
            "created": 1735322670,
            "currency": "usd",
            "interval": "month",
            "interval_count": 1,
            "livemode": true,
            "metadata": {},
            "meter": null,
            "nickname": null,
            "product": "prod_RTfEvk2UkyMQ8a",
            "tiers_mode": null,
            "transform_usage": null,
            "trial_period_days": null,
            "usage_type": "licensed"
          },
          "pretax_credit_amounts": [],
          "price": {
            "id": "price_1QahtiA9kBiWDgfZlVjhGnJ0",
            "object": "price",
            "active": true,
            "billing_scheme": "per_unit",
            "created": 1735322670,
            "currency": "usd",
            "custom_unit_amount": null,
            "livemode": true,
            "lookup_key": null,
            "metadata": {},
            "nickname": null,
            "product": "prod_RTfEvk2UkyMQ8a",
            "recurring": {
              "aggregate_usage": null,
              "interval": "month",
              "interval_count": 1,
              "meter": null,
              "trial_period_days": null,
              "usage_type": "licensed"
            },
            "tax_behavior": "unspecified",
            "tiers_mode": null,
            "transform_quantity": null,
            "type": "recurring",
            "unit_amount": 990,
            "unit_amount_decimal": "990"
          },
          "proration": false,
          "proration_details": {
            "credited_items": null
          },
          "quantity": 1,
          "subscription": "sub_1QcTDzA9kBiWDgfZ10X0646g",
          "subscription_item": "si_RVUCrLmywjWCjW",
          "tax_amounts": [],
          "tax_rates": [],
          "type": "subscription",
          "unit_amount_excluding_tax": "990"
        }
      ],
      "has_more": false,
      "total_count": 1,
      "url": "/v1/invoices/in_1QcTDzA9kBiWDgfZ8ytFsgjm/lines"
    },
    "livemode": true,
    "metadata": {},
    "next_payment_attempt": null,
    "number": "18A88461-0001",
    "on_behalf_of": null,
    "paid": false,
    "paid_out_of_band": false,
    "payment_intent": "pi_3QcTE0A9kBiWDgfZ1iNUNvcC",
    "payment_settings": {
      "default_mandate": null,
      "payment_method_options": {
        "acss_debit": null,
        "bancontact": null,
        "card": {
          "request_three_d_secure": "automatic"
        },
        "customer_balance": null,
        "konbini": null,
        "sepa_debit": null,
        "us_bank_account": null
      },
      "payment_method_types": null
    },
    "period_end": 1735742923,
    "period_start": 1735742923,
    "post_payment_credit_notes_amount": 0,
    "pre_payment_credit_notes_amount": 0,
    "quote": null,
    "receipt_number": null,
    "rendering": null,
    "shipping_cost": null,
    "shipping_details": null,
    "starting_balance": 0,
    "statement_descriptor": null,
    "status": "open",
    "status_transitions": {
      "finalized_at": 1735742923,
      "marked_uncollectible_at": null,
      "paid_at": null,
      "voided_at": null
    },
    "subscription": "sub_1QcTDzA9kBiWDgfZ10X0646g",
    "subscription_details": {
      "metadata": {
        "company_id": "673b3a81c3a2b76a3ff6cbd2"
      }
    },
    "subtotal": 990,
    "subtotal_excluding_tax": 990,
    "tax": null,
    "test_clock": null,
    "total": 990,
    "total_discount_amounts": [],
    "total_excluding_tax": 990,
    "total_pretax_credit_amounts": [],
    "total_tax_amounts": [],
    "transfer_data": null,
    "webhooks_delivered_at": null
  },
  "previous_attributes": null
}

Note

in event request company_id passed the correct value. but the webhook controller saved the customer id insted of compay id. check: Controller > payment > StripeWebhookController > handleCheckoutSessionCompleted

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions