evalue8bv/creditable-paywall

Official PayWall SDK for Creditable

0.4.0 2024-03-21 15:42 UTC

This package is auto-updated.

Last update: 2025-05-20 08:51:35 UTC


README

Creditable PayWall PHP Package

Latest Stable Version Total Downloads License

The Creditable-Paywall PHP package is a simple and easy-to-use wrapper for the Creditable API. Its purpose is to enable the integration of a Creditable button into an existing paywall system, thus enabling customers to pay for articles on a pay-per-article basis with credits.

Requirements

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

Installation

To install the package, use Composer by running the following command:

composer require evalue8bv/creditable-paywall

Usage

The javascript code of Creditable requires you to have the following HTML elements on your page:

<div id="creditable-container" class="creditable-container">
  <!-- the button -->
  <div id="creditable-button"></div>
  <!-- popup window -->
  <div id="creditable-window"></div>
</div>

Include the following stylesheet in your head element:

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

Setting environment to dev

require_once 'vendor/autoload.php';

use Creditable\CreditablePayWall;

$apiKey = 'your-api-key-here';
$options = [
    'environment' => 'dev'
];
$creditable = new CreditablePayWall($apiKey, $options);

// Rest of the code

Checking for article access

<?php

require_once 'vendor/autoload.php';

use Creditable\CreditablePayWall;

$apiKey = 'your-api-key-here';
$creditable = new CreditablePayWall($apiKey);

$creditable_article_id = "<<ARTICLE ID>>"; // Alphanumeric (required)
$creditable_article_title = "<<ARTICLE TITLE>>"; // Alphanumeric (required)
$creditable_topic_id = "<<TOPIC ID>>"; // Alphanumeric (required)
$creditable_topic_name = "<<TOPIC NAME>>"; // Alphanumeric (required)
$creditable_topic_desc = "<<TOPIC DESC>>"; // Alphanumeric (optional)
$creditable_topic_url = "<<TOPIC URL>>"; // Alphanumeric (optional)
$creditable_article_url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; // Alphanumeric (required)
$creditable_article_lang = "en-GB"; // ISO (required)
$creditable_article_authors  =   "<<ARTICLE AUTHORS>>";   // Alphanumeric (comma separated) String (optional)
$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

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

// Example usage
$data = [
    'jwt' => $creditable_cookie,
    'article_id' => $creditable_article_id,
    'article_name' => $creditable_article_title,
    'topic_id' => $creditable_topic_id,
    'topic_name' => $creditable_topic_name,
    'topic_desc' => $creditable_topic_desc,
    'topic_url' => $creditable_topic_url,
    '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
];

try {
    $result = $creditable->check($data);
    if ($result->isPaid()) {
        // Access granted
    } else {
        // Access denied
    }
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

JavaScript footer script:

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

API Documentation

For more information about the Creditable API, please refer to the official documentation.

Contributing

If you would like to contribute, please feel free to submit a pull request on our GitHub repository.

License

This package is released under the Apache license.

Support

Contact: www.creditable.newsinfo@creditable.news — +31 (0)24 350 54 00