[Bug]: "End now" on a subscription can return 404 although the subscription ended

Open
#4,368 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript, node.js
Domain
api, backend, payments

Research direction

Read portals/api-portal/src/services/subscriptionService.js and portals/api-portal/src/services/billing/paymentEventService.js, then trace the immediate deletion path and the customer.subscription.deleted webhook. Reproduce the timing in the API Portal billing journey against the testbench Stripe mock. Done means an immediate end returns success whether the webhook or request removes the subscription row first.

Written by the indexing model from the issue text.

Description

Area/DeveloperPortal Aspect/API Severity/Minor Type/Bug
Please select the area the issue is related to

DeveloperPortal

Please select the aspect the issue is related to

Aspect/API (API backends, definitions, contracts, interfaces, OpenAPI)

Description

Ending a paid subscription immediately ("End now", DELETE /api/v0.9/subscriptions/{id}?immediate=true) can return 404 "Subscription not found" even though the subscription was ended. The API Portal then shows "Failed to remove subscription: Not Found".

Two paths remove the same subscription row, and whichever runs second finds nothing:

  1. The request. deleteSubscription (portals/api-portal/src/services/subscriptionService.js) ends the subscription with the payment provider (subscriptionBillingService.endInProvider, immediate: true), then removes the row itself in a transaction. If removeSubscription removes nothing, it throws a 404.
  2. The webhook. Cancelling the subscription makes the provider send customer.subscription.deleted. paymentEventService (portals/api-portal/src/services/billing/paymentEventService.js, lines 75–76) reads the ended subscription and removes the same row through subscriptionService.removeSubscription.

When the webhook is processed before the request reaches its own removal, the request answers 404 for a subscription it did end.

Observed (UI suite, API Portal billing journey "a developer pays for a flat rate and a usage based plan, follows them and ends them", run against the testbench Stripe mock): https://github.com/wso2/api-platform/actions/runs/44452694997/job/135322505050

  • DELETE /api-portal/api/v0.9/subscriptions/2eaa99f9-… (cancel at period end): 200 {"message":"Your subscription has been cancelled. You will retain access until Dec 19, 2026.","endsAt":"2026-12-19T04:02:49.000Z"}
  • DELETE /api-portal/api/v0.9/subscriptions/2eaa99f9-…?immediate=true ("End now"), 2 seconds later: 404 {"status":"error","code":"RESOURCE_NOT_FOUND","message":"Not Found","errors":[{"message":"Subscription not found"}]}
  • The page shows "Failed to remove subscription: Not Found" where the journey expects "Subscription removed successfully!".

The body rules out a provider-side failure: an error from endInProvider (SubscriptionBillingError) is returned with its own code and no errors list. The 404 comes from the row being gone.

Expected

Ending a subscription immediately returns success once the subscription has ended, whichever path removes its row.

Steps to Reproduce
  1. In the API Portal, subscribe to an API on a flat-rate plan through checkout.
  2. On the subscription's page, choose to unsubscribe (cancel at period end).
  3. Choose "End now" and confirm.
  4. Intermittently, the request returns 404 and the page shows "Failed to remove subscription: Not Found", although the subscription is gone. In CI it depends on whether the provider's customer.subscription.deleted webhook is processed before the request removes the row.
Severity Level of the Issue

Severity/Minor (Minor functionality is broken. Doesn't need immediate attention)

Environment Details (with versions)

Current main. API Portal built from source and run by the UI suite (tests/framework, block api-portal-billing) against the testbench Stripe mock, in GitHub Actions.

Dominant language
Go
Stars
85
Forks
137
Avg merge
1d 12h
Merged PRs (30d)
247

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from wso2/api-platform

All issues in wso2/api-platform

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.