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

# Paying for orders using bulk payments

> Pay for multiple orders using a single transfer of funds

<Warning>
  **v1 (legacy).** This page documents the API before the v2 update. The v1
  format is not enabled for new accounts and must be enabled on your account by
  your account manager. New integrations should use the
  [current documentation](/introduction). To update an existing integration,
  follow the [migration guide](/migration).
</Warning>

### Requirements to start the flow.

<CardGroup cols={1}>
  <Card title="API key" icon="shield-keyhole">
    Have an API key ([Tutorial here](/quickstart#api-key-generation)).
  </Card>
</CardGroup>

### <Icon icon="arrow-progress" iconType="solid" /> Order flow

Some customers, especially those with smaller transaction sizes, may need to settle multiple orders at once in order to mitigate the operational overhead of paying for each transaction independently. To support this use case, we have created a suite of endpoints that allow users to pay for more than one buy order with a single bank transfer and more than one sell order with a single blockchain transaction. This guide will walk you through how to use the bulk crypto payment system for off ramps.

<Steps>
  <Step title="Create bulk payment">
    Before you can start creating orders, you need to create a bulk payment that you will use to pay for multiple orders at once. This needs to be done each time you want to create a new set of orders that a single payment will cover.

    Assuming you want to sell USDC (Solana) in Mexico, then you would pass the following fields in the request body:

    ```javascript theme={null}
    {
      "crypto":"SOL_USDC_PTHX",
      "country":"MX"
    }
    ```

    Keep the `id` from the response, since every order you want this payment to cover has to reference it. The bulk payment starts out in `awaitingDepositAddress` and has no `depositAddress` yet, which is fine because you do not need it until you are ready to pay.

    <Card title="Create bulk crypto payment" icon="square-code" href="/v1/api-reference/crypto-payments/create-bulk-crypto-payment" />
  </Step>

  <Step title="Create a quote">
    Create a quote for the order. Assuming you would like to sell USDC (Solana) for MXN, you would provide the following fields in the body:

    ```javascript theme={null}
      {
        "side":"sell",
        "crypto":"SOL_USDC_PTHX",
        "fiat":"MXN",
        "country":"MX"
      }
    ```

    Additionally, you need to specify the order size. You can either specify how much USDC (Solana) you would like to sell, like this (selling \$150,000 USDC (Solana)):

    ```javascript theme={null}
    "amountCrypto":150000
    ```

    Or you can alternatively specify the amount of MXN you would like to receive, like this (receiving \$1,000,000 MXN):

    ```javascript theme={null}
    "amountFiat":1000000
    ```

    Quotes expire. The `expiresAt` field is the date and time after which the quote can no longer be used to create an order, and the window is short, so create the order in the next step promptly. Quote each order right before you create it rather than quoting them all up front.

    <Card title="Go to create quote endpoint" icon="square-code" href="/v1/api-reference/quotes/create-quote" />

    <Card title="Learn more about how quotes work" icon="file-invoice-dollar" href="/v1/quotes" />
  </Step>

  <Step title="Create order">
    Once you are satisfied with a quote, you can create an order to book the trade. Assuming you would like to continue with the quote you created in the previous step to sell USDC (Solana) for MXN, then you would provide the following body:

    ```javascript theme={null}
    {
        "quoteId":"{{QUOTE_ID_FROM_PREVIOUS_RESPONSE}}",
        "payoutBankAccountId":"{{ID_OF_MXN_BANK_ACCOUNT}}",
        "bulkCryptoPaymentId":"{{ID_FROM_RESPONSE_OF_STEP_1}}"
    }
    ```

    The `bulkCryptoPaymentId` is what attaches the order to the bulk payment. An order created without it gets its own individual deposit address and has to be paid for on its own.

    <Card title="Go to create order" icon="square-code" href="/v1/api-reference/orders/create-order" />
  </Step>

  <Step title="Create more orders (optional)">
    Before settling this order, you can create other orders with the same
    `bulkCryptoPaymentId`. By doing so, you will add them to the bulk crypto
    payment and thus will only need to make one payment to settle multiple orders.
    Each order you add increases the `amount` of the bulk crypto payment by its
    `amountCrypto`, so only read that total once you have finished adding orders.
  </Step>

  <Step title="Wait for the order to be ready to accept payment">
    After creating an order, it will update its `status` field as it goes through its lifecycle. Once the `status` field is equal to `awaitingPayment`, the order is ready to receive payment. When all of the orders you added to the bulk crypto payment are in this status, you can get ready to send the payment.

    <Card title="Go to check order status" icon="square-code" href="/v1/api-reference/orders/get-order" />
  </Step>

  <Step title="Get payment instructions">
    Retrieve payment amount and the deposit address specified by the bulk payment you created earlier. Get the bulk crypto payment by its `id` and read the `amount` field, which is the total across every order attached to it, and the `depositAddress` field.

    <Card title="Get crypto bulk payment" icon="square-code" href="/v1/api-reference/crypto-payments/get-bulk-crypto-payment" />
  </Step>

  <Step title="Complete payment">
    Send the USDC (Solana) specified by the `amount` field of the bulk crypto
    payment to the address specified by the `depositAddress` field of the bulk
    crypto payment, in a single transfer. Make sure to send the exact amount to
    avoid delays. If the amount does not match, the bulk payment lands in
    `insufficientAmountReceived` or `excessAmountReceived` and needs to be sorted
    out with Rio before the orders can settle.
  </Step>

  <Step title="Order is complete">
    Once Rio confirms your payment, the orders attached to the bulk payment settle and Rio sends the fiat to the bank account you specified on each one. You will be able to view the details of the payout by inspecting the `payoutsSent` field of the `order`.
  </Step>
</Steps>

#### <Icon icon="check-to-slot" iconType="solid" /> Poll order status or subscribe to webhooks

<Card title="Go to check order status" icon="square-code" href="/v1/api-reference/orders/get-order" />

<Card title="Go to register a webhook" icon="arrow-progress" href="/v1/workflows/register-webhook">
  Subscribe to `orders` webhooks to get order updates pushed to you instead of
  polling.
</Card>

<Note>
  **Disclaimer**: All technical documentation is subject to the terms and
  conditions, which apply supplementarily and take precedence over the
  documentation.
</Note>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.