├── .gitignore ├── LICENSE ├── README.md ├── composer.json ├── composer.lock └── src ├── GoCardlessServiceProvider.php ├── config └── gocardless.php ├── helpers └── helpers.php └── services └── GoCardlessService.php /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/ 2 | node_modules/ 3 | npm-debug.log 4 | 5 | # Laravel 4 specific 6 | bootstrap/compiled.php 7 | app/storage/ 8 | 9 | # Laravel 5 & Lumen specific 10 | public/storage 11 | public/hot 12 | storage/*.key 13 | .env.*.php 14 | .env.php 15 | .env 16 | Homestead.yaml 17 | Homestead.json 18 | 19 | # Rocketeer PHP task runner and deployment package. https://github.com/rocketeers/rocketeer 20 | .rocketeer/ 21 | 22 | \.idea/ 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Olly Warren 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Go Cardless 2 | 3 | [![Total Downloads](https://poser.pugx.org/ollywarren/laravel-go-cardless/downloads)](https://packagist.org/packages/ollywarren/laravel-go-cardless) 4 | [![Latest Stable Version](https://poser.pugx.org/ollywarren/laravel-go-cardless/v/stable)](https://packagist.org/packages/ollywarren/laravel-go-cardless) 5 | [![License](https://poser.pugx.org/ollywarren/laravel-go-cardless/license)](https://packagist.org/packages/ollywarren/makepackage) 6 | 7 | A Laravel 5.5 Wrapper for the Go Cardless PHP Client Library. This package provides simple elegant access to the Go Cardless PHP Client API from across the Laravel Application. 8 | 9 | 10 | The included helper method makes accessing the underlying methods as easy as: 11 | 12 | ``` gocardless()->customers()->list()``` 13 | 14 | ## Installation Laravel 5.5 + 15 | 16 | Simply require the package through composer and let the Laravel Package Auto Discovery do the rest. 17 | 18 | ``` composer require ollywarren/laravel-go-cardless ``` 19 | 20 | Publish the vendor configuration: 21 | 22 | ``` php artisan vendor:publish``` (Select the relevant package from the list) 23 | 24 | Set two environment variables in your Apps .env file: 25 | 26 | ``` 27 | GOCARDLESS_ENV="sandbox" OR "live" 28 | GOCARDLESS_TOKEN="" 29 | 30 | ``` 31 | 32 | ## Installation Laravel 5.4 33 | 34 | Use composer to add it to your project dependencies: 35 | 36 | ``` composer require ollywarren/laravel-go-cardless ``` 37 | 38 | 39 | Then inside your ```config/app.php``` 40 | 41 | 42 | Add the package service provider to the providers array: 43 | 44 | ``` Ollywarren\LaravelGoCardless\GoCardlessServiceProvider::class, ``` 45 | 46 | Finally for good measure dump the composer autoloader to make sure we've pulled in the helper method: 47 | 48 | ``` composer dump-autoloader ``` 49 | 50 | Publish the vendor configuration: 51 | 52 | ``` php artisan vendor:publish``` 53 | 54 | Set two environment variables in your Apps .env file: 55 | 56 | ``` 57 | GOCARDLESS_ENV="sandbox" OR "live" 58 | GOCARDLESS_TOKEN="" 59 | 60 | ``` 61 | 62 | ## Usage Instructions 63 | 64 | This package exposes the underlaying Go Cardless PHP Client Library usign the ``` gocardless() ``` helper method. 65 | Any of the methods described in the API Documentation will be accessible. 66 | 67 | For example: 68 | 69 | ### Get a List of Customers 70 | 71 | ``` gocardless()->customers()->list();``` 72 | 73 | ### Create a New Customer 74 | 75 | ``` 76 | gocardless()->customers()->create([ 77 | 'params' => [ 78 | "given_name" => "Jack", 79 | "family_name" => "Sparrow", 80 | "email" => "oljacky@sparrowsnest.com" 81 | ] 82 | ]); 83 | ``` 84 | 85 | For a full breakdown of the API see the [Documentation](https://developer.gocardless.com/api-reference/#overview-errors "Go Cardless API Docs") or the [PHP Client Library](https://github.com/gocardless/gocardless-pro-php "Go Cardless PHP Client Library") 86 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ollywarren/laravel-go-cardless", 3 | "description": "A Laravel Wrapper for the Go Cardless PHP Client Library", 4 | "keywords": ["laravel","go cardless", "composer", "package"], 5 | "homepage": "https://github.com/ollywarren/laravel-go-cardless", 6 | "require": { 7 | "gocardless/gocardless-pro": "^3.0" 8 | }, 9 | "license": "MIT", 10 | "authors": [ 11 | { 12 | "name": "Olly Warren", 13 | "email": "olly@ollywarren.com" 14 | } 15 | ], 16 | "autoload": { 17 | "files": [ 18 | "src/helpers/helpers.php" 19 | ], 20 | "psr-4": { 21 | "Ollywarren\\LaravelGoCardless\\": "src/" 22 | } 23 | }, 24 | "extra": { 25 | "laravel": { 26 | "providers": [ 27 | "Ollywarren\\LaravelGoCardless\\GoCardlessServiceProvider" 28 | ] 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "f7ef972d7e374c22720a4ab7f8d4b520", 8 | "packages": [ 9 | { 10 | "name": "gocardless/gocardless-pro", 11 | "version": "3.0.0", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/gocardless/gocardless-pro-php.git", 15 | "reference": "4093dba20fde9213828c408d970dac2edf1bf3bc" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/gocardless/gocardless-pro-php/zipball/4093dba20fde9213828c408d970dac2edf1bf3bc", 20 | "reference": "4093dba20fde9213828c408d970dac2edf1bf3bc", 21 | "shasum": "" 22 | }, 23 | "require": { 24 | "ext-curl": "*", 25 | "ext-json": "*", 26 | "ext-mbstring": "*", 27 | "guzzlehttp/guzzle": "^6.0", 28 | "php": ">=5.6" 29 | }, 30 | "require-dev": { 31 | "phpdocumentor/phpdocumentor": "2.*", 32 | "phpunit/phpunit": "4.6.*", 33 | "satooshi/php-coveralls": "~0.6.1", 34 | "squizlabs/php_codesniffer": "~2.0" 35 | }, 36 | "type": "library", 37 | "autoload": { 38 | "psr-4": { 39 | "GoCardlessPro\\": "lib/" 40 | } 41 | }, 42 | "notification-url": "https://packagist.org/downloads/", 43 | "license": [ 44 | "MIT" 45 | ], 46 | "authors": [ 47 | { 48 | "name": "GoCardless and contributors", 49 | "homepage": "https://github.com/gocardless/gocardless-pro-php/contributors" 50 | } 51 | ], 52 | "description": "GoCardless Pro PHP Client Library", 53 | "homepage": "https://gocardless.com/", 54 | "keywords": [ 55 | "api", 56 | "direct debit", 57 | "gocardless" 58 | ], 59 | "time": "2018-09-19T16:27:04+00:00" 60 | }, 61 | { 62 | "name": "guzzlehttp/guzzle", 63 | "version": "6.3.3", 64 | "source": { 65 | "type": "git", 66 | "url": "https://github.com/guzzle/guzzle.git", 67 | "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba" 68 | }, 69 | "dist": { 70 | "type": "zip", 71 | "url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba", 72 | "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba", 73 | "shasum": "" 74 | }, 75 | "require": { 76 | "guzzlehttp/promises": "^1.0", 77 | "guzzlehttp/psr7": "^1.4", 78 | "php": ">=5.5" 79 | }, 80 | "require-dev": { 81 | "ext-curl": "*", 82 | "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", 83 | "psr/log": "^1.0" 84 | }, 85 | "suggest": { 86 | "psr/log": "Required for using the Log middleware" 87 | }, 88 | "type": "library", 89 | "extra": { 90 | "branch-alias": { 91 | "dev-master": "6.3-dev" 92 | } 93 | }, 94 | "autoload": { 95 | "files": [ 96 | "src/functions_include.php" 97 | ], 98 | "psr-4": { 99 | "GuzzleHttp\\": "src/" 100 | } 101 | }, 102 | "notification-url": "https://packagist.org/downloads/", 103 | "license": [ 104 | "MIT" 105 | ], 106 | "authors": [ 107 | { 108 | "name": "Michael Dowling", 109 | "email": "mtdowling@gmail.com", 110 | "homepage": "https://github.com/mtdowling" 111 | } 112 | ], 113 | "description": "Guzzle is a PHP HTTP client library", 114 | "homepage": "http://guzzlephp.org/", 115 | "keywords": [ 116 | "client", 117 | "curl", 118 | "framework", 119 | "http", 120 | "http client", 121 | "rest", 122 | "web service" 123 | ], 124 | "time": "2018-04-22T15:46:56+00:00" 125 | }, 126 | { 127 | "name": "guzzlehttp/promises", 128 | "version": "v1.3.1", 129 | "source": { 130 | "type": "git", 131 | "url": "https://github.com/guzzle/promises.git", 132 | "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" 133 | }, 134 | "dist": { 135 | "type": "zip", 136 | "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", 137 | "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", 138 | "shasum": "" 139 | }, 140 | "require": { 141 | "php": ">=5.5.0" 142 | }, 143 | "require-dev": { 144 | "phpunit/phpunit": "^4.0" 145 | }, 146 | "type": "library", 147 | "extra": { 148 | "branch-alias": { 149 | "dev-master": "1.4-dev" 150 | } 151 | }, 152 | "autoload": { 153 | "psr-4": { 154 | "GuzzleHttp\\Promise\\": "src/" 155 | }, 156 | "files": [ 157 | "src/functions_include.php" 158 | ] 159 | }, 160 | "notification-url": "https://packagist.org/downloads/", 161 | "license": [ 162 | "MIT" 163 | ], 164 | "authors": [ 165 | { 166 | "name": "Michael Dowling", 167 | "email": "mtdowling@gmail.com", 168 | "homepage": "https://github.com/mtdowling" 169 | } 170 | ], 171 | "description": "Guzzle promises library", 172 | "keywords": [ 173 | "promise" 174 | ], 175 | "time": "2016-12-20T10:07:11+00:00" 176 | }, 177 | { 178 | "name": "guzzlehttp/psr7", 179 | "version": "1.5.2", 180 | "source": { 181 | "type": "git", 182 | "url": "https://github.com/guzzle/psr7.git", 183 | "reference": "9f83dded91781a01c63574e387eaa769be769115" 184 | }, 185 | "dist": { 186 | "type": "zip", 187 | "url": "https://api.github.com/repos/guzzle/psr7/zipball/9f83dded91781a01c63574e387eaa769be769115", 188 | "reference": "9f83dded91781a01c63574e387eaa769be769115", 189 | "shasum": "" 190 | }, 191 | "require": { 192 | "php": ">=5.4.0", 193 | "psr/http-message": "~1.0", 194 | "ralouphie/getallheaders": "^2.0.5" 195 | }, 196 | "provide": { 197 | "psr/http-message-implementation": "1.0" 198 | }, 199 | "require-dev": { 200 | "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8" 201 | }, 202 | "type": "library", 203 | "extra": { 204 | "branch-alias": { 205 | "dev-master": "1.5-dev" 206 | } 207 | }, 208 | "autoload": { 209 | "psr-4": { 210 | "GuzzleHttp\\Psr7\\": "src/" 211 | }, 212 | "files": [ 213 | "src/functions_include.php" 214 | ] 215 | }, 216 | "notification-url": "https://packagist.org/downloads/", 217 | "license": [ 218 | "MIT" 219 | ], 220 | "authors": [ 221 | { 222 | "name": "Michael Dowling", 223 | "email": "mtdowling@gmail.com", 224 | "homepage": "https://github.com/mtdowling" 225 | }, 226 | { 227 | "name": "Tobias Schultze", 228 | "homepage": "https://github.com/Tobion" 229 | } 230 | ], 231 | "description": "PSR-7 message implementation that also provides common utility methods", 232 | "keywords": [ 233 | "http", 234 | "message", 235 | "psr-7", 236 | "request", 237 | "response", 238 | "stream", 239 | "uri", 240 | "url" 241 | ], 242 | "time": "2018-12-04T20:46:45+00:00" 243 | }, 244 | { 245 | "name": "psr/http-message", 246 | "version": "1.0.1", 247 | "source": { 248 | "type": "git", 249 | "url": "https://github.com/php-fig/http-message.git", 250 | "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" 251 | }, 252 | "dist": { 253 | "type": "zip", 254 | "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", 255 | "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", 256 | "shasum": "" 257 | }, 258 | "require": { 259 | "php": ">=5.3.0" 260 | }, 261 | "type": "library", 262 | "extra": { 263 | "branch-alias": { 264 | "dev-master": "1.0.x-dev" 265 | } 266 | }, 267 | "autoload": { 268 | "psr-4": { 269 | "Psr\\Http\\Message\\": "src/" 270 | } 271 | }, 272 | "notification-url": "https://packagist.org/downloads/", 273 | "license": [ 274 | "MIT" 275 | ], 276 | "authors": [ 277 | { 278 | "name": "PHP-FIG", 279 | "homepage": "http://www.php-fig.org/" 280 | } 281 | ], 282 | "description": "Common interface for HTTP messages", 283 | "homepage": "https://github.com/php-fig/http-message", 284 | "keywords": [ 285 | "http", 286 | "http-message", 287 | "psr", 288 | "psr-7", 289 | "request", 290 | "response" 291 | ], 292 | "time": "2016-08-06T14:39:51+00:00" 293 | }, 294 | { 295 | "name": "ralouphie/getallheaders", 296 | "version": "2.0.5", 297 | "source": { 298 | "type": "git", 299 | "url": "https://github.com/ralouphie/getallheaders.git", 300 | "reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa" 301 | }, 302 | "dist": { 303 | "type": "zip", 304 | "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/5601c8a83fbba7ef674a7369456d12f1e0d0eafa", 305 | "reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa", 306 | "shasum": "" 307 | }, 308 | "require": { 309 | "php": ">=5.3" 310 | }, 311 | "require-dev": { 312 | "phpunit/phpunit": "~3.7.0", 313 | "satooshi/php-coveralls": ">=1.0" 314 | }, 315 | "type": "library", 316 | "autoload": { 317 | "files": [ 318 | "src/getallheaders.php" 319 | ] 320 | }, 321 | "notification-url": "https://packagist.org/downloads/", 322 | "license": [ 323 | "MIT" 324 | ], 325 | "authors": [ 326 | { 327 | "name": "Ralph Khattar", 328 | "email": "ralph.khattar@gmail.com" 329 | } 330 | ], 331 | "description": "A polyfill for getallheaders.", 332 | "time": "2016-02-11T07:05:27+00:00" 333 | } 334 | ], 335 | "packages-dev": [], 336 | "aliases": [], 337 | "minimum-stability": "stable", 338 | "stability-flags": [], 339 | "prefer-stable": false, 340 | "prefer-lowest": false, 341 | "platform": [], 342 | "platform-dev": [] 343 | } 344 | -------------------------------------------------------------------------------- /src/GoCardlessServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([__DIR__.'/config/gocardless.php' => config_path('gocardless.php'),]); 17 | } 18 | 19 | /** 20 | * Register the application services. 21 | * 22 | * @return void 23 | */ 24 | public function register() 25 | { 26 | $this->app->bind('GoCardless', GoCardlessService::class); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/config/gocardless.php: -------------------------------------------------------------------------------- 1 | env('GOCARDLESS_ENV', 'SANDBOX'), 4 | 'token' => env('GOCARDLESS_TOKEN', 'ABC123') 5 | ]; 6 | -------------------------------------------------------------------------------- /src/helpers/helpers.php: -------------------------------------------------------------------------------- 1 | token = config('gocardless.token'); 17 | $this->environment = config('gocardless.environment'); 18 | 19 | $this->client = new Client( array ( 20 | 'access_token' => $this->token, 21 | 'environment' => $this->environment 22 | )); 23 | } 24 | 25 | public function __call($method, $args) { 26 | if( is_callable([$this->client, $method]) ) { 27 | return call_user_func_array([$this->client, $method],$args); 28 | } else { 29 | throw new BadMethodCallException("Method $method does not exist on Go Cardless Library"); 30 | } 31 | } 32 | 33 | public function __get($property) { 34 | if( property_exists($this->client, $property) ) { 35 | return $this->client->{$property}; 36 | } else { 37 | throw new BadMethodCallException("Property $property does not exist on Go Cardless Library"); 38 | } 39 | } 40 | } 41 | --------------------------------------------------------------------------------