broxman/fbapi

Fusebill API 的 PHP 库 (https://developer.fusebill.com/v1.0/reference)

1.0.5 2021-07-07 16:17 UTC

This package is auto-updated.

Last update: 2024-09-07 23:43:56 UTC


README

Fusebill API 的 PHP 库 (https://developer.fusebill.com/v1.0/reference)

依赖关系

需要 PHP 版本 >= 7。

需要以下 PHP 扩展

  • curl

安装

将 Fusebill API 添加到您的 composer.json 文件中。

{
  "require": {
    "broxman/fbapi": "*"
  }
}

示例

初始化 api

<?php
try {
    $fbl = new \Broxman\Fbapi\Fbapi('https://secure.fusebill.com/v1', 'APIKEY');
    // ...
}
catch (Exception $e){
    echo $e->getMessage() . "\n";
}
?>

创建客户

<?php
    $Customer = $fbl->postCustomers(null, null, [
        'firstName' => 'FirstName',
        'lastName' => 'LastName',
        'primaryEmail' => 'test@email.com',
        'primaryPhone' => '0000000',
        'reference' => '123456',
        'customerReference' => [
            'reference3' => 'Additional Reference Field',
        ],
    ]);
    print_r($Customer);
?>

激活客户

<?php
    $Customer = $fbl->postCustomerActivation(null, null, [
        "customerId" => 123456,
        "activateAllSubscriptions" => true,
        "activateAllDraftPurchases" => true,
        "temporarilyDisableAutoPost" => false,
    ]);
    print_r($Customer);
?>

更新客户

<?php
    $Customer = $fbl->putcustomers(null, null, [
        'id' => 123456,
        'firstName' => 'FirstName',
        'lastName' => 'LastName',
        'primaryEmail' => 'test@email.com',
        'primaryPhone' => '0000000',
        'reference' => '123456',
        'customerReference' => [
            'reference3' => 'Additional Reference Field',
        ],
        'status' => 'Active',
    ]);
    print_r($Customer);
?>

获取客户

<?php
    $Customer = $fbl->getcustomers(123456);
    print_r($Customer);
?>

创建购买

<?php
    $Purchase = $fbl->postPurchases(null, null, [
        'customerId' => 123456,
        'productId' => 123,
        'name' => 'Package Name',
        'quantity' => 1,
    ]);
    print_r($Purchase);
?>

最终化购买

<?php
    $Purchase = $fbl->postPurchases('Purchase',[
//        'buyNow' => 'true',
        'preview' => 'false',
        'showZeroDollarCharges' => 'false',
        'temporarilyDisableAutoPost' => 'false',
    ], [
        'customerId' => 123456,
        'purchaseIds' => [
            12345,
        ],
        'invoiceCollectOptions' => [
            "useAnyAvailableFundsFirst" => 'true',
            "rollbackOnFailedPayment" => 'true',
            "paymentMethod" => "UseDefaultPaymentMethod",
//            "paymentMethodId" => '1234',
        ],
    ]);
    print_r($Purchase);
?>

删除草稿购买

<?php
    $fbl->deletePurchases(12345);
?>

获取客户的发票

<?php
    $Invoices = $fbl->getCustomers([123456, 'Invoices']);
    foreach ($Invoices as $j => $Invoice) {
        echo "{$j}. {$Invoice->id}\n";
    }
?>

获取发票

<?php
    $Invoice = $fbl->getInvoices(1234567);
    print_r($Invoice);
?>

获取 PDF 发票

<?php
    $Invoicepdf = $fbl->getInvoices(['pdf', 1234567]);
    file_put_contents('invoice.pdf', $Invoicepdf);
?>

以数组形式接收响应

<?php
    // Create the handler
    $json_handler = new \Httpful\Handlers\JsonHandler(array('decode_as_array' => true));
    // Register it with Httpful
    \Httpful\Httpful::register('application/json', $json_handler);
?>

文档

许可证

MIT 许可证 (MIT)