|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Part of the GoCardless Pro PHP Client package integration for Laravel |
|
4
|
|
|
* |
|
5
|
|
|
* NOTICE OF LICENSE |
|
6
|
|
|
* |
|
7
|
|
|
* Licensed under the MIT License. |
|
8
|
|
|
* |
|
9
|
|
|
* This source file is subject to the MIT License that is |
|
10
|
|
|
* bundled with this package in the LICENSE file. |
|
11
|
|
|
* |
|
12
|
|
|
* @package Gocardless Laravel |
|
13
|
|
|
* @version 0.1.0 |
|
14
|
|
|
* @author Nested.net |
|
15
|
|
|
* @license MIT |
|
16
|
|
|
* @link https://nested.net |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace Nestednet\Gocardless; |
|
20
|
|
|
|
|
21
|
|
|
use GoCardlessPro\Client; |
|
22
|
|
|
use Illuminate\Support\Facades\Route; |
|
23
|
|
|
use Illuminate\Support\ServiceProvider; |
|
24
|
|
|
|
|
25
|
|
|
class GocardlessServiceProvider extends ServiceProvider |
|
26
|
|
|
{ |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritDoc} |
|
30
|
|
|
*/ |
|
31
|
|
|
public function boot() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->publishes([ |
|
34
|
|
|
__DIR__.'/config/gocardless.php' => config_path('gocardless.php'), |
|
|
|
|
|
|
35
|
|
|
], 'config'); |
|
36
|
|
|
|
|
37
|
|
|
if (! class_exists('CreateGocardlessWebhookClassTable')) { |
|
38
|
|
|
$timestamp = date('Y_m_d_His', time()); |
|
39
|
|
|
|
|
40
|
|
|
$this->publishes([ |
|
41
|
|
|
__DIR__.'/../database/migrations/create_gocardless_webhook_calls_table.php.stub' => database_path('migrations/'.$timestamp.'_create_gocardless_webhook_calls_table.php'), |
|
|
|
|
|
|
42
|
|
|
], 'migrations'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
Route::macro('gocardlessWebhooks', function ($url) { |
|
46
|
|
|
return Route::post($url, '\Nestednet\Gocardless\Controllers\GocardlessWebhookController'); |
|
47
|
|
|
}); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* {@inheritDoc} d |
|
52
|
|
|
*/ |
|
53
|
|
|
public function register() |
|
54
|
|
|
{ |
|
55
|
|
|
$this->mergeConfigFrom(__DIR__ . '/config/gocardless.php', 'gocardless'); |
|
56
|
|
|
|
|
57
|
|
|
$this->registerGocardless(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* {@inheritDoc} |
|
62
|
|
|
*/ |
|
63
|
|
|
public function provides() |
|
64
|
|
|
{ |
|
65
|
|
|
return [ |
|
66
|
|
|
'gocardless', |
|
67
|
|
|
]; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Register the Gocardless API class. |
|
72
|
|
|
* |
|
73
|
|
|
* @return void |
|
74
|
|
|
*/ |
|
75
|
|
|
protected function registerGocardless() |
|
76
|
|
|
{ |
|
77
|
|
|
$this->app->singleton('gocardless', function ($app) { |
|
78
|
|
|
$config = $app['config']->get('gocardless'); |
|
79
|
|
|
$token = isset($config['token']) ? $config['token'] : null; |
|
80
|
|
|
$environment = isset($config['environment']) ? $config['environment'] : null; |
|
81
|
|
|
return new Client( array ( |
|
82
|
|
|
'access_token' => $token, |
|
83
|
|
|
'environment' => $environment |
|
84
|
|
|
)); |
|
85
|
|
|
}); |
|
86
|
|
|
$this->app->alias('gocardless', 'GoCardlessPro\Client'); |
|
87
|
|
|
} |
|
88
|
|
|
} |