Stripe adapter (mockable seam: checkout + webhook -> idempotent credit) #3
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Goal
Stripe adapter as a mockable seam: checkout session creation + payment webhook -> idempotent credits. Real impl behind env keys; mock impl for deterministic tests. No live Stripe key needed in CI.
Depends on: issue #1 (billing core). Files allowed:
gitea_saas/stripe_client.py,tests/test_stripe_client.py. Do NOT modify anything else.Spec
StripeClientinterface (abstract or duck):create_checkout_session(client_id, amount_minor, currency='usd', success_url, cancel_url) -> dict {checkout_url, session_id}process_webhook(payload: bytes, signature: str) -> dict {event_id, type, client_id?, amount_minor?}— raisesStripeSignatureErroron bad signature.MockStripeClient— deterministic, records events, no network. Default whenSTRIPE_SECRET_KEYabsent.StripeClient(real) — usesstripepython lib only ifSTRIPE_SECRET_KEY+STRIPE_WEBHOOK_SECRETset; CI runs mock-only.payment.succeededevents call corecredit(client_id, amount_minor, idempotency_key=event_id). Duplicate webhook delivery (same event_id) must not double-credit.Acceptance
payment.succeeded-> credit applied once; re-delivered same event_id -> no double creditpayment.succeededto(client_id, amount_minor)correctly from event payloadVerification:
python -m pytest tests/test_stripe_client.py -qpasses, no network.