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:
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.
{
"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
}
Description
I am encountering an issue in my Spring Boot application while handling Stripe webhooks for payment processing. Specifically, the
invoice.createdevent fails with the following error: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_idinstead ofcompany_idfrom themetadatafield). These problems make the webhook integration unreliable.Steps to Reproduce
Observed Behavior
invoice.createdevent processing fails with aNullPointerExceptionbecauseInvoice.getDueDate()returnsnull.customer.subscription.createdalso exhibit inconsistent data handling:company_idfrom themetadatais not saved.planNamefield is missing.Expected Behavior
invoice.createdevent should process successfully without errors.Environment
Additional Details
Event
Note
in event request
company_idpassed the correct value. but the webhook controller saved the customer id insted of compay id. check:Controller > payment > StripeWebhookController > handleCheckoutSessionCompleted