Skip to content

Commit

Permalink
Merge b0eba35 into 6dd089d
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissrogers committed Jan 29, 2020
2 parents 6dd089d + b0eba35 commit 93d0e46
Show file tree
Hide file tree
Showing 19 changed files with 806 additions and 209 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ node_js:
cache:
directories:
- node_modules
script: make test-ci
script: make test
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ test: $(PKG)
@npm test
test-debug: $(PKG)
@node --inspect-brk node_modules/.bin/jest --runInBand
test-watch: $(PKG)
@npm test -- --watchAll

docs: $(PKG)
@npm run storybook
Expand Down
4 changes: 3 additions & 1 deletion README.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<img src="https://i.imgur.com/gGxJ8zx.png" align="right" />

# react-recurly &middot; [![build status][travis-image]][travis-url]
# react-recurly &middot; [![build status][travis-image]][travis-url] [![coverage][coverage-image]][coverage-url]

React components for [Recurly.js][docs-recurly-js]

Expand Down Expand Up @@ -142,6 +142,8 @@ MIT
[github-issues]: https://github.com/recurly/react-recurly/issues
[travis-url]: https://travis-ci.org/recurly/react-recurly/builds
[travis-image]: https://img.shields.io/travis/recurly/react-recurly/master.svg?style=flat-square
[coverage-url]: https://coveralls.io/github/recurly/react-recurly
[coverage-image]: https://img.shields.io/coveralls/github/recurly/react-recurly.svg?style=flat-square

[docs]: https://recurly.github.io/react-recurly
[docs-component-recurly-provider]: https://recurly.github.io/react-recurly/?path=/docs/components-recurlyprovider--page
Expand Down
7 changes: 6 additions & 1 deletion jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import '@testing-library/jest-dom/extend-expect';
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

// TODO: Lock to CDN distribution
import recurly from 'recurly.js';

global.recurly = recurly;

Enzyme.configure({ adapter: new Adapter() });
8 changes: 7 additions & 1 deletion lib/element/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,14 @@ export default class Element extends React.PureComponent {
constructor (props, context) {
super(props, context);

const { elementClassName } = this.constructor;

if (!context || !context.elements) {
throw new Error(`<${elementClassName}> must be within an <Elements> tree.`);
}

const options = extractOptions(this.props);
const element = this._element = context.elements[this.constructor.elementClassName](options);
const element = this._element = context.elements[elementClassName](options);
this._container = React.createRef();

element.on('ready', (...args) => this.props.onReady(...args));
Expand Down
21 changes: 16 additions & 5 deletions lib/three-d-secure-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import React from 'react';
import PropTypes from 'prop-types';
import { RecurlyContext } from './provider';

export const ThreeDSecureActionContext = React.createContext();

export default class ThreeDSecureAction extends React.PureComponent {
static propTypes = {
/**
Expand Down Expand Up @@ -31,14 +29,26 @@ export default class ThreeDSecureAction extends React.PureComponent {
* @callback ThreeDSecureAction~onToken
* @param {ThreeDSecureActionResultToken}
*/
onToken: PropTypes.func
onToken: PropTypes.func,

/**
* Called when an error is encountered
* @type {ThreeDSecureAction~onError}
*/

/**
* @callback ThreeDSecureAction~onError
* @param {RecurlyError}
*/
onError: PropTypes.func
};

static defaultProps = {
id: undefined,
className: undefined,
actionTokenId: '',
onToken: () => {}
onToken: () => {},
onError: e => { throw e }
};

static contextType = RecurlyContext;
Expand All @@ -55,7 +65,8 @@ export default class ThreeDSecureAction extends React.PureComponent {
this._container = React.createRef();
this._risk = this.context.recurly.Risk();
this._threeDSecure = this._risk.ThreeDSecure({ actionTokenId });
this._threeDSecure.on('token', res => this.props.onToken(res));
this._threeDSecure.on('token', (...args) => this.props.onToken(...args));
this._threeDSecure.on('error', (...args) => this.props.onError(...args));
}

componentDidMount () {
Expand Down

0 comments on commit 93d0e46

Please sign in to comment.