# eSIM payment QA and evidence

## Local checks

Single-switch verification (2026-11-23): 139 common service tests passed (594
assertions), including the local HTTP gateway contract without a numeric Stripe
method ID, old Razorpay API with Stripe off/on, saved-provider retries in both
switch directions, and an uncertain Stripe creation with no Razorpay fallback.
The focused gateway suite passed 58 tests; 9 dedicated-MySQL storage tests were
skipped (67 discovered, 729 assertions). These checks used fixtures/mocks, not
production databases or real provider/payment calls. Postman simulation was not
available: the installed executable is the desktop app and fails to start as a CLI.

Common suite (no live DB, provider purchase or email):

```sh
ESIM_CONTRACT_GATEWAY_DIR=/path/to/payment-gateway-components \
SYMFONY_DEPRECATIONS_HELPER=disabled php8.1 \
  /path/to/payment-gateway-components/vendor/bin/phpunit \
  --no-configuration --do-not-cache-result --bootstrap vendor/autoload.php \
  src/AppBundle/Tests/Services
```

ESIM_CONTRACT_GATEWAY_DIR enables an isolated localhost Laravel fixture process.
The actual Symfony cURL client reaches actual gateway auth/routes/services; only
Stripe and storage/credential lookup are fixtures. It exercises native initiate/
status, encrypted hosted Checkout, and invalid signatures. Fixture code is gated
to PHP cli-server plus ESIM_CONTRACT_FIXTURE=1 and is never a public route. Production
still requires verified HTTPS; only the test client redirects to localhost HTTP.

Gateway focused suite:

```sh
APPLE_PAY_TEST_MYSQL_DATABASE= DB_CONNECTION=sqlite DB_DATABASE=:memory: \
php8.1 vendor/bin/phpunit --do-not-cache-result \
  --filter 'EsimCheckoutCompatibilityTest|StripeApplePayTest|StripeCheckoutBrandingTest|StripeApplePayStorageTest'
```

The SQLite name prevents accidental default DB use; these tests mock database
access and do not need the SQLite extension. Storage tests SKIP until explicit
APPLE_PAY_TEST_MYSQL_* test credentials are supplied. Use dedicated test credentials,
not parameters.yml or production .env credentials. Session-only temporary MySQL
tables exercise store reuse, rollback, event markers and web/native isolation;
they do not establish cross-connection locking under load.

Postman simulation was unavailable locally: `postman` resolved to the desktop
application and failed with `bad option: --no-sandbox`. The executable cross-repo
HTTP test above is the retained contract evidence, not a claimed Postman run.

## Staging acceptance matrix

| Check | Required result |
| --- | --- |
| Old eSIM app + Stripe switch off/on | Old link API remains Razorpay, same transport/envelope/amount behaviour |
| New API + Stripe switch 0/missing | Razorpay link through the shared legacy eSIM transport; no Stripe configuration required |
| Other application DB | Its own missing/0 Stripe switch keeps Razorpay; existing authentication/project credentials remain enforced |
| Retired router/mode/user/currency/method settings | Not read, not inserted by the new SQL |
| Existing Stripe URL settings | API prefix has no duplicate /api; existing success/failure URLs are passed unchanged |
| Stripe on + Android / missing wallet / web | Hosted Stripe Checkout, not an unexpected Razorpay route |
| Stripe on + invalid signing secret / return URL | Error before new transaction creation; no automatic Razorpay charge |
| Unsupported currency | Rejected without charging or silently changing currency |
| Switch changed after saved Stripe or Razorpay attempt | Same request_id retains original provider; never a second-provider checkout |
| Web USD and coupon (1.00 minus 10%) | Hosted Checkout charges 90 cents |
| Web refresh, double tap, network timeout | Same Checkout, no second payable session |
| Native Apple Pay on physical iPhone | Native sheet, correct merchant/amount, no Checkout page |
| Native decline/cancel/processing | No provisioning; state remains correct/retryable |
| Repeated native initiation | Same token and PaymentIntent |
| Wrong HMAC/expired timestamp/wrong project | Rejected, no Stripe/storage side effects |
| Wrong amount/currency/quote/plan/mode/reference | Rejected, no provisioning |
| Native non-Apple-Pay captured card | Rejected for manual review/refund; no false fulfilment |
| Invalid Stripe signature | HTTP 400 |
| Webhook replay/out-of-order delivery | No duplicate eSIM or customer email |
| Webhook arrives before local creation finishes | Retry safely; status recovery works |
| App closes before callback | Worker verifies payment and assigns only once |
| Gateway outage | Same attempt retained; never blindly switch provider |
| Provider timeout/unknown purchase | Internal alert, no success mail, no second purchase |
| Provider accepted, QR pending | Pending order reused; success email only with QR/ICCID |
| Email failure after assignment | Internal alert; email-only recovery, not a second purchase |
| Concurrent requests on disposable MySQL | One gateway reservation and one assignment |
| Existing gateway Checkout/recurring/Razorpay | Existing response, callbacks, branding and reports work |
| INR | Correct server quote; actual account eligibility tested, not assumed UPI |
| Disable common Stripe switch after a paid attempt | In-flight Stripe status/worker still recovers with original gateway credentials retained |

Before enabling each case, verify BOTH staging DBs, test Stripe keys, provider
sandbox/mock and QA mail destinations. Approve any real low-cost provider test
separately. Do not use real customer transactions to force failure cases.

## Inspect without secrets

Common read-only query:

```sql
SELECT id, tracking_id, payment_mode, status, provisioning_status,
       payment_link_id, customer_payment_id, payment_id, tgt_order_no,
       failure_email_sent_at, success_email_sent_at, payment_last_checked_at
FROM esim_transactions WHERE checkout_request_key IS NOT NULL
ORDER BY id DESC LIMIT 20;
```

Gateway read-only query (substitute the actual numeric staging app ID):

```sql
SELECT id, app_id, payment_id, transaction_id, payment_type, status, currency,
       total_amount FROM transactions
WHERE app_id = QA_APP_ID ORDER BY id DESC LIMIT 20;
```

Native rows use native_ap_... token and pi_... transaction ID. Signed hosted
eSIM rows use esim_cs_... token, checkout_session_id metadata and eventual pi_...
transaction ID. Filter metadata by transactions_id and the independent
stripe_apple_pay.* or esim_checkout.* prefixes. Do not export secrets/client secrets.

## Release decision

Local contract tests establish interface compatibility against fixture Stripe/
storage, not a production certification. MySQL storage/concurrency, actual
webhook delivery, native certificates/SDK and real Stripe test payments remain
mandatory staging gates. Keep ESIM_STRIPE_ENABLED=0 until evidence is recorded.
No automatic production enablement or push is part of this implementation.

The unrelated scaffold ExampleTest still expects GET / to return 200, whereas
this gateway currently returns 404 at that path. The payment-focused suite is
run separately so that known root-page mismatch is not reported as payment success.
