# Vendure

Part of the Orboni API reference: https://orboni.com/docs. This page: https://orboni.com/docs/vendure.

The Orboni plugin adds crypto to a Vendure store. The buyer chooses Orboni at the payment step and pays on Orboni’s payment page, picking a coin and paying from any wallet or exchange. The money goes to the wallets you set in the dashboard, and the order is paid once the payment is final — by the webhook or the buyer’s return, whichever comes first.

It is a payment plugin for Vendure 3, tested end to end on Vendure 3.8. It is free, and its source is open, under the MIT licence: https://github.com/orboni/vendure-plugin-orboni on GitHub, https://www.npmjs.com/package/@orboni/vendure-plugin on npm.

## Set it up

```bash
npm install @orboni/vendure-plugin
```

In `vendure-config.ts`, add it to the plugins, then restart the server:

```ts
import { OrboniPlugin } from '@orboni/vendure-plugin';

export const config: VendureConfig = {
  // …
  plugins: [
    // …
    OrboniPlugin.init(),
  ],
};
```

1. In the Orboni dashboard, set the wallets you want to be paid to under Wallets, and copy a secret key under Developers → API keys — a test key (`sk_test_…`) first.
2. In the Vendure dashboard, open Settings → Payment methods, create one with the **Orboni** handler (say, “Crypto (USDT, USDC, BTC and more)”, code `crypto`), enter the Secret key, and the Return address of your storefront’s page for a paid order (below). Assign it to your channel.
3. In the Orboni dashboard, under Developers → Webhooks, add an endpoint at `https://<your Vendure server>/payments/orboni/<channel token>` (the token is under Settings → Channels) with the `checkout.session.*` events, and enter its signing secret (`whsec_…`) as the payment method’s Webhook signing secret.
4. Send the buyer to the payment page from your storefront (below), place an order, and on its payment page, signed in to the dashboard, press **Simulate payment**: the order is paid. Then swap in your live key (`sk_live_…`) and the live endpoint’s secret. The key decides test or live at Orboni.

## The storefront

Orboni is a redirect payment: the storefront asks the Shop API for the order’s payment page, sends the buyer there, and records the payment when they come back. With a Return address such as `https://shop.example.com/order/{ORDER_CODE}?session={CHECKOUT_SESSION_ID}` the page knows both:

```graphql
# The payment step: the order has its customer, address and shipping.
mutation {
  createOrboniPaymentIntent(input: { paymentMethodCode: "crypto" }) {
    url        # send the buyer here
    sessionId
  }
}

# Back from the payment page (the Return address carries the session):
mutation {
  addPaymentToOrder(input: { method: "crypto", metadata: { sessionId: "cs_…" } }) {
    ... on Order { code state }        # PaymentSettled, or PaymentAuthorized
    ... on ErrorResult { errorCode message }
  }
}
```

`createOrboniPaymentIntent` moves the active order to ArrangingPayment and takes `successUrl` and `cancelUrl` too, over the payment method’s. Paying again opens the same page while the order’s total stays the same. When the buyer is back before the money is final, `addPaymentToOrder` answers with an error that says why (not paid yet, part paid): show it, and let the buyer pay or choose another way. When the webhook was first, the order is no longer active: read it with `orderByCode`.

## How orders move

The plugin reads the payment back from Orboni with your key before Vendure records it, so a webhook sent twice, late or out of order changes nothing, and a storefront cannot record a payment that is not there. Without the webhook a payment is still recorded once the buyer comes back; a buyer who pays and closes the tab needs it, so set it up all the same.

| Payment | Orboni says | In Vendure |
| --- | --- | --- |
| Paid in full | `complete, paid` | A Settled payment naming the coin, the order PaymentSettled — by the webhook or the buyer’s return, whichever comes first |
| On the chain, not final yet; or held for your review | `processing, held` | An Authorized payment, the order PaymentAuthorized; settled by the webhook once paid |
| Part paid | `partially_paid` | Nothing recorded; the payment page asks the buyer for the rest |
| Back before paying | `open, unpaid` | Nothing recorded, the buyer told so; paying again opens the same page |
| Ran out unpaid | `expired` | Nothing recorded |
| Money that paid it left the chain | `payment_reversed` | A private note on the order not to ship it until the dashboard shows it paid again |

An order taken back to AddingItems and changed gets a new page for its new total, and the old one is closed, so it can no longer be paid.

## The payment method’s settings

| Setting | Type | What |
| --- | --- | --- |
| Secret key | string | Required. sk_test_… or sk_live_…; the key decides test or live. |
| Webhook signing secret | string | The endpoint’s whsec_…. Without it the webhook is answered 503 and nothing is read. |
| Return address | string | Your storefront’s page the buyer comes back to; {ORDER_CODE} is filled in by the plugin, {CHECKOUT_SESSION_ID} by Orboni. |
| Back address | string | Where the payment page’s back link goes; {ORDER_CODE} is filled in. |

## Good to know

- The currency: the order’s own — US dollars, euros, pounds, yen or any other currency a checkout session takes (Currencies in the API reference). The payment page shows the total in it, and the buyer pays its worth in the coin they pick. In a currency Orboni does not take, the intent fails with a reason, and the buyer chooses another way.
- The least is worth $1.00. Below it the intent fails with Orboni’s reason.
- Refunds: the money is in your wallet, so send it back from there, then refund the payment in Vendure: it is recorded in Orboni, and nothing moves by itself.
- Several channels, or several Vendure servers, can share one Orboni project: each channel adds its own endpoint, with its token in the address, and acts only on its own orders.
- Errors from Orboni reach the storefront with Orboni’s own message, as “Orboni: …”, and Vendure’s log under OrboniPlugin; keys and secrets never do.

## What the plugin sends

Each intent makes a checkout session through `POST /v1/checkout/sessions`, with an idempotency key of the channel, the order and its total, so a double press never makes a second one.

| Parameter | Type | What |
| --- | --- | --- |
| `amount` | integer | What is left to pay of the order, in the currency’s smallest unit: cents, or whole yen. |
| `currency` | string | The order’s currency, in lower case: usd, eur, jpy… |
| `description` | string | The order’s lines with their quantities: “Blue mug × 2”; cut at 250 characters. |
| `details` | string | The order code: “Order PTZ6JXBG23H3GXRD”. |
| `client_reference_id` | string | The order code, which the webhook finds the order by. |
| `metadata` | object | vendure_order_code, vendure_order_id, vendure_channel (the channel’s token) and vendure_payment_method (the method’s code). |
| `customer_email` | string | The order’s customer’s email, where Orboni sends the receipt when your project sends receipts. |
| `locale` | string | The request’s language, as en. |
| `success_url`, `cancel_url` | string | The storefront’s, or the payment method’s Return and Back addresses. |

No address, phone number or other buyer data is sent. A payment in the dashboard, an export or a webhook leads to its order by `client_reference_id`, and an order to its payment by the session id, the payment’s transaction id in Vendure.
