Custom/Advanced Integration
How to Retrieve the Stripe Subscription ID from Your Backend
Most applications store the Stripe subscription ID in their own database after a successful checkout. Here are examples for different backend frameworks:
Node.js/Express Example
// Example: Fetching Stripe subscription ID from your database (Node.js/Express)
app.get('/account', async (req, res) => {
// Assume you have a User model with a reference to a Subscription
const user = await User.findById(req.user.id).populate('subscription');
const subscriptionId = user.subscription?.stripeSubscriptionId;
res.json({ subscriptionId });
});PHP (Laravel) Example
// Example: Fetching Stripe subscription ID from your database (Laravel)
public function showAccount() {
$user = Auth::user();
$subscription = $user->subscription;
$subscriptionId = $subscription ? $subscription->stripe_subscription_id : null;
return response()->json(['subscriptionId' => $subscriptionId]);
}Ruby on Rails Example
Python (Django) Example
Fetching from Stripe API (Node.js Example)
Note: Never expose your Stripe secret key in client-side code. Always fetch subscription IDs securely from your backend.
Opting Out of Automatic Cancellation
If you have your own cancellation flow and want to prevent Staysignal from automatically cancelling subscriptions, you can opt out in two ways:
Config option: Pass
cancelOptOut: trueto the widget init config in JavaScript.Button attribute: Add
data-ss-cancel-optout="true"to your cancel button element.
Precedence: If either method is set, cancellation is skipped and a message is logged to the console.
Advanced Flows After Cancellation
After a cancellation, you may want to trigger additional actions (e.g., send a survey, update your CRM, or notify your team). Use the onComplete callback in the widget config to run custom logic after a successful cancellation:
Other Advanced Options
Use
onErrorcallback to handle errors in your own UI.Integrate with your analytics or logging system in
onCompleteoronError.Customize the widget appearance or behavior using additional config options (see documentation).
Last updated