Trigger {#uc-integration-methods-trigger}
=========================================

Trigger UI {#uc-integration-methods-trigger_section_rrx_wlh_njc}
----------------------------------------------------------------

This image shows the `Unified Checkout` trigger UI.

#### Figure: {#uc-integration-methods-trigger_fig_unb_2qh_njc}

`Unified Checkout` Trigger UI ![](/content/dam/documentation/cybs/en-us/topics/payments-processing/card-processing/unified-checkout/images/uc-int-trigger-750x315.svg/jcr:content/renditions/original)

Trigger Integration JavaScript Example {#uc-integration-methods-trigger_section_iqk_xlh_njc}
--------------------------------------------------------------------------------------------

```
// ============================================================
// TRIGGER API - USAGE GUIDE V2
// ============================================================

// Triggers load the payment UI without displaying the Unified Checkout
// button. Use when a custom event should initiate the payment flow.
// Supported payment types: PANENTRY and CLICKTOPAY only.

// IMPORTANT: Trigger always opens in SIDEBAR mode only.
// The displayMode: 'sidebar' option must be set when creating the trigger.
// The merchant provides their own button/element to launch the payment flow.

// ============================================================
// FLOW 1: AUTO-PROCESSING (autoProcessing: true)
// Mount returns complete payment result
// ============================================================

// Initialize the Unified Checkout client
const client = await window.VAS.UnifiedCheckout(sessionJWT);

// Create trigger — sidebar is the only supported display mode for Trigger
const trigger = client.createTrigger('PANENTRY', {
    displayMode: 'sidebar',
    autoProcessing: true
});

// Mount is called when the merchant's own button is clicked
// This opens the sidebar payment UI and resolves when payment is complete
document.getElementById('your-pay-button').addEventListener('click', async () =&gt; {
    const paymentResult = await trigger.mount('#payment-container');
    console.log('Payment complete:', paymentResult);
});

// Clean up
trigger.destroy();


// ============================================================
// FLOW 2: MANUAL COMPLETE (autoProcessing: false)
// Mount returns transient token, then the merchant can manually complete payment
// ============================================================

// Initialize the Unified Checkout client
const client = await window.VAS.UnifiedCheckout(sessionJWT);

// Create trigger with auto-processing disabled
const trigger = client.createTrigger('PANENTRY', {
    displayMode: 'sidebar',
    autoProcessing: false
});

// Mount is called when the merchant's own button is clicked
document.getElementById('your-pay-button').addEventListener('click', async () =&gt; {
    const token = await trigger.mount('#payment-container');
    console.log('Received token:', token);

    // Manually complete the payment
    const paymentResult = await trigger.complete(token);
    console.log('Payment complete:', paymentResult);
});

// Clean up
trigger.destroy();


// ============================================================
// FLOW 3: TRANSIENT TOKEN ONLY (autoProcessing: false, no complete)
// Mount returns transient token only — server handles payment authorisation
// ============================================================

// Initialize the Unified Checkout client
const client = await window.VAS.UnifiedCheckout(sessionJWT);

// Create trigger with auto-processing disabled
const trigger = client.createTrigger('PANENTRY', {
    displayMode: 'sidebar',
    autoProcessing: false
});

// Mount is called when the merchant's own button is clicked
document.getElementById('your-pay-button').addEventListener('click', async () =&gt; {
    const token = await trigger.mount('#payment-container');
    console.log('Received token:', token);

    // Pass transient token to your server for payment authorisation
    sendToServer(token);
});

// Clean up
trigger.destroy();


// ============================================================
// LIFECYCLE METHODS (available in all flows)
// ============================================================

// Mount - opens the sidebar payment UI (called from merchant's own click handler)
const result = await trigger.mount('#payment-container');

// Unmount - hide the form without destroying it
trigger.unmount();

// Remount - can mount again after unmounting
await trigger.mount('#payment-container');

// Check mounted state
const mounted = trigger.isMounted();  // true or false

// Destroy - permanently destroy the trigger
trigger.destroy();

// Check destroyed state
const destroyed = trigger.isDestroyed();  // true or false


// ============================================================
// EVENT HANDLING (optional for all flows)
// ============================================================

// Subscribe to events
trigger.on('mounted', () =&gt; console.log('Sidebar payment UI displayed'));
trigger.on('unmounted', () =&gt; console.log('Sidebar payment UI hidden'));
trigger.on('error', (err) =&gt; console.error('Trigger error:', err.code, err.message));
trigger.on('destroyed', () =&gt; console.log('Trigger destroyed'));


// ============================================================
// SUPPORTED TRIGGER TYPES
// ============================================================

// IMPORTANT: When using createTrigger() for Click to Pay,
// you must create a custom UI. See Click to Pay UI Guidelines.

client.createTrigger('PANENTRY', { displayMode: 'sidebar' });   // Manual card entry
client.createTrigger('CLICKTOPAY', { displayMode: 'sidebar' }); // Click to Pay


// ============================================================
// CAPTURE CONTEXT REQUIREMENT
// ============================================================

// The capture context allowedPaymentTypes must include the payment type
// used in createTrigger(). For PANENTRY, ensure your session request includes:
//
// "allowedPaymentTypes": ["PANENTRY", ...]
//
// Without PANENTRY in allowedPaymentTypes, createTrigger('PANENTRY') will
// fail silently and the sidebar will not open.
```

