Events

Table of contents

  1. onOpenPaymentWindow
  2. onClosePaymentWindow
  3. onUpdated
  4. onPaymentAccepted

You can listen for various events emitted throughout the paymnet lifecycle. These events allow you to track user interactions (such as opening or closing the payment window), get real-time updates to the payment status and handle the outcome once a payment is accepted.

You do not need to initialize the button with the JS SDK to listen for events, the events will be triggered on the element.

<script src="https://cdn.posfra.com/posfra.js"></script>

<div 
  class="posfra-pay-button"
  embed-token="f419128f528d75174399b3662a2e0ceaed29b98a59cbc9d33601fa2f903c1b6f"
  usd="50"
></div>

<script>
  document.addEventListener('DOMContentLoaded', () => {
    const element = document.querySelector('.posfra-pay-button');

    element.addEventListener('onOpenPaymentWindow', (event) => {
      console.log('The button was clicked', event);
    });
  });
</script>

onOpenPaymentWindow

Triggered when a user clicks the button to open the payment popup.

onClosePaymentWindow

Triggered when the user closes the payment popup (either manually or after payment is complete).

onUpdated

Fired whenever the transaction status changes or new data is available (providing updated transaction details).

onPaymentAccepted

Fired when the payment is successfully accepted and confirmed, including transaction details (amount, ref, txid, etc.).


No AI was used in the creation of this documentation.