rpr

react-payment-request-api

High order component to drive Payment Request widget

Showing:

Popularity

Downloads/wk

49

GitHub Stars

57

Maintenance

Last Commit

3yrs ago

Contributors

1

Package

Dependencies

2

Size (min+gzip)

3.7KB

License

MIT

Type Definitions

Built-In

Tree-Shakeable

No?

Readme

React high order component to drive payment request widget on react applications 💳.

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:

ParameterTypeDescription
isSupportedbooleanTrue if the payment request api is supported by the browser.
showfunction: () => PaymentRequestIt will begin the process when the merchant site want to create a new PaymentRequest.
abortfunction: () => voidYou can intentionally abort a PaymentRequest by calling the abort method after show has been called.

Configuration of the high order component:

ParameterTypeDescription
methodDataobjectRequired payment method data.
detailsobjectRequired information about transaction.
optionsobjectOptional parameter for things like shipping, etc.
onShowSuccessPromise 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.
onShowFailPromise based callback: (error)The handler will be executed if the filling of the form is not successfull (like when the user dismiss the form).
onShippingAddressChangePromise 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.
onShippingOptionChangePromise 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.
onMerchantValidationPromise 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).

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Tutorials

No tutorials found
Add a tutorial