Buy

Buy a supported quote currency by paying the equivalent amount in the base currency.

The POST /api/v1/swap/buy endpoint collects the base_currency from the caller and, once payment is completed, pays out the quote_currency to the specified beneficiary_account.

Endpoint

POST {{base_url}}/api/v1/swap/buy

Authorization

Bearer Token

Headers

HeaderRequiredDescription
AuthorizationYesBearer authentication token
Content-TypeYesapplication/json
x-merchant-refYesMerchant reference

Request Body

{
  "user_ref": "UREFB71CBD5EE9BE4AEFB0A1587839EAD87D007QQ",
  "beneficiary_account": {
    "account_no": "string",
    "bank_code": "string",
    "receiver_phone": "string",
    "network": "string",
    "receiver_name": "string",
    "receiver_email": "string",
    "narration": "string",
    "to_wallet_address": "crypto-wallet-address-xxxx"
  },
  "txn_merchant_ref": "trf000001_0122",
  "base_currency": "NGN",
  "quote_currency": "EUSD:MOB",
  "amount": 10000,
  "swap_type": "CHECKOUT_LINK",
  "pay_meta_data": {},
  "notification_url": "string"
}

Request Parameters

ParameterTypeRequiredDescription
user_refStringYesReference of the LedgerBlock user initiating the swap.
beneficiary_accountObjectYesDetails of the beneficiary who will receive the quote_currency. The required fields depend on the payout rail.
txn_merchant_refStringYesUnique transaction reference generated by the merchant.
base_currencyStringYesCurrency the caller pays, e.g. NGN.
quote_currencyStringYesCurrency the caller receives, e.g. EUSD:MOB.
amountNumberYesAmount of the base_currency being paid.
swap_typeStringYesDetermines how the payment is completed.
pay_meta_dataObjectNoAdditional payment metadata.
notification_urlStringConditionalURL where LedgerBlock sends transaction status notifications.

Beneficiary Account Parameters

The fields required inside beneficiary_account depend on the payout rail.

ParameterTypeRequiredDescription
account_noStringConditionalBeneficiary bank account number. Required for bank payouts.
bank_codeStringConditionalBeneficiary bank code. Required for bank payouts.
receiver_phoneStringConditionalBeneficiary's phone number. Required for mobile money payouts.
networkStringConditionalMobile money network. Required for mobile money payouts.
receiver_nameStringConditionalBeneficiary's name.
receiver_emailStringConditionalBeneficiary's email address.
narrationStringConditionalDescription or narration for the transaction.
to_wallet_addressStringConditionalDestination wallet address. Required for crypto payouts.

Payout Rails

Payout RailRequired Fields
Bankaccount_no, bank_code
Mobile Moneyreceiver_phone, network
Cryptoto_wallet_address

Swap Type

ValueDescription
CHECKOUT_LINKCreates a hosted checkout payment link where the customer pays the base_currency.
SERVER_2_SERVERAllows the merchant to complete the payment directly through a server-to-server flow, where supported.

Amount and Currency

For a Buy transaction:

  • base_currency is the currency the caller pays.
  • quote_currency is the currency the caller receives.
  • amount is denominated in the base_currency.

For example:

base_currency  = NGN
quote_currency = EUSD:MOB
amount         = 10000

This means the caller pays 10,000 NGN and receives the equivalent amount of EUSD:MOB based on the applicable exchange rate.

Response

{
  "status": "success",
  "message": "Please complete payment via pay_link",
  "data": {
    "payment_ref": "fb9f49b7-fcd3-42d5-9283-3e7b5f05586b",
    "txn_merchant_ref": "trf000001_0122",
    "base_currency": "NGN",
    "quote_currency": "EUSD:MOB",
    "amount": 10000,
    "expected_quote_amount": 5.882352941176471,
    "rate_used": 1700,
    "payment_status": "AWAITING_PAYMENT",
    "pay_data": {
      "pay_link": "https://blockpay.fuspay.finance/checkout?ref=fb9f49b7-fcd3-42d5-9283-3e7b5f05586b&currency=NGN&amount=10000&txn_ref=trf000001_0122"
    }
  }
}

Response Parameters

ParameterTypeDescription
payment_refStringUnique reference generated for the payment.
txn_merchant_refStringMerchant's transaction reference.
base_currencyStringCurrency paid by the caller.
quote_currencyStringCurrency received by the beneficiary.
amountNumberAmount of the base_currency being paid.
expected_quote_amountNumberExpected amount of quote_currency to be received based on the applied rate.
rate_usedNumberExchange rate used for the transaction.
payment_statusStringCurrent payment status.
pay_dataObjectContains payment information required to complete the transaction.
pay_data.pay_linkStringHosted checkout link used by the customer to complete payment.

Checkout Flow

When swap_type is set to CHECKOUT_LINK, LedgerBlock returns a pay_link under data.pay_data.

The merchant should redirect the customer to the returned pay_link to complete payment.

The initial response returns:

payment_status: AWAITING_PAYMENT

This indicates that the base_currency payment has not yet been completed.

Once the customer completes payment:

  1. LedgerBlock receives and verifies the base_currency payment.
  2. The equivalent quote_currency is calculated using the applicable exchange rate.
  3. LedgerBlock pays out the quote_currency to the specified beneficiary_account.
  4. Transaction status updates are sent to the configured notification_url.

Important: Always use the pay_link returned in the API response. Do not construct the checkout URL manually.


Did this page help you?