Merchant Customer Portal JavaScript API Documentation


What is the Seal Subscriptions Merchant Customer Portal JavaScript API?

The Customer Portal JavaScript API documentation explains how to use various JavaScript events and methods in the customer portal within the Seal Subscriptions app. For example, when your customer opens a subscription in your shop, this API allows you to intercept the cancellation event and show additional popups (created by yourself) to the customer and then cancel subscription through our API. You can also use this API to customize the customer portal after the customer portal is loaded in your shop.

When the customer portal is loaded

When the customer portal is loaded, a custom JavaScript event called sealsubs_portal:loaded will be triggered on the document.
You can use this event to know when you can apply any adjustments to the customer portal with custom JavaScript code.

Here is how you can configure a listener for said event:
// This event will be fired when the customer portal is loaded 
document.addEventListener('sealsubs_portal:loaded', function(e) {
	// Subscription widget was created
	// Do your magic :)
});
	


When customer clicks the "Cancel subscription" button

To take over the control over the cancellation of the subscription when the customer clicks the Cancel subscription button, simply define the window.sealOvertakeCancelButton() function on your document.
When the customer clicks the cancel button, the app will check if this function is defined. And if it is, the app will execute it and won't continue with the default cancellation logic. This allows you to create a popup in the customer portal, ask customer for more info about the cancellation, offer them a discount and more. This is useful if you want to set up your own cancellation flow process.

Here is how you can configure this in your shop's theme:

 window.sealOvertakeCancelButton = function() {
	// Configuring this function (even if it is empty) will stop the default cancellation process 
	// You can customize the checkout process 
	// And when you are ready to cancel the subscription, call window.SealApi.cancelSubscription() method.
	window.SealApi.cancelSubscription(); // Cancel the subscription
 }
	


Cancel a subscription

As mentioned above, when you are ready to cancel the subscription in the customer portal, call the window.SealApi.cancelSubscription() function.
When you execute this function, the subscription will only be cancelled if the customer first clicked the Cancel subscription button. If they didn't click it, then this function won't do anything. It will simply log a message in the console: "Subscription can't be cancelled because the customer didn't click on the cancel button."
Warning: Executing this function will cancel the customer's subscription without any prompt.

Here is how you can use this function:

 window.sealOvertakeCancelButton = function() {
	// Configuring this function (even if it is empty) will stop the default cancellation process 
	// You can customize the checkout process 
	// And when you are ready to cancel the subscription, call window.SealApi.cancelSubscription() method.
	window.SealApi.cancelSubscription(); // Cancel the subscription
 }