spira / zuora-laravel-sdk
Lumen/Laravel服务提供者,用于与Zuora SOAP API接口
Requires
- illuminate/support: ^5.2
- monolog/monolog: ~1.0
Requires (Dev)
- fabpot/php-cs-fixer: ~1.11
- fzaninotto/faker: ^1.4
- mockery/mockery: ^0.9.4
- phpunit/phpunit: ~4.0
- satooshi/php-coveralls: ~1.0
- symfony/var-dumper: ^3.0
This package is not auto-updated.
Last update: 2024-09-14 20:04:06 UTC
README
Lumen/Laravel服务提供者,用于与Zuora SOAP API交互
安装和配置
您可以通过Composer安装此包。
直接使用(框架无关)
为了使用Zuora API,您应该注册一个账户并获取访问API的凭据。所有凭据都通过结构化的数组传递到API::__construct
方法中。
[ 'wsdl' => '/path/to/zuora.wsdl', 'username' => 'user@example.com', 'password' => 'very-good-password', 'endpoint' => 'https://apisandbox.zuora.com/apps/services/a/74.0', ]
您可以在storage/config.dist.php
中找到示例配置文件。
Lumen\Laravel服务提供者
- 在您的应用中注册
ZuoraSdkServiceProvider
。 - 在config文件夹中创建一个名为
zuora.php
的配置文件,并将storage/config.dist.php
的内容放入其中。 - 祝您玩得开心
测试
此库使用PHPUnit和Mockery进行测试。
如果您想运行完整的集成测试套件,您应该填写您的storage/config.php
文件,该文件不包括在源树中,并由Composer的post-install-cmd
自动从config.dist.php
复制。否则,所有执行真实API调用的测试都将被跳过。请确保您提供了沙盒凭据!
类参考
所有类都位于Spira\ZuoraSdk
命名空间下,以下省略。
API
此类
- 配置并存储
\SoapClient
,您可以使用getClient()
和setClient(\SoapClient $client)
方法进行访问。 - 在第一次请求时执行懒授权。
- 提供操作
DataObject
实体的方法。 - 提供使用ZOQL选择
DataObject
的方法。 - 将Zuora API错误转换为抛出的
\Spira\ZuoraSdk\Exception\ApiException
。
当前实现的函数列表
create($objects)
- 在API中创建对象。接受DataObject|DataObject[]
update($objects)
- 在API中更新对象。接受DataObject|DataObject[]
delete($type, $ids)
- 删除类型为$type
且ID为int|array $ids
的对象query($query, $limit = null)
- 执行查询并返回查询类型的对象。queryMore($limit)
- 如果query()
的结果集有多个页面,使用此方法获取上一个调用中的下一页。hasMore()
- 检查最后的query()
是否有下一页的结果集。
DataObject
DataObject
是一个在操作API时存储数据的对象。
它扩展了\Illuminate\Support\Fluent
,因此所有数据操作都可以在数组或对象语法中轻松完成。
QueryBuilder
Zuora API提供ZOQL - 简化的查询语言,用于从API查询对象。
QueryBuilder允许以流畅的方式构建此类查询。
$builder = new QueryBuilder('Products', ['Id', 'Name']); $builder->where('Age', '=', $age) ->orWhere('Id', '=', $id); echo $builder->toZoql(); // Output: SELECT Id, Name FROM Products WHERE Age = 18 OR Id = 1
它主要用于在下面描述的Zuora
类中执行查询。
Zuora
此类提供查询助手和API使用的部分通用逻辑。
getAll($table, array $columns, $limit = null, \Closure $filtered = null)
- 构建查询并返回类型为$table
的对象数组。getOne($table, array $columns, \Closure $filtered = null)
- 构建查询并返回一个类型为$table
的对象getOneById($table, $columns, $id)
- 与getOne
类似,但内置了按 id 过滤的功能。
将 QueryBuilder
的实例传递给 $filtered
匿名函数,以便在需要时添加查询条件。由于 ZOQL 不支持列的通配符,您应手动提供列的列表。
对于某些类型的对象,添加了自定义方法。
产品
getAllProducts(array $columns = null, $limit = null, \Closure $filtered = null)
getOneProduct($id, array $columns = null)
getAllProductRatePlans(array $columns = null, $limit = null, \Closure $filtered = null)
getRatePlansForProduct($product, array $columns = null, $limit = null)
getOneProductRatePlan($id, array $columns = null)
getOneProductRatePlanActiveCurrencies($ratePlan)
getAllProductRatePlanCharges(array $columns = null, $limit = null, \Closure $filtered = null)
getChargesForProductRatePlan($ratePlan, array $columns = null, $limit = null)
getOneProductRatePlanCharge($id, array $columns = null)
getAllProductRatePlanChargeTiers(array $columns = null, $limit = null, \Closure $filtered = null)
getTiersForProductRatePlanCharge($ratePlanCharge, array $columns = null, $limit = null)
getOneProductRatePlanChargeTier($id, array $columns = null)
账户
getAllAccounts(array $columns = null, $limit = null, \Closure $filtered = null)
getOneAccount($id, array $columns = null)
getContactsForAccount($account, array $columns = null, $limit = null)
getOneContact($id, array $columns = null)
getPaymentMethodsForAccount($account, array $columns = null, $limit = null)
getOnePaymentMethod($id, array $columns = null)
getAllPaymentMethods(array $columns = null, $limit = null, \Closure $filtered = null)
createAccount(Account $account, Contact $contact, PaymentMethod $paymentMethod = null)
订阅
getAllSubscriptions(array $columns = null, $limit = null, \Closure $filtered = null)
getOneSubscription($id, array $columns = null)
getSubscriptionsForAccount($account, array $columns = null, $limit = null)
subscribe(Account $account, Subscription $subscription, ProductRatePlan $ratePlan, ProductRatePlanCharge $ratePlanCharge = null, PaymentMethod $paymentMethod = null, Contact $contact = null, SubscribeOptions $subscribeOptions = null)
支付 & 发票
getAllPayments(array $columns = null, $limit = null, \Closure $filtered = null)
getOnePayment($id, array $columns = null)
getPaymentsForAccount($account, array $columns = null, $limit = null)
getAllInvoices(array $columns = null, $limit = null, \Closure $filtered = null)
getOneInvoice($id, array $columns = null)
getInvoicesForAccount($account, array $columns = null, $limit = null)
使用示例
use Monolog\Logger; use Spira\ZuoraSdk\API; use Spira\ZuoraSdk\Zuora; use Monolog\Handler\StreamHandler; use Spira\ZuoraSdk\DataObjects\Product; $config = require '/path/to/config.php'; $logger = new Logger('zuora', [new StreamHandler('path/to/zuora.log')]); // optional logger usage $api = new API($config, $logger); $zuora = new Zuora($api); // Create a new product $product = new Product(['Name' => 'My Product']); $api->create($product); // Get list of a products /** @var $products Product[] */ $products = $zuora->getAllProducts(); // Delete product $api->delete('Product', [$product->Id]);
您可以在测试中找到更多示例。
贡献
所有提交都必须遵循 PSR-2 编码风格指南。
您可以使用 PHP-CS-Fixer 手动,或使用 hooks/pre-commit
中提供的 git pre-commit
钩子。遵循文件中的说明,并确保它是可执行的。