1.2.2 • Published 28 days ago

payload-react v1.2.2

Weekly downloads
12
License
MIT
Repository
github
Last release
28 days ago

Payload.js React Library

A React library for integrating Payload.js Secure Input.

Installation

Install using npm

npm install payload-react

Get Started

Once you've installed the Payload.js React library to your environment, import the payload-react components to get started.

import {
    PaymentForm,
    PaymentMethodForm,
    PayloadInput,
    CardNumber,
    Expiry,
    CardCode,
    RoutingNumber,
    AccountNumber,
    ProcessingAccountForm,
    openProcessingAccountForm,
    Checkout,
    openCheckout
} from 'payload-react';

API Authentication

To authenticate with the Payload, you'll need a live or test client token for Payload.js. Client tokens can be generated using the secret key accessible from within the Payload dashboard. For more information on generating a client token, see Authentication.

Simple Checkout Form

Below is an example of a react checkout form utilizing Payload.js Secure Inputs and styled with Bootstrap 4.

import React from 'react';
import {
    PaymentForm,
    PayloadInput,
    CardNumber,
    Expiry,
    CardCode
} from 'payload-react';

function CheckoutForm() {
    return <PaymentForm
      clientToken='client_key_2zsp9Pske5l2Bgcy3bySES'
      className="container"
      styles={{invalid: 'is-invalid'}}
      onProcessed={(evt)=>{
        console.log('processed', evt.transaction_id)
      }}
      onError={(evt)=>{
        alert(evt.message)
      }}
    >
        <PayloadInput attr="amount" type="hidden" value="10.00"/>
        <div className="row pt-2">
            <div className="form-group col-7 px-1">
                <label>Card</label>
                <CardNumber className="form-control" onInvalid={(evt)=>{
                    alert(evt.message)
                }}/>
            </div>
            <div className="form-group col-3 px-1">
                <label>Expiration</label>
                <Expiry className="form-control" onInvalid={(evt)=>{
                    alert(evt.message)
                }}/>
            </div>
            <div className="form-group col-2 px-1">
                <label>CVC</label>
                <CardCode className="form-control"/>
            </div>
        </div>
        <div className="row pt-2">
            <button className="btn btn-primary" type="submit">Pay Now</button>
        </div>
    </PaymentForm>
}

Processing Account Form

Below is an example of how to open the Payload.js ProcessingAccountForm modal from react.

import {
    openProcessingAccountForm
} from 'payload-react';

function OnboardButton() {
    return <button
        className="btn btn-primary"
        onClick={(e) =>
          openProcessingAccountForm({
            clientToken: 'client_key_2zsp9Pske5l2Bgcy3bySES',
            onSuccess(evt) {
                console.log(evt.account.id)
            }
          })
        }>
        Open Processing Account Form Modal
    </button>
}

Documentation

To get further information on the Payload.js Secure Input library and capabilities, visit the unabridged Payload Documentation.

1.2.2

28 days ago

1.2.0

1 month ago

1.2.1

1 month ago

1.1.0

2 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

9 months ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.9

3 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

5 years ago