Note This project is still active, however this repository is archived and the source is moved into a private repository. The unmangled source code is still available publically and published as part of the npm package contents.
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.
- framepay-react
- Table of Contents
- FramePay documentation
- Demos
- Installation
- Getting started
- The FramePay context (
FramePayProvider
) - Setting up your payment form
- WARNING
- withFramePay (All props)
- withFramePayCardComponent (Card props)
- withFramePayBankComponent (Bank props)
- withFramePayApplePayComponent (Apple Pay props)
- withFramePayGooglePayComponent (Google Pay props)
- withFramePayPaypalComponent (Paypal props)
- With FramePay (
withFramePay
) HOC - Card elements (
withFramePayCardComponent
) HOC - Bank elements (
withFramePayBankComponent
) HOC
- The FramePay context (
- Advanced options
- Troubleshooting
- Developer instructions
- Table of Contents
For more information on FramePay see its official documentation.
- Use with react-redux (CodeSandbox)
- Use with react-router (CodeSandbox)
- Examples from README file (CodeSandbox, React 14/15)
- Multiple Payment Methods (CodeSandbox)
- Multiple Payment Methods Short version (CodeSandbox)
- Separated fields for the payment card method (CodeSandbox)
- Other Payment Methods (CodeSandbox)
- TypeScript (CodeSandbox)
- More examples from the E2E tests
Install using Yarn:
yarn add @rebilly/framepay-react
Or using NPM:
npm install @rebilly/framepay-react --save
The example described in this readme can be found here (CodeSandbox)
FramePayProvider provides settings to the FramePay API. See Rebilly.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"
Please, don't implementing the unmount functionality, use the examples.
The react lifecycle methods already implemented in the library.
- Rebilly - FramePay's namespace
BankAccountNumberElement
BankAccountTypeElement
BankRoutingNumberElement
CardElement
CardCvvElement
CardExpiryElement
CardNumberElement
ApplePayElement
GooglePayElement
PaypalElement
- Rebilly
CardElement
CardCvvElement
CardExpiryElement
CardNumberElement
- Rebilly
BankAccountNumberElement
BankAccountTypeElement
BankRoutingNumberElement
- Rebilly
ApplePayElement
- Rebilly
GooglePayElement
- Rebilly
PaypalElement
This simple FramePay HOC is used to provide the Rebilly
API in your component. It is most commonly used in combination with multiple payment methods.
- Payment cards and ACH (CodeSandbox)
- Payment cards and ACH Short version (CodeSandbox)
- Alternative methods (Bitcoin) (CodeSandbox)
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://rebilly.github.io/framepay-docs/reference/rebilly.html#rebilly-createtoken
this.props.Rebilly.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);
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://rebilly.github.io/framepay-docs/reference/rebilly.html#rebilly-createtoken
this.props.Rebilly.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);
The framepay-react package supports all the FramePay initialization settings. See Rebilly.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.
The createToken
method supports all FramePay arguments. See Rebilly.createToken for more details.
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.
import * as React from 'react';
import {withFramePayCardComponent} from 'framepay-react'
class SomeComponent extends React.Component {
render(){
return(<div>
{withFramePayCardComponent(MyCardComponent)}
</div>)
}
}
import * as React from 'react';
import {withFramePayCardComponent} from 'framepay-react'
const MyCardElement = withFramePayCardComponent(MyCardComponent);
class SomeComponent extends React.Component {
render(){
return(<div>
<MyCardElement />
</div>)
}
}
Before proceeding further, download and install Node.js in case you have not already. Node.js v12 or higher is required.
-
Clone the repository
-
Install dependencies using Yarn:
yarn install
Or using NPM:
npm install
In order to manually preview the examples, use serve:e2e
command. It builds the project and starts the local server on the port 8000.
Unit tests can be run using the test:unit
command.
- Ensure you are running the preview examples, otherwise all E2E tests will fail
- Run one of the following commands:
test:cypress:run
- runs all tests headlesslytest:cypress:open
- opens GUI which allows you to interact with each test visually