cba85/wave-api-php-client

Wave GraphQL API PHP client

dev-master 2020-06-01 14:17 UTC

This package is auto-updated.

Last update: 2024-04-29 04:20:53 UTC


README

A PHP client for Wave API.

Note: I've created this package for my personal need. Not all the Wave API operation has been implemented. But you can add an operation by creating a new class in src/Operations.

Install

$ composer require cba85/wave-api-php-client

Usage

use Wave\Wave;

$wave = new Wave('YOUR_WAVE_FULL_ACCESS_TOKEN');

Available methods

Get user

https://developer.waveapps.com/hc/en-us/articles/360032552912-Query-Get-user

$optionalFields = ['user' => ['id', 'firstName']];
$user = $wave->getUser($optionalFields);

List businesses

https://developer.waveapps.com/hc/en-us/articles/360032908111-Query-List-businesses

$optionalFields = ['pageInfo' => ['totalCount']];
$optionalArguments = ['businesses' => ['pageSize' => 25]];
$businesses = $wave->listbusinesses($optionalFields, $optionalArguments);

List products

https://developer.waveapps.com/hc/en-us/articles/360032572872-Query-Paginate-list-of-products

 $wave = new Wave(getenv('WAVE_FULL_ACCESS_TOKEN'));
$products = $wave->listProducts([], [], [
    'businessId' => getenv('WAVE_BUSINESS_ID'),
    'page' => 1,
    'pageSize' => 1
]);

Get customer by ID

https://developer.waveapps.com/hc/en-us/articles/360032911011-Query-Get-customer-by-id

$optionalFields = ['customer' => ['id', 'name', 'email']];
$wave = new Wave(getenv('WAVE_FULL_ACCESS_TOKEN'));
$customer = $wave->getCustomerById($optionalFields, [], [
    'businessId' => getenv('WAVE_BUSINESS_ID'),
    'customerId' => getenv('WAVE_CUSTOMER_ID')
]);

Create customer

https://developer.waveapps.com/hc/en-us/articles/360032569232-Mutation-Create-customer

$optionalFields = ['customer' => ['id', 'name', 'email']];
$wave = new Wave(getenv('WAVE_FULL_ACCESS_TOKEN'));
$customerCreate = $wave->createCustomer($optionalFields, [], [
    'input' => [
        'businessId' => getenv('WAVE_BUSINESS_ID'),
        'name' => "Santa",
        'firstName' => "Saint",
        'lastName' => "Nicolas",
        'email' => "santa@claus.com",
        'address' => [
            'city' => "North Pole",
            'postalCode' => "H0H H0H",
            'countryCode' => "CA"
        ],
        'currency' => "EUR"
    ]
]);

Patch customer

https://developer.waveapps.com/hc/en-us/articles/360033059491-Mutation-Patch-customer

$optionalFields = ['customer' => ['id', 'name', 'email']];
$wave = new Wave(getenv('WAVE_FULL_ACCESS_TOKEN'));
$customerPatch = $wave->patchCustomer([], [], [
    'input' => [
        'id' => getenv('WAVE_CUSTOMER_ID'),
        'email' => "new@email.com"
    ]
]);

Create invoice

https://developer.waveapps.com/hc/en-us/articles/360019968212-API-Reference

$wave = new Wave(getenv('WAVE_FULL_ACCESS_TOKEN'));
$invoiceCreate = $wave->createInvoice([], [], [
    'input' => [
        'businessId' => getenv('WAVE_BUSINESS_ID'),
        'customerId' => getenv('WAVE_CUSTOMER_ID'),
        'status' => "DRAFT",
        'items' => [
            'productId' => getenv('WAVE_PRODUCT_ID'),
            'description' => "test",
            'quantity' => 1,
            'unitPrice' => 14.99,
            'taxes' => [
                'salesTaxId' => getenv('WAVE_TAX_ID'),
            ]
        ]
    ]
]);

GraphQL query

It's also possible to manually send a GraphQL query using the GraphQL client included behind the scene:

 $query = <<<'GRAPHQL'
            query {
                user {
                    id
                    firstName
                    lastName
                    defaultEmail
                    createdAt
                    modifiedAt
                }
            }
            GRAPHQL;
$wave = new Wave('YOUR_WAVE_FULL_ACCESS_TOKEN');
$results = $wave->client->runRawQuery($query, false);

Wave API documentation

See Wave API documentation for reference.

Tests

Add Wave tokens and ids in an .env file based on .env.example file example to test Wave API.

  • WAVE_FULL_ACCESS_TOKEN : You Wave account full access token.
  • WAVE_BUSINESS_ID : Wave Business ID you can use for tests only.
    • List them and pick one using :
    $ ./vendor/bin/phpunit --filter testListBusiness
  • WAVE_CUSTOMER_ID : Wave Customer ID you can use for tests only.
  • WAVE_PRODUCT_ID : Wave Product ID you can use for tests only.
    • List them and pick one using :
    $ ./vendor/bin/phpunit --filter testListProducts
  • WAVE_TAX_ID : A Wave Tax ID used for invoice creation tests.
    • Find your defaultSalesTaxes using :
    $ ./vendor/bin/phpunit --filter testListProducts

Then launch tests:

$ ./vendor/bin/phpunit