Skip to main content

Freemius Hosted Checkout

If you want your customers to be redirected to a specific URL to complete their purchase, Freemius Hosted Checkout makes this possible.

In addition to the JavaScript Buy Button API, this features makes your Checkout more robust with simple links that you can share anywhere, including:

  • Your own website
  • Social media platforms
  • Emails and in-app notifications

Here is an example.

Setting Up Hosted Checkout

The redirection URL is required for this feature to work properly. It determines where customers are taken after completing a successful purchase.

Start by going to the Plans page and clicking the Get Checkout button. From there, you'll find several links depending on how you've configured your plan.

You can also set different pricings inside an individual plan page. If you want a link to a specific pricing option, click the Checkout Link button next to that pricing.

Hosted Checkout URL Schema

If you want to programmatically generate Checkout URLs for your product, here is the URL schema

 https://checkout.freemius.com/product/{product_id}/plan/{plan_id}/[licenses/{number|'unlimited'}]/[currency/{'usd'|'eur'|'gbp'}]

Given your product ID is 1234 and plan ID is 5678, here are some valid examples:

  • Pre-select the single license pricing - https://checkout.freemius.com/product/1234/plan/5678/.
  • Preselect the 10 licenses pricing - https://checkout.freemius.com/product/1234/plan/5678/licenses/10/.
  • Preselect the EUR pricing of single license - https://checkout.freemius.com/product/1234/plan/5678/currency/eur/.
  • Preselect the EUR pricing of 10 licenses - https://checkout.freemius.com/product/1234/plan/5678/licenses/10/currency/eur/.

Additionally every configuration you see in the Buy Button API can be passed as URL query parameters. For example:

https://checkout.freemius.com/product/1234/plan/5678/?title=Awesome%20Product
warning

Make sure to url-encode the parameter values.

tip

To add a coupon to a URL, so your customers automatically arrive to the Freemius Checkout page with a coupon activated, all you need to do is add ?coupon=12345 to the end of the URL. 12345 should be replaced with the coupon code.

Configuring the Back Button

A back button can be shown to a hosted Checkout. Here's how it works:

  • If a valid cancel_url=... is set in the URL query parameters, Checkout will use that URL.
  • If the above is not present but there’s a valid HTTP referrer, it will be used.
  • If neither of the above is available and you've set a Website / Marketing Page URL under your product settings, that URL will be used instead.

The button's icon is generated automatically from the favicon of the website. However, you can customize it by passing a valid image URL using the cancel_icon parameter.

Here’s an example of a Checkout URL with both parameters:

https://checkout.freemius.com/product/{product_id}/plan/{plan_id}/?cancel_url=https%3A%2F%2Fexample.com&cancel_icon=https%3A%2F%2Fexample.com%2Flogo.png

Redirection After a Successful Purchase

You can configure a redirection URL after a successful purchase. This setting is available in the Developer Dashboard.

Go to Plans → Customization and enable the Redirect Checkout to a custom URL toggle. Then, enter a valid HTTPS URL in the input field.

After a successful purchase (including license or payment method updates), buyers will be redirected to the specified URL. The following purchase data will be appended as query parameters:

  • user_id – ID of the buyer
  • plan_id – ID of the purchased plan
  • email – Buyer's email address
  • subscription_id – ID of the subscription (not present for one-off purchases)
  • billing_cycle – Subscription billing frequency (not present for one-off purchases)
  • payment_id – ID of the one-time payment (only for one-off purchases)
  • license_id – ID of the associated license
  • expiration – License expiration date (not present for one-off purchases)
  • quota – Quota associated with the license
  • action – One of purchase, license_update, payment_method_update or trial indicating the type of action that was performed
  • trial – In case of a trial this will have value either free or paid explaining the type of the trial
  • trial_ends_at – In case of a trial this will have a YYYY-MM-DD HH:MM:SS date explaining when the trial ends

Verifying the Data

When redirecting to the success URL, Freemius Checkout appends a signature query parameter that allows you to verify the authenticity of the request. Here’s how:

const FS_PRODUCT_SECRET_KEY = 'sk_productSecretKey';

// Get the current absolute URL
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https" : "http";
$host = $_SERVER['HTTP_HOST'];
$current_url = $protocol . "://" . $host . $_SERVER['REQUEST_URI'];

// Remove the "&signature=..." part using string slicing
$signature_pos = strpos($current_url, '&signature=');
$clean_url = substr($current_url, 0, $signature_pos);

// Calculate the HMAC hash
$calculated_signature = hash_hmac('sha256', $clean_url, FS_PRODUCT_SECRET_KEY);

// Compare the calculated signature with the provided one
$signature = $_GET['signature'] ?? null;

if ($signature && hash_equals($calculated_signature, $signature)) {
echo "✅ Signature is valid.";
} else {
echo "❌ Invalid signature.";
}

Verification algorithm:

  1. Take the full absolute URL.
  2. Remove the &signature=... from the end of the URL.
  3. Calculate the SHA-256 hash of the resulting string.
  4. Compare it with the value of the signature parameter.
warning

Please make sure the URL you enter does not redirect in your server. Otherwise the signature validation will fail following the algorithm. Also if you want to redirect to the root of the server, kindly add a /, for example https://example.com/, as browsers will do that when URL parameters are added.

Next Steps

You're now ready to start sharing your hosted checkout links!

To go further:

If you run into any issues or have questions, don't hesitate to contact our support by clicking the Help button on the bottom right of the screen.