https://github.com/davidjeddy/yii2-stripe
Yii2 Stripe wrapper extension
https://github.com/davidjeddy/yii2-stripe
Last synced: 5 months ago
JSON representation
Yii2 Stripe wrapper extension
- Host: GitHub
- URL: https://github.com/davidjeddy/yii2-stripe
- Owner: davidjeddy
- License: gpl-2.0
- Fork: true (ruskid/yii2-stripe)
- Created: 2016-05-11T19:56:12.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-08-02T21:27:48.000Z (almost 9 years ago)
- Last Synced: 2024-12-26T06:47:15.341Z (5 months ago)
- Language: PHP
- Homepage:
- Size: 56.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Yii2 Stripe Wrapper.
======
Badges
------
[](https://insight.sensiolabs.com/projects/f6411434-fdb3-41a3-bc0d-b8fd9516d68d)Installation
--------------------------The preferred way to install this extension is through http://getcomposer.org/download/.
Either run
```sh
php composer.phar require davidjeddy/yii2-stripe "dev-master"
```or add
```json
"davidjeddy/yii2-stripe": "~1.0"
```to the require section of your `composer.json` file.
Usage
--------------------------
Add a new component in main.php
```php
'components' => [
...
'stripe' => [
'class' => 'davidjeddy\stripe\Stripe',
'publicKey' => "pk_test_xxxxxxxxxxxxxxxxxxx",
'privateKey' => "sk_test_xxxxxxxxxxxxxxxxxx",
],
...```
To render simple checkout form just call the widget in the view, it will automatically register the scripts.
Check stripe documentation for more options.
```php
use davidjeddy\stripe\StripeCheckout;=
StripeCheckout::widget([
'action' => '/',
'name' => 'Demo test',
'description' => '2 widgets ($20.00)',
'amount' => 2000,
'image' => '/128x128.png',
]);
?>
```Custom checkout form is an extended version of simple form, but you can customize the button (see buttonOptions) and handle token as you want (tokenFunction).
```php
use davidjeddy\stripe\StripeCheckoutCustom;=
StripeCheckoutCustom::widget([
'action' => '/',
'name' => 'Demo test',
'description' => '2 widgets ($20.00)',
'amount' => 2000,
'image' => '/128x128.png',
'buttonOptions' => [
'class' => 'btn btn-lg btn-success',
],
'tokenFunction' => new JsExpression('function(token) {
alert("Here you should control your token.");
}'),
'openedFunction' => new JsExpression('function() {
alert("Model opened");
}'),
'closedFunction' => new JsExpression('function() {
alert("Model closed");
}'),
]);
?>
```
Example of a custom form. StripeForm is an extended ActiveForm so you can perform validation of amount and other attributes you want.
Use of Jquery Payment library is optional, you can disable format and validation and write your own implementation.
You can also change JsExpression for response and request handlers.```php
use davidjeddy\stripe\StripeForm;'stripeToken',
'errorContainerId' => 'payment-errors',
'brandContainerId' => 'cc-brand',
'errorClass' => 'has-error',
'applyJqueryPaymentFormat' => true,
'applyJqueryPaymentValidation' => true,
'options' => ['autocomplete' => 'on']
]);
?>
Card number
= $form->numberInput() ?>
CVC
= $form->cvcInput() ?>
Card expiry
= $form->monthAndYearInput() ?>
Month
= $form->monthInput() ?>
Year
= $form->yearInput() ?>
= Html::submitButton('Submit'); ?>
```Contribution / Credit
--------------------------
Forked From: https://github.com/ruskid/yii2-stripe
I would like to give the original author all due credit, great package.