npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nearpay/nearpay-sdk

v3.3.8

Published

SDK to conveniently communicate with NearPay widget

Downloads

144

Readme

NearPay Widget SDK

@nearpay/nearpay-sdk allows you to easily integrate the NearPay widget into your web app and communicate with it.

Using this SDK is not necessary, although it will simplify your experience and therefore is recommended.

It's written with TypeScript, with all the typings defined out of the box.

Installation

You can find the package here - https://www.npmjs.com/package/@nearpay/nearpay-sdk.

Install via Yarn:

yarn add @nearpay/nearpay-sdk

Install via npm:

npm install @nearpay/nearpay-sdk

Quick Start

import {
  NearPay,
  SignedWidgetParams,
  EventType,
  ResizePayload,
} from '@nearpay/nearpay-sdk';

// more info about params available at SignedWidgetParams definition
const params: SignedWidgetParams = {
  fromCurrency: '',
  fromAmount: '',
  toAmount: '',
  toCurrency: '',
  toWallet: '',
  signature: '',
  apiKey: 'your-public-api-key',
  contractCall: {
    method: '',
    args: {},
  },
};

const body = document.querySelector('body');

const widget = new NearPay({
  mountElement: body,
  environment: 'stage', // or production
  params,
});

// Subscribing to events
widget.addListener(EventType.Onload, (data: OnLoadedEvent) => {
  // react to changes!
});
// You can also subscribe to all events using wildcard
widget.addListener(EventType.Any, (data: WidgetEvent) => {
  // react to changes!
});

// render iframe
widget.init();

NearPay Events

NearPay widget notifies parent window (your website), via window.postMessage interface. In listener you get event object with browser type of MessageEvent. It has property data, which contains our event object with type WidgetMessageEventData and properties source and data, where data is object with type WidgetEvent.

Type of NearPay event :

interface WidgetMessageEventData {
  source: 'nearpay_widget';
  data: WidgetEvent;
}

Example of NearPay event:

{
    source: 'nearpay_widget',
    data: {
        type: 'onload',
        payload: {
            width: 480,
            height: 612
        }
    }
}

Available Events

All the typings for events and their payload are defined and exported from @nearpay/nearpay-sdk

// EventType is a union type that consist of every event type available
import {
  EventType,
  WidgetEvent,
  WidgetMessageEventData,
  OnLoadedEvent,
  OnErrorEvent,
  OnResizeEvent,
  OnExitEvent,
  OnStartedEvent,
  OnOperationCreated,
  OnPaymentSent,
  OnOperationPending,
  OnOperationSuccess,
  OnOperationFail,
  OnUnsupported,
  OnForceContinue,
  OnMerchantOrderIdExists,
  OnPaymentPending
} from '@nearpay/nearpay-sdk';

off-ramp events: | Event | Description | |----------|----------| | onoperationcreated | The user had been authenticated and order had been created | | onpaymentpending | The user entered the card and clicked "Confirm & Proceed" and received the deposit address | | onmerchantorderidexists | When an error is triggered that the merchantOrderId has already been used |

on-ramp events: | Event | Description | |---------------------------|-----------------------------------------------------------------------------| | onoperationcreated | The user had been authenticated and order had been created | | onpaymentsent | Sending payment data - the user clicked on Pay, does not contain data | | onoperationsuccess | The order completed, payment has been received | | onoperationfail | The order declined, due to service failure, fraud control, or other | | onoperationpending | The payment is pending to be confirmed | | onunsupported | Detected user country is unsupported | | onforcecontinue | The user clicks "Force continue" button and default country (US) is applied | | onmerchantorderidexists | When an error is triggered that the merchantOrderId has already been used |

📖 Integration Docs

Look for more info about integrating NearPay into your products here