RespireSoft InvoicingAPI docsReferenceWebhooks

Checkout.js

A small script that opens the hosted payment page from a button on your website. It never sees a secret key.

How it works

  1. Your server makes a checkout session with POST /v1/checkout_sessions (for an invoice or for an amount). The answer has a url that is shown only once.
  2. Your page loads checkout.js and shows a button for that url. On a desktop the payment page opens in an overlay. On a phone the browser goes to the page itself, and the payer comes back to your success_url or cancel_url.
  3. Your server learns the result from the checkout.completed and payment.succeeded webhooks. The browser events below are hints for your page only.

1. Make the session on your server

curl
curl -X POST https://api.invoicing.respiresoft.com/v1/checkout_sessions \
  -H "Authorization: Bearer $RESPIRESOFT_KEY" \
  -H "Idempotency-Key: order-1042" \
  -H "Content-Type: application/json" \
  -d '{"amount":4900,"currency":"EUR","description":"Order 1042","success_url":"https://shop.example/thanks","cancel_url":"https://shop.example/cart"}'
Node
const res = await fetch("https://api.invoicing.respiresoft.com/v1/checkout_sessions", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.RESPIRESOFT_KEY}`, "Idempotency-Key": "order-1042", "Content-Type": "application/json" },
  body: JSON.stringify({ amount: 4900, currency: "EUR", description: "Order 1042", success_url: "https://shop.example/thanks", cancel_url: "https://shop.example/cart" }),
})
const { url } = await res.json() // pass this to your page
PHP
$ch = curl_init("https://api.invoicing.respiresoft.com/v1/checkout_sessions");
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => ["Authorization: Bearer " . getenv("RESPIRESOFT_KEY"), "Idempotency-Key: order-1042", "Content-Type: application/json"],
    CURLOPT_POSTFIELDS => json_encode(["amount" => 4900, "currency" => "EUR", "description" => "Order 1042", "success_url" => "https://shop.example/thanks", "cancel_url" => "https://shop.example/cart"])]);
$url = json_decode(curl_exec($ch), true)["url"];
Python
import os, requests
r = requests.post("https://api.invoicing.respiresoft.com/v1/checkout_sessions",
                  headers={"Authorization": "Bearer " + os.environ["RESPIRESOFT_KEY"], "Idempotency-Key": "order-1042"},
                  json={"amount": 4900, "currency": "EUR", "description": "Order 1042", "success_url": "https://shop.example/thanks", "cancel_url": "https://shop.example/cart"})
url = r.json()["url"]

2. Show the button

<script src="https://pay.respiresoft.com/js/v1/checkout.js" async></script>
<respire-pay-button session="https://pay.respiresoft.com/c/Ab3…" label="Pay now"></respire-pay-button>

Or open it from your own code:

RespirePay.open({
  session: "https://pay.respiresoft.com/c/Ab3…",   // the url from step 1, or just the token at its end
  onComplete(e) { /* e.session: show a thank you, but confirm on your server */ },
  onFailed(e) {},
  onClose() {},
})

The button also fires bubbling DOM events respire-pay:complete, respire-pay:failed and respire-pay:close with detail: { session }.

Allowed websites

The payment page may only be shown in a frame on websites you list under Settings, Pay, Allowed websites. From any other website the page refuses to be framed and the button opens it in a new tab. Loading the script proves nothing and grants nothing, so any website can load it.

Confirm on your server

Never ship goods because the browser said "complete". Wait for the checkout.completed or payment.succeeded webhook, or for invoice.paid when the session was made for an invoice. Verify its signature as shown in the webhooks guide.