This repository has been archived by the owner on Jan 3, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Brian Faust
committed
Nov 4, 2016
0 parents
commit c19525d
Showing
14 changed files
with
546 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Path-based git attributes | ||
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html | ||
|
||
# Ignore all test and documentation with "export-ignore". | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/.travis.yml export-ignore | ||
/phpunit.xml.dist export-ignore | ||
/.scrutinizer.yml export-ignore | ||
/tests export-ignore | ||
/.github/CONTRIBUTING.md export-ignore | ||
/CHANGELOG.md export-ignore | ||
/README.md export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
composer.lock | ||
phpunit.xml | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
preset: laravel | ||
|
||
linting: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
language: php | ||
|
||
php: | ||
- 5.6 | ||
- 7.0 | ||
- 7.1 | ||
- hhvm | ||
|
||
sudo: false | ||
|
||
before_script: | ||
- travis_retry composer self-update | ||
- travis_retry composer update --no-interaction --prefer-source | ||
|
||
script: | ||
- if [ "$TRAVIS_PHP_VERSION" != "5.6" ]; then vendor/bin/phpunit; fi | ||
- if [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then vendor/bin/phpunit --coverage-clover build/logs/clover.xml; fi | ||
|
||
after_script: | ||
- if [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi | ||
- if [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml; fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Brian Faust <hello@brianfaust.de> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# Laravel Stripe | ||
|
||
> A [Stripe](https://stripe.com) bridge for Laravel. | ||
## Installation | ||
|
||
Require this package, with [Composer](https://getcomposer.org/), in the root directory of your project. | ||
|
||
```bash | ||
$ composer require faustbrian/laravel-stripe | ||
``` | ||
|
||
Add the service provider to `config/app.php` in the `providers` array. | ||
|
||
```php | ||
BrianFaust\Stripe\StripeServiceProvider::class | ||
``` | ||
|
||
If you want you can use the [facade](http://laravel.com/docs/facades). Add the reference in `config/app.php` to your aliases array. | ||
|
||
```php | ||
'Stripe' => BrianFaust\Stripe\Facades\Stripe::class | ||
``` | ||
|
||
## Configuration | ||
|
||
Laravel Stripe requires connection configuration. To get started, you'll need to publish all vendor assets: | ||
|
||
```bash | ||
$ php artisan vendor:publish --provider="BrianFaust\Stripe\StripeServiceProvider" | ||
``` | ||
|
||
This will create a `config/stripe.php` file in your app that you can modify to set your configuration. Also, make sure you check for changes to the original config file in this package between releases. | ||
|
||
#### Default Connection Name | ||
|
||
This option `default` is where you may specify which of the connections below you wish to use as your default connection for all work. Of course, you may use many connections at once using the manager class. The default value for this setting is `main`. | ||
|
||
#### Stripe Connections | ||
|
||
This option `connections` is where each of the connections are setup for your application. Example configuration has been included, but you may add as many connections as you would like. | ||
|
||
## Usage | ||
|
||
#### StripeManager | ||
|
||
This is the class of most interest. It is bound to the ioc container as `stripe` and can be accessed using the `Facades\Stripe` facade. This class implements the ManagerInterface by extending AbstractManager. The interface and abstract class are both part of [Graham Campbell's](https://github.com/GrahamCampbell) [Laravel Manager](https://github.com/GrahamCampbell/Laravel-Manager) package, so you may want to go and checkout the docs for how to use the manager class over at that repository. Note that the connection class returned will always be an instance of `Stripe\Stripe`. | ||
|
||
#### Facades\Stripe | ||
|
||
This facade will dynamically pass static method calls to the `stripe` object in the ioc container which by default is the `StripeManager` class. | ||
|
||
#### StripeServiceProvider | ||
|
||
This class contains no public methods of interest. This class should be added to the providers array in `config/app.php`. This class will setup ioc bindings. | ||
|
||
### Examples | ||
|
||
Here you can see an example of just how simple this package is to use. Out of the box, the default adapter is `main`. After you enter your authentication details in the config file, it will just work: | ||
|
||
```php | ||
// You can alias this in config/app.php. | ||
use BrianFaust\Stripe\Facades\Stripe; | ||
|
||
Stripe::getCharge()->create([ | ||
'card' => $myCard, | ||
'amount' => 2000, | ||
'currency' => 'usd' | ||
]); | ||
// We're done here - how easy was that, it just works! | ||
|
||
// The above is the same as the following with the official Stripe SDK. | ||
// \Stripe\Stripe\Charge::create(array('card' => $myCard, 'amount' => 2000, 'currency' => 'usd')); | ||
``` | ||
|
||
The Stripe manager will behave like it is a `Stripe\Stripe`. If you want to call specific connections, you can do that with the connection method: | ||
|
||
```php | ||
use BrianFaust\Stripe\Facades\Stripe; | ||
|
||
// Writing this… | ||
Stripe::connection('main')->getCharge()->create($params); | ||
|
||
// …is identical to writing this | ||
Stripe::getCharge()->create($params); | ||
|
||
// and is also identical to writing this. | ||
Stripe::connection()->getCharge()->create($params); | ||
|
||
// This is because the main connection is configured to be the default. | ||
Stripe::getDefaultConnection(); // This will return main. | ||
|
||
// We can change the default connection. | ||
Stripe::setDefaultConnection('alternative'); // The default is now alternative. | ||
``` | ||
|
||
If you prefer to use dependency injection over facades like me, then you can inject the manager: | ||
|
||
```php | ||
use BrianFaust\Stripe\StripeManager; | ||
|
||
class Foo | ||
{ | ||
protected $stripe; | ||
|
||
public function __construct(StripeManager $stripe) | ||
{ | ||
$this->stripe = $stripe; | ||
} | ||
|
||
public function bar($params) | ||
{ | ||
$this->stripe->getCharge()->create($params); | ||
} | ||
} | ||
|
||
App::make('Foo')->bar($params); | ||
``` | ||
|
||
## Documentation | ||
|
||
There are other classes in this package that are not documented here. This is because the package is a Laravel wrapper of [the official Stripe package](https://github.com/stripe/Stripe-PHP-SDK). | ||
|
||
## Security | ||
|
||
If you discover a security vulnerability within this package, please send an e-mail to Brian Faust at hello@brianfaust.de. All security vulnerabilities will be promptly addressed. | ||
|
||
## License | ||
|
||
The [The MIT License (MIT)](LICENSE). Please check the [LICENSE](LICENSE) file for more details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"name": "faustbrian/laravel-stripe", | ||
"description": "A Stripe bridge for Laravel", | ||
"keywords": ["laravel", "framework", "Laravel-Stripe", "Laravel Stripe", "Brian Faust", "faustbrian"], | ||
"license": "MIT", | ||
"authors": [{ | ||
"name": "Brian Faust", | ||
"email": "hello@brianfaust.de", | ||
"homepage": "https://brianfaust.de", | ||
"role": "Developer" | ||
}], | ||
"require": { | ||
"php": "^5.6 || ^7.0", | ||
"illuminate/support": "5.1.* || 5.2.* || 5.3.*", | ||
"stripe/stripe-php": "^4.1" | ||
}, | ||
"require-dev": { | ||
"graham-campbell/testbench": "^3.1", | ||
"mockery/mockery": "^0.9.4", | ||
"phpunit/phpunit": "^5.0", | ||
"scrutinizer/ocular": "~1.1", | ||
"squizlabs/php_codesniffer": "~2.3" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"BrianFaust\\Stripe\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"BrianFaust\\Tests\\Stripe\\": "tests" | ||
} | ||
}, | ||
"config": { | ||
"preferred-install": "dist" | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "1.0-dev" | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Default Connection Name | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Here you may specify which of the connections below you wish to use as | ||
| your default connection for all work. Of course, you may use many | ||
| connections at once using the manager class. | ||
| | ||
*/ | ||
|
||
'default' => 'main', | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Vimeo Connections | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Here are each of the connections setup for your application. Example | ||
| configuration has been included, but you may add as many connections as | ||
| you would like. | ||
| | ||
*/ | ||
|
||
'connections' => [ | ||
|
||
'main' => [ | ||
'key' => 'your-private-key', | ||
], | ||
|
||
], | ||
|
||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
beStrictAboutTestsThatDoNotTestAnything="true" | ||
beStrictAboutOutputDuringTests="true" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
failOnRisky="true" | ||
failOnWarning="true" | ||
processIsolation="false" | ||
stopOnError="false" | ||
stopOnFailure="false" | ||
verbose="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Laravel Stripe Test Suite"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">src/</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace BrianFaust\Stripe\Facades; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
|
||
class Stripe extends Facade | ||
{ | ||
/** | ||
* Get the registered name of the component. | ||
* | ||
* @return string | ||
*/ | ||
protected static function getFacadeAccessor() | ||
{ | ||
return 'stripe'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace BrianFaust\Stripe; | ||
|
||
use Stripe\Stripe as SDK; | ||
|
||
class Stripe | ||
{ | ||
public function __construct($apiKey) | ||
{ | ||
$this->setApiKey($apiKey); | ||
} | ||
|
||
public function __call(string $method, array $arguments) | ||
{ | ||
$sdkClass = substr($method, 3); | ||
|
||
if (class_exists($apiClass = "Stripe\\$sdkClass")) { | ||
return new $apiClass(); | ||
} | ||
|
||
return forward_static_call_array([SDK::class, $method], $arguments); | ||
} | ||
} |
Oops, something went wrong.