Skip to content

739 — Upgrade stripe-php 9.9 → ^22.1 and pin the Stripe API version explicitly ​

Objective ​

stripe/stripe-php is locked at v9.9.0 (2022), which sends no Stripe-Version header, so every shop silently runs on its own Stripe account's default API version. Move to ^22.1 — the first line whose CI tests PHP 8.5 (epic #971) — and set one explicit API version at every SDK entry point, fixing the two places the newer API breaks or exposes (payment_method_types, no_payment_required). Live Stripe test-account checks happen later, when a client provides test keys.

Acceptance criteria ​

Copied verbatim from issue #739 — first the body's criteria, then the "Amended at triage" changes (owner decisions, 2026-11-10), which supersede the body where they conflict.

Body criteria (verbatim) ​

  • Prerequisite, and it gates every criterion below: the Stripe account's current default API version has been read from the Stripe Dashboard (Workbench, API versions) and recorded in a comment on this issue. It cannot be derived from the repository, and it determines whether the pin step is a no-op or a migration.
  • composer.json declares "stripe/stripe-php": "^21.0", and composer show stripe/stripe-php reports an installed 21.x version.
  • composer why-not stripe/stripe-php 21.3.1 returns no blocking line attributable to our own constraint.
  • All four SDK entry points pass an explicit API version equal to the value recorded above: src/Stripe/Checkout/StripeCheckout.php:147 and :285 via the StripeClient config key stripe_version, and src/Domains/Checkout/Payment/Adapters/StripeAdapter.php:31 plus src/Rest/Checkout/Controllers/Checkout.php:1489 via Stripe::setApiVersion(). Verify by grepping for stripe_version and setApiVersion and confirming four hits, none of them a hardcoded dahlia value at this stage.
  • vendor/bin/phpunit is green on all four suites (Unit, Integration, Database, Legacy), compared against the same run on develop before the bump. Regenerate autoload_classmap.php and delete cache/container.php first, or phantom failures will be misread as real.
  • composer check-container exits 0 — a green Unit suite is not proof the DI container compiles.
  • vendor/bin/phpcs shows no new sniff or message on each changed file versus git show develop:<file> for that same file. The baseline is not green, so only a delta counts.
  • Unit coverage exists for at least one SDK-touching path. There is none today: every stripe hit under tests/ is currently a bare string or a comment.
  • On a test Stripe account, each of these completes end to end and reaches a PAID order: a normal card checkout through the legacy storefront; a REST-placed order via POST /rest/checkout/place-order with payway stripe; and one run each with ENABLE_PRODUCT_PRICES_API on and off, and ENABLE_CUSTOMERS_API on and off (the four STRIPE keys at ecommercen/eshop/libraries/AdvPaymentsRegistry.php:644-654).
  • A changelog fragment is added, and an entry appended to rest_api_versions.php if any REST-observable behaviour changes. If nothing observable changes, the PR says so explicitly instead.

Amended at triage (verbatim) ​

Acceptance criteria — changes from the owner decisions above (all other criteria in the body stand)

  • The "prerequisite" criterion (read the account default from the Dashboard) is dropped: the version is fixed by decision 2.
  • composer.json declares "stripe/stripe-php": "^22.1"; composer show stripe/stripe-php reports 22.x; composer why-not stripe/stripe-php 22.1.0 returns no blocking line from our own constraint. The lock diff moves only stripe/stripe-php (and the content hash).
  • All four entry points (lines above) pass an explicit API version equal to \Stripe\Util\ApiVersion::CURRENT of the installed SDK — stripe_version in the StripeClient config, Stripe::setApiVersion() next to setApiKey(). No registry key or admin field is added.
  • StripeAdapter no longer sends payment_method_types; the Session it creates is still card-capable under endive (replacement chosen at delivery: allowed_payment_method_types or the account's dynamic payment methods), proven by a unit test on the request params.
  • no_payment_required is handled in both places (legacy switch at Adv_checkout.php:3359 and REST Checkout.php:2090): an order whose Stripe session reports status = complete and payment_status = no_payment_required is treated as paid; unit coverage for both.
  • The end-to-end test-account checkout criterion is moved out of the merge gate (decision 4); unit tests with a mocked Stripe HTTP layer cover each SDK-touching path changed here.
  • Changelog fragment with a Check for overrides / composer note for the 35 forks that pin ^9.5, and an entry in rest_api_versions.php only if a REST response changes (otherwise the PR says so).

Decisions ​

  • Target version — "stripe/stripe-php": "^22.1" (v22.1.0). Why: owner decision; first line CI-tested on PHP 8.5, needs PHP >= 7.4 (we support 8.1 and 8.5). Rejected: ^21.3 (CI only to 8.4; the endive break would come later anyway).
  • One API version, from one place — a small new class Advisable\Stripe\StripeApiVersion (src/Stripe/StripeApiVersion.php) with current(): string returning \Stripe\Util\ApiVersion::CURRENT of the installed SDK (2026-10-28.endive for v22.1.0). All four entry points use it: StripeCheckout.php:147 and :285 switch new StripeClient(<key>) to new StripeClient(['api_key' => <key>, 'stripe_version' => StripeApiVersion::current()]); StripeAdapter.php:32 and Checkout.php:2087 add \Stripe\Stripe::setApiVersion(StripeApiVersion::current()) next to setApiKey(). Why: owner decision (fixed version, no registry override) plus one place to change when the SDK moves. Rejected: a per-installation STRIPE.API_VERSION registry key (owner declined; would also need an Elxis Settings.php port); hard-coding the date string at four sites (drifts from the SDK).
  • Fail loudly on an old SDK (owner decision, 2026-11-10, after the independent PR review) — StripeApiVersion::current() first calls assertSupported(\Stripe\Stripe::VERSION) and throws a RuntimeException ("stripe/stripe-php 22.1.0 or later is required ...") when the installed SDK is older than MINIMUM_SDK_VERSION (22.1.0). Why: stripe-php 9.9.0 also has ApiVersion::CURRENT (2022-08-01), setEnableTelemetry() and the stripe_version option, so a fork that merges this code but keeps ^9.5 would otherwise run silently on API 2022-08-01, where allowed_payment_method_types does not exist (the global no-hidden-fallbacks rule). Rejected: relying on the changelog note alone (11 forks conflict on that composer.json line). The test fake also sets a stale global API version so the static-path pin tests can fail; the StripeClient pin cannot be told apart by a behavioural test while the SDK's own default equals current(), and stays as the explicit pin.
  • payment_method_types → allowed_payment_method_types — StripeAdapter.php:35 replaces 'payment_method_types' => ['card'] with 'allowed_payment_method_types' => ['card'] (after the developer confirms that parameter exists for Checkout\Session::create in v22.1.0 / API 2026-10-28.endive; if it does not, STOP and report). Why: endive removed payment_method_types; this keeps today's card-only behaviour. Rejected: dropping the parameter and relying on the account's dynamic payment methods (would change which methods customers see, per account, untested).
  • no_payment_required = paid — a Stripe session with status = complete and payment_status = no_payment_required is treated exactly like paid: the legacy switch in ecommercen/checkout/controllers/Adv_checkout.php (~3359) gets that case on the paid arm, and Checkout::verifyStripePayment() (src/Rest/Checkout/Controllers/Checkout.php:2090) accepts both. Why: owner decision; a 100%-discount order otherwise falls through with no outcome. Rejected: a separate issue.
  • Implementer — domain-developer for the whole change. Why: almost all of it is in src/ (Stripe wrapper, Domains adapter, REST controller); the legacy part is one switch case in Adv_checkout.php, too small for a second agent. Rejected: splitting legacy/modern across two developers.
  • Lock change kept minimal — composer require stripe/stripe-php:^22.1 --no-update (or edit the line), then composer update stripe/stripe-php (no -W). The composer.lock diff may move only stripe/stripe-php and the content hash. Why: reviewable dependency PR. Rejected: a full update.
  • Tests — unit tests with the SDK's injectable HTTP client (a fake \Stripe\HttpClient\ClientInterface via ApiRequestor::setHttpClient, or the StripeClient http_client option — whichever v22.1.0 supports) for each changed path: the Stripe-Version header equals StripeApiVersion::current() at all four entry points; StripeAdapter sends allowed_payment_method_types and not payment_method_types; verifyStripePayment() true for paid and no_payment_required, false otherwise; the legacy no_payment_required arm. Tests restore any global SDK state they set (Stripe::$apiKey, $apiVersion, the HTTP client).
  • SDK side effects to check, not assume — the issue body names two v20+/v21 behaviours: telemetry, and trigger_error(E_USER_WARNING) on a Stripe notice header (v22.0.0 adds STRIPE_SUPPRESS_NOTICES). The developer reads the v22.1.0 source and reports what each does; if the SDK writes any file outside the app (e.g. under $HOME/%APPDATA%), disable that at the same four sites. Notice warnings stay on (they reach the existing error logging). Why: the body's description dates from v21 and is unverified.
  • REST changelog — the docs agent adds a rest_api_versions.php entry only if a REST response or contract changes (accepting no_payment_required in verification changes an outcome for such orders, so it decides and says so). Why: repo convention.

Contracts ​

  • New Advisable\Stripe\StripeApiVersion::current(): string — the one source of the pinned Stripe API version.
  • Checkout::verifyStripePayment() (REST) — now also returns true for payment_status = no_payment_required (with status = complete).
  • Every Stripe API request from our code carries Stripe-Version: <StripeApiVersion::current()> (today: none).
  • No existing public/protected method signature changes; no registry key, config key or DB change. Amended 2026-11-10 (owner, after review): two additive test seams are accepted — Adv_checkout::stripeResponseSuccess() widened from private to protected (its sibling stripeResponseFail() already is) and a new protected Checkout::stripeSecretKey() in the REST controller; no fork declares either name (all fork checkouts checked), and the changelog fragment carries the Check for overrides note.

Out of scope ​

  • Running the Database test suite locally for this change — waived by the owner (2026-11-10): the change touches no database code; the fast suite (all suites except the database group) gave identical failing names before and after, and the Bitbucket pipeline runs the fast suite on PHP 8.1 and 8.5, with the full suite nightly on develop.
  • The live end-to-end checkouts on a Stripe test account — later, when a client provides test keys (owner decision 4).
  • A Stripe webhook handler — #723 (it must match this pin when it lands).
  • application/libraries/merchant/Merchant_stripe.php (raw cURL, loaded by nothing).
  • A per-installation API-version setting (owner declined).
  • Porting the 35 forks' own composer.json pins — they get the changelog note.

Open questions carried ​

  • None blocking. The two SDK side effects (telemetry, notice warnings) are verified by the developer, with the rule above.

Last updated: