Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds hostname configuration #217

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});
});