定制 napp/fenerum-api-client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

napp/fenerum-api-client

Composer 安装命令:

composer require napp/fenerum-api-client

包简介

API Client for Fenerum

README 文档

README

Latest Version on Packagist Build Status Quality Score Total Downloads Code Coverage

Installation

You can install the package via composer:

composer require napp/fenerum-api-client

Installation

  1. Add to .env - Fenerum API Token and a user/pass combo to allow Fenerum to post webhook events.
FENERUM_API_TOKEN=
FENERUM_AUTH_USERNAME=myuser
FENERUM_AUTH_PASSWORD=mypass
  1. add FenerumServiceProvider to config/app.php
[
    ...
    \Fenerum\FenerumServiceProvider::class,
    ...
]
  1. Add route to receive webhooks
Route::post('my-webhook-url', '\Fenerum\Webhooks\Http\Controllers\WebhookController@handle');
  1. Register events in app/Providers/EventServiceProvider
AccountCreated::class => [
    MyAccountCreatedListener::class
],
AccountUpdated::class => [
    MyAccountUpdatedListener::class
],
CancelSubscription::class => [
    MyCancelSubscriptionListener::class
],

Webhook Events supported

  • AccountCreated
  • AccountUpdated
  • CancelSubscription
  • NewActivity
  • NewInvoice
  • PaidInvoice
  • PlanTermsCreated
  • PlanTermsUpdated
  • RenewSubscriptionSoon

Usage

// use DI to resolve dependencies
$accounts = app(\Fenerum\ApiService::class)->account();

// or without DI
$client = new \Fenerum\ApiClient();
$fenerum = new \Fenerum\ApiService($client);
$accounts = $fenerum->account();

Examples

Get accounts

use Fenerum\ApiService;

$accounts = app(ApiService::class)->account()->listAccounts();

Update Subscription - User Seats

// find account with id "1234"
$myAccount = $fenerum->account()->getAccount('1234');

// get the first subscription
$subId = $myAccount['subscription_set'][0]['uuid'];

// update subscription user seat count
$updatedSubscription = $fenerum->subscription()->updateSubscription([
    'quantity' => 59
], $subId);

Create account and add subscription (simple version)

/** @var \Fenerum\ApiService $fenerum */
$fenerum = app(\Fenerum\ApiService::class);

$localAccountCode = '12345678';
$planTermId = 'c82a888e-2149-4b3c-8e14-ff5086e49417';

// create an account
$fenerum->account()->createAccount([
    'company_name' => 'Foo Bar Inc',
    'code' => $localAccountCode,
    'legal_address' => 'Road 123',
    'legal_zipcode' => '90210',
    'legal_city' => 'Hollywood',
    'legal_country' => 'US',
    'billing_same_as_legal' => true,
    'language' => 'en',
    'legal_vat_number' => 'US22223344',
]);

// add subscription to the account
$result = $fenerum->subscription()->createSubscription([
   'account' => $localAccountCode,
   'terms' => $planTermId,
   'collection_method' => 'invoice',
   'start_date' => now()->endOfMonth()->toIso8601String(),
   'payment_terms' => 14
]);

Create account and add recipient, contract, discount and a subscription (advanced version)

/** @var \Fenerum\ApiService $fenerum */
$fenerum = app(\Fenerum\ApiService::class);

$localAccountCode = '12345678';
$planTermId = 'c82a888e-2149-4b3c-8e14-ff5086e49417';

// create an account
$account = $fenerum->account()->createAccount([
    'company_name' => 'Foo Bar Inc',
    'code' => $localAccountCode,
    'legal_address' => 'Road 123',
    'legal_zipcode' => '90210',
    'legal_city' => 'Hollywood',
    'legal_country' => 'US',
    'billing_same_as_legal' => true,
    'language' => 'en',
    'legal_vat_number' => 'US22223344',
]);

// create a recipient
$fenerum->recipient()->createRecipient([
    'account' => $account['uuid'],
    'name' => 'John Doe',
    'email' => 'john@doe.com',
    'receive_invoice' => true,
    'receive_payment_confirmation' => true,
    'receive_subscription_notifications' => true,
]);

// assign a 24 month contract to the account
$contract = $fenerum->contract()->createContract([
    'plan_terms' => $planTermId,
    'start_date' => now()->startOfDay()->toIso8601String(),
    'commitment_length' => 24
], $localAccountCode);

// add 10% discounting
$fenerum->contractTier()->createContractTier([
    'minimum_quantity' => 1,
    'discount' => '10',
    'discount_type' => 'percent',
], $localAccountCode, $contract['uuid']);

// add subscription to the account
$result = $fenerum->subscription()->createSubscription([
   'account' => $localAccountCode,
   'terms' => $planTermId,
   'collection_method' => 'invoice',
   'start_date' => now()->endOfMonth()->toIso8601String(),
   'payment_terms' => 14
]);

Download invoice

$invoice = app(\Fenerum\ApiService::class)
            ->invoice()
            ->getInvoice('24260f57-f190-4cfa-a2a0-d8a8d827bda8');

$filePath = public_path('invoice_'.$invoice['invoice_number'].'.pdf');
file_put_contents($filePath, base64_decode($invoice['pdf_base64']));

return response()->download($filePath)->deleteFileAfterSend(true);

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.

napp/fenerum-api-client 适用场景与选型建议

napp/fenerum-api-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 11 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「api」 「webhooks」 「fenerum」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 napp/fenerum-api-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 napp/fenerum-api-client 我们能提供哪些服务?
定制开发 / 二次开发

基于 napp/fenerum-api-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-11-18