Overview
The Payments API provides secure payment processing through Stripe with automatic marketplace commission handling. It supports PaymentIntents for modern payment flows, handles platform fees, and integrates seamlessly with the order creation system. Location:convex/customers/payments.ts
Payment Flow
1
Create Payment Intent
Generate Stripe PaymentIntent with cart totals and commission validation
2
Process Payment
Handle payment on frontend using Stripe Elements or Payment Sheet
3
Webhook Processing
Automatic order creation via Stripe webhooks on successful payment
4
Order Fulfillment
Store receives order and begins fulfillment process
Create Payment Intent
Creates a Stripe PaymentIntent for cart checkout with platform commission validation.Customer ID making the purchase
Store ID receiving the order
Order subtotal before fees
Delivery fee amount
Platform commission fee
Total order amount (subtotal + delivery + platform fee)
Currency code (default: “usd”)
Cart items for payment metadata
Delivery method
Delivery address details (required for delivery orders)
Get Payment Intent Status
Retrieve the current status of a Stripe PaymentIntent.Stripe PaymentIntent ID to check
Cancel Payment Intent
Cancel a Stripe PaymentIntent if user cancels checkout.Stripe PaymentIntent ID to cancel
Complete Payment Integration
Here’s a complete payment integration with Stripe Elements:Payment Status Monitoring
Monitor payment status for order processing:Stripe Webhook Integration
The payment system automatically processes orders via webhooks:Payment Methods
Credit Cards
Supported: Visa, Mastercard, American Express
Processing: Instant via Stripe
Fees: Standard Stripe rates
Processing: Instant via Stripe
Fees: Standard Stripe rates
Debit Cards
Supported: Local and international debit cards
Processing: Instant verification
Fees: Lower processing rates
Processing: Instant verification
Fees: Lower processing rates
Digital Wallets
Supported: Apple Pay, Google Pay
Processing: One-touch payments
Fees: Same as card rates
Processing: One-touch payments
Fees: Same as card rates
Commission Handling
The payment system automatically handles marketplace commissions:Error Handling
Payment Intent creation failed
Payment Intent creation failed
Status Code:
400Payment declined
Payment declined
Status Code:
402Invalid payment method
Invalid payment method
Status Code:
400Commission validation failed
Commission validation failed
Status Code:
400Security Features
PCI Compliance
All card data is handled by Stripe, ensuring PCI DSS compliance
Fraud Detection
Stripe’s machine learning fraud detection protects against fraudulent transactions
3D Secure
Automatic 3D Secure authentication for enhanced security
Webhook Verification
All webhooks are verified using Stripe signatures
The payment system automatically validates platform commission amounts to ensure consistency between frontend calculations and backend processing.
