Skip to content

fix(stripe): handle Basil invoice subscription references - #1838

Merged
superdav42 merged 2 commits into
mainfrom
fix/stripe-invoice-subscription
Sep 9, 2026
Merged

fix(stripe): handle Basil invoice subscription references#1838
superdav42 merged 2 commits into
mainfrom
fix/stripe-invoice-subscription

Conversation

@superdav42

@superdav42 superdav42 commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

Handle the Stripe Basil invoice subscription reference and explicitly pin outgoing Stripe requests and newly created webhook endpoints to 2025-08-27.basil.

Basil places the invoice subscription reference under parent.subscription_details.subscription; looking only at the legacy top-level field can leave an existing membership payment pending after settlement. The pin makes the integration's chosen version independent of future Stripe SDK defaults. It matches the default in the currently bundled SDK; this is not an intentional API upgrade.

Changes and review scope

  • inc/gateways/class-base-stripe-gateway.php: resolve legacy or nested invoice subscription references, normalize expanded objects to their ID, and retrieve subscriptions only for nonempty string IDs.
  • Add one private STRIPE_API_VERSION constant (2025-08-27.basil), used as the client's stripe_version and the webhook api_version in both OAuth and direct-key creation paths.
  • Existing webhook endpoints keep their configured API version. Re-enabling a disabled endpoint still changes only its status. No endpoint replacement or account-wide version change.
  • tests/WP_Ultimo/Gateways/Stripe_Webhook_Process_Test.php: existing five-case invoice-reference regression, covering legacy/Basil IDs and expanded objects plus absent reference.
  • tests/WP_Ultimo/Gateways/Stripe_API_Version_Test.php: direct/OAuth client configuration for both Stripe gateways, both new-endpoint creation paths, and preservation of existing enabled/disabled endpoints.
  • No credential, gateway-setting, public-routing, SDK-dependency, or release-metadata changes.

Verification

For added pin commit a20cb1ce:

  • Configured PHPCS passed for both files changed by that commit.
  • PHPStan on the production gateway passed in the pre-commit hook.
  • vendor/bin/phpunit --no-coverage --filter Stripe_API_Version_Test passed: 10 tests / 14 assertions. No real Stripe requests are made by these tests.
  • git diff --check passed.
  • A combined run and a later invoice-only rerun encountered an existing customer fixture setup failure at Stripe_Webhook_Process_Test.php:66 (wu_create_customer() returned WP_Error, assigned to a typed Customer property). Those reruns did not establish invoice-test success. The initial PR's isolated fixture run was reported as 5 tests / 25 assertions; it is separate evidence, not a claim that the latest combined local run passed.

Reproduction commands with the WordPress multisite test environment configured:

vendor/bin/phpcs inc/gateways/class-base-stripe-gateway.php tests/WP_Ultimo/Gateways/Stripe_API_Version_Test.php tests/WP_Ultimo/Gateways/Stripe_Webhook_Process_Test.php
vendor/bin/phpunit --no-coverage --filter Stripe_API_Version_Test
vendor/bin/phpunit --no-coverage --filter test_invoice_payment_completes_active_membership

No live charge, remote endpoint migration, release, or production deployment is part of this PR. Public webhook delivery and complete payment-provider sandbox flows remain separate integration checks. Existing installations may continue delivering older event shapes, so retain backward-compatible parsing.


aidevops.sh v3.32.317 plugin for OpenCode v1.18.30 with gpt-6-astra spent 7h 53m and 603,926 tokens on this with the user in an interactive session.

Summary by CodeRabbit

  • Bug Fixes

    • Improved Stripe webhook processing for the latest API payload format while retaining support for legacy invoice data.
    • Correctly handles expanded subscription details and invoices without subscription references.
    • Ensures linked invoice payments complete successfully while unlinked invoices remain pending.
  • Improvements

    • Stripe clients and newly created webhooks now use a consistent pinned API version.
    • Existing webhooks are preserved, while disabled webhooks can be re-enabled without unnecessary recreation.

@superdav42 superdav42 added the origin:interactive Created by interactive user session label Sep 9, 2026
@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 8846c9cb-4fe3-4d15-a986-1a48b4866578

📥 Commits

Reviewing files that changed from the base of the PR and between 0e431d4 and a20cb1c.

📒 Files selected for processing (3)
  • inc/gateways/class-base-stripe-gateway.php
  • tests/WP_Ultimo/Gateways/Stripe_API_Version_Test.php
  • tests/WP_Ultimo/Gateways/Stripe_Webhook_Process_Test.php

Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The Stripe gateway now pins API requests and webhook endpoints to 2025-08-27.basil. Webhook processing supports legacy and Basil subscription references, including expanded subscription objects. Tests cover direct, OAuth, lifecycle, and payment-processing paths.

Changes

Stripe gateway updates

Layer / File(s) Summary
Pin Stripe API version
inc/gateways/class-base-stripe-gateway.php, tests/WP_Ultimo/Gateways/Stripe_API_Version_Test.php
The gateway pins Stripe clients and webhook endpoint creation to 2025-08-27.basil. Tests cover direct and OAuth clients, endpoint creation, reuse, and re-enabling.
Resolve webhook subscriptions
inc/gateways/class-base-stripe-gateway.php, tests/WP_Ultimo/Gateways/Stripe_Webhook_Process_Test.php
Webhook processing resolves legacy and Basil subscription references, including expanded objects. Tests verify linked payments complete and unlinked payments remain pending.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to a20cb

Stripe requests and newly created webhook endpoints now use the Basil API version, while invoice webhooks support both legacy and Basil subscription references. Existing endpoint settings are preserved, and no actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: updating Stripe handling for Basil invoice subscription references.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/stripe-invoice-subscription

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@superdav42
superdav42 marked this pull request as ready for review September 9, 2026 22:13
@superdav42
superdav42 merged commit a7911bc into main Sep 9, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

origin:interactive Created by interactive user session

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant