Skip to content

Commit

Permalink
Merge pull request #96 from turbo124/main
Browse files Browse the repository at this point in the history
Update for all endpoints
  • Loading branch information
turbo124 authored Dec 19, 2022
2 parents b854a36 + bb508f0 commit dd61bbf
Show file tree
Hide file tree
Showing 10 changed files with 628 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ $invoices = $ninja->invoices->all();
- TaxRates
- Statics
- Expenses
- Expense Categories
- Recurring Invoices
- Credits
- Projects
- Tasks
- Vendors
- Companies
- Subscriptions
- Purchase Orders
- Bank Integrations
- Bank Transactions

### Retrieving Models

Expand Down
30 changes: 30 additions & 0 deletions src/Endpoints/BankIntegrations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/sdk-php source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/MIT
*/

namespace InvoiceNinja\Sdk\Endpoints;

use GuzzleHttp\Exception\GuzzleException;
use InvoiceNinja\Sdk\InvoiceNinja;

class BankIntegrations extends BaseEntity
{

protected InvoiceNinja $ninja;

protected string $uri = "/api/v1/bank_integrations";

public function __construct(InvoiceNinja $ninja)
{
$this->ninja = $ninja;
}

}

30 changes: 30 additions & 0 deletions src/Endpoints/BankTransactions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/sdk-php source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/MIT
*/

namespace InvoiceNinja\Sdk\Endpoints;

use GuzzleHttp\Exception\GuzzleException;
use InvoiceNinja\Sdk\InvoiceNinja;

class BankTransactions extends BaseEntity
{

protected InvoiceNinja $ninja;

protected string $uri = "/api/v1/bank_transactions";

public function __construct(InvoiceNinja $ninja)
{
$this->ninja = $ninja;
}

}

30 changes: 30 additions & 0 deletions src/Endpoints/PurchaseOrders.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/sdk-php source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/MIT
*/

namespace InvoiceNinja\Sdk\Endpoints;

use GuzzleHttp\Exception\GuzzleException;
use InvoiceNinja\Sdk\InvoiceNinja;

class PurchaseOrders extends BaseEntity
{

protected InvoiceNinja $ninja;

protected string $uri = "/api/v1/purchase_orders";

public function __construct(InvoiceNinja $ninja)
{
$this->ninja = $ninja;
}

}

30 changes: 30 additions & 0 deletions src/Endpoints/Subscriptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/sdk-php source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/MIT
*/

namespace InvoiceNinja\Sdk\Endpoints;

use GuzzleHttp\Exception\GuzzleException;
use InvoiceNinja\Sdk\InvoiceNinja;

class Subscriptions extends BaseEntity
{

protected InvoiceNinja $ninja;

protected string $uri = "/api/v1/subscriptions";

public function __construct(InvoiceNinja $ninja)
{
$this->ninja = $ninja;
}

}

16 changes: 16 additions & 0 deletions src/InvoiceNinja.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\RequestException;
use InvoiceNinja\Sdk\Endpoints\BankIntegrations;
use InvoiceNinja\Sdk\Endpoints\BankTransactions;
use InvoiceNinja\Sdk\Endpoints\Clients;
use InvoiceNinja\Sdk\Endpoints\Companies;
use InvoiceNinja\Sdk\Endpoints\Credits;
Expand All @@ -24,9 +26,11 @@
use InvoiceNinja\Sdk\Endpoints\Payments;
use InvoiceNinja\Sdk\Endpoints\Products;
use InvoiceNinja\Sdk\Endpoints\Projects;
use InvoiceNinja\Sdk\Endpoints\PurchaseOrders;
use InvoiceNinja\Sdk\Endpoints\Quotes;
use InvoiceNinja\Sdk\Endpoints\RecurringInvoices;
use InvoiceNinja\Sdk\Endpoints\Statics;
use InvoiceNinja\Sdk\Endpoints\Subscriptions;
use InvoiceNinja\Sdk\Endpoints\Tasks;
use InvoiceNinja\Sdk\Endpoints\TaxRates;
use InvoiceNinja\Sdk\Endpoints\Vendors;
Expand Down Expand Up @@ -80,6 +84,14 @@ class InvoiceNinja

public GroupSettings $group_settings;

public Subscriptions $subscriptions;

public PurchaseOrders $purchase_orders;

public BankTransactions $bank_transactions;

public BankIntegrations $bank_integrations;

/**
* @param string $token
* @return void
Expand Down Expand Up @@ -113,6 +125,10 @@ private function initialize()
$this->companies = new Companies($this);
$this->expense_categories = new ExpenseCategories($this);
$this->group_settings = new GroupSettings($this);
$this->subscriptions = new Subscriptions($this);
$this->purchase_orders = new PurchaseOrders($this);
$this->bank_transactions = new BankTransactions($this);
$this->bank_integrations = new BankIntegrations($this);

return $this;
}
Expand Down
87 changes: 87 additions & 0 deletions tests/BankIntegrationsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/sdk-php source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/MIT
*/

namespace InvoiceNinja\Sdk\Tests;

use InvoiceNinja\Sdk\InvoiceNinja;
use PHPUnit\Framework\TestCase;

class BankIntegrationsTest extends TestCase
{
protected string $token = "company-token-test";
protected string $url = "http://ninja.test:8000";



public function setUp() :void
{
parent::setUp();
$this->faker = \Faker\Factory::create();
}

public function testBankIntegrations()
{
$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$bank_integrations = $ninja->bank_integrations->create(['bank_account_name' => $this->faker->firstName]);

$this->assertTrue(is_array($bank_integrations));

}

public function testBankIntegrationGet()
{

$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$integration = $ninja->bank_integrations->create(['bank_account_name' => $this->faker->firstName]);

$this->assertTrue(is_array($integration));

$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$bank_integrations = $ninja->bank_integrations->get($integration['data']['id']);

$this->assertTrue(is_array($bank_integrations));

}


public function testBankIntegrationPut()
{

$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$integration = $ninja->bank_integrations->create(['bank_account_name' => $this->faker->firstName]);

$bank_integrations = $ninja->bank_integrations->update($integration['data']['id'], ['bank_account_name' => $this->faker->firstName]);

$this->assertTrue(is_array($bank_integrations));

}


public function testBankIntegrationPost()
{

$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$bank_integrations = $ninja->bank_integrations->create(['bank_account_name' => $this->faker->firstName]);

$this->assertTrue(is_array($bank_integrations));

}
}
95 changes: 95 additions & 0 deletions tests/BankTransactionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/sdk-php source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/MIT
*/

namespace InvoiceNinja\Sdk\Tests;

use InvoiceNinja\Sdk\InvoiceNinja;
use PHPUnit\Framework\TestCase;

class BankTransactionsTest extends TestCase
{
protected string $token = "company-token-test";
protected string $url = "http://ninja.test:8000";



public function setUp() :void
{
parent::setUp();
$this->faker = \Faker\Factory::create();
}

public function testBankTransactions()
{
$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$bank_integrations = $ninja->bank_integrations->create(['bank_account_name' => $this->faker->firstName]);

$transactions = $ninja->bank_transactions->create(['bank_integration_id' => $bank_integrations['data']['id'], 'name' => $this->faker->firstName]);

$this->assertTrue(is_array($transactions));

}

public function testTransactionGet()
{

$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$bank_integrations = $ninja->bank_integrations->create(['bank_account_name' => $this->faker->firstName]);

$transaction = $ninja->bank_transactions->create(['bank_integration_id' => $bank_integrations['data']['id'],'name' => $this->faker->firstName]);

$this->assertTrue(is_array($transaction));

$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$transactions = $ninja->bank_transactions->get($transaction['data']['id']);

$this->assertTrue(is_array($transactions));

}


public function testTransactionPut()
{

$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$bank_integrations = $ninja->bank_integrations->create(['bank_account_name' => $this->faker->firstName]);

$transaction = $ninja->bank_transactions->create(['bank_integration_id' => $bank_integrations['data']['id'], 'name' => $this->faker->firstName]);

$transactions = $ninja->bank_transactions->update($transaction['data']['id'], ['bank_integration_id' => $bank_integrations['data']['id'], 'name' => $this->faker->firstName, 'date' => '2022-10-10', 'amount' => 100]);

$this->assertTrue(is_array($transactions));

}


public function testTransactionPost()
{

$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$bank_integrations = $ninja->bank_integrations->create(['bank_account_name' => $this->faker->firstName]);

$transactions = $ninja->bank_transactions->create(['bank_integration_id' => $bank_integrations['data']['id'], 'name' => $this->faker->firstName]);

$this->assertTrue(is_array($transactions));

}
}
Loading

0 comments on commit dd61bbf

Please sign in to comment.