Skip to content

Implement Stripe payment gateway#692

Open
Cameron-xuan wants to merge 3 commits into
SecureBananaLabs:mainfrom
Cameron-xuan:payment-gateway-1
Open

Implement Stripe payment gateway#692
Cameron-xuan wants to merge 3 commits into
SecureBananaLabs:mainfrom
Cameron-xuan:payment-gateway-1

Conversation

@Cameron-xuan
Copy link
Copy Markdown

@Cameron-xuan Cameron-xuan commented May 25, 2026

Closes #1

/claim #1

Demo

demos/stripe-payment-intent-demo.mov — 15s screen recording showing all 9 tests passing via npm test.

Changes

apps/api/src/services/paymentService.js

  • Replaced stub createPaymentIntent with real Stripe SDK integration
  • Input validation: amount required and must be a positive integer (cents); currency defaults to "usd"
  • Calls stripe.paymentIntents.create({ amount, currency }) and returns { clientSecret, paymentId }
  • Catches Stripe errors and re-throws with original message preserved
  • Uses lazy singleton stripeClient (initialised from STRIPE_SECRET_KEY env var)

apps/api/src/controllers/paymentController.js

  • Added try/catch: validation errors (status 400) return fail(res, message, 400); Stripe/unexpected errors propagate to errorHandler

apps/api/src/tests/payment.test.js

  • 8 unit tests using injected mock Stripe client (no network calls)
  • Verifies correct arguments passed to stripe.paymentIntents.create
  • Covers: happy path, currency default, missing amount, zero/negative/float amount, Stripe error propagation
  • 1 environment-gated integration smoke test (runs only when STRIPE_SECRET_KEY=sk_test_*)

apps/api/package.json

  • Fixed test script: node --test src/tests/*.test.js (glob so all test files are discovered)

Test results

✔ GET /health returns ok payload
✔ returns clientSecret and paymentId from Stripe
✔ passes correct amount and currency to stripe.paymentIntents.create
✔ defaults currency to usd when omitted
✔ throws 400 error when amount is missing
✔ throws 400 error when amount is zero
✔ throws 400 error when amount is negative
✔ throws 400 error when amount is a float
✔ propagates Stripe API errors with original message
﹣ integration: creates real PaymentIntent in Stripe test mode # SKIP
pass 9, fail 0, skipped 1

Replace stub createPaymentIntent with real Stripe SDK integration.
- Validate amount (required, positive integer in cents); currency defaults to usd
- Return { clientSecret, paymentId } from stripe.paymentIntents.create()
- Catch and re-throw Stripe errors with original message preserved
- Controller returns 400 for validation errors, delegates Stripe errors to errorHandler
- 8 unit tests with mocked Stripe client; 1 environment-gated integration smoke test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Secure Payment Gateway and Payment Service

1 participant