Skip to content

Commit

Permalink
Adds hostname configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissrogers committed Oct 2, 2023
1 parent cd95939 commit fcb8352
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
9 changes: 7 additions & 2 deletions lib/provider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export default class RecurlyProvider extends React.Component {
* [API Access](https://app.recurly.com/go/developer/api_access).
*/
publicKey: PropTypes.string,

/**
* Register the current hostname
*/
hostname: PropTypes.string,
/**
* Sets a default currency
*/
Expand Down Expand Up @@ -56,7 +61,7 @@ export default class RecurlyProvider extends React.Component {
constructor (props) {
super(props);

if (!this.props.publicKey) {
if (!(this.props.publicKey || this.props.hostname)) {
throw new Error(`
Please pass your 'publicKey' value to this RecurlyProvider.
Example: <RecurlyProvider publicKey="MY_PUBLIC_KEY">
Expand All @@ -82,7 +87,7 @@ export default class RecurlyProvider extends React.Component {
}
}

render() {
render () {
return (
<Provider value={{ recurly: this._recurly }}>{this.props.children}</Provider>
);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions test/provider.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,12 @@ describe('<RecurlyProvider />', function () {
}
});
});

describe('with a hostname', function () {
it('does not throw an error', function () {
expect(() => {
render(<RecurlyProvider hostname="test-hostname" api={api} />);
}).not.toThrow();
});
});
});

0 comments on commit fcb8352

Please sign in to comment.