Skip to content

feat: integrate Stripe SDK for payment intent creation#300

Closed
niufox wants to merge 1 commit into
SecureBananaLabs:mainfrom
niufox:stripe-payment-issue-1
Closed

feat: integrate Stripe SDK for payment intent creation#300
niufox wants to merge 1 commit into
SecureBananaLabs:mainfrom
niufox:stripe-payment-issue-1

Conversation

@niufox
Copy link
Copy Markdown

@niufox niufox commented May 19, 2026

Summary

Implements the secure payment gateway by replacing the stub createPaymentIntent with real Stripe SDK integration. Closes #1

Changes Made

apps/api/src/services/paymentService.js

  • Initialize Stripe client using STRIPE_SECRET_KEY from the existing env config
  • Validate payload.amount as a positive integer (smallest currency unit, e.g. cents) — throws descriptive error if missing or invalid
  • Default payload.currency to "usd" when not provided, consistent with existing behavior
  • Call stripe.paymentIntents.create() with { amount, currency }
  • Return clientSecret (mapped from paymentIntent.client_secret) and paymentId (mapped from paymentIntent.id)
  • Remove stub pay_${Date.now()} id generation
  • Catch and re-throw Stripe-specific errors (StripeCardError, StripeInvalidRequestError, etc.) with original error details

apps/api/src/controllers/paymentController.js

  • Wrap createPaymentIntent call in try/catch
  • Forward service errors to the client with appropriate HTTP status codes

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

  • Add test coverage for input validation (null, undefined, negative, zero, float amounts)
  • Add test coverage for currency default behavior

apps/api/package.json

  • Add stripe dependency

Acceptance Criteria Checklist

  • stripe npm package is installed and STRIPE_SECRET_KEY environment variable is used to initialise the client — no hardcoded keys
  • payload.amount is required and must be a positive integer; function throws with a descriptive error if missing or invalid
  • payload.currency defaults to "usd" if not provided
  • A real stripe.paymentIntents.create() call is made with at minimum { amount, currency }
  • The resolved value includes clientSecret and paymentId
  • The stub pay_${Date.now()} id generation is removed
  • Stripe errors are caught and re-thrown with the original Stripe error

Closes #1

- Replace stub createPaymentIntent with real Stripe SDK integration
- Initialize Stripe client using STRIPE_SECRET_KEY from env config
- Validate payload.amount as positive integer (smallest currency unit)
- Default payload.currency to 'usd' when not provided
- Call stripe.paymentIntents.create() with amount and currency
- Return clientSecret and paymentId from PaymentIntent response
- Remove stub pay_${Date.now()} id generation
- Add error handling for Stripe-specific and unexpected errors
- Update paymentController to catch and forward service errors
- Add test coverage for input validation and currency defaults
- Add stripe dependency to package.json
@Adamchaua
Copy link
Copy Markdown

Monitoring this PR. For any approved payout: EVM 0x1ecab01075f3bdf1b56b7d849c8e28ef88943624; PayPal ckelvinkhanh32@gmail.com.

@niufox
Copy link
Copy Markdown
Author

niufox commented May 20, 2026

Friendly follow-up on this PR!

This implementation:

  • Uses the official stripe Node.js SDK (v17.7.0)
  • Full error handling with proper HTTP status codes
  • Includes unit tests for validation and success cases
  • All acceptance criteria from Issue Implement Stripe payment intent service #359 are met

Would love a review when you have a moment. Thanks!

@niufox
Copy link
Copy Markdown
Author

niufox commented May 20, 2026

💰 Payment info for bounty payout:

  • PayPal: niufox@qq.com

Please use this PayPal account for any approved bounty reward. Thank you!

@niufox
Copy link
Copy Markdown
Author

niufox commented May 20, 2026

Closing: identified as fake bounty project, no actual payouts

@niufox niufox closed this May 20, 2026
@niufox niufox deleted the stripe-payment-issue-1 branch May 20, 2026 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Secure Payment Gateway and Payment Service

2 participants