license-bridge / wordpress-sdk
License Bridge WordPress SDK
1.0.28
2022-05-13 08:03 UTC
Requires
- php: >=5.4
README
这是官方的 License Bridge WordPress SDK。将此 SDK 添加到您的 WordPress 插件中,您将启用 License Bridge 平台的所有功能。
- WordPress 插件的授权
- 带有安全结账功能的着陆页,供客户购买授权。购买后,插件将自动更新为高级版本。
- 周期性支付 - 通过周期性支付建立可持续的业务。出售年度或月度订阅。
- WordPress 插件和主题的自动更新
将 SDK 集成到 WordPress 插件中
这是一个示例,说明您如何创建仅用于您插件的独特方法,以及您的全局变量,该变量将保存 SDK。
请确保将 my_license
替换为您自己的参考。
if (!function_exists('my_license')) {
// Create a helper function for easy SDK access.
function my_license()
{
global $my_license;
if ($my_license) {
return $my_license;
}
include __DIR__ . '/vendor/license-bridge/wordpress-sdk/src/Boot/bootstrap.php';
$pluginFilePath = __FILE__;
$my_license = Loader::register($pluginFilePath, [
'plugin-slug' => plugin_basename(__FILE__),
'license-product-slug' => 'my-first-product',
]);
return $my_license;
}
my_license();
}
- plugin-slug 是您的插件 slug,通常创建如下:
plugin_basename(__FILE__)
- license-product-slug 是代表您的产品/插件/主题在 License Bridge 平台上的 slug。 链接到帮助文件
使用示例
要访问 SDK,您可以使用您为插件创建的全局变量。
$my_license
或通过调用将返回 SDK 而不每次都创建的自定义方法。
my_license()
为您的产品获取独特的着陆页 URL
$link = $my_license->purchase_link($plugin_slug);
// https://licensebridge.com/market/my-plugin
检查用户是否有授权密钥
if ($my_license->license_exists($plugin_slug)) {
// User have the license
}
检查授权是否有效
if ($my_license->is_license_active($plugin_slug)) {
// User license is active
}
获取授权详情
$response = $my_license->license($plugin_slug);
如果授权不存在,则响应可以为 false。预期的响应是一个包含授权详情的数组
array (size=13)
'first_name' => string 'John' (length=11)
'last_name' => string 'Doe' (length=10)
'full_name' => string 'John Doe' (length=22)
'email' => string 'johndoe@mail.com' (length=20)
'plan_type' => string 'month' (length=5)
'plan_name' => string 'plan' (length=4)
'charge_type' => string 'subscription' (length=12)
'gateway' => string 'stripe' (length=6)
'active' => boolean true
'created_at' => string '01/27/2022 18:07:48' (length=19)
'subscribed' => boolean true
'cancelled' => boolean true
'subscription' =>
array (size=4)
'stripe_id' => string 'sub_0KMcNuxCqoZozrbaG75rgcZs' (length=28)
'stripe_customer_id' => string 'cus_L2hnYEuIw2p3pE' (length=18)
'ends_at_formated' => string 'February 27, 2022' (length=17)
'is_ended' => boolean false
取消用户授权请求
有时,当用户订阅了您的插件时,您可以允许用户取消对您的插件的订阅。以下是用户如何取消授权订阅的方式。
if ($my_license->cancel_license($plugin_slug)) {
// User license is canceled
}
授权
版权所有 (c) License Bridge。
许可协议:GNU 通用公共许可证(版本 3)。