Lumen/Laravel service provider for interfacing with Zuora SOAP api
PHP Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
hooks hooks and readme update Feb 26, 2016
storage Updating WSDL and resetting default columns. Nov 24, 2016
tests Apply style patch. Jun 3, 2016
.coveralls.yml Updated satooshi/coveralls to ~1.0 removed deprecated src_dir option Jan 26, 2016
.gitignore Refactored API. Added Logger. Jan 25, 2016
.travis.yml Mocked out the service provider file, composer deps, travis, styleci … Jan 22, 2016 Breaking interface commit! Mar 3, 2016
phpunit.xml payment with tests Feb 9, 2016


Lumen/Laravel service provider for interacting with Zuora SOAP API

Build Status Coverage Status StyleCI

Install and configuration

You can install this package via Composer.

Direct usage (framework agnostic)

For using Zuora API you should register an account and get credentials for accessing an API. All credentials are passed into API::__construct method in array with structure:

    'wsdl'     => '/path/to/zuora.wsdl',
    'username' => '',
    'password' => 'very-good-password',
    'endpoint' => '',

You can find sample config file in storage/config.dist.php

Lumen\Laravel Service Provider

  1. Register ZuoraSdkServiceProvider in your app
  2. Create a config file named zuora.php in config folder and put there contents of storage/config.dist.php
  3. Have fun


This library is tested using PHPUnit and Mockery.

If you want to run full set of integration tests you should fill your storage/config.php file, which is excluded from source tree and copied automatically from config.dist.php with Composer's post-install-cmd. Otherwise all tests making real api calls will be skipped. Make sure you provided sandbox credentials!

Class Reference

All classes are located under Spira\ZuoraSdk namespace is omitted below.


This class:

  • Configures and stores \SoapClient, you can use getClient() and setClient(\SoapClient $client) methods for access
  • Performs lazy authorization on first request
  • Provides methods for operating with DataObject entites
  • Provides methods for selecting DataObject with ZOQL
  • Converts Zuora API Errors to thrown \Spira\ZuoraSdk\Exception\ApiException

Current list of implemented methods:

  • create($objects) - Create object in API. Accepts DataObject|DataObject[]
  • update($objects) - Update object in API. Accepts DataObject|DataObject[]
  • delete($type, $ids) - Delete objects of $type with IDs int|array $ids
  • query($query, $limit = null) - Runs a query and returns objects of type was queried.
  • queryMore($limit) - If resultset for query() has few pages use this method to get next pages of previous call.
  • hasMore() - Check does last query() has next page of resultset.


DataObject is an object for storing data while operating with API.

It extends \Illuminate\Support\Fluent so all data manipulation is done easilly in array- or object-like syntax.


Zuora API provides ZOQL - simplified query language for querying objects from api.

QueryBuilder allows building such queries in fluent style:

$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

Mostly it used for making queries in Zuora class described below.


This class provides querying helpers and some part of common logic for using API.

  • getAll($table, array $columns, $limit = null, \Closure $filtered = null) - builds a query and returns an array of objects of type $table
  • getOne($table, array $columns, \Closure $filtered = null) - builds a query and returns one object of type $table
  • getOneById($table, $columns, $id) - pretty the same as getOne but with built-in filter by id.

Instance of QueryBuilder is passed into $filtered lambda for adding conditions to query if needed. While ZOQL does not support wildcards for columns you should provide list of them manually.

For some types of objects there are added custom methods:


  • 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)

Payments & Invoices

  • 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)

Usage Example

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']);

// Get list of a products

/** @var $products Product[] */
$products = $zuora->getAllProducts();

// Delete product

$api->delete('Product', [$product->Id]);

You can find more samples in tests.


All commits MUST follow PSR-2 coding style guide.

You may use the PHP-CS-Fixer manually or use git pre-commit hook supplied in hooks/pre-commit. Follow instructions in file and make sure it is executable.