React Component Library
Example BS4+React checkout form
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)=>{
alert(`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>
}
Use the payload-react
component library when integrating Payload UI elements with React.
Installation
npm install payload-react
View on Github
API Authentication
To authenticate with the Payload, you'll need a client token with the appropriate intent. 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.
Get started
Once you've installed the Payload.js React library as shown above, import the payload-react module to get started.
import {
PaymentForm,
PaymentMethodForm,
PayloadInput,
CardNumber,
Expiry,
CardCode,
RoutingNumber,
AccountNumber,
ProcessingAccountForm,
openProcessingAccountForm
} from 'payload-react';
Options
Name |
Description |
clientToken |
required The client token used for client-side authentication. See client authentication for more information. |
autoSubmit |
optional Specify if the form submit should trigger. Default: true |
styles |
optional Change the default classnames |
payment |
optional An object that can include any additional and valid transaction attributes to be included when submitting the payment to Payload. Use only with <PaymentForm /> |
paymentMethod |
optional An object that can include any additional and valid payment method attributes to be included when submitting the payment to Payload. Use only with <PaymentMethodForm /> |
Callbacks
Name |
Description |
onProcessing |
Triggered once a request is sent to Payload |
onSuccess |
Triggered if the from submission completed successfully |
onProcessed |
Triggered if the payment was successfully processed |
onAuthorized |
Triggered if the payment was successfully authorized |
onDeclined |
Triggered if the payment was declined * |
onError |
Triggered for any API error response |
onCreated |
Triggered if the payment method was successfully saved |
onInvalid |
Triggered if the any of the input field values were invalid |
onValid |
Triggered if the any of the input field values are now valid |
onFocus |
Triggered if a secure input receives focus |
onBlur |
Triggered if a secure input loses focus |
Name |
Description |
onChange |
Triggered if the input value changed |
onInvalid |
Triggered if the input value is invalid |
onValid |
Triggered if the input value is now valid |
onFocus |
Triggered if a secure input receives focus |
onBlur |
Triggered if a secure input loses focus |
Name |
Description |
clientToken |
required The client intent token used for client-side authentication. See client authentication for more information. |
Callbacks
Name |
Description |
onLoaded |
Triggered after the form has loaded |
onSuccess |
Triggered after the form has been successfully completed |
onClosed |
Triggered after the form has been closed |