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

@rebilly/framepay-react

v6.56.0

Published

A React wrapper for Rebilly's FramePay offering out-of-the-box support for Redux and other common React features

Downloads

2,714

Readme

framepay-react

npm Build Status

React components for FramePay.js

Supported: React 14 to 18.

This package is a wrapper for FramePay offering out-of-the-box support for Redux and other common React features.

Table of Contents

FramePay documentation

For more information on FramePay see its official documentation.

Demos

Installation

Install using Yarn:

yarn add @rebilly/framepay-react

Or using NPM:

npm install @rebilly/framepay-react --save

Getting started

The example described in this readme can be found here (CodeSandbox)

The FramePay context (FramePayProvider)

FramePayProvider provides settings to the FramePay API. See Framepay.initialize for a list of all configuration options.

// index.js
import React from 'react';
import { render } from 'react-dom';
import { FramePayProvider } from 'framepay-react';

import MyCardPageComponent from './MyCardPageComponent';

const App = () => {
    return (
        <FramePayProvider injectStyle publishableKey="pk_sandbox_1234567890">
            <MyCardPageComponent/>
        </FramePayProvider>
    );
};

render(<App/>, document.getElementById('root'));

Define configuration parameters as attributes on the provider tag.

publishableKey="pk_sandbox_1234567890"

Setting up your payment form

WARNING

Please, don't implementing the unmount functionality, use the examples.

The react lifecycle methods already implemented in the library.

withFramePay (All props)
  • Framepay - FramePay's namespace
  • BankAccountNumberElement
  • BankAccountTypeElement
  • BankRoutingNumberElement
  • CardElement
  • CardCvvElement
  • CardExpiryElement
  • CardNumberElement
  • ApplePayElement
  • GooglePayElement
  • PaypalElement
withFramePayCardComponent (Card props)
  • Framepay
  • CardElement
  • CardCvvElement
  • CardExpiryElement
  • CardNumberElement
withFramePayBankComponent (Bank props)
  • Framepay
  • BankAccountNumberElement
  • BankAccountTypeElement
  • BankRoutingNumberElement
withFramePayApplePayComponent (Apple Pay props)
  • Framepay
  • ApplePayElement
withFramePayGooglePayComponent (Google Pay props)
  • Framepay
  • GooglePayElement
withFramePayPaypalComponent (Paypal props)
  • Framepay
  • PaypalElement
With FramePay (withFramePay) HOC

This simple FramePay HOC is used to provide the Framepay API in your component. It is most commonly used in combination with multiple payment methods.

Card elements (withFramePayCardComponent) HOC

Wrapper for the payment card features.

// MyCardPageComponent.js
import React from 'react';
import { withFramePayCardComponent } from 'framepay-react';

class MyCardPageComponent extends React.Component {
    constructor(props) {
        super(props);
        this.formNode = null;
        this.state = { firstName: '', lastName: '' };
        this.onSubmit = this.onSubmit.bind(this);
    }

    onSubmit(e) {
        e.preventDefault();
        // @see https://www.rebilly.com/docs/dev-docs/framepay-global-reference/#framepay.createtoken
        this.props.Framepay.createToken(
            this.formNode,
            { billingAddress: { ...this.state } }
        )
            .then(data => alert(JSON.stringify(data, null, 2)))
            .catch(err => alert(JSON.stringify(err, null, 2)));
    }

    render() {
        return (<form
            ref={node => this.formNode = node}
            onSubmit={this.onSubmit}>
            <div>
                <input
                    type="text"
                    name="firstName"
                    placeholder="First Name"
                    defaultValue={this.state.firstName}
                    onChange={(e) => this.setState({ firstName: e.target.value })}/>
            </div>
            <br/>
            <div>
                <input
                    type="text"
                    name="lastName"
                    placeholder="Last Name"
                    defaultValue={this.state.lastName}
                    onChange={(e) => this.setState({ lastName: e.target.value })}/>
            </div>
            <br/>
            <this.props.CardElement/>
            <hr/>
            <button>Make Payment</button>
        </form>);
    }
}

export default withFramePayCardComponent(MyCardPageComponent);
Bank elements (withFramePayBankComponent) HOC

Wrapper for the ACH features.

import React from 'react';
import { withFramePayBankComponent } from 'framepay-react';

class MyBankPageComponent extends React.Component {
    constructor(props) {
        super(props);
        this.formNode = null;
        this.state = { firstName: '', lastName: '' };
        this.onSubmit = this.onSubmit.bind(this);
    }

    onSubmit(e) {
        e.preventDefault();
        // @see https://www.rebilly.com/docs/dev-docs/framepay-global-reference/#framepay.createtoken
        this.props.Framepay.createToken(
            this.formNode,
            { billingAddress: { ...this.state } }
        )
            .then(data => alert(JSON.stringify(data, null, 2)))
            .catch(err => alert(JSON.stringify(err, null, 2)));
    }

    render() {
        return (<form
            ref={node => this.formNode = node}
            onSubmit={this.onSubmit}>
            <div>
                <input
                    type="text"
                    name="firstName"
                    placeholder="First Name"
                    defaultValue={this.state.firstName}
                    onChange={(e) => this.setState({ firstName: e.target.value })}/>
            </div>
            <br/>
            <div>
                <input
                    type="text"
                    name="lastName"
                    placeholder="Last Name"
                    defaultValue={this.state.lastName}
                    onChange={(e) => this.setState({ lastName: e.target.value })}/>
            </div>
            <br/>
            <this.props.BankElement/>
            <hr/>
            <button>Make Payment</button>
        </form>);
    }
}

export default withFramePayBankComponent(MyBankPageComponent);

Advanced options

Initialization settings

The framepay-react package supports all the FramePay initialization settings. See Framepay.initialize for all customizations.

Additionally injectStyle is available. When defined in the FramePayProvider it will add the default FramePay CSS in the header of your application.

<FramePayProvider injectStyle publishableKey="pk_sandbox_1234567890">
    <MyCardPageComponent/>
</FramePayProvider>

The CSS file is hosted on Rebilly's CDN and is found at this URL: https://cdn.rebilly.com/framepay/v1/rebilly.css

See adding default element styles in FramePay's documentation for more details.

Create Token Parameters

The createToken method supports all FramePay arguments. See Framepay.createToken for more details.

Troubleshooting

The methods withFramePay, withFramePayCardComponent and withFramePayBankComponent are higher-order-components. They can't be called directly from your render() method, so assign the generated component to a variable in the global scope before use.

Incorrect
import * as React from 'react';
import {withFramePayCardComponent} from 'framepay-react'

class SomeComponent extends React.Component {
    render(){
        return(<div>
            {withFramePayCardComponent(MyCardComponent)}
        </div>)
    }
}
Correct
import * as React from 'react';
import {withFramePayCardComponent} from 'framepay-react'

const MyCardElement = withFramePayCardComponent(MyCardComponent);

class SomeComponent extends React.Component {
    render(){
        return(<div>
            <MyCardElement />
        </div>)
    }
}

Developer instructions

Manual preview

In order to manually preview the examples, use serve:e2e command. It builds the project and starts the local server on the port 8000.

How to run unit tests?

Unit tests can be run using the test:unit command.

How to run E2E tests?

  • Ensure you are running the preview examples, otherwise all E2E tests will fail.
  • Run one of the following commands:
    • test:e2e:pr - runs a smaller subset of E2E tests tests headlessly.
    • test:e2e:post-merge - runs the complete set of E2E tests tests headlessly.
    • test:e2e:open - opens the cypress GUI, allowing you to interact with each test visually.