-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 00cb0e9
Showing
16 changed files
with
718 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,5 @@ | ||
*~ | ||
*.iml | ||
.idea/ | ||
/vendor/ | ||
composer.lock |
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,55 @@ | ||
Licenses | ||
======== | ||
|
||
You may use this package under the terms of either | ||
the New BSD License or the GNU General Public License (GPL) version 2 or 3. | ||
|
||
The BSD License is recommended for most projects. It is easy to understand and it places almost no restrictions on what | ||
you can do with the framework. If the GPL fits better to your project, you can use the package under this license. | ||
|
||
You don't have to notify anyone which license you are using. You can freely use this package in commercial projects | ||
as long as the copyright header remains intact. | ||
|
||
|
||
|
||
New BSD License | ||
--------------- | ||
|
||
Copyright (c) 2015 GrowJOB s.r.o. (http://growjob.com) | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
* Neither the name of "Nette Tester" nor the names of its contributors | ||
may be used to endorse or promote products derived from this software | ||
without specific prior written permission. | ||
|
||
This software is provided by the copyright holders and contributors "as is" and | ||
any express or implied warranties, including, but not limited to, the implied | ||
warranties of merchantability and fitness for a particular purpose are | ||
disclaimed. In no event shall the copyright owner or contributors be liable for | ||
any direct, indirect, incidental, special, exemplary, or consequential damages | ||
(including, but not limited to, procurement of substitute goods or services; | ||
loss of use, data, or profits; or business interruption) however caused and on | ||
any theory of liability, whether in contract, strict liability, or tort | ||
(including negligence or otherwise) arising in any way out of the use of this | ||
software, even if advised of the possibility of such damage. | ||
|
||
|
||
|
||
GNU General Public License | ||
-------------------------- | ||
|
||
GPL licenses are very very long, so instead of including them here we offer | ||
you URLs with full text: | ||
|
||
- [GPL version 2](http://www.gnu.org/licenses/gpl-2.0.html) | ||
- [GPL version 3](http://www.gnu.org/licenses/gpl-3.0.html) |
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,31 @@ | ||
# MetisFW/Stripe | ||
|
||
WARNING this package is experimental and out-of-date | ||
|
||
[![Downloads this Month](https://img.shields.io/packagist/dm/metisfw/stripe.svg)](https://packagist.org/packages/metisfw/stripe) | ||
[![Latest stable](https://img.shields.io/packagist/v/metisfw/stripe.svg)](https://packagist.org/packages/metisfw/stripe) | ||
|
||
## About | ||
|
||
Stripe payment integration to Nette framework. Internally use [stripe/stripe-php](https://github.com/stripe/stripe-php). | ||
|
||
Inspired by [Kdyby/PayPalExpress](https://github.com/Kdyby/PayPalExpress) | ||
|
||
## Installation | ||
The best way to install is using [Composer](http://getcomposer.org/): | ||
|
||
```sh | ||
$ composer require metisfw/stripe | ||
``` | ||
|
||
## Documentation | ||
|
||
Learn more in the [documentation](https://github.com/MetisFW/Stripe/blob/master/docs/en/index.md). | ||
|
||
There are other classes in this package that are not documented here. | ||
This is because the package is a Nette wrapper of [the official Stripe PHP library](https://github.com/stripe/stripe-php). | ||
|
||
## License | ||
|
||
You may use this package under the terms of either | ||
the New BSD License or the GNU General Public License (GPL) version 2 or 3. |
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,42 @@ | ||
{ | ||
"name": "metisfw/stripe", | ||
"type": "library", | ||
"description": "Stripe integration for Nette Framework", | ||
"keywords": ["nette", "stripe", "pay", "checkout", "payment"], | ||
"homepage": "https://github.com/MetisFW", | ||
"license": ["BSD-3-Clause", "GPL-2.0", "GPL-3.0"], | ||
"authors": [ | ||
{ | ||
"name": "GrowJOB s.r.o", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Martin Jonáš", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"support": { | ||
"email": "[email protected]", | ||
"issues": "https://github.com/MetisFW/Stripe/issues" | ||
}, | ||
"require": { | ||
"php": ">=5.6.0", | ||
"nette/di": "^2.3", | ||
"nette/application": "^2.3", | ||
"stripe/stripe-php": "^7.45.0" | ||
}, | ||
"require-dev": { | ||
"nette/bootstrap": "^2.3@dev", | ||
"nette/robot-loader": "^2.3@dev", | ||
"nette/tester": "^2.3.2@dev", | ||
"mockery/mockery": "^0.9@dev" | ||
}, | ||
"autoload": { | ||
"psr-0": { | ||
"MetisFW\\Stripe\\": "src/" | ||
} | ||
}, | ||
"archive": { | ||
"exclude": ["tests", ".travis.yml"] | ||
} | ||
} |
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,152 @@ | ||
# MetisFW/Stripe | ||
|
||
## Setup | ||
|
||
1) Register extension | ||
``` | ||
extensions: | ||
stripe: MetisFW\Stripe\DI\StripeExtension | ||
``` | ||
|
||
2) Set up extension parameters | ||
|
||
```neon | ||
stripe: | ||
secretApiKey: "sk_live_*" | ||
publicApiKey: "pk_live_*" | ||
paymentIntent: | ||
currency: "USD" | ||
``` | ||
|
||
paymentIntent is default config to [Stripe PaymentIntent](https://stripe.com/docs/api/payment_intents/object) | ||
|
||
|
||
##Usage | ||
|
||
##### Sample usage of `PaymentControl` | ||
|
||
###### In Presenter | ||
|
||
```php | ||
use \MetisFW\Stripe\Payment\SimplePaymentOperation; | ||
use \MetisFW\Stripe\UI\PaymentControl; | ||
use Stripe\Api\Payment; | ||
use Nette\Application\UI\Presenter; | ||
|
||
class MyPresenter extends Presenter { | ||
|
||
public function createComponentStripePayment(SimplePaymentOperationFactory $factory) { | ||
$operation = $factory->create('Coffee', 5); | ||
$control = new PaymentControl($operation); | ||
|
||
//set different template if u want to use own | ||
$control->setTemplateFilePath(__DIR__ . './myStripePayment.latte'); | ||
|
||
//called after successfully completed payment proccess | ||
$control->onSuccess[] = function(PaymentControl $control, Payment $paid) { | ||
//something | ||
}; | ||
|
||
//called when payment process fails | ||
$control->onError[] = function(PaymentControl $control) { | ||
//something | ||
}; | ||
|
||
return $control; | ||
} | ||
} | ||
``` | ||
|
||
###### In latte | ||
|
||
```latte | ||
#just | ||
{control stripePayment} | ||
#or | ||
#cannot use attributes directly in control | ||
{var attributes = array('class' => 'stripe-payment-button')} | ||
{control stripePayment $attributes, 'Pay me now!'} | ||
``` | ||
|
||
##### Sample usage of `SimplePaymentOperation` | ||
|
||
```php | ||
public function createComponentStripePayment(SimplePaymentOperationFactory $factory) { | ||
$operation = $factory->create('Coffee', 10); | ||
$control = new PaymentControl($operation); | ||
return $control; | ||
} | ||
``` | ||
|
||
##### Sample usage of `PlainPaymentOperation` | ||
|
||
```php | ||
use Stripe\Api\Transaction; | ||
|
||
public function createComponentStripePayment(PlainPaymentOperationFactory $factory) { | ||
// see https://stripe.com/docs/api/payment_intents/object | ||
$params = array( | ||
'amount' => 5, | ||
'description' => "Coffeee" | ||
); | ||
|
||
$operation = $factory->create($params); | ||
$control = new PaymentControl($operation); | ||
return $control; | ||
} | ||
``` | ||
|
||
##### Sample usage of own descendant `\MetisFW\Stripe\Payment\BasePaymentOperation` | ||
|
||
```php | ||
<?php | ||
|
||
namespace MetisApp\Components\Payment; | ||
|
||
use MetisFW\Stripe\Payment\BasePaymentOperation; | ||
use MetisFW\Stripe\StripeContext; | ||
|
||
class OrderStripeOperation extends BasePaymentOperation { | ||
|
||
/** @var Order */ | ||
private $order; | ||
|
||
/** | ||
* @param StripeContext $context | ||
* @param mixed $order some data - object/array/... | ||
*/ | ||
public function __construct(StripeContext $context, Order $order) { | ||
parent::__construct($context); | ||
$this->order = $order; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
protected function getPaymentIntentParams() { | ||
return array( | ||
'amount' => $order->totalAmount, | ||
'description' => $order->orderNumber | ||
); | ||
} | ||
|
||
} | ||
|
||
``` | ||
|
||
###### Events in Operation | ||
```php | ||
public function createComponentStripePaymentButton(FactorType $factory) { | ||
$operation = $factory->create(); | ||
$operation->onSuccess[] = function(PaymentOperation $operation, PaymentIntent $paid) { | ||
//something | ||
} | ||
$operation->onError[] = function(PaymentOperation $operation) { | ||
//something | ||
} | ||
|
||
... | ||
} | ||
``` |
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,42 @@ | ||
<?php | ||
|
||
namespace MetisFW\Stripe\DI; | ||
|
||
use Nette\Configurator; | ||
use Nette\DI\Compiler; | ||
use Nette\DI\CompilerExtension; | ||
use Nette\Utils\Validators; | ||
|
||
class StripeExtension extends CompilerExtension { | ||
|
||
/** | ||
* @var array | ||
*/ | ||
public $defaults = array( | ||
"paymentIntent" => array() | ||
); | ||
|
||
public function loadConfiguration() { | ||
$builder = $this->getContainerBuilder(); | ||
$config = $this->getConfig($this->defaults); | ||
|
||
Validators::assertField($config, 'publicApiKey', 'string'); | ||
Validators::assertField($config, 'secretApiKey', 'string'); | ||
Validators::assertField($config, 'paymentIntent', 'array'); | ||
|
||
$builder->addDefinition($this->prefix('Stripe')) | ||
->setClass('MetisFW\Stripe\StripeContext', array($config['publicApiKey'], $config['secretApiKey'])) | ||
->addSetup('setPaymentIntentDefaults', array($config['paymentIntent'])); | ||
|
||
} | ||
|
||
/** | ||
* @param Configurator $configurator | ||
*/ | ||
public static function register(Configurator $configurator) { | ||
$configurator->onCompile[] = function ($config, Compiler $compiler) { | ||
$compiler->addExtension('stripe', new StripeExtension()); | ||
}; | ||
} | ||
|
||
} |
Oops, something went wrong.