I'm trying to add the drop-in checkout to a react SPA, following .html#implementation. I'm dynamically adding chargebee.js
after the rest of the view gets rendered, and then call registerAgain()
.
ponentDidMount() {
const el = document.createElement('script');
el.onload = () => {
window.Chargebee.registerAgain();
// this.setState({ chargebeeReady: true });
};
el.setAttribute('data-cb-site', 'derp-test');
el.setAttribute('src', '.js');
document.body.appendChild(el);
}
render() {
// [...]
<a
href="javascript:void(0)"
data-cb-type="checkout"
data-cb-plan-id="asdf-test"
>
Subscribe
</a>
// [...]
}
when clicking subscribe
I get an error:
Uncaught TypeError: Cannot read property 'getCart' of null
at t.a (event-binding.ts:24)
at Function.value (chargebee.ts:46)
at HTMLScriptElement.el.onload (Subscribe.js:23)
I'm trying to add the drop-in checkout to a react SPA, following https://www.chargebee./checkout-portal-docs/drop-in-tutorial.html#implementation. I'm dynamically adding chargebee.js
after the rest of the view gets rendered, and then call registerAgain()
.
ponentDidMount() {
const el = document.createElement('script');
el.onload = () => {
window.Chargebee.registerAgain();
// this.setState({ chargebeeReady: true });
};
el.setAttribute('data-cb-site', 'derp-test');
el.setAttribute('src', 'https://js.chargebee./v2/chargebee.js');
document.body.appendChild(el);
}
render() {
// [...]
<a
href="javascript:void(0)"
data-cb-type="checkout"
data-cb-plan-id="asdf-test"
>
Subscribe
</a>
// [...]
}
when clicking subscribe
I get an error:
Uncaught TypeError: Cannot read property 'getCart' of null
at t.a (event-binding.ts:24)
at Function.value (chargebee.ts:46)
at HTMLScriptElement.el.onload (Subscribe.js:23)
Share
Improve this question
edited Sep 27, 2023 at 3:59
Bharathvaj Ganesan
3,2041 gold badge21 silver badges35 bronze badges
asked Jul 12, 2018 at 9:10
kindoflikekindoflike
4876 silver badges22 bronze badges
2 Answers
Reset to default 10Chargebee instance will be created when DOMContentLoaded event is triggered.Since, you are loading it asynchronously, instance is not getting created. So you can create the instance using Chargebee.init().
ponentDidMount() {
const el = document.createElement('script');
el.onload = () => {
window.Chargebee.init({
"site": "derp-test"
});
window.Chargebee.registerAgain();
// this.setState({ chargebeeReady: true });
};
el.setAttribute('src', 'https://js.chargebee./v2/chargebee.js');
document.body.appendChild(el);
}
<script src="https://js.chargebee./v2/chargebee.js"></script>
<script>
window.addEventListener('load', function () {
Chargebee.init({
site: "site_name", // your test site
publishableKey: "test_"
})
Chargebee.registerAgain();
})
</script>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744183068a4562071.html
评论列表(0条)