PHP SDK SETUP AND USE

Hi,

I’m a newbie trying to set up the php sdk. I’ve checked the forum thread but can’t seem to find the solution.

I’m working on a local server on OSX.

I’m using invoiceninja.com

I used composer to download the SDK folder InvoiceNinja.

I’m developing a WordPress plugin. And I have put the SDK-PHP in the same directory as my plugin folder.

IM TRYING TO USE THIS SETUP
https://github.com/invoiceninja/sdk-php

This is where I’m having problems.

In my script file which sits in the same directory as the SDK

Do I need to include the sdk config file like this at top of the script?

include_once ‘InvoiceNinja/Config.php’;

use InvoiceNinja\Config as NinjaConfig;
use InvoiceNinja\Models\Client;
NinjaConfig::setURL(‘https://app.invoiceninja.com/api/v1’);
NinjaConfig::setToken(‘my token is here’);

When i run the script, My php script bombs with an error:

Parse error: parse error on line: use InvoiceNinja\Config as NinjaConfig;

Any help appreciated. I’m sure I’m missing so very simple knowledge here :slight_smile:

Chhers

Are you familiar with PSR 4?

https://www.php-fig.org/psr/psr-4/

Read up on setting up a new project using PSR4, to get going quickly using the following resource:

https://getcomposer.org/doc/01-basic-usage.md

You shouldn’t need this line: “include_once ‘InvoiceNinja/Config.php’;”

@Hillel, @DavidBomba thanks for the info.

However, I have a few more questions. (still trying to work my brain around this :slight_smile:

  1. Composer created the vendor directory one level up /outside my web root.

Do I need to move this inside my app folder?
https://www.dropbox.com/s/nvk0gihju69ymbd/path.jpg?dl=0

If yes how best to do this considering that the structure on the dev server is different than the production server.

Is this what is causing my script to fail?

  1. The problem I’m having is I don’t understand how I can to load the SDK into my project / script.

If I use:

use InvoiceNinja\Config as NinjaConfig;

Where is the connection between my script and the SDK?
Or does composer load the SDK and make it available to PHP?

  1. My PHP version is 5.5.38. Does this work with the SDK ?

Thanks again

1 and 2. You may want to post to a PHP forum for help with composer or you can try using the API directly instead.

  1. The app requires PHP 7, I haven’t tested with SDK with PHP < 7 but it may work.