paydemic/paydemic-php-sdk

Paydemic.com REST API 的 PHP SDK。

1.1.0 2018-09-24 20:07 UTC

This package is not auto-updated.

Last update: 2024-09-18 02:23:11 UTC


README

Paydemic.com 的 PHP API

安装

composer require paydemic/paydemic-php-sdk

API 概览

每个资源都通过您的 paydemic 实例访问

$paydemic = new PaydemicPhpSdk('<accessKey>', '<secretAccessKey>')
$paydemic->{ RESOURCE_NAME }->{ METHOD_NAME }

每个资源方法都返回 PromiseInterface 实例(https://promisesaplus.com/),因此您不需要使用常规回调。例如

// Create a new purchase link:
$finalUrl = "https://paywalledsite.com/paid-access-article";
$title = "My paid access article title";
$currencyCode = "USD";
$price = 4.0;
$description = "Extra information";

$paydemic->PurchaseLinks->create(
    $finalUrl,
    $title,
    $currencyCode,
    $price,
    $description
)->then(
    // on success
    function ($purchaseLink) { /* some code */ },
    // on exception
    function ($exception) { /* some error handling code */ },
)

还有一个 wait() 方法,它只需等待 Promise 完成,并返回结果

// Create a new purchase link:
$purchaseLink = $paydemic->PurchaseLinks->create(
    $finalUrl,
    $title,
    $currencyCode,
    $price
)->wait();

// Retrieve an existing purchase link:
$retrieved = $paydemc->PurchaseLinks->retrieve($purchaseLink['id'])->wait();

// List all the existing purchase links under this project:
$listed = $paydemic->PurchaseLinks->listAll()->wait();

// Update an existing purchase link:
$finalUrlUpdate = $finalUrl . '#updated';
$titleUpdate = $title . ' UPDATED';
$priceUpdate = 6.0;
$descriptionUpdate = $description . ' UPDATED';

$updated = $paydemic->PurchaseLinks->update(
    $purchaseLink['id'],
    $finalUrlUpdate,
    $titleUpdate,
    $currencyCode,
    $priceUpdate,
    $descriptionUpdate
)->wait();

// Delete an existing purchase link:
$paydemic->PurchaseLinks->delete($purchaseLink['id'])->wait();

可用资源和方法

开发

在本地运行测试

composer install
composer test

运行静态分析工具,运行测试以覆盖率和生成 API 文档

composer build

完成后,查看 build 文件夹。

贡献

  • 如果您想贡献,请fork存储库并提交拉取请求。