PHPackages                             tuyakhov/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. tuyakhov/yii2-braintree

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

tuyakhov/yii2-braintree
=======================

Braintree for Yii2

1.0.2(11y ago)54849[3 issues](https://github.com/tuyakhov/yii2-braintree/issues)MITPHPPHP &gt;=5.4.0

Since May 27Pushed 10y ago4 watchersCompare

[ Source](https://github.com/tuyakhov/yii2-braintree)[ Packagist](https://packagist.org/packages/tuyakhov/yii2-braintree)[ Docs](https://github.com/tuyakhov/yii2-braintree)[ RSS](/packages/tuyakhov-yii2-braintree/feed)WikiDiscussions master Synced yesterday

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

Yii2-braintree
==============

[](#yii2-braintree)

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

[![Latest Stable Version](https://camo.githubusercontent.com/7ca97a2ec8474337156ca13e789a69dcb0c0c70e62eeb6c43ad2746c5d862be8/68747470733a2f2f706f7365722e707567782e6f72672f747579616b686f762f796969322d627261696e747265652f762f737461626c652e706e67)](https://packagist.org/packages/tuyakhov/yii2-braintree)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/137618a1935392ea901c4e825c718f3c91911c32ffeaba9ca9cb07b2e36cdd72/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f747579616b686f762f796969322d627261696e747265652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/tuyakhov/yii2-braintree/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/ac0453fc912d217e450f9004bcb43ab29021844ecd8e31f2d9de83da2f4c8fe6/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f747579616b686f762f796969322d627261696e747265652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/tuyakhov/yii2-braintree/?branch=master)[![Build Status](https://camo.githubusercontent.com/9f9d60af876a9252cccb09d51c7b3bac6b9e5cfab1bdd1583fe3eb565e31c8dc/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f747579616b686f762f796969322d627261696e747265652f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/tuyakhov/yii2-braintree/build-status/master)[![Total Downloads](https://camo.githubusercontent.com/66f44b7600a32e8b97391c5de015d180d4d69affbea9d77ad390052dc3fe0573/68747470733a2f2f706f7365722e707567782e6f72672f747579616b686f762f796969322d627261696e747265652f646f776e6c6f6164732e706e67)](https://packagist.org/packages/tuyakhov/yii2-braintree)

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist tuyakhov/yii2-braintree "*"

```

or add

```
"tuyakhov/yii2-braintree": "*"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

You should add Braintree component to your yii config first:

```
'components' => [
    'braintree' => [
        'class' => 'tuyakhov\braintree\Braintree',
        'merchantId' => 'YOUR_MERCHANT_ID',
        'publicKey' => 'YOUR_PUBLIC_KEY',
        'privateKey' => 'YOUR_PRIVATE_KEY',
    ],
]

```

Once the extension is installed, simply use it in your code by :

`BraintreeForm` provide all basic operations for sales and stores customer info. Operation name equals scenario name. Available scenarios:

`creditCard` - create a credit card [doc](https://developers.braintreepayments.com/ios+php/reference/request/credit-card/create)
`address` - create an address [doc](https://developers.braintreepayments.com/ios+php/reference/request/address/create)
`customer` - create a customer [doc](https://developers.braintreepayments.com/ios+php/reference/request/customer/create)
`sale` - create a transaction [doc](https://developers.braintreepayments.com/ios+php/reference/request/transaction/sale)
`saleFromVault` - create a transaction from your Vault [doc](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 your view:

```
