PHPackages                             kdn/yii2-braintree - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. kdn/yii2-braintree

ActiveYii2-extension[Payment Processing](/categories/payments)

kdn/yii2-braintree
==================

Braintree for Yii 2.

2.0.0(3y ago)061MITPHPPHP &gt;=7.3.0

Since Aug 5Pushed 3y ago1 watchersCompare

[ Source](https://github.com/dmitry-kulikov/yii2-braintree)[ Packagist](https://packagist.org/packages/kdn/yii2-braintree)[ RSS](/packages/kdn-yii2-braintree/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (2)Used By (0)

yii2-braintree
==============

[](#yii2-braintree)

Integrate a credit card payment form with Braintree's API into Yii 2. Inspired by [braintreeapi](https://www.yiiframework.com/extension/braintreeapi).

[![License](https://camo.githubusercontent.com/47898ffb8eff2e70a67731dfdf0fb711fed59ed52e9dd099220433ddbd8951b8/68747470733a2f2f706f7365722e707567782e6f72672f6b646e2f796969322d627261696e747265652f6c6963656e7365)](https://packagist.org/packages/kdn/yii2-braintree)[![Latest Stable Version](https://camo.githubusercontent.com/a8efcacd7ec80e19d6525012e49e9ff0158a23eff662a39ba6e769cb4ba1f7f9/68747470733a2f2f706f7365722e707567782e6f72672f6b646e2f796969322d627261696e747265652f762f737461626c65)](https://packagist.org/packages/kdn/yii2-braintree)[![Code Coverage](https://camo.githubusercontent.com/5fe9a64943a13f5d40b10d3dca98df873e5e405a30b204f777cd0ed2ec882b12/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f646d697472792d6b756c696b6f762f796969322d627261696e747265652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/dmitry-kulikov/yii2-braintree/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/53ef8b48bcd85d41ab038a1b755a98ff6b49bd0e02e030f5d2648788ab558728/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f646d697472792d6b756c696b6f762f796969322d627261696e747265652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/dmitry-kulikov/yii2-braintree/?branch=master)[![Code Climate](https://camo.githubusercontent.com/a4553f5c43eae154969df70acdae0391f81329e36abff25719ad381d856fc400/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f646d697472792d6b756c696b6f762f796969322d627261696e747265652f6261646765732f6770612e737667)](https://codeclimate.com/github/dmitry-kulikov/yii2-braintree)

Requirements
------------

[](#requirements)

- PHP 7.2 or later;
- Yii framework 2.

Installation
------------

[](#installation)

The preferred way to install this extension is through [Composer](https://getcomposer.org).

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
-----

[](#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 documentation](https://developer.paypal.com/braintree/docs/reference/request/address/create)
- `creditCard` - create a credit card - [API documentation](https://developer.paypal.com/braintree/docs/reference/request/credit-card/create)
- `customer` - create a customer - [API documentation](https://developer.paypal.com/braintree/docs/reference/request/customer/create)
- `sale` - create a transaction - [API documentation](https://developer.paypal.com/braintree/docs/reference/request/transaction/sale)
- `saleFromVault` - create a transaction from the vault - [API documentation](https://developers.braintreepayments.com/ios+php/reference/request/transaction/sale)

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();
?>
