Integration Manual

How to integrate Creditable into your website?

Introduction

This document describes the integration of Creditable script into your website to enable the Creditable Pay-per-article button on your Paywall or PayGate.

Requirements

To use the Creditable pay per article button, the following things are required:

  • Get yourself a free Creditable Partner Account at https://partner.creditable.news. No signup costs are applicable.
  • Login to your dashboard at https://partner.creditable.news and add your mediatitle(s).
  • An apikey will be generated for each mediatitle you add.
  • Install the Creditable PayWal PHP Package from Github
  • Include the following 4 pieces of code into your article pages.

Scripts to include

Include the following PHP script, HTML snippet, Javascript and stylesheet into your article pages.

PHP Script

Install the Creditable Paywall PHP package, use Composer by running the following command:

composer require evalue8bv/creditable-paywall

You can also download the PHP Package from Github and install it manualy.

Include the following PHP code into your article pages to check for article access.

  • Make sure you insert your APIKEY of the correct Mediatitle
  • Make sure you add the required article info at the right position in the script.
  • Use the variable $cResult->isPaid() to determine if your Paygate can be skipped.
<?php

// Require the autoload.php file to load the CreditablePayWall library
require_once 'vendor/autoload.php';

// Import the CreditablePayWall class from the Creditable namespace
use Creditable\CreditablePayWall;

//**************** CREDITABLE PAGE CODE *******************//

// SET PARTNER VARS
$creditable_apikey = "<<APIKEY>>"; // (required)
// Obtain the apikey from the Creditable Partner CMS.
// NOTE: Each website/mediatitle has its own APIKEY.

// SET ARTICLE INFO
$creditable_topic_id = "<<TOPIC ID>>"; // Alphanumeric (required)
$creditable_topic_name = "<<TOPIC NAME>>"; // Alphanumeric (required)
$creditable_topic_url = "<<TOPIC URL>>"; // Alphanumeric (optional)
$creditable_topic_desc = "<<TOPIC DESC>>"; // Alphanumeric (optional)
$creditable_article_id = "<<ARTICLE ID>>"; // Alphanumeric (required)
$creditable_article_title = "<<ARTICLE TITLE>>"; // Alphanumeric (required)
$creditable_article_url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; // Alphanumeric (required)
$creditable_article_lang = "nl-NL"; // ISO (required)
$creditable_article_desc = "<<ARTICLE DESC>>"; // Alphanumeric (optional) teaser, used to tease recommended articles to users)
$creditable_article_tags = "<<TAGS>>"; // Alphanumeric (optional) comma delimited list or json (optional keywords, used to find recommended articles for users
$creditable_article_img = "<<ARTICLE IMG URL>>"; // Alphanumeric (optional) URL for article image
$creditable_article_authors  =   "<<ARTICLE AUTHORS>>";   // Alphanumeric (optional) String, comma separated authornames or JSON with scheme [{"lastname":"Writer","firstname":"Ad","initials":"A.B.","uid":"123"},{"lastname":"Author","firstname":"Co","initials":"C.","uid":"234"}]

// INSTANTIATE THE CREDITABLE CLASS
$creditable = new CreditablePayWall($creditable_apikey);

// GET LOCAL CREDITABLE JWT COOKIE
$creditable_cookie = $_COOKIE['cjwt'] ?? "";

// CHECK IF ARTICLE HAS BEEN PAID
try {
    
    $cResult = $creditable->check(array(
        'jwt' => $creditable_cookie,
        'topic_id' => $creditable_topic_id,
        'topic_name' => $creditable_topic_name,
        'topic_desc' => $creditable_topic_desc,
        'topic_url' => $creditable_topic_url,
        'article_id' => $creditable_article_id,
        'article_name' => $creditable_article_title,        
        'article_url' => $creditable_article_url,
        'article_lang' => $creditable_article_lang,
        'article_authors' => $creditable_article_authors,
        'article_desc' => $creditable_article_desc, 
        'article_tags' => $creditable_article_tags,
        'article_img' => $creditable_article_img
    ));

} catch (Exception $e) {
        //echo "creditable exception: ".  $e->getMessage();
}

//***************** CREDITABLE PAGE CODE END ********************//

?>


PayWall Script

Paste this HTML code into your paywall/paygate at the position where the creditable button should appear.

<!-- *****************   CREDITABLE PAYWALL CODE  ******************** -->
<!-- creditable container -->
<div id="creditable-container" class="creditable-container">
    <!-- the button -->
    <div id="creditable-button"></div>
    <!-- popup window -->
    <div id="creditable-window"></div>
</div>
<!-- ***************** CREDITABLE PAYWAL CODE END ******************** -->

 

Header Script

This is the stylesheet for the creditable user interface (buttons and forms). Paste this code in the header of the article page. Just before the </head> tag.

<!-- creditable styles -->
<link rel="stylesheet" type="text/css" href="<?= $creditable->getCssDependency(); ?>;" />

 

Footer Script

This is the Javascript which handles the Creditable button. Paste this code in the footer of the article page. Just before the </body> tag.

<!-- creditable scripts -->
<?php if (!$cResult->isPaid()){ ?>
<script type="text/javascript>
    <!--//
    const cUid = <?= $cResult->getUid(); ?>;
    var cAff_id = ''; //optional affiliate_id
    //-->
</script>
<script src="<?= $creditable->getJsDependency(); ?>" type="text/javascript"></script>
<?php } ?>

 

Support

If you encounter a problem integrating the Creditable scripts into your site, please do not hesitate to contact our support department.