# Take online payments with Yoco

Connect your Yoco account so customers can pay for bookings by card through Yoco's hosted checkout, refunds can be sent back through Yoco, and Finance → Takings can check what your card machine took. You need a Yoco merchant account, its Checkout API secret key, and a verified domain at Yoco before live keys unlock.

Source: https://help.pigi.io/guides/integrations/payments/yoco

## Quick answers

**Which Yoco keys does PiGi need?**
Only the **Secret Key** is required. It starts with `sk_test_` for sandbox or
`sk_live_` for production. The **Public Key** is optional and only used for an inline
popup. The **Business API Key** is optional and only powers the Yoco check on
Finance → Takings.

**Where do I find my Yoco secret key?**
In the Yoco app, open the Checkout API integration (app.yoco.com → Connect → Checkout
API) and tap **How to connect**. Test keys are shown straight away; live keys appear
there once your domain is verified.

**Why are my Yoco live keys locked?**
Yoco keeps the live public and secret keys locked until you verify at least one
domain under **Verified Domains** in the Yoco app. Tap **Add domain**, enter your
business website, and wait for Yoco to approve it. Test keys work before that.

**What is the Yoco Business API Key and do I need it?**
You don't need it to take payments. It lets PiGi read what your Yoco account took —
card machine and online — so Finance → Takings can match hand-written payments to
real swipes. Create it in the Yoco Developer Console at developer.yoco.com/ui. Yoco
shows the key only once, so copy it straight into PiGi.

**Does the Business API Key read my test or live account?**
Always your live Yoco account, even while the Yoco gateway in PiGi is set to Sandbox.
It is read-only, so nothing is charged.

**Do I need to set up a webhook in Yoco?**
No. When your keys pass **Verify**, PiGi registers its own notification address with
your Yoco account. That way a customer who pays and closes the page before coming
back still has their booking marked as paid.

**Can I refund a Yoco payment from PiGi?**
Yes, for payments made through PiGi's online checkout — full or part of the amount.
Switch on **Enable Programmatic Refunds** under the gateway's **Refunds** row first.
Payments taken on the card machine have to be refunded on the machine or in Yoco.

**Why can't I pick Production for Yoco?**
Production is only offered on the live PiGi site and only once production keys are
stored. Add your `sk_live_` key under the **Production** tab of the credentials
dialog first.

**I get "Test keys cannot be used in production environment". What's wrong?**
You saved an `sk_test_` key in the Production credentials. Replace it with your
`sk_live_` key. The reverse message, "Live keys should not be used in sandbox
environment", means a live key is in the Sandbox credentials.

## What this does

Connecting Yoco lets customers pay for bookings and gift vouchers by card on Yoco's
hosted checkout page, then returns them to PiGi with the booking marked as paid.
PiGi can also send refunds back through Yoco and, with the optional Business API Key,
compare what Yoco actually took with what your staff recorded on Finance → Takings.

You need a Yoco merchant account. Yoco charges a fee per transaction — see Yoco's
pricing page for current rates. PiGi does not add Yoco's fee to the customer's total.

## Before you start

- The **admin** role on your company in PiGi.
- A Yoco merchant account with access to the Yoco app (app.yoco.com).
- For live payments: a business website you can verify with Yoco.
- Optional: access to the Yoco Developer Console for the Business API Key.

## Set up Yoco

1. Sign in to the Yoco app and open the **Checkout API** integration (Connect →
   Checkout API), then tap **How to connect**.
2. Copy the **test secret key** (`sk_test_…`). Copy the test public key too if you
   want it.
3. To unlock live keys, go to **Verified Domains → Add domain**, enter your website
   address and wait for Yoco to approve it. Then copy the **live secret key**
   (`sk_live_…`) from the same **How to connect** screen.
4. Optional: open the Yoco Developer Console (developer.yoco.com/ui) and create an
   API key for your application. Yoco shows it only once — keep it somewhere safe
   until you paste it into PiGi.

## Connect it to PiGi

1. Open **Company → Settings → Finance → Payment Gateways** and click **Connect** on
   the Yoco card, then **Connect Yoco**. The credentials dialog opens.
2. On the **Sandbox** tab, paste the `sk_test_…` key into **Secret Key** (and the
   optional **Public Key** and **Business API Key**), then click **Save
   credentials**.
3. Click **Verify sandbox connection**. "Credentials verified successfully" means
   Yoco accepted the key, and the status pill reads "Connected".
4. Switch to the **Production** tab, paste your `sk_live_…` key and click **Save
   credentials**, then **Verify production connection**.
5. In the Yoco sheet, turn on **Offer at booking checkout** so customers see Yoco
   when they book online. For invoice "Pay Now" links, also tick Yoco under
   Invoicing → Settings → Online Payments.
6. To send refunds through Yoco, open **Refunds**, switch on **Enable Programmatic
   Refunds** and click **Save**.
7. When you're ready for real money, click **Production** on the Sandbox |
   Production switch in the Yoco sheet and confirm with **Go live**. The toast reads
   "Yoco now uses production". Other gateways are not changed.

The full screen — fees, limits, ordering and the page-wide Sandbox/Production
switch — is covered in [Connect a payment gateway](../company-setup/payment-gateways.md).

## Test it

1. With Yoco on **Sandbox** and offered at checkout, make a booking on your public
   booking page and choose Yoco.
2. On Yoco's page, pay with the test card shown under **Test card details** in the
   Yoco app's How to connect screen.
3. Check the booking in PiGi shows the payment. Yoco test transactions do not appear
   on your Yoco dashboard or sales report.
4. After going live, make one small real payment and refund it from PiGi to prove
   both directions.

## Troubleshooting

| Message | Fix |
|---|---|
| "Secret Key is required" / "Secret key is required" | Enter the secret key; it is the one required field. |
| "Secret Key format is invalid" or "Invalid secret key format - should start with sk_test_ or sk_live_" | You pasted the public key or a Business API Key into Secret Key. Use the `sk_…` key. |
| "Test keys cannot be used in production environment" | Put the `sk_live_` key in the Production credentials. |
| "Live keys should not be used in sandbox environment" | Put the `sk_test_` key in the Sandbox credentials. |
| "Invalid credentials - Yoco refused this secret key" | The key was revoked, mistyped or belongs to another account. Copy it again from How to connect. |
| "Unexpected answer from Yoco (HTTP …)" | Yoco answered with something other than its API. Try again later; if it persists, contact PiGi support. |
| "Could not connect to payment gateway" / "Connection timed out - gateway may be unavailable" | Yoco could not be reached. Try again later. |
| "No Yoco business API key stored…" on Takings | Add the **Business API Key** under the gateway's credentials. |
| "Yoco will not return more than 31 days at a time." | Pick a shorter date range on Takings. |

## Known limitations

- Verify checks only the Secret Key. A wrong Business API Key shows up as an error on
  the Takings Yoco check, not when you verify.
- Card-machine payments cannot be refunded from PiGi — refund them on the machine or
  in Yoco.
- Saved keys are never shown back to you, not even partly. If you lose one, copy it
  again from Yoco.
- PiGi's notification registration happens quietly when you verify; the screen does
  not confirm it separately.

## Sources

- [Yoco Checkout API — authentication and keys](https://developer.yoco.com/docs/checkout-api/authentication.md)
- [Yoco Checkout API — testing](https://developer.yoco.com/docs/checkout-api/testing.md)
- [Yoco Checkout API — refund a checkout](https://developer.yoco.com/api-reference/checkout-api/checkout/refund-checkout.md)
- [Yoco API — managing API keys](https://developer.yoco.com/docs/api/authentication/api-keys/managing-api-keys.md)
