Skip to content

Commit

Permalink
Merge pull request #217 from recurly/hostname
Browse files Browse the repository at this point in the history
Adds hostname configuration
  • Loading branch information
douglasmiller authored Oct 2, 2023
2 parents cd95939 + fcb8352 commit 0f4dcb4
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 0f4dcb4

Please sign in to comment.