> ## Documentation Index
> Fetch the complete documentation index at: https://baas-api-docs.rexmfbank.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Buy a data plan

> Debits the partner Master account and buys a data plan. `amount` must
match the selected plan (`tariffTypeId`). Requires an `Idempotency-Key`
header.

If the selected provider is down but an alternative is available, the
API returns **HTTP 409 with `status: success`** and a `plans` list —
not an error envelope. Show those plans and retry with a **new**
idempotency key, because the body will have changed.




## OpenAPI

````yaml /openapi.yaml post /services/bills-payment/data
openapi: 3.1.0
info:
  title: Rex Banking-as-a-Service API
  version: 1.0.0
  summary: Embed real bank accounts, transfers, and collections into your product.
  description: |
    The Rex BaaS API lets you provision virtual bank accounts, move money
    between them, accept inbound transfers, collect at merchant terminals, and
    pay bills for your end customers — all under your own brand, backed by a
    real bank ledger.

    This reference covers every endpoint your integration will call. If
    you're just getting started, read **[Getting Started](/introduction)**
    and **[Authentication](/authentication)** first — most integration
    questions are answered there, not in the endpoint list.

    All endpoints are versioned under `/baas/api/v1` and return JSON. See
    **[Errors](/errors)** for the shared error envelope, and
    **[Sandbox vs. Live](/guides/sandbox-vs-live)** for how test and
    production credentials differ.
  contact:
    name: Rex BaaS Support
    email: baas-support@rexmfbank.com
  license:
    name: Proprietary — for approved Rex BaaS partners only
servers:
  - url: https://api.rexmfbank.com/baas/api/v1
    description: Rex BaaS API
security:
  - BearerAuth: []
tags:
  - name: Authentication
    description: Register a partner account, verify it, log in, and manage credentials.
  - name: Onboarding
    description: |
      The one-time KYB (Know Your Business) flow every partner completes
      before going live — business details, a compliance representative,
      supporting documents, and signing the partner agreement.
  - name: Wallet
    description: >-
      Your business's own settlement balance — the account every virtual account
      nets into.
  - name: Virtual Accounts
    description: |
      The core product — dedicated bank account numbers you issue to your
      own end users, with full transfer and transaction capabilities.
  - name: Webhooks
    description: Configure where and how Rex notifies your system of events in real time.
  - name: Partner Settings
    description: >-
      Account security, team members, disputes, and document management for your
      own partner account.
  - name: Services
    description: |
      The catalog of optional products a partner can subscribe to. Virtual
      accounts are not in this list — they are available without a
      subscription. Bills payment is.
  - name: Bills Payment
    description: |
      Buy airtime, data, electricity, and cable TV for your end customers.
      Each purchase debits your own Master account. Requires a Bills Payment
      subscription — see **[Services](/guides/service-subscriptions)**.
paths:
  /services/bills-payment/data:
    post:
      tags:
        - Bills Payment
      summary: Buy a data plan
      description: |
        Debits the partner Master account and buys a data plan. `amount` must
        match the selected plan (`tariffTypeId`). Requires an `Idempotency-Key`
        header.

        If the selected provider is down but an alternative is available, the
        API returns **HTTP 409 with `status: success`** and a `plans` list —
        not an error envelope. Show those plans and retry with a **new**
        idempotency key, because the body will have changed.
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - phone
                - amount
                - network
                - tariffTypeId
              properties:
                phone:
                  type: string
                  pattern: ^0\d{10}$
                amount:
                  type: number
                  minimum: 50
                  maximum: 500000
                  description: Must match the selected plan.
                network:
                  type: string
                  maxLength: 15
                  description: '`mtn`, `glo`, `airtel`, or `9mobile`.'
                tariffTypeId:
                  type: string
                  description: Plan identifier from **Get data plans**.
                force_provider:
                  type: string
                  nullable: true
                  description: Force a specific provider key.
                email:
                  type: string
                  format: email
                  nullable: true
                customer_reference:
                  type: string
                  nullable: true
                  maxLength: 100
            example:
              phone: '08012345678'
              amount: 1500
              network: mtn
              tariffTypeId: MTN_DATA_2GB
              email: customer@example.com
              customer_reference: customer-123
      responses:
        '200':
          description: 'Purchased. `data` is a bills transaction with `bill_type: data`.'
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/SuccessEnvelope'
                  - type: object
                    properties:
                      data:
                        $ref: '#/components/schemas/BillsTransaction'
        '400':
          description: '`INSUFFICIENT_BALANCE`, or a missing `Idempotency-Key`'
        '403':
          description: '`NOT_SUBSCRIBED`'
        '409':
          description: |
            Either a conflict (`MASTER_NOT_PROVISIONED`, `DUPLICATE_REFERENCE`,
            idempotency still processing) **or** a provider fallback. The
            fallback is `status: success` with `failed_provider`,
            `next_provider`, and `plans` — retry that selection with a new
            idempotency key.
          content:
            application/json:
              example:
                status: success
                message: >-
                  Your selected provider is temporarily unavailable. Please
                  choose a plan from the alternative provider.
                data:
                  failed_provider: provider-a
                  next_provider: provider-b
                  plans: []
        '422':
          description: '`INVALID_PLAN_AMOUNT`, `DAILY_CAP_EXCEEDED`, or `VALIDATION_FAILED`'
components:
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: true
      description: |
        Required on purchase endpoints. Use a new key for each intended
        purchase, and reuse that same key when retrying the same request
        after a timeout. A completed key replays the original response. The
        same key with a different body is rejected. Keys expire after 24
        hours. A missing key returns `400` with no `error_code`.
      schema:
        type: string
        maxLength: 255
  schemas:
    SuccessEnvelope:
      type: object
      properties:
        status:
          type: string
          enum:
            - success
        message:
          type: string
        data:
          description: Endpoint-specific payload — see each operation.
    BillsTransaction:
      type: object
      description: |
        A bills-payment debit against the partner Master account. `id` and
        every `*_id` are strings. Money fields are decimal strings.
      properties:
        id:
          type: string
          example: '101'
        company_id:
          type: string
          example: '28'
        master_savings_id:
          type: string
          example: '55'
        bill_type:
          type: string
          enum:
            - airtime
            - data
            - electricity
            - cable
        direction:
          type: string
          enum:
            - debit
        amount:
          type: string
          example: '1000.00'
        fee_amount:
          type: string
          example: '0.00'
        balance_after:
          type: string
          example: '49000.00'
        reference:
          type: string
          example: PROVIDER-REFERENCE
        status:
          type: string
          example: successful
        narration:
          type: string
        savings_transaction_id:
          type: string
          example: '9001'
        meta:
          type: object
          additionalProperties: true
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: sk_live_... / sk_sandbox_...
      description: |
        See **[Authentication](/authentication)** for the full explanation
        of session tokens vs. API keys and when each is used.

````