For the complete documentation index, see llms.txt. This page is also available as Markdown.

Sphere-hosted Checkout

Create a Sphere-hosted checkout page where Sphere calculates tax and Stripe processes payment in a single API call.

Overview

Sphere-hosted Checkout is the simplest way to take a Stripe payment with Sphere tax applied. You make one server-side API call with your cart; Sphere returns a hosted checkout URL you redirect the buyer to. Sphere renders the checkout page, collects the buyer's address (and tax ID where it applies), calculates tax live, and Stripe processes the payment.

Unlike the Stripe Elements and Stripe-hosted Checkout flows, you do not call the Tax Calculation API or create Stripe Tax Rate objects yourself. Sphere handles tax end to end.

  1. Create a hosted checkout session (one API call) and receive a checkout URL.

  2. Redirect the buyer to the URL.

  3. The buyer completes checkout on Sphere's page; Sphere applies tax and Stripe takes payment.


Step 1: Create a hosted checkout session

Make a POST request with your Sphere API key. The checkout_session object accepts standard Stripe Checkout Session parameters (line items, mode, and so on). Sphere forwards them to Stripe and layers tax on top.

Endpoint: https://api.getsphere.com/v1/stripe/checkout/hosted_sessions

Request Headers:

  • Header Key: X-API-KEY

  • Header Value: YOUR_API_KEY

Sample Request (one-time payment):

curl -X POST https://api.getsphere.com/v1/stripe/checkout/hosted_sessions \
  -H "Content-Type: application/json" \
  -H "X-API-KEY: sph_api_key" \
  -d '{
    "success_url": "https://your-site.com/order/complete",
    "publishable_key": "pk_live_your_key",
    "checkout_session": {
      "mode": "payment",
      "line_items": [
        {
          "price_data": {
            "currency": "usd",
            "product_data": { "name": "Pro plan" },
            "unit_amount": 4000
          },
          "quantity": 1
        }
      ]
    }
  }'

Sample Response:

Notes:

  • success_url (required): where the buyer is sent after a successful payment.

  • publishable_key: your Stripe publishable key (pk_…), used to mount the session in the buyer's browser. It is not a secret. On a direct-install Connect connection you may omit it, and Sphere uses the connected account's own key.

  • checkout_session: your Stripe Checkout Session parameters. Use price IDs instead of price_data if you prefer, set "mode": "subscription" for recurring billing, "allow_promotion_codes": true, and so on.

  • Sphere owns the hosted experience and tax, so a few Stripe parameters are set for you and rejected if included: ui_mode, return_url, cancel_url, success_url (use the top-level success_url instead), and the tax parameters automatic_tax, tax_id_collection, and the line-item tax_rates and dynamic_tax_rates.

  • Optional prefill pre-populates the form: "prefill": { "country": "US", "email": "buyer@example.com", "name": "Ada Lovelace" }.


Step 2: Redirect the buyer

Redirect the buyer to the url from Step 1. On Sphere's hosted page the buyer enters their email and address (and a tax ID where reverse charge applies), Sphere calculates tax from the address in real time, and Stripe's Payment Element collects payment. On success the buyer is returned to your success_url.


What Sphere handles

  • Tax, calculated live from the buyer's address - US sales tax, EU/UK VAT, GST, and more.

  • Reverse charge applied automatically when the buyer enters a valid tax ID in a supported jurisdiction.

  • One-time payments and subscriptions, via mode.

  • The hosted page, the Stripe Payment Element, and the order summary.

Notes:

  • Checkout sessions expire 24 hours after creation.

  • (Connect) A platform creating sessions on a connected account can pass stripe_account_id.


API reference

The full request and response schema for the hosted checkout endpoint, generated from the Sphere API's OpenAPI specification.

The checkout_session object accepts the standard Stripe Checkout Session create parameters such as line_items, mode, subscription_data, allow_promotion_codes, and so on - except the few Sphere sets for you (listed under Step 1).

Start a Sphere-hosted embedded checkout

post
/stripe/checkout/hosted_sessions

Send the cart, currency, and a success_url (plus your publishable key, unless it is a direct-install connection whose key Sphere already holds). Sphere creates an embedded Stripe Checkout Session (no tax yet) and returns a url. Redirect the buyer to it instead of to Stripe; they enter their address on the Sphere-hosted page, tax is attached to the session, and they pay there via Stripe's embedded Checkout.

Authorizations
X-API-KEYstringRequired
Body

checkout_session takes your own checkout.sessions.create params and forwards them to Stripe, except the ones Sphere sets itself. The other fields have no Stripe equivalent: publishable_key mounts the session in the browser (it is not a secret) and may be omitted on a direct-install connection, where Sphere uses the connected account's own key. success_url becomes the session's return_url. allow_promotion_codes is set at the top level, not inside checkout_session.

publishable_keystring · nullableOptionalDefault: nullPattern: ^pk_
stripe_account_idstring · nullableOptionalDefault: nullPattern: ^acct_
success_urlstring · min: 1Required
allow_promotion_codesbooleanOptionalDefault: false
Responses
201Success
application/json

Redirect the buyer here instead of to Stripe. Opaque — do not parse it.

urlstringRequired
post/stripe/checkout/hosted_sessions
POST /v1/stripe/checkout/hosted_sessions HTTP/1.1
Host: api.getsphere.com
X-API-KEY: YOUR_API_KEY
Content-Type: application/json
Accept: */*
Content-Length: 220

{
  "publishable_key": "text",
  "stripe_account_id": "text",
  "success_url": "text",
  "allow_promotion_codes": false,
  "prefill": {
    "country": "text",
    "email": "text",
    "name": "text"
  },
  "checkout_session": {
    "ANY_ADDITIONAL_PROPERTY": "anything"
  }
}
{
  "url": "text"
}

Last updated

Was this helpful?