evalue8bv/creditable-paywall

信用支付的官方SDK

0.4.0 2024-03-21 15:42 UTC

This package is auto-updated.

Last update: 2024-09-20 07:28:01 UTC


README

信用支付墙PHP包

Latest Stable Version Total Downloads License

信用支付墙PHP包是一个简单的Creditable API包装器,易于使用。其目的是将信用支付墙按钮集成到现有的支付墙系统中,从而使用户能够以每篇文章支付的方式使用信用进行支付。

要求

要使用信用支付墙的每篇文章支付按钮,需要以下事项:

安装

要安装此包,请运行以下命令使用Composer

composer require evalue8bv/creditable-paywall

使用方法

信用支付墙的JavaScript代码要求您的页面上有以下HTML元素

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

在您的head元素中包含以下样式表

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

设置环境为开发模式

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

检查文章访问权限

<?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页脚脚本

<!-- 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文档

有关Creditable API的更多信息,请参阅官方文档

贡献

如果您想贡献,请随时在我们的GitHub仓库提交拉取请求。

许可

此包根据Apache许可证发布。

支持

联系方式: www.creditable.newsinfo@creditable.news — +31 (0)24 350 54 00