caelum0x 1bab00e74b feat(mint): add Google Play direct payments (RTDN + Developer API)
Closes the other half of I31 ("Direct ASSN v2 and Play RTDN in Mint") —
Apple App Store Server Notifications v2 was already built; this adds the
matching direct (no-aggregator) integration for Google Play.

New ProviderId::PlayStore in mint-payments, mirroring the AppStore adapter's
shape but necessarily async: an RTDN notification carries neither a price
nor the Mint account to credit, so a mintable delivery is re-confirmed
against the Play Developer API (OAuth2 service-account JWT, RS256 via the
already-vendored `ring` crate — no new dependency) before it mints.

Key correctness decisions, documented in the module:
- deposit_ref is keyed on the Developer API's own order id, not the purchase
  token (which Play keeps stable across a subscription's own renewals) — a
  renewal mints again instead of idempotently replaying the original
  purchase, covered by a dedicated regression test.
- USD price comes from a static PLAYSTORE_PRICES_JSON catalog: neither the
  v3 ProductPurchase nor SubscriptionPurchaseV2 Developer API resource
  carries a price field.
- voidedPurchaseNotification (Google's refund signal) reverses by its own
  orderId with no second network call; REVOKED/CANCELED on the primary
  notification types are deliberately Ignored in favor of that cleaner,
  orderId-bearing signal.
- the Pub/Sub push auth token travels as a `?token=` query parameter (push
  subscriptions can't attach a custom static header); mint-server's
  deposits.rs bridges it into a synthetic header so mint-payments itself
  stays axum/query-string-free.

18 new unit tests in playstore.rs (the OAuth2 path signs with a real
synthetic RSA test key, not a mocked signer) plus 4 in mint-server's
deposits.rs for the query->header bridge. Full existing suites re-run green
with zero regressions: mint-payments 112+13+6+6+3, mint-server
22+13+14+3+3+6+8. cargo clippy --all-targets: zero warnings in any touched
file.

Also closes the gap in scripts/parity/recount.mjs: new wave-s.mjs moves I31
MISSING -> DONE on real evidence; infra now 30/10/4 (was 29/10/5),
--self-test still exits 0, recount.test.mjs extended with a Wave S test.

Not deployed: PLAYSTORE_SERVICE_ACCOUNT_KEY / CLIENT_EMAIL / PACKAGE_NAME /
WEBHOOK_TOKEN / PRICES_JSON all need a real Google Play Console service
account and a Pub/Sub push subscription, which is an owner-only step.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-21 16:30:40 +03:00

43 lines
1.9 KiB
JavaScript

/**
* Wave S verified row change (Mint Play Store direct integration, 2026-10-21).
*
* Closes I31 ("Direct ASSN v2 and Play RTDN in Mint", RY-MT3). Apple's half
* (App Store Server Notifications v2 + Server API) was already DONE before
* this wave, verified in apps/mint/crates/mint-payments/src/iap/appstore.rs —
* this wave adds the other half, Google Play Real-time Developer
* Notifications + the Play Developer API, as a new direct (no-aggregator)
* provider: apps/mint/crates/mint-payments/src/iap/playstore.rs.
*
* Verified 2026-10-21: `cargo test -p mint-payments -p mint-server` —
* 112 + 13 + 6 + 6 + 3 (mint-payments) and 22 + 13 + 14 + 3 + 3 + 6 + 8
* (mint-server) all green, including 18 new playstore.rs unit tests covering
* token auth, notification-type gating, the Developer API re-confirmation
* path (OAuth2 service-account JWT over a real RSA test key, not mocked),
* the per-charge order-id idempotency (a renewal must mint again, not replay
* the original purchase), account-binding and stale-order-id refusal, and
* the voided-purchase reversal path.
*/
/** @typedef {import('./rows.mjs').Status} Status */
/**
* @typedef {Object} Change
* @property {string} id
* @property {Status} status
* @property {string} evidence repo path of the code that proves the row
* @property {string} pkg the wave/date tag
* @property {string} [note]
*/
/** @type {readonly Change[]} */
export const WAVE_S = Object.freeze([
{
id: 'I31',
status: 'DONE',
pkg: '2026-10-21',
evidence: 'apps/mint/crates/mint-payments/src/iap/playstore.rs',
note:
'Apple ASSN v2 + Server API direct (appstore.rs) was already DONE; this wave adds Google Play RTDN + Developer API direct (playstore.rs) — 18 new unit tests, 0 regressions across mint-payments/mint-server. Not yet deployed to railyard-box (code-only; needs a real Play service account + PLAYSTORE_* secrets, an owner step).',
},
]);