Skip to main content

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.
customerId
Id<'customers'>
required
Customer ID making the purchase
storeId
Id<'stores'>
required
Store ID receiving the order
subtotal
number
required
Order subtotal before fees
deliveryFee
number
required
Delivery fee amount
platformFee
number
required
Platform commission fee
totalAmount
number
required
Total order amount (subtotal + delivery + platform fee)
currency
string
Currency code (default: “usd”)
cartItems
Array<object>
required
Cart items for payment metadata
deliveryType
'delivery' | 'pickup'
required
Delivery method
deliveryAddress
object
Delivery address details (required for delivery orders)

Get Payment Intent Status

Retrieve the current status of a Stripe PaymentIntent.
paymentIntentId
string
required
Stripe PaymentIntent ID to check

Cancel Payment Intent

Cancel a Stripe PaymentIntent if user cancels checkout.
paymentIntentId
string
required
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

Debit Cards

Supported: Local and international debit cards
Processing: Instant verification
Fees: Lower processing rates

Digital Wallets

Supported: Apple Pay, Google Pay
Processing: One-touch payments
Fees: Same as card rates

Commission Handling

The payment system automatically handles marketplace commissions:

Error Handling

Status Code: 400
Status Code: 402
Status Code: 400
Status Code: 400

Security 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.
Always handle payment failures gracefully and provide clear error messages to users. Use Stripe’s test cards for development and testing.