Modern and idiomatic React interface to Authorize.Net.
Integrating the Authorize.Net platform with a modern web application can be painful.
Their whole platform is very unfriendly to SPAs and even more so to the beautiful programming model offered by React.
The main goal of this library is to abstract some of this pain away.
npm install --save react-authorize-net
This component can be used to easily implement and integrate a payment form in a React application.
string
Your Authorize.Net Client Key.
string
Your Authorize.Net API Login ID.
number
The amount of money that is being charged by the payment form.
"sandbox" | "production"
Which underlying Accept.js library to use.
The libaries are unique to both Authorize.Net environments (production and sandbox), so it is important to load the sandbox library if you are testing transactions, and to use the production library for live transaction processing, as shown below.
(response: Accept.Response) => void
Function called on successful reception of payment nonce.
(errors: string[]) => void
Function called on failed form submission.
FormContainer
expect a function returning some React elements (a component) passed in the render
prop. This should allow for maximum flexibility during the implementation of your payment form UX.
This function will be called with an object containing the following properties:
{ cardCode: string, cardNumber: string, expDate: string }
values
represents the values backing your underlying input elements.
(keyof FormType, React.ChangeEvent<any>) => React.ChangeEvent<any>
handleChange
is the callback used to notify FormContainer
about changes to the raw values backing your form inputs.
{ cardCode: boolean, cardNumber: boolean, expDate: boolean }
validationErrors
is an object used to represent any invalid state (invalid user input) present in your payment form.
The validation is made according to the shape of data that Authorize.Net API is expecting.
[]string
apiErrors
represents any errors that Authorize.Net API might return while making the underlying API request.
This component allows you to create forms that are fully SAQ-A compliant, through an idiomatic and easy-to-use API.
It is essentially a wrapper around Accept Hosted.
Custom styles can be applied to the form by supplying an appropriate style
or className
prop.
The button used to trigger the actual payment form can be customized by using the children
prop.
<AcceptHosted formToken={'...'}>
<button>Pay now</button>
</AcceptHosted>
string
formToken
is used to represent the transaction itself.
It is returned by Authorize.Net API.
'sandbox' | 'production'
If you're using the sandbox environment or not.
'redirect' | 'iframe'
Renders the form either as an iframe or redirect link.
(width: number, height: number) => void
Called for every resizeWindow
messages from Accept Hosted.
() => void
Called for every cancel
messages from Accept Hosted.
(response: TransactionResponse) => void
Called for every transactResponse
messages from Accept Hosted.
(queryStr: string) => void
Low level handler for raw communication between Accept Hosted and client code.
(message: Message) => void
Called for every valid messages coming from Accept Hosted.
You can use this repo as a reference point on how to integrate the library in an existing React application.
Are you having trouble integrating Authorize.Net with the rest of your infrastructure? Do you need a feature that is not supported in react-authorize-net yet?
Reach out at hello@jeremyallard.dev!