# Use Bayarcash in n8n

> Install the Bayarcash community node in n8n, connect it with your Personal Access Token, and create payments or read transactions in a workflow.
>
> Source: https://docs.bayarcash.com/n8n/

The Bayarcash node for [n8n](https://n8n.io) lets a workflow create payment intents, check them, and read your portals and transactions without code. It is a community node, published on npm as `n8n-nodes-bayarcash`, and uses Bayarcash API v3.

## Install the node

Community nodes can be installed on self-hosted n8n. To install it:

1. In n8n, open **Settings** → **Community Nodes**.
2. Install the npm package [`n8n-nodes-bayarcash`](https://www.npmjs.com/package/n8n-nodes-bayarcash).
3. Search for **Bayarcash** when you add a node to a workflow.

The n8n guide to [installing community nodes](https://docs.n8n.io/integrations/community-nodes/installation/) has the full steps and other ways to install.

## Connect your Bayarcash account

The node signs in with a credential called **Bayarcash API**. To create it:

1. Add a **Bayarcash** node, and under the credential choose to create a new one.
2. Fill in the fields:

   | Field | What to enter |
   |---|---|
   | **Personal Access Token (PAT)** | Your Personal Access Token from the merchant dashboard. |
   | **Environment** | **Sandbox - api.console.bayarcash-sandbox.com/v3** while you test, or **Production - api.console.bayar.cash/v3** for real payments. It is set to **Production** until you change it. |

3. Save. n8n tests the credential by listing your portals.

Use a sandbox token with **Sandbox** and a production token with **Production**. They do not work across environments.

## What the node can do

Choose a **Resource**, then an **Operation**:

| Resource | Operation | What it does |
|---|---|---|
| Payment Intent | **Create** | Creates a payment and returns the `url` to send your customer to. |
| Payment Intent | **Get Status** | Gets a payment intent by its **Payment Intent ID**. |
| Payment Intent | **Delete** | Cancels a payment intent by its **Payment Intent ID**. |
| Portal | **List All Portals** | Lists your portals. |
| Portal | **Get Portal Channels** | Gets one portal, with its payment channels, by **Portal ID**. |
| Transaction | **Get Transaction by ID** | Gets one transaction by its **Transaction ID**. |
| Transaction | **List Transactions** | Lists transactions. Add **Filters** for **Order Number**, **Status**, **Payment Channel**, **Exchange Reference Number** or **Payer Email**. |

## Create a payment intent

To create a payment from a workflow:

1. Add a **Bayarcash** node and choose **Payment Intent** → **Create**.
2. Choose the portal in **Portal Name or ID**. The list comes from your account.
3. Fill in **Order Number**, **Amount**, **Payer Name** and **Payer Email**. These are required.
4. Optionally choose one or more **Payment Channel** values. Leave it empty to let the customer choose on the Bayarcash page.
5. Optionally fill in **Payer Telephone Number**, **Callback URL** and **Return URL**.
6. Run the node. Send the `url` from its output to your customer, for example by email or WhatsApp.

## Receive the result in n8n

The Bayarcash node does not start workflows by itself. To act when a payment finishes:

1. Start a second workflow with n8n's **Webhook** node, set to receive a POST.
2. Put that webhook's URL in **Callback URL** when you create the payment intent.
3. In the callback workflow, verify the `checksum` with your API Secret Key before you trust the data. See [Verify callbacks and checksums](/callbacks-and-checksum/).
4. Use **Get Transaction by ID** with the callback's `transaction_id` to read the full, current record.

Make the webhook answer with HTTP 200, or Bayarcash sends the callback again.

## Tips

- **Build the workflow on the sandbox first.** Switch the credential's **Environment** to **Production**, with a production token, only once a test payment runs end to end.
- **Keep the order number unique for each payment.** It is how you match a callback or transaction back to the row, deal or invoice that started the workflow.

## Common issues

### The node fails with "Authentication failed: Invalid or expired PAT token. Please check your credentials." What should I check?

Check that you pasted the whole Personal Access Token, and that Environment matches where the token came from. A sandbox token only works with Sandbox, and a production token only with Production.

### Creating a payment intent fails with "Forbidden" and mentions the payment channel. Why?

The channel you chose in Payment Channel is not enabled on your account. New accounts only have FPX. Choose another channel, leave the field empty, or ask Bayarcash to enable the channel.

### Why does Get Portal Channels say the resource does not exist?

Portal ID needs the portal's ID, not its portal key. Run List All Portals first and copy the ID from its output.
