@solvapay/react components (checkout, top-up, plans, balance, renewals,
auto-recharge, history) call a set of routes on your backend: /api/check-purchase,
/api/create-payment-intent, /api/list-plans and so on. NewWebHandler serves
all of them from Go, with the same answers as the TypeScript SDK: a shared
conformance suite checks both on every change.
Your React app doesn’t change. Only the backend behind /api is Go.
Prerequisites
- A SolvaPay product with at least one plan, and a sandbox secret key in
SOLVAPAY_SECRET_KEY. See Installation. - A web app that signs its users in. The routes act for the user your app has verified; they never sign anyone in themselves.
- The React components set up in your frontend. See the React guide.
Serve the routes
NewWebHandler returns an http.Handler. GetUser is required: it verifies the
request with your app’s own auth and answers who the user is. Answer nil, nil
when there’s no valid session (the route answers 401), and an error when the check
itself failed (500).
main.go
NewWebHandler returns an error when Client or GetUser is nil, so a server
can’t start without an identity check.
Options on WebOptions:
Point the React components at it
SolvaPayProvider sends your app’s credentials on every call. With a session
cookie on the same origin, the browser sends it by itself. With a bearer token,
pass it through an auth adapter:
Who the customer is
- Only
GetUserdecides.WebUser.IDbecomes the SolvaPay customer’sexternalRef. The customer is created on first use, with the email and name you return. - No user, no access. A nil user gets a 401 before SolvaPay is called. There’s no anonymous or default customer.
- Nothing the browser sends is identity. An
x-user-idheader is ignored. A cachedx-solvapay-customer-refis used only when that customer belongs to the verified user. - Purchases are checked. Cancelling or reactivating a renewal works only on the caller’s own purchase (403 otherwise), and auto-recharge is always saved for the caller’s own customer.
merchant, get-product and list-plans answer without a user, as in TypeScript.
Routes
Another path answers 404, and a known path with the wrong method answers 405 with
Allow. Webhooks aren’t among them: mount a receiver with
VerifyWebhook.
Where Go differs
On paths no shared case covers, Go is stricter than TypeScript:- A failed customer read in
check-purchase, or a failed balance read during a top-up, fails the request. - A body that isn’t a JSON object gets 400
Invalid JSON body. A required string field that isn’t a non-empty string, or a top-upamountthat isn’t above 0, gets the same 400 as a missing one.
Example
examples/react-web-checkout
runs one React app against a Go and a Python backend. Checkout, top-up, renewals,
auto-recharge and history were tested on both in sandbox.