Skip to Content
Docs

Update metadata

Attach key-value metadata to an active payment session from the browser for routing rules.

checkout.updateMetadata() attaches key-value pairs to an active payment session from the browser so your routing rules can react to customer choices (such as a promotion toggle or shipping tier) without recreating the session.

checkout.updateMetadata(
  metadata: Record<string, string | number | boolean>
): Promise<void>

Parameters

ParameterTypeRequiredDescription
metadataRecord<string, string | number | boolean>YesKey-value pairs to attach to the session (at least one). Nested objects and arrays are not supported.

Returns

Promise<void>. Resolves when metadata is saved and rejects if the call fails.

Behavior

Every call follows these rules.

PropertyBehavior
TimingCall it after the content_ready (Universal checkout) or headless_ready (Headless checkout) event fires. Listen for them with checkout.on(). Calling it before rendering rejects with Unable to perform checkout actions before rendering.
Repeat callsAllowed. Call it as many times as you need before payment is submitted.
Merge semanticsEach call is a partial update. Keys you send are added or overwritten, and keys you don't send are left unchanged.
ValuesStored as text. For example, true becomes "true", and 3 becomes "3".
ScopeThe current checkout session only. A new pay.checkout(...) call starts a fresh session with its own metadata.
UI effectNone. Metadata doesn't change what the customer sees, the amount, or the available payment methods.

Key naming

Each key you send is stored on the session with a checkout_ prefix. A key named customer_tier becomes metadata.checkout_customer_tier in routing rule conditions. Send the plain key. The prefix is added automatically.

The prefix separates metadata set from the browser from metadata set on the server when the session was created, so your routing rules can distinguish between the two sources. Values arrive as text, so compare against "true", not true.

Errors

The promise rejects with the standard Pay.com error shape:

try {
  await checkout.updateMetadata({ customer_tier: 'gold' })
} catch (error) {
  // error.message → 'Failed to update metadata'
  // error.data    → the metadata object you passed
}

Always await the call or attach a .catch() handler. Otherwise, a failed call surfaces as an unhandled promise rejection on your page.

Example

const pay = await Pay.com({ identifier: 'YOUR_MERCHANT_ID' })

const checkout = pay.checkout({
  clientSecret: CLIENT_SECRET,
  onSuccess: (payment) => console.log('Payment succeeded:', payment),
  onFailure: (error) => console.log('Payment failed:', error),
})

checkout.universal({ container: '#payment-element' })

// Wait for the SDK to render, then update metadata when the customer acts
checkout.on(checkout.EVENT_TYPES.CONTENT_READY, () => {
  // A customer opts into a draw. Update metadata so routing rules can
  // send this payment to the correct processor
  document.querySelector('#enter-draw').addEventListener('change', async (e) => {
    await checkout.updateMetadata({ enter_draw: e.target.checked })
  })
})

A routing rule referencing metadata.checkout_enter_draw can then direct the payment to a different acquirer when the value is "true". You create routing rules in the Pay.com dashboard. See Routing rules.

Don't put cardholder data, PII you don't need, or secrets in metadata. It's stored on the transaction and visible wherever the transaction is visible.

Next steps

Was this page helpful?