TinyPass Developer's Resources

Upsell - Adding a secondary offer

In this simple case, the Tinypass popup ticket contains only one offer. This experience can be enhanced by adding a '*secondary offer*', aka an '*upsell*' offer.

The secondary offer is an opportunity for a customer to purchase an additional resource.

For example, if a site sells access to individual movies, they could also provide a secondary offer for access to their entire library of movies.

10: <!-- Embed tinypass.js in the HTML header -->
11: <script type='text/javascript' src='http://code.tinypass.com/tinypass.js'></script>
12: <?php
13:
14: $article_rid = "...";
15: $site_access_rid = "site-access";
16:
17: //Configure Tinypass
18: TinyPass::$AID="AIDxxAIDxx";
19: TinyPass::$PRIVATE_KEY="XxXx...XxXx";
20:
21: /* Parse cookie based token and check if the user already has access
22:  * to this particular article or the whole site (purchased the upsell)
23:  */
24: $store = new TPAccessTokenStore();
25: $store->loadTokensFromCookie($_COOKIE);
26: $token = $store->getAccessToken($article_rid);
27: $siteToken = $store->getAccessToken($site_access_rid);
28: if($token->isAccessGranted() || $siteToken->isAccessGranted()) {
29:     //Access Granted! Display the article
30:
31: } else {
32:     //Access Denied! Configure and display a Tinypass button.
33:
34:     //Create a Primary Offer
35:     $resource = new TPResource($article_rid, "Name of this article...");
36:     $po = new TPPriceOption("0.05");
37:     $primaryOffer = new TPOffer($resource, $po);
38:
39:     //Create a Secondary Offer
40:     $upSellResource = new TPResource($site_access_rid, "Full Premium Access - 24 Hours");
41:     $po1 = new TPPriceOption("0.50", "24 hours");
42:     $secondaryOffer = new TPOffer($upSellResource, $po1);
43:
44:     //display a page with button that tells your user he has to pay
45:     $purchaseRequest = new TPPurchaseRequest($primaryOffer);
46:     $purchaseRequest->setSecondaryOffer($secondaryOffer);
47:     $buttonHTML = $purchaseRequest->generateTag();
48:     echo $buttonHTML;
49: }

// Embed tinypass.js in the HTML header
out.println(
  "<script type='text/javascript' src='http://code.tinypass.com/tinypass.js'></script>"
);
 
String article_rid = "...";
String site_access_rid = "site-access";
 
//Configure Tinypass
TinyPass.AID="AIDxxAIDxx";
TinyPass.PRIVATE_KEY="XxXx...XxXx";
 
/* Parse cookie based token and check if the user already has access
 * to this particular article or the whole site (purchased the upsell)
 */
AccessTokenStore store = new AccessTokenStore();
store.loadTokensFromCookie(request.getHeader("cookie"));
if(store.getAccessToken(article_rid).isAccessGranted() ||
        store.getAccessToken(site_access_rid).isAccessGranted()) {
    //Access Granted! Display the article
 
} else {
    //Access Denied! Configure and display a Tinypass button.
 
    //Create a Primary Offer
    Resource resource = new Resource(article_rid, "Name of this article...");
    PriceOption po = new PriceOption("0.05");
    Offer primaryOffer = new Offer(resource, po);
 
    //Create a Secondary Offer
    Resource upSellResource = new Resource(site_access_rid, "Full Premium Access - 24 Hours");
    PriceOption po1 = new PriceOption("0.50", "24 hours");
    Offer secondaryOffer = new Offer(upSellResource, po1);
 
    //display a page with button that tells your user he has to pay
    PurchaseRequest purchaseRequest = new PurchaseRequest(primaryOffer);
    purchaseRequest.setSecondaryOffer(secondaryOffer);
    String buttonHTML = purchaseRequest.generateTag();
    out.println(buttonHTML);
}

// Embed tinypass.js in the HTML header
// <script type='text/javascript' src='http://code.tinypass.com/tinypass.js'></script>
 
var article_rid = "...";
var site_access_rid = "site-access";
 
// Configure Tinypass
TinyPass.TP.AID="AIDxxAIDxx";
TinyPass.TP.PRIVATE_KEY="XxXx...XxXx";
 
/* Parse cookie based token and check if the user already has access
 * to this particular article or the whole site (purchased the upsell)
 */
var store = new AccessTokenStore();
store.LoadTokensFromCookie(Request.Headers["cookie"]);
if(store.GetAccessToken(article_rid).IsAccessGranted() ||
        store.GetAccessToken(site_access_rid).IsAccessGranted()) {
    //Access Granted! Display the article
 
} else {
    //Access Denied! Configure and display a Tinypass button.
 
    //Create a Primary Offer
    var resource = new Resource(article_rid, "Name of this article...");
    var po = new PriceOption("0.05");
    var primaryOffer = new Offer(resource, po);
 
    //Create a Secondary Offer
    var upSellResource = new Resource(site_access_rid, "Full Premium Access - 24 Hours");
    var po1 = new PriceOption("0.50", "24 hours");
    var secondaryOffer = new Offer(upSellResource, po1);
 
    //display a page with button that tells your user he has to pay
    var purchaseRequest = new PurchaseRequest(primaryOffer);
    purchaseRequest.SetSecondaryOffer(secondaryOffer);
    var buttonHTML = purchaseRequest.GenerateTag();
    Response.Write(buttonHTML);
}

<!-- Embed tinypass.js in the HTML header -->
<script type='text/javascript' src='http://code.tinypass.com/tinypass.js'></script>
 
article_rid = "..."
site_access_rid = "site-access"
 
# Configure Tinypass
Tinypass.aid = "AIDxxAIDxx"
Tinypass.private_key = "XxXx...XxXx"
 
# Parse cookie based token and check if the user already has access
# to this particular article or the whole site (purchased the upsell)
 
store = Tinypass::AccessTokenStore.new
store.load_tokens_from_cookie(cookies)
 
if store.get_access_token(article_rid).access_granted? || store.get_access_token(site_access_rid).access_granted?
    # Access Granted! Display the article
else
    # Access Denied! Configure and display a Tinypass button.
 
    resource = Tinypass::Resource.new(article_rid, 'Name of this article')
    po1 = Tinypass::PriceOption.new('0.05')
    primary_offer = Tinypass::Offer.new(resource, po1)
 
    # Create a secondary offer
    upsell_resource = Tinypass::Resource.new(site_access_rid, 'Full Premium Access - 24 Hours')
    po2 = Tinypass::PriceOption.new('0.50', '24 hours')
    secondary_offer = Tinypass::Offer.new(upsell_resource, po2)
 
    # Display a page with button that tells your user he has to pay
    purchase_request = Tinypass::PurchaseRequest.new(primary_offer)
    purchase_request.secondary_offer = secondary_offer
    button_html = purchase_request.generate_tag
end