-
Notifications
You must be signed in to change notification settings - Fork 49
Description
Description
I am getting an error when trying to finalize a subscription through Stripe. It shows the error Unable to start the subscription. Undefined array key "current_period_end", which looks like it is coming from the vendor/craftcms/commerce-stripe/src/responses/SubscriptionResponse.php on line 75 of the file. It seems like Stripe isn't responding back with the correct schema based on the API version being set by the plugin. I have verified that my webhook version is using the the same API version 2022-11-15. I am also seeing other errors like when clicking on the subscription (admin/commerce/subscriptions/115678) in the control panel to see the detail and I get an error of Undefined array key "payment_intent". This might be a related issue but I am not sure.
Steps to reproduce
- Using the demo templates from Craft Commerce, input credit card and attempt to finalize subscription
- Error message showing and no subscription starts in Craft but it does in Stripe.
Additional info
- Craft CMS version: 4.16.8
- Stripe for Craft Commerce version: 4.1.8
- PHP version: 8.1.2
- Database driver & version: MySQL
- Plugins & versions: Craft Commerce version: 4.9.1
Webhook response:
{
"id": "evt_1RpxVbFRlWuxexVIpASG2ooc",
"object": "event",
"api_version": "2022-11-15",
"created": 1753733934,
"data": {
"object": {
"id": "sub_1RpxVYFRlWuxexVIvNAZMHiq",
"object": "subscription",
"application": null,
"application_fee_percent": null,
"automatic_tax": {
"disabled_reason": null,
"enabled": false,
"liability": null
},
"billing_cycle_anchor": 1753733932,
"billing_cycle_anchor_config": null,
"billing_mode": {
"type": "classic"
},
"billing_thresholds": null,
"cancel_at": null,
"cancel_at_period_end": false,
"canceled_at": null,
"cancellation_details": {
"comment": null,
"feedback": null,
"reason": null
},
"collection_method": "charge_automatically",
"created": 1753733932,
"currency": "usd",
"customer": "cus_SkGSJBZqNwq1Ld",
"days_until_due": null,
"default_payment_method": null,
"default_source": null,
"default_tax_rates": [],
"description": null,
"discounts": [],
"ended_at": null,
"invoice_settings": {
"account_tax_ids": null,
"issuer": {
"type": "self"
}
},
"items": {
"object": "list",
"data": [
{
"id": "si_SlUUSzjrMj057a",
"object": "subscription_item",
"billing_thresholds": null,
"created": 1753733933,
"current_period_end": 1785269932,
"current_period_start": 1753733932,
"discounts": [],
"metadata": {},
"plan": {
"id": "price_1RoFpnFRlWuxexVIxDnxudsE",
"object": "plan",
"active": true,
"amount": 7500,
"amount_decimal": "7500",
"billing_scheme": "per_unit",
"created": 1753327723,
"currency": "usd",
"interval": "year",
"interval_count": 1,
"livemode": false,
"metadata": {},
"meter": null,
"nickname": "professional-member",
"product": "prod_SjjIKJIlExCs1q",
"tiers_mode": null,
"transform_usage": null,
"trial_period_days": null,
"usage_type": "licensed",
"aggregate_usage": null
},
"price": {
"id": "price_1RoFpnFRlWuxexVIxDnxudsE",
"object": "price",
"active": true,
"billing_scheme": "per_unit",
"created": 1753327723,
"currency": "usd",
"custom_unit_amount": null,
"livemode": false,
"lookup_key": null,
"metadata": {},
"nickname": "professional-member",
"product": "prod_SjjIKJIlExCs1q",
"recurring": {
"interval": "year",
"interval_count": 1,
"meter": null,
"trial_period_days": null,
"usage_type": "licensed",
"aggregate_usage": null
},
"tax_behavior": "unspecified",
"tiers_mode": null,
"transform_quantity": null,
"type": "recurring",
"unit_amount": 7500,
"unit_amount_decimal": "7500"
},
"quantity": 1,
"subscription": "sub_1RpxVYFRlWuxexVIvNAZMHiq",
"tax_rates": []
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/subscription_items?subscription=sub_1RpxVYFRlWuxexVIvNAZMHiq"
},
"latest_invoice": "in_1RpxVYFRlWuxexVIVYUtsTQN",
"livemode": false,
"metadata": {},
"next_pending_invoice_item_invoice": null,
"on_behalf_of": null,
"pause_collection": null,
"payment_settings": {
"payment_method_options": null,
"payment_method_types": null,
"save_default_payment_method": "off"
},
"pending_invoice_item_interval": null,
"pending_setup_intent": null,
"pending_update": null,
"plan": {
"id": "price_1RoFpnFRlWuxexVIxDnxudsE",
"object": "plan",
"active": true,
"amount": 7500,
"amount_decimal": "7500",
"billing_scheme": "per_unit",
"created": 1753327723,
"currency": "usd",
"interval": "year",
"interval_count": 1,
"livemode": false,
"metadata": {},
"meter": null,
"nickname": "professional-member",
"product": "prod_SjjIKJIlExCs1q",
"tiers_mode": null,
"transform_usage": null,
"trial_period_days": null,
"usage_type": "licensed",
"aggregate_usage": null
},
"quantity": 1,
"schedule": null,
"start_date": 1753733932,
"status": "active",
"test_clock": null,
"transfer_data": null,
"trial_end": null,
"trial_settings": {
"end_behavior": {
"missing_payment_method": "create_invoice"
}
},
"trial_start": null,
"current_period_end": 1785269932,
"current_period_start": 1753733932,
"discount": null
}
},
"livemode": false,
"pending_webhooks": 2,
"request": {
"id": "req_q1e4OyiQoP6auR",
"idempotency_key": "ea451085-b36a-4258-a649-e4b76db817d7"
},
"type": "customer.subscription.created"
}
Example of Request POST body
{
"customer": "cus_SlVMl9tqqtKmDz",
"expand": {
"0": "latest_invoice.payment_intent"
},
"items": {
"0": {
"plan": "price_1RoFpnFRlWuxexVIxDnxudsE"
}
},
"trial_period_days": "0"
}
Example of Response Body
{
"id": "sub_1RpyMWFRlWuxexVIF6kQNNq3",
"object": "subscription",
"application": null,
"application_fee_percent": null,
"automatic_tax": {
"disabled_reason": null,
"enabled": false,
"liability": null
},
"billing_cycle_anchor": 1753737216,
"billing_cycle_anchor_config": null,
"billing_mode": {
"type": "classic"
},
"billing_thresholds": null,
"cancel_at": null,
"cancel_at_period_end": false,
"canceled_at": null,
"cancellation_details": {
"comment": null,
"feedback": null,
"reason": null
},
"collection_method": "charge_automatically",
"created": 1753737216,
"currency": "usd",
"customer": "cus_SlVMl9tqqtKmDz",
"days_until_due": null,
"default_payment_method": null,
"default_source": null,
"default_tax_rates": [],
"description": null,
"discounts": [],
"ended_at": null,
"invoice_settings": {
"account_tax_ids": null,
"issuer": {
"type": "self"
}
},
"items": {
"object": "list",
"data": [
{
"id": "si_SlVNL5PYcrBrf9",
"object": "subscription_item",
"billing_thresholds": null,
"created": 1753737216,
"current_period_end": 1785273216,
"current_period_start": 1753737216,
"discounts": [],
"metadata": {},
"plan": {
"id": "price_1RoFpnFRlWuxexVIxDnxudsE",
"object": "plan",
"active": true,
"amount": 7500,
"amount_decimal": "7500",
"billing_scheme": "per_unit",
"created": 1753327723,
"currency": "usd",
"interval": "year",
"interval_count": 1,
"livemode": false,
"metadata": {},
"meter": null,
"nickname": "professional-member",
"product": "prod_SjjIKJIlExCs1q",
"tiers_mode": null,
"transform_usage": null,
"trial_period_days": null,
"usage_type": "licensed"
},
"price": {
"id": "price_1RoFpnFRlWuxexVIxDnxudsE",
"object": "price",
"active": true,
"billing_scheme": "per_unit",
"created": 1753327723,
"currency": "usd",
"custom_unit_amount": null,
"livemode": false,
"lookup_key": null,
"metadata": {},
"nickname": "professional-member",
"product": "prod_SjjIKJIlExCs1q",
"recurring": {
"interval": "year",
"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": 7500,
"unit_amount_decimal": "7500"
},
"quantity": 1,
"subscription": "sub_1RpyMWFRlWuxexVIF6kQNNq3",
"tax_rates": []
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/subscription_items?subscription=sub_1RpyMWFRlWuxexVIF6kQNNq3"
},
"latest_invoice": {
"id": "in_1RpyMWFRlWuxexVIX5DtvjNU",
"object": "invoice",
"account_country": "US",
"account_name": "SHOF Sandbox",
"account_tax_ids": null,
"amount_due": 7500,
"amount_overpaid": 0,
"amount_paid": 7500,
"amount_remaining": 0,
"amount_shipping": 0,
"application": null,
"attempt_count": 1,
"attempted": true,
"auto_advance": false,
"automatic_tax": {
"disabled_reason": null,
"enabled": false,
"liability": null,
"provider": null,
"status": null
},
"automatically_finalizes_at": null,
"billing_reason": "subscription_create",
"collection_method": "charge_automatically",
"created": 1753737216,
"currency": "usd",
"custom_fields": null,
"customer": "cus_SlVMl9tqqtKmDz",
"customer_address": null,
"customer_email": "[email protected]",
"customer_name": "Ross Kenney",
"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,
"discounts": [],
"due_date": null,
"effective_at": 1753737216,
"ending_balance": 0,
"footer": null,
"from_invoice": null,
"hosted_invoice_url": "REDACTED",
"invoice_pdf": "REDACTED",
"issuer": {
"type": "self"
},
"last_finalization_error": null,
"latest_revision": null,
"lines": {
"object": "list",
"data": [
{
"id": "il_1RpyMWFRlWuxexVIM1Dad8Gr",
"object": "line_item",
"amount": 7500,
"currency": "usd",
"description": "1 × Professional (at $75.00 / year)",
"discount_amounts": [],
"discountable": true,
"discounts": [],
"invoice": "in_1RpyMWFRlWuxexVIX5DtvjNU",
"livemode": false,
"metadata": {},
"parent": {
"invoice_item_details": null,
"subscription_item_details": {
"invoice_item": null,
"proration": false,
"proration_details": {
"credited_items": null
},
"subscription": "sub_1RpyMWFRlWuxexVIF6kQNNq3",
"subscription_item": "si_SlVNL5PYcrBrf9"
},
"type": "subscription_item_details"
},
"period": {
"end": 1785273216,
"start": 1753737216
},
"pretax_credit_amounts": [],
"pricing": {
"price_details": {
"price": "price_1RoFpnFRlWuxexVIxDnxudsE",
"product": "prod_SjjIKJIlExCs1q"
},
"type": "price_details",
"unit_amount_decimal": "7500"
},
"quantity": 1,
"taxes": []
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/invoices/in_1RpyMWFRlWuxexVIX5DtvjNU/lines"
},
"livemode": false,
"metadata": {},
"next_payment_attempt": null,
"number": "IZE5YUEP-0001",
"on_behalf_of": null,
"parent": {
"quote_details": null,
"subscription_details": {
"metadata": {},
"subscription": "sub_1RpyMWFRlWuxexVIF6kQNNq3"
},
"type": "subscription_details"
},
"payment_settings": {
"default_mandate": null,
"payment_method_options": null,
"payment_method_types": null
},
"period_end": 1753737216,
"period_start": 1753737216,
"post_payment_credit_notes_amount": 0,
"pre_payment_credit_notes_amount": 0,
"receipt_number": null,
"rendering": null,
"shipping_cost": null,
"shipping_details": null,
"starting_balance": 0,
"statement_descriptor": null,
"status": "paid",
"status_transitions": {
"finalized_at": 1753737216,
"marked_uncollectible_at": null,
"paid_at": 1753737216,
"voided_at": null
},
"subtotal": 7500,
"subtotal_excluding_tax": 7500,
"test_clock": null,
"total": 7500,
"total_discount_amounts": [],
"total_excluding_tax": 7500,
"total_pretax_credit_amounts": [],
"total_taxes": [],
"webhooks_delivered_at": null
},
"livemode": false,
"metadata": {},
"next_pending_invoice_item_invoice": null,
"on_behalf_of": null,
"pause_collection": null,
"payment_settings": {
"payment_method_options": null,
"payment_method_types": null,
"save_default_payment_method": "off"
},
"pending_invoice_item_interval": null,
"pending_setup_intent": null,
"pending_update": null,
"plan": {
"id": "price_1RoFpnFRlWuxexVIxDnxudsE",
"object": "plan",
"active": true,
"amount": 7500,
"amount_decimal": "7500",
"billing_scheme": "per_unit",
"created": 1753327723,
"currency": "usd",
"interval": "year",
"interval_count": 1,
"livemode": false,
"metadata": {},
"meter": null,
"nickname": "professional-member",
"product": "prod_SjjIKJIlExCs1q",
"tiers_mode": null,
"transform_usage": null,
"trial_period_days": null,
"usage_type": "licensed"
},
"quantity": 1,
"schedule": null,
"start_date": 1753737216,
"status": "active",
"test_clock": null,
"transfer_data": null,
"trial_end": null,
"trial_settings": {
"end_behavior": {
"missing_payment_method": "create_invoice"
}
},
"trial_start": null
}