Skip to content

Commit

Permalink
Merge pull request #24 from darthsoup/next
Browse files Browse the repository at this point in the history
feat: new structure with laravel-manager for multiple connections
  • Loading branch information
darthsoup authored Jan 20, 2022
2 parents 9dd5ba8 + e23e064 commit 75f0822
Show file tree
Hide file tree
Showing 15 changed files with 307 additions and 256 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: tests

on: [push, pull_request]
on:
push:
pull_request:

jobs:

Expand All @@ -10,12 +12,11 @@ jobs:
strategy:
matrix:
operating-system:
- 'ubuntu-latest'
- 'ubuntu-20.04'
php-version:
- '7.2'
- '7.3'
- '7.4'
- '8.0'
- '8.1'

runs-on: ${{ matrix.operating-system }}

Expand Down
73 changes: 41 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,71 +6,63 @@ Laravel WHMCS
[![License](https://poser.pugx.org/darthsoup/laravel-whmcs/license)](https://packagist.org/packages/darthsoup/laravel-whmcs)

An interface for interaction with the WHMCS API in Laravel.
This Package is heavily inspired by [Laravel GitLab](https://github.com/GrahamCampbell/Laravel-GitLab) created by [Graham Campbell](https://github.com/GrahamCampbell/).

> **Notice:**
>
> The working legacy branch can be found [here](https://github.com/darthsoup/laravel-whmcs/tree/legacy)
> The legacy version 0.3 can be found [here](https://github.com/darthsoup/laravel-whmcs/tree/legacy)
## Installation

Laravel WHMCS requires PHP ^7.4 | ^8.0 with at least Laravel version 6.

Install the package through [Composer](http://getcomposer.org/). Run the Composer require command from the Terminal:

```bash
composer require darthsoup/laravel-whmcs
```

Package will be installed automaticlly through composer package discovery. If not, then you need to register
the `DarthSoup\Whmcs\WhmcsService` service provider in your config/app.php.
Package will be installed automatically through composer package discovery. If not, then you need to register
the `DarthSoup\Whmcs\WhmcsService` service provider in your `config/app.php`.

Optionally, you can add the alias if you prefer to use the Facade
Optionally, you can add the alias if you prefer to use the Facade:

```php
'Whmcs' => DarthSoup\Whmcs\Facades\Whmcs::class
```

## Configuration

To get started, you'll need to publish all vendor assets.
To get started, you'll need to publish vendor assets for Laravel-Whmcs.

```bash
php artisan vendor:publish --provider=DarthSoup\Whmcs\WhmcsServiceProvider
```

Then open `config\whmcs.php` to fill your WHMCS api credentials in

Now you can use the WHMCS API in your Laravel project.

### Lumen
This will create the `config/whmcs.php` file in your app, modify it to set your configuration.

Copy the config file from the package to your projects config directory:
#### Default Connection

```bash
cp vendor/darthsoup/laravel-whmcs/config/whmcs.php config/whmcs.php
```
The option `default` is where you specify the default connection.

Then open `config\whmcs.php` to fill your WHMCS api credentials in.

To finish this, register the config file and the service provider in `bootstrap/app.php`:

```php
$app->configure('whmcs');
$app->register(DarthSoup\Whmcs\WhmcsServiceProvider::class);
```
#### Whmcs Connections

Now you can use the WHMCS API in your Lumen project.
The option `connections` is where you can add multiple connections to your whmcs instances.
You can choose between both API connection types from whmcs. These methods are `password` and `token`.
Example connections has been included, but you can add as many connections you would like.

## Basic Usage
## Usage

You can call your WHMCS API directly by calling the `\WHMCS::{WHMCSAPIFUNCTION}` facade.
#### via dependency injection

If you prefer dependency injection, you can inject the manager like this:
If you prefer to use Dependency Injection, you can easily add it to your controller as below:

```php
use DarthSoup\Whmcs\WhmcsManager;

class WhmcsController extends Controller
{
private $whmcsManager;
private WhmcsManager $whmcsManager;

public function __construct(WhmcsManager $whmcsManager)
{
Expand All @@ -79,31 +71,48 @@ class WhmcsController extends Controller

public function index()
{
$this->whmcsManager->execute('GetInvoice', ['invoiceid' => '1337']);
$result = $this->whmcsManager->client()->getClients();
dd($result);
}
}
```
**Hint**: The execute command will also support your self-created WHMCS api commands.

#### Via Facade

### Examples
If you prefer the classic Laravel facade style, this might be the way to go:

```php
use \DarthSoup\Whmcs\Facades\Whmcs;
# or
use \Whmcs;

\Whmcs::Client()->getClientsDomains([
'clientid' => '1'
]);
```

#### API Examples

Obtain a list of client purchased products:

```php
\Whmcs::GetClientsProducts([
use \DarthSoup\Whmcs\Facades\Whmcs;

\Whmcs::Client()->getClientsProducts([
'clientid' => '12345'
]);
```

Retrieve a specific invoice:

```php
\Whmcs::GetInvoice([
\Whmcs::Billing()->getInvoice([
'invoiceid' => '1337'
]);
```

For more information on how to use the WhmcsApi Client `DarthSoup\WhmcsApi\Client` class, check out the documentation at https://github.com/darthsoup/php-whmcs-api

## Support

[Please open an issue in github](https://github.com/darthsoup/laravel-whmcs/issues)
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"illuminate/support": "~7.0|~8.0",
"illuminate/session": "~7.0|~8.0",
"illuminate/events": "~7.0|~8.0",
"darthsoup/php-whmcs-api": "~1.0"
"darthsoup/php-whmcs-api": "~1.0",
"graham-campbell/manager": "^4.6"
},
"require-dev": {
"guzzlehttp/guzzle": "^7.0",
Expand Down
56 changes: 26 additions & 30 deletions config/whmcs.php
Original file line number Diff line number Diff line change
@@ -1,50 +1,46 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| HTTP Driver
|--------------------------------------------------------------------------
|
| Supported: "guzzlehttp"
*/
declare(strict_types=1);

'driver' => 'guzzlehttp',
return [

/*
|--------------------------------------------------------------------------
| API Credentials
| Default Connection
|--------------------------------------------------------------------------
|
| Enter the unhashed variant of your password if you use 'password' as 'auth_type'
|
| Supported auth types': "api", "password"
| Define your default whmcs connection
|
*/

'auth_type' => env('WHMCS_AUTH_TYPE', 'password'),

'apiurl' => env('WHMCS_API_URL', 'https://url.to.whmcs.tld/whmcs/includes/api.php'),

'api' => [
'identifier' => env('WHMCS_API_IDENTIFIER', 'YOUR_API_IDENTIFIER'),
'secret' => env('WHMCS_API_SECRET', 'YOUR_API_SECRET'),
],

'password' => [
'username' => env('WHMCS_USERNAME', 'YOUR_USERNAME'),
'password' => env('WHMCS_PASSWORD', 'YOUR_PASSWORD'),
],
'default' => 'primary',

/*
|--------------------------------------------------------------------------
| ResponseType
| WHMCS Connections
|--------------------------------------------------------------------------
|
| Supported auth types': "json", "xml"
| Define your whmcs connections here.
| Do not add the path `/includes/api.php` to the URL, it will be added automatically.
|
| Methods: "password", "token"
|
*/

'responsetype' => env('WHMCS_RESPONSE_TYPE', 'json'),
'connections' => [

'primary' => [
'method' => env('WHMCS_AUTH_TYPE', 'password'),
'url' => env('WHMCS_API_URL', 'https://url.to.whmcs.tld/whmcs'),
'username' => env('WHMCS_USERNAME', 'YOUR_USERNAME'),
'password' => env('WHMCS_PASSWORD', 'YOUR_PASSWORD'),
],

'secondary' => [
'method' => env('WHMCS_AUTH_TYPE', 'token'),
'url' => env('WHMCS_API_URL', 'https://url.to.whmcs.tld/whmcs'),
'identifier' => env('WHMCS_API_IDENTIFIER', 'YOUR_API_IDENTIFIER'),
'secret' => env('WHMCS_API_SECRET', 'YOUR_API_SECRET'),
]
]
];
11 changes: 0 additions & 11 deletions src/Adapter/ConnectorInterface.php

This file was deleted.

95 changes: 0 additions & 95 deletions src/Adapter/GuzzleHttpAdapter.php

This file was deleted.

19 changes: 19 additions & 0 deletions src/Auth/AbstractAuth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace DarthSoup\Whmcs\Auth;

use DarthSoup\WhmcsApi\Client;

abstract class AbstractAuth implements AuthInterface
{
protected ?Client $client;

public function with(Client $client): AuthInterface
{
$this->client = $client;

return $this;
}
}
Loading

0 comments on commit 75f0822

Please sign in to comment.