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

@loke/webview-payments-client

v1.0.4

Published

SDK for making payments from a webview inside LOKE mobile apps.

Downloads

3

Readme

webview-payments-client

SDK for making payments from a webview inside LOKE mobile apps.

Installation

npm i @loke/webview-payments-client

Usage

Please refer to the example project for more context.

import { LokeApp } from "@loke/webview-payments-client";
const lokeApp = new LokeApp({ clientId: "loke-provided-client-id" });

Example React Project

import { LokeApp } from "@loke/webview-payments-client";

// You may want to pass in lokeApp as a prop, or initialise some other way
const lokeApp = new LokeApp({ clientId: "loke-provided-client-id" });

function App() {
  const handleClick = async () => {
    try {
      const { nonce } = await lokeApp.payment({
        total: 550,
        tax: 50,
        orderRef: "my-unique-ref",
        orderStoreId: "your-unique-id-shared-with-loke",
        items: [
          { amount: 450, name: "Coffee", quantity: 1 },
          { amount: 100, name: "Hug", quantity: 10 },
        ],
      });

      // TODO: send the nonce to your backend, have your backend complete the transaction.
    } catch (err) {
      console.error(err);
      alert("Sorry, payment failed - " + err.message);
    }
  };

  if (!lokeApp.isAvailable()) {
    return <div>Something went wrong - LOKE app is not available.</div>;
  }

  return (
    <div>
      <p>{lokeApp.getFirstName()} {lokeApp.getLastName()}</p>
      <p>{lokeApp.getEmail()}</p>
      <p>{lokeApp.getPhone()}</p>
      <button onClick={handleClick}>Do Payment</button>
    </div>
  );
}

export default App;

Example React Project - Development

You will need to also provide the "mock window" with some test data:

import { createMockWindow, LokeApp } from "@loke/webview-payments-client";

const customer = {
  token: "test-access-token",
  firstName: "John",
  lastName: "Smith",
  phone: "+61412345678",
  email: "[email protected]",
  cardId: "test-card-id",
};

// To use within a LOKE app just do not supply the mock window
// To use outside a LOKE app you need to provide a mock for the 
// window object with the required bound functionality
const mockWindow = createMockWindow({
  interactive: true,
  customer,
});
const lokeApp = new LokeApp({ clientId: "loke-provided-client-id", window: mockWindow });

function App() {
  // ...

Using the Mock for Development Purposes

import { LokeApp, createMockWindow } from "@loke/webview-payments-client";

// When using this in development in a browser pass in a mock "window" object.
const mockWindow = createMockWindow({
  // If you want to use this within a browser
  interactive: true,
  // You need to pass in details for the customer linked to the mock
  customer,
})
const lokeApp = new LokeApp({ clientId: "loke-provided-client-id", window: mockWindow });

Using the Mock for Test Automation Purposes

import { LokeApp, createMockWindow } from "@loke/webview-payments-client";
import nodeFetch from "node-fetch";

// When using this in development for automated tests pass in a mock "window" object.
const window = createMockWindow({
  // If you want to use this without user interaction set this false
  interactive: false,
  // If running outside of the browser you will need to pass in something that implements the fetch API.
  // eg node-fetch or unfetch
  // You could also use a fetch variant with mocked or recorded responses for tests
  fetch: nodeFetch,
  // You need to pass in details for the customer linked to the mock
  customer,
})
// You can then pass in the mock window to LokeApp and it will provide the behaviour of the app
const lokeApp = new LokeApp({ clientId: "loke-provided-client-id", window });