Skip to content
OnCharge.io
View as Markdown
Developer docs

Testing & going live

OnCharge does not currently offer a self-serve sandbox account. Test the parts you build against the published test vectors and local fixtures, then confirm the whole flow with a small live payment that you refund. If you need a separate test configuration for your store, ask your OnCharge contact before launch.

1. Request signing#

Check your signing code against the test vector before calling the API: with secret oc_sec_example_secret_do_not_use and timestamp 1767225600, a POST /api/v1/checkout/sessions with the sample body must produce 7b0e1f9370475ae2a926804c0c9927c5f391c8a3c2e09a8071d98891aa01fdc7.

Then make one real request with your keys. A wrong signature fails with 401 invalid_signature before anything is created, so this is safe. Common causes are listed under Errors.

2. Webhooks#

  • Unit-test your verifier with the webhook test vector (allow a large tolerance, because its timestamp is in the past).
  • Sign your own fixtures to test your handler end to end. With Node:
send-test-webhook.mjs
import { createHmac } from 'node:crypto';

const secret = process.env.ONCHARGE_WEBHOOK_SECRET;
const body = JSON.stringify({
  id: `evt_test_${Date.now()}`,
  type: 'payment.captured',
  created: Math.floor(Date.now() / 1000),
  livemode: false,
  data: { session_id: '8b0f6f2e-4d1a-4c4e-9a52-6f3e1d2c7b11', order_id: '1001', reference: 'order-1001', amount: 4900, currency: 'USD', status: 'captured' },
});
const t = Math.floor(Date.now() / 1000);
const v1 = createHmac('sha256', secret).update(`${t}.${body}`).digest('hex');

const res = await fetch('http://localhost:3000/api/webhooks/oncharge', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json', 'OnCharge-Event-Id': JSON.parse(body).id, 'OnCharge-Signature': `t=${t},v1=${v1}` },
  body,
});
console.log(res.status);

With the Node SDK, OnCharge.webhooks.generateTestHeader({ payload: body, secret }) builds the same header.

  • Send the same event twice and check that the second is ignored.
  • Send a tampered body and check that you respond 400.

3. Checkout display#

  • The page that shows the checkout must be on a registered store domain and served over HTTPS. Staging domains must be registered too.
  • If you use a Content Security Policy, allow frame-src https://app.oncharge.io (and script-src for the hosted script).
  • For local development, register localhost as a domain: a registered localhost may frame the checkout from any port. Remove it before launch if you do not need it.
  • Test on a phone: the iframe should resize to its content, and nothing on your page should cover it.
  • Create a session, wait 30 minutes and reload: you should create a fresh session instead of showing an expired one.

4. Shipments#

  • Report a tracking number for an unpaid session: expect 409 order_not_paid.
  • Report an invalid number: expect "status": "rejected" with tracking_number_invalid.
  • After your live test payment, report a real tracking number and check GET /api/v1/shipments?session_id=… shows in_transit.

5. A live end-to-end payment#

  1. Create a low-value order on your production store and pay with a real card.
  2. Confirm the payment.captured webhook marked the order paid, and that the shopper landed on your return_url.
  3. Refund it with POST /api/v1/refunds (with an Idempotency-Key) and confirm the refund.succeeded webhook.

Go-live checklist#

  • API secret and webhook secret are stored server-side only (not in the browser bundle, not in the repository).
  • Every production domain (with and without www) is registered for the store.
  • Sessions are created on the server with an Idempotency-Key per order or cart.
  • shipping is sent for every order that ships.
  • Orders are marked paid from the webhook or a server-side status check, never from the browser.
  • The webhook endpoint verifies OnCharge-Signature, deduplicates on the event ID and answers within 10 seconds.
  • Tracking numbers are reported for every shipped order (USPS, UPS, FedEx or DHL Express).
  • Refunds send an Idempotency-Key.
  • Server clock is synced (requests are rejected more than 300 seconds off).
  • RUO stores only: the compliance feed is connected and verified in the portal, and a reviewer login is set up.