Skip to content

Popular searches

Bayarcash API documentation and sandbox

Updated

The Bayarcash API lets your own website or app create payments, check transactions and manage Direct Debit mandates. Use API v3 for everything new. The full reference is at api-reference.bayarcash.com.

Bayarcash has two API versions:

Version Status When to use it
v3 Current Every new integration. New features (DuitNow QR on your own page, idempotency, payer identity verification, transaction search) are v3 only.
v2 Deprecated Only if you already run on it. It gets no new features. Plan a move to v3.

Build and test in the sandbox first. No real money moves there. The two environments are separate: each has its own merchant dashboard, its own account and its own keys.

Environment API base URL Merchant dashboard
Sandbox https://api.console.bayarcash-sandbox.com/v3 console.bayarcash-sandbox.com
Production https://api.console.bayar.cash/v3 console.bayar.cash

When you go live, change the base URL and swap in your production keys. Keys from one environment never work in the other.

To test in the sandbox:

  1. Sign in to the sandbox merchant dashboard and copy its Personal Access Token, Portal Key and API Secret Key. See Find your API keys.
  2. Send your requests to the sandbox base URL. In an SDK, call the sandbox option, for example useSandbox() (see Choose a Bayarcash SDK). In a plugin, tick its sandbox setting, for example Sandbox Mode in WooCommerce.
  3. Create a payment and pay it. No real money moves.
  4. When it works, change to the production base URL and your production keys.

For a quick test, use the shared sandbox account. Its login page shows it:

  • Email: sandbox@bayarcash.com
  • Password: sandbox@bayarcash.com

Other developers use the same account, and Bayarcash resets all its data every day at 12:00 midnight. For your own sandbox account, choose Register on the sandbox login page.

Every v3 integration uses these from your merchant dashboard:

Item What it does
Personal Access Token (PAT) Proves who you are on every API request.
Portal key Says which of your portals receives the payment.
API Secret Key Signs requests and verifies callbacks with a checksum. Never sent on its own.

Keep the token and the secret key on your server only. Never put them in a mobile app, browser JavaScript or a public repository.

Send your Personal Access Token as a bearer token in the Authorization header of every request:

Authorization: Bearer <your Personal Access Token>
Accept: application/json

For example, to check that your token works, list your portals in the sandbox:

Terminal window
curl https://api.console.bayarcash-sandbox.com/v3/portals \
-H "Authorization: Bearer $BAYARCASH_PAT" \
-H "Accept: application/json"

A typical payment through the API goes like this:

  1. Your server creates a payment intent with the portal key, order number, amount, payer name and email, and your callback_url and return_url.
  2. Bayarcash answers with a url. Redirect your customer there to pay.
  3. When the payment reaches a final state, Bayarcash sends a callback to your callback_url, server to server. Verify its checksum and update the order.
  4. Bayarcash sends the customer back to your return_url to show them the result.

The callback is the one to trust. See Verify callbacks and checksums.

The API answers with an HTTP status code. These are the codes in the API reference:

Code What it means What to do
403 The request is not allowed for this item, for example a payment intent that is already paid or a channel that cannot do this action Check the status of the item first. Read the message in the response
404 The item was not found Check the ID, and check that you use the same environment (sandbox or production) as the item
409 A request with the same Idempotency-Key is still in progress Wait, then send the request again
422 A field is not valid, the item is in the wrong state, or the same Idempotency-Key was used with different fields Read the errors in the response and correct the request
429 Too many requests Wait for the time in the Retry-After header, then send again
500 Bayarcash could not process the request (“Error processing request.”) See below

If you get HTTP 500:

  1. Do not create the payment again straight away. First check if the first request made a payment intent or a transaction.
  2. If the first request had an Idempotency-Key, send it again with the same key. Bayarcash then does not create a second payment.
  3. If the error continues, contact Bayarcash. Give the endpoint, the time of the request and the response body. Never send your Personal Access Token or API Secret Key.
  • Use an SDK if there is one for your language. It handles the base URL, the bearer token, checksums and callback verification for you. See Choose a Bayarcash SDK.
  • Send an Idempotency-Key header when you create a payment intent. If a request times out, you can send it again with the same key without creating a second payment. Keys expire after 24 hours.
  • Store each transaction ID and check it before you act on a callback. Callbacks can arrive more than once, and this stops you fulfilling the same order twice.

Common issues

My token works in production but the sandbox says it is not valid. Why?

Sandbox and production issue separate tokens. A production Personal Access Token does not work against the sandbox API, and a sandbox token does not work in production. Get each token from its own merchant dashboard.

Should I still use API v2?

No. API v2 is deprecated and gets no new features. Use v3 for every new integration. Most SDKs still default to v2, so switch them to v3 (see Choose a Bayarcash SDK).

Where is the full list of endpoints and fields?

In the API reference at api-reference.bayarcash.com. This help centre explains the ideas; the reference has every endpoint, field and response.

Was this article helpful?

Cookie settings

We use Google Analytics to see which guides help and where readers get stuck. It is on by default, and you can turn it off. This device keeps your choice.