JS SDK

Track purchase status with our JavaScript SDK.


Overview

The Ramp Instant widget sends some events that you can react to in your web app.

Each event has the following fields:

  • type - type of the event, i.e. what happened,
  • payload - any additional info related to the event,
  • widgetInstanceId - a random number-string, unique to each widget instance. You can use this if you have many instances of the widget and want to distinguish which event came from which instance.

Available Events

The package also exports a RampInstantEvents type which contains all possible events and RampInstantEventTypes which is an enum of all possible event type values.

Subscribe to events

In order to subscribe to an event, use the .on(eventType, callback) method on your SDK instance.

The .on(eventType, callback) method accepts either a string with the event's type when you want to subscribe to a specific kind of an event, or * for subscribing to all event.

  • callback is called each time a given event occurs.
  • .on(eventType, callback) is chainable.

The callback function will receive an event object which will contain details specific to given even type. Check events reference for more details.

Examples

Listen to purchase created event

import { RampInstantSDK } from "@ramp-network/ramp-instant-sdk";

let widget = new RampInstantSDK({...});

widget.on("PURCHASE_CREATED", (event) => {
  // ... do something useful

  console.log(event.payload.purchase.id);
  console.log(event.payload.purchase.fiatValue);
  console.log(event.payload.purchase.fiatCurrency);
});

Listen to all events

import { RampInstantSDK } from "@ramp-network/ramp-instant-sdk";

let widget = new RampInstantSDK({...});

widget.on("*", () => {
  // ... do something useful
});