1. Home
  2. Documentation
  3. Selling with Freemius
  4. Freemius Checkout / Buy Button

Freemius Checkout / Buy Button

Selling with Freemius from any website takes just a few minutes to configure. Once you have your product’s plans and pricing set up within the Freemius Dashboard, simply go to the PLANS section and click the GET CHECKOUT CODE button. You’ll get a ready-to-use simple JavaScript snippet that you can embed on any website.

Here’s a simple example of the checkout code will look like for a plan that offers 3 multi-site prices:

<select id="licenses">
   <option value="1" selected="selected">Single Site License</option>
   <option value="5">5-Site License</option>
   <option value="25">25-Site License</option>
</select>
<button id="purchase">Buy Button</button>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://checkout.freemius.com/checkout.min.js"></script>
<script>
    var handler = FS.Checkout.configure({
        plugin_id:  '<productID>',
        plan_id:    '<planID>',
        public_key: '<productPublicKey>',
        image:      'https://your-plugin-site.com/logo-100x100.png'
    });

    $('#purchase').on('click', function (e) {
        handler.open({
            name     : '<productTitle>',
            licenses : $('#licenses').val(),
            // You can consume the response for after purchase logic.
            success  : function (response) {
                // alert(response.user.email);
            }
        });
        e.preventDefault();
    });
</script>

You can find more advanced multi-plan + multi-site licenses example via this Gist.

Argument Description Type Default
plugin_id * Required product ID (whether it’s a plugin, theme, add-on, or SaaS). number
public_key * Require product public key. string
name An optional string to override the product’s title. string Defaults to the product’s title set within the Freemius dashboard.
subtitle An optional string to override the checkout’s subtitle. string Defaults to “You’re one step closer to our {{ planTitle }} features”
image An optional icon that loads at the checkout and will override the product’s icon uploaded to the Freemius Dashboard. Use a secure path to the image over HTTPS. While the checkout will remain PCI compliant, credit-card automatic prefill by the browser will not work. string Defaults to the product’s title set within the Freemius dashboard.
plan_id The ID of the plan that will load with the checkout. When selling multiple plans you can set the param when calling the open() method. number Defaults to the 1st paid plan.
licenses A multi-site licenses prices that will load immediately with the checkout. A developer-friendly param that can be used instead of the pricing_id. To specify unlimited licenses prices, use one of the following values: 0, null, or 'unlimited'. number Defaults to 1.
pricing_id Use the licenses param instead. An optional ID of the exact multi-site license prices that will load once the checkout opened. number Defaults to the plan’s single-site prices ID.
billing_cycle An optional billing cycle that will be auto selected when the checkout is opened. Can be one of the following values: 'monthly', 'annual', 'lifetime'. enum 'annual'
coupon An optional coupon code to be automatically applied on the checkout immediately when opened. string
trial When set to true, it will open the checkout in a trial mode. This will only work if you’ve activated the Free Trial functionality in the plan configuration. boolean false
cancel A callback handler that will execute once a user closes the checkout by clicking the close icon. This handler only executes when the checkout is running in a dialog mode. function
purchaseCompleted An after successful purchase/subscription completion callback handler.
Notice: When the user subscribes to a recurring billing plan, this method will execute upon a successful subscription creation. It doesn’t guarantee that the subscription’s initial payment was processed successfully as well. If you’d like to leverage this method for the in-dashboard/WP-Admin checkout, you’ll need to utilize a special filter named checkout/purchaseCompleted as in this example.
function
success An optional callback handler, similar to purchaseCompleted. The main difference is that this callback will only execute after the user clicks the “Got It”” button that appears in the after purchase screen as a declaration that they successfully received the after purchase email. This callback is obsolete when the checkout is running in a dashboard mode.” function

All the parameters can be preset when configuring the checkout using FS.Checkout.configure(). If you need to set different param values based on the user’s selection, you can set all the params except plugin_id and public_key when executing the handler.open() method.