Skip to main content

Create Payment Intent

Initializes a payment session for course enrollment. Automatically selects the appropriate payment gateway (Stripe or Flutterwave) based on user currency.

Request Body

number
required
Course ID to purchase
string
Enrollment mode (informational)
string
Course title (used for payment description)
string
Redirect context: “course-detail” or “courses-list”

Response

Response varies by payment gateway:

Stripe Response

string
Stripe Checkout session URL
string
“stripe”
number
Payment amount in user’s currency
string
User’s preferred currency
number
Original course price in platform currency
string
Platform’s default currency

Flutterwave Response

Flutterwave payment page URL
string
“flutterwave”
string
Transaction reference ID
number
Payment amount
string
Payment currency

Example Request

Example Response (Stripe)

Example Response (Flutterwave)


Record Payment

Records a completed payment in the database. Called after successful payment via gateway callback.

Request Body

number
required
Course ID
number
required
Payment amount
string
required
Payment gateway: “stripe” or “flutterwave”

Response

boolean
Payment recording status
object
Created payment record

Example Request


Payment Gateway Selection

The API automatically selects the payment gateway based on the user’s currency preference:

Currency Conversion

Course prices are stored in the platform’s default currency (configurable in platform_settings). The API:
  1. Fetches the course price in platform currency
  2. Gets the user’s preferred currency from their profile
  3. Converts the amount using real-time exchange rates
  4. Creates a payment session in the user’s currency
  5. Stores both original and payment amounts for reporting

Currency Fields

  • original_amount: Course price in platform currency
  • original_currency: Platform’s default currency (e.g., “USD”)
  • payment_amount: Amount charged to user (after conversion)
  • payment_currency: User’s payment currency
  • exchange_rate: Rate used for conversion (amountUSD / originalAmount)

Payment Callbacks

Stripe Callback

Handles Stripe Checkout session completion. Query Parameters:
  • success: “true” for successful payment
  • courseId: Course ID
  • referrer: Redirect context

Flutterwave Callback

Handles Flutterwave payment completion. Query Parameters:
  • status: Payment status
  • tx_ref: Transaction reference
  • transaction_id: Flutterwave transaction ID
  • courseId: Course ID
  • referrer: Redirect context

Payment Webhooks

Stripe Webhook

Receives and processes Stripe webhook events for payment confirmations and updates.

Payment Flow

  1. User initiates payment: POST to /api/payments/create-intent
  2. API creates payment session:
    • Converts price to user’s currency
    • Selects appropriate gateway (Stripe or Flutterwave)
    • Returns checkout/payment URL
  3. User completes payment: On gateway-hosted page
  4. Gateway redirects to callback: /api/payments/callback/{gateway}
  5. Callback records payment: Calls /api/payments/record-payment
  6. User enrolled automatically: Callback creates enrollment record
  7. User redirected: To course page or courses list

Error Codes