kdn / yii2-braintree
Braintree for Yii 2.
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 11
Open Issues: 0
Type:yii2-extension
Requires
- php: >=7.3.0
- braintree/braintree_php: >=3.23.1 <7.0
- npm-asset/braintree-web: >=2.32.1 <4.0
- yiisoft/yii2: 2.*
- yiisoft/yii2-bootstrap: 2.*
Requires (Dev)
- phpunit/phpunit: >=7.0 <10.0
Replaces
This package is auto-updated.
Last update: 2024-12-07 18:14:05 UTC
README
Integrate a credit card payment form with Braintree's API into Yii 2. Inspired by braintreeapi.
Requirements
- PHP 7.2 or later;
- Yii framework 2.
Installation
The preferred way to install this extension is through Composer.
To install, either run
php composer.phar require kdn/yii2-braintree "*"
or add
"kdn/yii2-braintree": "*"
to the require
section of your composer.json
file.
Usage
You should add Braintree component to your Yii configuration first:
'components' => [ 'braintree' => [ 'class' => 'tuyakhov\braintree\Braintree', 'merchantId' => 'YOUR_MERCHANT_ID', 'publicKey' => 'YOUR_PUBLIC_KEY', 'privateKey' => 'YOUR_PRIVATE_KEY', ], ]
BraintreeForm
provides all basic operations for sales and stores customer info. Operation name equals scenario name.
Available scenarios:
address
- create an address - API documentationcreditCard
- create a credit card - API documentationcustomer
- create a customer - API documentationsale
- create a transaction - API documentationsaleFromVault
- create a transaction from the vault - API documentation
Action example:
public function actionSale() { $model = new BraintreeForm(); $model->setScenario('sale'); if ($model->load(Yii::$app->request->post()) && $model->send()) { // do something } return $this->render('purchase', ['model' => $model]); }
Form widget for a view:
use tuyakhov\braintree\ActiveForm; use yii\helpers\Html; use yii\widgets\MaskedInput; $form = ActiveForm::begin(); ?> <?= $form->field($model, 'creditCard_number'); ?> <?= $form->field($model, 'creditCard_cvv'); ?> <?= $form->field($model, 'creditCard_expirationDate') ->widget(MaskedInput::class, ['mask' => '99/9999']); ?> <?= $form->field($model, 'amount'); ?> <?= Html::submitButton(); ?> <?php ActiveForm::end();