0

I am working on integrating Chargebee into a Blazor app. The way the drop-in script for Chargebee works is I need to include a javascript script, which I am doing in my index.html file.

<script src="https://js.chargebee.com/v2/chargebee.js" data-cb-site="sitename-test"></script>

Then, in theory I should be able to just include a drop in link in one of my razor views like this.

<a href="javascript:void(0)" data-cb-type="checkout" data-cb-item-0="Product-Name" data-cb-item-0-quantity="1"> Subscribe </a>

But when I do this and run the site, click the link, nothing happens, no error, no drop-in popup. Is there something about Blazor that doesn't allow this action to work the way it would work with another framework? I have tested this with plain HTML files and it works fine.

Thanks in advance for any help.

G_Man
  • 1,323
  • 2
  • 21
  • 33
  • I think you are mixing different concepts. Go through this link. Blazor is not like MVC. You can't simply use js directly in razor pages. https://code-maze.com/how-to-call-javascript-code-from-net-blazor-webassembly/ – Sandeep Ingale Jun 16 '22 at 15:49
  • I see now, JavaScript is called a different way, I read through the article, and although I now understand, I am not sure there is a way to specify variables in the script initialization and actual call, especially since I am not sure what the function being called is named. Will keep researching. – G_Man Jun 16 '22 at 16:36
  • Right. You need to use Blazor control for chargebee if they have it available. If not then not sure how it can be done. – Sandeep Ingale Jun 16 '22 at 16:40

1 Answers1

2

You will need to call Chargebee.init(options); via JSInterop. See the documentation linked below for more details on the Chargebee JS API.

https://www.chargebee.com/checkout-portal-docs/api.html#chargebee-object

Kevin
  • 401
  • 3
  • 10