Implement Stripe payment integration with webhook handling and refund processing #108
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds Stripe Checkout, webhook processing, and refund capabilities for multi-tenant e-commerce orders.
Schema Changes
paidAttimestamp for payment completion trackingstripeAccountId,stripeSecretKey,stripePublishableKey) for multi-tenant payment routingPayment Service
PaymentServicesingleton with:createCheckoutSession()- Generates Stripe Checkout with line items, multi-currency support, and Stripe Connect routingprocessRefund()- Handles full/partial refunds with inventory restoration on full refundsgetPaymentIntent()- Retrieves payment intent detailsMulti-currency: Amounts converted to smallest unit (cents for USD, paisa for BDT). Currency code normalized to lowercase for Stripe API.
Stripe Connect: When
Store.stripeAccountIdexists, passesstripeAccountparameter to route payments to connected account.API Routes
POST /api/payments/create-sessionCreates Stripe Checkout session. Validates user store access via Membership relation and order status (PENDING or PAYMENT_FAILED only).
POST /api/payments/refundProcesses refunds with idempotency key generation. Validates refund amount ≤ order total and order status (PAID/PROCESSING/DELIVERED). Restores inventory on full refunds, updates
refundedAmounton partial refunds.POST /api/webhooks/stripeSignature-verified event handlers:
checkout.session.completed→ Order to PAID, PaymentAttempt to SUCCESS, audit log createdpayment_intent.succeeded→ PaymentAttempt to SUCCESSpayment_intent.payment_failed→ Order to PAYMENT_FAILED with error detailscharge.refunded→ Refund to COMPLETEDReturns 400 for invalid signatures, 500 on processing errors (triggers Stripe retry).
Security
stripe.webhooks.constructEvent()storeId, user access validated via MembershipExample Usage
Environment Variables
Original prompt
This section details on the original issue you should resolve
<issue_title>[Phase 1] Stripe Payment Integration</issue_title>
<issue_description>## Priority: P0
Phase: 1
Epic: #26 Payment Integration
Estimate: 2 days
Type: Story
Context
Stripe Payment Integration provides the payment processing infrastructure for StormCom, enabling secure credit/debit card payments, handling asynchronous webhooks for payment confirmation, and supporting refund processing. This implementation must handle idempotency, webhook signature verification, and seamless integration with the Order Processing API.
According to the research documentation, payment processing requires atomic transaction handling to prevent order creation without payment confirmation, proper webhook security to prevent spoofing attacks, and comprehensive error handling for declined payments.
Acceptance Criteria
checkout.session.completed,payment_intent.succeeded,charge.refundedevents with signature verification, idempotency key validationTechnical Implementation
1. Stripe Checkout Session Creation