ROKIConnect
Connectors Start API SDKs Migrate MCP Portal ES
DocumentationMode 4 - Hosted fields

Mode 4 - Hosted fields

You build the whole checkout page. ROKI hosts three iframes - card number, expiry, CVV - that you place anywhere in your layout. Amount, currency and customer are locked on your server in a sale session; the browser receives only a client_secret and cannot change them. There is no tok_* and no separate confirm call: fields.pay() charges the session. If 3-D Secure is required, ROKI opens the challenge in a modal on your page and pay() resolves after it.

Verified 2026-10-28: session creation, idempotent replay, conflict, read, not-found, expired expires_at, unknown fields, and that the browser SDK at /connect/components/v1/roki.js ships hostedFields, clientSecret and load_error. A charge through fields.pay() with a card was not run.

27.1 Create the sale session (backend)

POST /api/connect/v1/sales/sessions
Authorization: Bearer sk_test_...
Idempotency-Key: venta-13

{
  "amount": 349.00,
  "currency_code": "HNL",
  "external_reference": "venta-13",
  "description": "First month",
  "customer": {
    "name": "Maria Lopez",
    "email": "maria@example.com",
    "phone": "+50499999999",
    "identification_type": "DNI",
    "identity_number": "0801199012345"
  },
  "metadata": { "sale_id": "13" }
}

Required: amount, currency_code, external_reference, customer with name, email, identification_type and identity_number, and the Idempotency-Key header. Optional: customer.phone, description, metadata, expires_at (Honduras time, future; default 30 minutes after creation), three_ds_return_url.

What the probe measured:

Case Answer
First call
201, status: "open", session_id and client_secret
Same key, same body
200, same session, no client_secret
Same key, different body
409 idempotency_conflict
Unknown field
201, field ignored, named in warnings (like POST /payments)
expires_at in the past
422 expires_at_invalid
Missing fields
all reported at once in errors; code names one of them
currency_code
echoed as sent: "HNL" returns "HNL", "340" returns "340"

Keep the client_secret from the first response. It is never shown again - not on replay, not on GET /sales/sessions/{session_id}. If your first request timed out after ROKI created the session, a replay gives you the session without the secret: create a new session with a new key.

27.2 Mount and pay (frontend)

<div id="card-number"></div>
<div id="card-expiry"></div>
<div id="card-cvv"></div>
<button type="button" id="pay-btn">Pay</button>

<script src="https://aura.roki.systems/connect/components/v1/roki.js"></script>
<script>
  const fields = RokiConnect({ publishableKey: 'pk_test_...', locale: 'es' })
    .hostedFields({ clientSecret, locale: 'es' });   // clientSecret from your backend

  fields.on('load_error', (err) => {
    // publishable_key_invalid, sale_session_client_secret_invalid,
    // sale_session_not_open, sale_session_expired
    showError(err.message);
  });

  fields.create('cardNumber').mount('#card-number');
  fields.create('expiry').mount('#card-expiry');
  fields.create('cvv').mount('#card-cvv');

  document.getElementById('pay-btn').addEventListener('click', async () => {
    const result = await fields.pay();   // approved | declined, after any 3DS modal
    if (result.status === 'approved') showThanks(result.brand, result.last4);
    else showError((result.Errors && result.Errors[0] && result.Errors[0].Message) || result.message);
  });
</script>

Pass the SDK only pk_* and client_secret - never amount or customer. A session is paid once; calling pay() again returns the first result. Fulfil the order from the payment.approved webhook, exactly as in every other mode; GET /sales/sessions/{session_id} (open or paid, with transaction_id, brand, last4, paid_at once paid) is a status check, not the webhook body.