Code Monkey home page Code Monkey logo

react-authorize-net's Introduction

Modern and idiomatic React interface to Authorize.Net.

Why

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.

Features

  • Modern idiomatic React interface to Authorize.Net
  • Small API surface
  • Fully typed interface (using TypeScript)
  • Quick and easy integration in any modern React stack
  • Elegant and beautiful form UX available by default
  • Simple authentication with Authorize.Net platform
  • Easy validation of user input

Installation

ES Module

npm install --save react-authorize-net

API

<FormContainer />

This component can be used to easily implement and integrate a payment form in a React application.

Props

clientKey

string

Your Authorize.Net Client Key.

apiLoginId

string

Your Authorize.Net API Login ID.

amount

number

The amount of money that is being charged by the payment form.

environment

"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.

onSuccess

(response: Accept.Response) => void

Function called on successful reception of payment nonce.

onError

(errors: string[]) => void

Function called on failed form submission.

render

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:

values

{ cardCode: string, cardNumber: string, expDate: string }

values represents the values backing your underlying input elements.

handleChange

(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.

validationErrors

{ 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.

apiErrors

[]string

apiErrors represents any errors that Authorize.Net API might return while making the underlying API request.

<AcceptHosted />

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.

Styling

Custom styles can be applied to the form by supplying an appropriate style or className prop.

Custom element

The button used to trigger the actual payment form can be customized by using the children prop.

<AcceptHosted formToken={'...'}>
  <button>Pay now</button>
</AcceptHosted>

Props

formToken

string

formToken is used to represent the transaction itself.

It is returned by Authorize.Net API.

mode

'sandbox' | 'production'

If you're using the sandbox environment or not.

type

'redirect' | 'iframe'

Renders the form either as an iframe or redirect link.

More information

onResize

(width: number, height: number) => void

Called for every resizeWindow messages from Accept Hosted.

onCancel

() => void

Called for every cancel messages from Accept Hosted.

onTransact

(response: TransactionResponse) => void

Called for every transactResponse messages from Accept Hosted.

onReceiveCommunication

(queryStr: string) => void

Low level handler for raw communication between Accept Hosted and client code.

onMessage

(message: Message) => void

Called for every valid messages coming from Accept Hosted.

How to use

Code sample

You can use this repo as a reference point on how to integrate the library in an existing React application.

Commercial support

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 [email protected]!

react-authorize-net's People

Contributors

boguskrzysztof avatar j-em avatar jeremy-hunter avatar jgarib avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-authorize-net's Issues

Subscriptions

Is it possible to create subscriptions, cancel them and change the preferred payment method once is set using this library? Or is it only for one time payments?

SyntaxError: Cannot use import statement outside a module (possibly caused by Next.js?)

I'm getting this error after I install the component.

I'm using CRA, and I'm not sure if this is caused by Next.js, since the example app works for me.

This is the log:

Module._compile
internal/modules/cjs/loader.js:892:18
Module._extensions..js
internal/modules/cjs/loader.js:973:10
Module.load
internal/modules/cjs/loader.js:812:32
Function.Module._load
internal/modules/cjs/loader.js:724:14
Module.require
internal/modules/cjs/loader.js:849:19
require
internal/modules/cjs/helpers.js:74:18
react-authorize-net
webpack:/external "react-authorize-net":1

> 1 | module.exports = require("react-authorize-net");


View compiled
__webpack_require__
./webpack/bootstrap:21
  18 | // Execute the module function
  19 | var threw = true;
  20 | try {
> 21 | 	modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
     | ^  22 | 	threw = false;
  23 | } finally {
  24 | 	if(threw) delete installedModules[moduleId];

User authentication failed due to invalid authentication values.

Using my sandbox creds, I am able to create transactions in my sandbox using other Authorize.net API Calls (API LIVE in Authorize.net Developer and the NODE Payment Transaction). With this app with the default creds I get this error:

{code: "E_WC_10", text: "Please provide valid apiloginid."}
{code: "E_WC-18", text: :"Client key is required."}

When I swap out the creds with those that work elsewhere
//let clientKey = process.env.REACT_APP_AUTHORIZENET_CLIENTKEY as string;
//let apiLoginId = process.env.REACT_APP_AUTHORIZENET_LOGINID as string;

const clientKey = "8896XXXXXXXXXXXX";
const apiLoginId = "675XXXXXXX";

Then I get the "User authentication failed due to invalid authentication values" error.

Finally, if I copy the creds from the .env file in react-authorize.net I don't get console error/message, I get app screen that says:
Failed to process payment.

Any guidance would be greatly appreciated

Question: AVS / Preventing Fraud

Is there a way to prevent fraud or is that done on the backend? I'm new to this process so I'm still understanding how it all works.

Is this module essentially just running a "pre-authorization" and the rest of it gets sent to the server for final charge? Is that how the process works?

Should I have the user add their card, store the opaqueData object returned and post both the opaqueData and address information to the server for processing with Authorize.net's API, then have it do AVS that way?

Apologies in advance, but I'm trying to wrap my head around the whole process.

Thanks!

SyntaxError: Unexpected identifier

Facing the following issue while using react-authorize-net with next js

import _extends from '@babel/runtime/helpers/extends';

Please check screenshot for more details

Screenshot_2

Authorize.net not processing transaction

Data is flowing between authorize.net and my react app, and I receive success message, but the card is never actually charged. Here is my FormContainer:

<FormContainer
environment="production"
onError={onErrorHandler}
onSuccess={onSuccessHandler}
amount={1}
component={FormComponent}
clientKey={clientKey}
apiLoginId={apiLoginId}

Two requests are sent to Authorize.net. The first is an empty OPTIONS request which comes back with "Error reading JToken from JsonReader. Path '', line 0, position 0."

The second request is a POST request and contains the card data which returns a resultCode of "OK" and a message of "Successful."

Is there another option I need to pass to get this to work?

cardData expects expDate to be an array

Hi - thank you for this library, Accept.js is a pain to implement :)

In FormContainer submitHandler it expects expDate to be an array but since I have linked it to an input field my event.target.value is a string value. The original code sends a single digit month and year to auth.net which fails validation.

My workaround is below - is this something to be fixed or do I need to adjust how I'm handling my input?

submitHandler(): Promise<Accept.Response> {
    const authData = {
      apiLoginID: this.props.apiLoginId,
      clientKey: this.props.clientKey
    }
    const cardData = {
      cardCode: this.state.values.cardCode,
      cardNumber: this.state.values.cardNumber,
      month: **this.state.values.expDate.split("/")[0],**
      year: **this.state.values.expDate.split("/")[1]**
    }

Custom Payment Form submission trigger.

Can we remove the default FormComponent button, and trigger the card submission ourselves?

In our case, Payment form is a part of another form, and Pay button is triggering the form submission. Or do I need to create a custom payment form for this?

Webpack issues?

Apologies if this is a newbie question but I'm new to react so maybe I don't have something configured correctly, but I'm having trouble getting this component to load properly. I'm currently running React 16.9.0 and NextJS 9.0.3 and the component loads fine if I navigate to the page where the component is, but if I'm already on that page and I click refresh in my browser, I have Webpack errors:

SyntaxError: Unexpected identifier
Module._compile
internal/modules/cjs/loader.js:703:23
Module._extensions..js
internal/modules/cjs/loader.js:770:10
Module.load
internal/modules/cjs/loader.js:628:32
Function.Module._load
internal/modules/cjs/loader.js:555:12

Module.require
internal/modules/cjs/loader.js:666:19
require
internal/modules/cjs/helpers.js:16:16
react-authorize-net
webpack:/external "react-authorize-net":1

__webpack_require__
./webpack/bootstrap:21

... (and so forth)

I'm not having this problem anywhere else on the site. Is this something possibly with my Webpack config with NextJS?

allow custom styling

I notice there's an exposed className prop in the FormComponent, but I'm not able to read the Typescript enough to understand how it all works. Is there a way to drop in custom styles? I tried overriding the class names generated by Styled Components, but the buildpack I'm using defaults to the old style.

hosted form

is this example showing the hosted form of accept.js?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.