Tutorial 2 - Creating Offers

In previous tutorial Protect your content, you learned how to implement PHP SDK and how protect your content. In this tutorial, you will take the last basic step to sell your content.

If you want to sell anything with Cleeng, you have to describe it, give it a name, price etc. You have to create an offer.


  1. What is Cleeng offer ?
  2. Get Offer Id
  3. Combine everything
  4. Testing payment

1. What is Cleeng offer?

Every user before purchasing your content, has to know precisely what this is about. So if you want to sell with Cleeng, you have to describe it, give a name, set a price, choose type of an offer etc. More info about parameters connected with the offer that we allow to change you can find in Offer API.

Below, you can read about all types of Cleeng offers:

Offer type Payment recurring? Access period Description
Single 1 time payment Anytime After purchasing, user has access to content anytime and anywhere.
Rental 1 time payment 1h, 3h, 12h, publisher defines in hours Rental offers have specific period when user has access to content.
Example: "Rent this video now for 48h"
Subscription multiple payments week / month / 3months / 6months / year , it is a publisher choice After purchasing user has access to every offer with tag included in accessToTags array parameter.
Example: "Get unlimited access to all tutorials. Subscribe for only $49/month."
Learn more about Subscriptions
Pass 1 time payment Choose from day / week / 2weeks / month / 3months / 6months / year or set your own expire date After purchasing user has access to every offer with tag included in accessToTags array parameter.
Example: "Buy Pass for one month access to all tutorials."
Learn more about Passes

This tutorial will be based on Rental Offers.


2. Get Offer Id

2.1 Implementation

This is the second tutorial, so probably you have example files. If not, please download it and place them on your server.

Remember, you have to open publisher account first. All the information about further actions, you can find in Tutorials

Then, get a publisher token. Section 2.2.1 below shows how to use this token.

2.2 Creating offer

In the first tutorial, we described how you can protect your content. As you probably remember, we've been working on default offer. Right now, we are going to create our own offer.

Please open create_offer.php. This file will use Cleeng API to create new rental offer, then it will print offerId on your screen. This offerId you can use later in purchase.php as we did with default offer id in Tutorial 1.


        <?php
        
        $publisherToken = 'YOUR_PUBLISHER_TOKEN';
        
        $offerSetup = array(
            'title' => 'Super Cool article for just $0.49. You will love it!',
            'period' => '48',
            'price' => 0.49,
            'url' => 'http://your-site.com/view-offer-here',
            'description' => 'This is my first Rental Offer, after buying this, you will get 48 hours of accesss to my Super Cool article.'
        );
        
        // include PHP SDK
        include_once('../cleeng-php-sdk/cleeng_api.php');
        
        // create Cleeng API object and set publisher token
        $cleengApi = new Cleeng_Api();
        $cleengApi->setPublisherToken($publisherToken);
        // create rental offer on Cleeng Platform
        $offer = $cleengApi->createRentalOffer($offerSetup);
        
        // print ID of new offer
        echo 'Created rental offer with id = ' . $offer->id . "\n";

        ?>
        

        <?php

        $offerId = 'PUT_YOUR_OFFER_ID_HERE';

        // include PHP SDK
        include_once('../cleeng-php-sdk/cleeng_api.php');

        $cleengApi = new Cleeng_Api();

        ?>

        <script type="text/javascript" src="<?php echo $cleengApi->getJsApiUrl() ?>">
        CleengApi.trackOfferImpression("<?php echo $offerId ?>");

        function cleengPurchase() {
            CleengApi.purchase("<?php echo $offerId ?>", function(result) {
                if (result.accessGranted) {
                    // improve the user experience - learn how to load with AJAX in tutorial 5
                    window.location.reload();
                }
            });
        }
        </script>

        ... place the following within your HTML.
        if ($cleengApi->isAccessGranted($offerId)) {
            echo 'This content is accessible when you purchase it! Place here the stuff you want to sell.';
        } else {
            echo 'Content not accessible. <a href="/javascript:cleengPurchase()">Buy</a>';
        }
        .....remainder of your webpage.

2.2.1 Prove that you're publisher

First step is to set your publisher Token, which you can find in api-keys.

e.g. $publisherToken = 'Xlrx-SjTLVMCsaRsOf2q2hvWKOlrF57yHknDRRRMX-13Fz-x';

2.2.2 Describe your offer

All information about parameters you can find in API Reference


$offerSetup = array(
    'title' => 'Bip Bip and Coyotte - Episode 12 -  Dailymotion',
    'period' => '48',
    'price' => 0.49,
    'url' => 'http://your-site.com/view-offer-here',
    'description' => 'See how Bip Bip and Coyotte are chasing each other for the 12th time.'
);

2.2.3 The rest of the Cleeng magic


// include PHP SDK
include_once('./../cleeng-php-sdk/cleeng_api.php');

// create Cleeng API object using your publisher token
$cleengApi = new Cleeng_Api();
$cleengApi->setPublisherToken($publisherToken);

// create rental offer on Cleeng Platform, using your offer description
$offer = $cleengApi->createRentalOffer($offerSetup);

// print ID of new offer
echo 'Created rental offer with id = ' . $offer->id . "\n";

3. Combine everything.

At this time in purchase.php you have to set offer ID, which you get from point 2.

e.g. $offerId = 'R688881907_NL';

You are now ready to protect and sell digital content from your own website!


4. Testing payment

During testing, as you probably can see, you can't complete you purchase unless you pay with real money. In Tutorial How to use Cleeng sandbox, you can read how to use Sandbox to test payment and be able to finish the purchase process.

Go to Sandbox testing tutorial »