All files / src/lib/api-docs/endpoints payments.ts

100% Statements 90/90
100% Branches 0/0
100% Functions 0/0
100% Lines 90/90

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 911x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
/**
 * Payments Endpoints
 * Payment processing with Stripe endpoints
 */
 
import type { ApiEndpoint } from '@/types/api-docs';
 
export const paymentsEndpoints: ApiEndpoint[] = [
  {
    id: 'payments-create-intent',
    method: 'POST',
    path: '/api/payments/create-intent',
    summary: 'Create payment intent',
    description: 'Creates a Stripe payment intent for checkout',
    category: 'payments',
    requiresAuth: true,
    requestBody: {
      contentType: 'application/json',
      fields: [
        { name: 'amount', type: 'number', required: true, description: 'Amount in cents' },
        { name: 'currency', type: 'string', required: false, description: 'Currency code (default: usd)' },
      ],
    },
    responses: [
      {
        status: 200,
        description: 'Payment intent created',
        example: {
          success: true,
          data: {
            clientSecret: 'pi_xxx_secret_xxx',
            paymentIntentId: 'pi_xxx',
            amount: 15999,
            currency: 'usd',
          },
        },
      },
      {
        status: 400,
        description: 'Invalid amount',
        example: { success: false, error: { code: 'VALIDATION_ERROR', message: 'Amount must be a positive number' } },
      },
      {
        status: 401,
        description: 'Not authenticated',
        example: { success: false, error: { code: 'UNAUTHORIZED', message: 'Authentication required' } },
      },
    ],
  },
  {
    id: 'payments-process',
    method: 'POST',
    path: '/api/payments',
    summary: 'Process payment',
    description: 'Processes a payment after checkout',
    category: 'payments',
    requiresAuth: true,
    requestBody: {
      contentType: 'application/json',
      fields: [
        { name: 'paymentIntentId', type: 'string', required: true, description: 'Stripe payment intent ID' },
        { name: 'orderId', type: 'number', required: true, description: 'Order ID' },
      ],
    },
    responses: [
      {
        status: 200,
        description: 'Payment processed',
        example: {
          success: true,
          data: {
            status: 'succeeded',
            orderId: 1,
            transactionId: 'txn_xxx',
          },
        },
      },
      {
        status: 400,
        description: 'Payment failed',
        example: { success: false, error: { code: 'PAYMENT_FAILED', message: 'Payment was declined' } },
      },
      {
        status: 401,
        description: 'Not authenticated',
        example: { success: false, error: { code: 'UNAUTHORIZED', message: 'Authentication required' } },
      },
    ],
  },
];