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

react-payment-request-api

v3.1.0

Published

React high order component that expose the payment request api

Downloads

160

Readme

Browser support

Payment request api is supported on Chrome for desktop v. ^61.0, Chrome for Android and Android Webview v. ^56.0, Microsoft Edge v. ^15.0.

Demo

You can find a working demo here. Be sure to use a supported browser.

NPM Install

npm install react-payment-request-api --save

Usage

Consume the UI component in the hight order component button.js:

import React from "react";
import paymentRequest from 'react-payment-request-api';

const Button = ({ show, isSupported }) => isSupported
    ? <button onClick={show}>Pay now!</button>
    : <span>Payment request not supported</span>;

export default paymentRequest<OwnProps>()(Button);

Pass the configuration to the high order component smartComponent.js:

import React from "react";

import Button from "./button";

const SmartComponent = (config) =>
  <Button config={config} foo="bar" />;

export default SmartComponent;

FAQ

How does it work?

It takes a configuration prop that define how the native widget should behave and any other property you want to pass to the UI component. It spread all the properties a part from the configuration to the enhanced UI component. The UI component will also receive other props that will help improving the experience allowing complete control on the renderer and on the action handler.

Does it support Redux or any other flux implementation?

Yes, with version 1.0 we have changed the interface allowing the user to inject the configuration from the parent component. In this way it does not matter which flux implementation you are using. At the same time, we are preserving the high order component pattern so you have complete control on the renderer and on the action handler.

Does it support Typescript?

Yes, you don't need to install any typescript dependecies because types come with the library. It export PaymentRequestParams (injected configuration) and PaymentRequestInterface (UI component extended props) typescript interfaces. All the examples are written in typescript.

API

Your wrapped component will be decorated with this injected props:

Parameter | Type | Description ----------- | ------------------------------ | ----------- isSupported | boolean | True if the payment request api is supported by the browser. show | function: () => PaymentRequest | It will begin the process when the merchant site want to create a new PaymentRequest. abort | function: () => void | You can intentionally abort a PaymentRequest by calling the abort method after show has been called.

Configuration of the high order component:

Parameter | Type | Description ----------------------- | -------------------------------------------------- | ----------- methodData | object | Required payment method data. details | object | Required information about transaction. options | object | Optional parameter for things like shipping, etc. onShowSuccess | Promise based callback: (result, resolve, reject) | The handler will be executed after the filling of the form is successfull. You should post your payment request and then resolve or reject the promise. onShowFail | Promise based callback: (error) | The handler will be executed if the filling of the form is not successfull (like when the user dismiss the form). onShippingAddressChange | Promise based callback: (request, resolve, reject) | The handler will be executed if the shipping address has change. You can change the request and then resolve the promise. onShippingOptionChange | Promise based callback: (request, resolve, reject) | The handler will be executed if the shipping option has change. You can change the request and then resolve the promise. onMerchantValidation | Promise based callback: (event) | Thde handler is used by Apple pay to validate the merchant.

License

See the LICENSE file for license rights and limitations (MIT).