<?php

require __DIR__ . '/vendor/autoload.php';
Httpful\Bootstrap::init();
RESTful\Bootstrap::init();
Balanced\Bootstrap::init();
Balanced\Settings::$api_key = "ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY";
$order = Balanced\Order::get("/orders/OR3vURGwVtqDnnkRS9fgH41G");
$bank_account = Balanced\BankAccount::get("/bank_accounts/BA45anEaEr8g0lOhzhcE9VAN/credits");
$order->creditTo($bank_account, 5000);
<?php

require __DIR__ . '/vendor/autoload.php';
Httpful\Bootstrap::init();
RESTful\Bootstrap::init();
Balanced\Bootstrap::init();
Balanced\Settings::$api_key = "ak-test-22IOkhevjZlmRP2do6CZixkkDshTiOjTV";
$bank_account = Balanced\BankAccount::get("/bank_accounts/BA3Y63fK5STwlhKNMkE3Utmd");
$bank_account->credits->create(array("amount" => "5000"));
Exemple #3
0
 public function actionAddBankAccount()
 {
     Yii::import('application.extensions.vendor.autoload', true);
     Httpful\Bootstrap::init();
     Balanced\Bootstrap::init();
     Balanced\Settings::$api_key = Yii::app()->params['balancedAPISecret'];
     $outcome = array('success' => 0);
     $transaction = Yii::app()->db->beginTransaction();
     try {
         if (isset($_POST['data']) && isset($_POST['merchantData'])) {
             $data = json_decode($_POST['data']);
             $merchantData = json_decode($_POST['merchantData']);
             $uri = $data->uri;
             $user = $this->getUser();
             if ($user->bankAccount != null) {
                 $bankAccount = $user->bankAccount;
                 $balancedBankAccount = Balanced\BankAccount::get($bankAccount->URI);
                 $balancedBankAccount->delete();
                 $bankAccount->Active = 0;
                 $bankAccount->save();
             }
             $account = new BankAccount();
             $account->User_ID = $user->User_ID;
             $account->URI = $uri;
             if ($account->save()) {
                 $balancedAccount = $this->getUserAccount();
                 $balancedAccount->addBankAccount($uri);
                 if (!in_array('merchant', $balancedAccount->roles)) {
                     $balancedAccount->promoteToMerchant($merchantData);
                 }
                 $outcome = array('success' => 1, 'BankAccount_ID' => $account->BankAccount_ID);
             } else {
                 $outcome = array('success' => 0, 'Errors' => $account->getErrors());
             }
         }
         $transaction->commit();
     } catch (Balanced\Errors\IdentityVerificationFailed $error) {
         $transaction->rollback();
         /* could not identify this account. */
         $outcome = array('success' => 0, 'Errors' => "redirect merchant to:" . $error->redirect_uri . "\n");
     } catch (Balanced\Errors\HTTPError $error) {
         $transaction->rollback();
         /* TODO: handle 400 and 409 exceptions as required */
         $outcome = array('success' => 0, 'Errors' => print_r($error, true));
     } catch (Exception $error) {
         $transaction->rollback();
         $outcome = array('success' => 0, 'Errors' => print_r($error, true));
     }
     echo CJSON::encode($outcome);
 }
<?php

// $bank_account_href is the stored href for the BankAccount
// $order_href is the stored href for the Order
$bank_account = Balanced\BankAccount::get($bank_account_href);
$bank_account->credits->create(array("amount" => "100000", "description" => "Payout for order #1111", 'order' => $order_href));
<?php

require __DIR__ . '/vendor/autoload.php';
Httpful\Bootstrap::init();
RESTful\Bootstrap::init();
Balanced\Bootstrap::init();
Balanced\Settings::$api_key = "ak-test-22IOkhevjZlmRP2do6CZixkkDshTiOjTV";
$bank_account = Balanced\BankAccount::get("/bank_accounts/BA3PDwDCkdeC4OgPtPNwoCWl");
$bank_account->meta = array("facebook.user_id" => "0192837465", "my-own-customer-id" => "12345", "twitter.id" => "1234987650");
$bank_account->save();
<?php

require __DIR__ . '/vendor/autoload.php';
Httpful\Bootstrap::init();
RESTful\Bootstrap::init();
Balanced\Bootstrap::init();
Balanced\Settings::$api_key = "ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY";
$bank_account = Balanced\BankAccount::get("/bank_accounts/BA3Ya2sAlEQE14O1iS17FN0Q");
$bank_account->meta = array("facebook.user_id" => "0192837465", "my-own-customer-id" => "12345", "twitter.id" => "1234987650");
$bank_account->save();
<?php

require __DIR__ . '/vendor/autoload.php';
Httpful\Bootstrap::init();
RESTful\Bootstrap::init();
Balanced\Bootstrap::init();
Balanced\Settings::$api_key = "ak-test-22IOkhevjZlmRP2do6CZixkkDshTiOjTV";
// NOTE: Bank account must be associated with a customer before initiating a verification
$bank_account = Balanced\BankAccount::get("/bank_accounts/BA3IhKG3bIN22cLHbaOIGtHb");
$verification = $bank_account->verify();
<?php

require __DIR__ . '/vendor/autoload.php';
Httpful\Bootstrap::init();
RESTful\Bootstrap::init();
Balanced\Bootstrap::init();
Balanced\Settings::$api_key = "ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY";
// NOTE: Bank account must be associated with a customer before initiating a verification
$bank_account = Balanced\BankAccount::get("/bank_accounts/BA3LVXVgJLrzkmB3vUntKJ6t");
$verification = $bank_account->verify();
Exemple #9
0
 public static function BalancedCallback($post)
 {
     Yii::import('application.extensions.vendor.autoload', true);
     Httpful\Bootstrap::init();
     Balanced\Bootstrap::init();
     Balanced\Settings::$api_key = Yii::app()->params['balancedAPISecret'];
     $log = "Received callback... \n";
     try {
         $data = json_decode($post);
         if (!isset($data->type)) {
             $log .= "Error parsing data: \n";
             $log .= "Raw post: \n" . $post . "\n";
             $log .= "Parsed data: \n" . print_r($data, true) . "\n";
             throw new Exception("Error parsing data");
         }
         if ($data->type == 'debit.succeeded') {
             try {
                 $log .= "Customer debit succeeded. Paying the host...\n";
                 $paymentID = $data->entity->meta->Payment_ID;
                 $log .= "Payment_ID: {$paymentID}\n";
                 $payment = Payment::model()->findByPk($paymentID);
                 $hostAmount = $payment->Amount * Yii::app()->params['HostPercentage'];
                 $log .= "Host's share is \${$hostAmount}\n";
                 // Convert to cents
                 $hostAmount *= 100;
                 $hostBankAccount = Balanced\BankAccount::get($payment->bankAccount->URI);
                 $credit = $hostBankAccount->credit($hostAmount);
                 $log .= 'Sent credit, response is: ' . print_r($credit, true) . "\n";
             } catch (Exception $e) {
                 Mail::Instance()->Alert("Error crediting host account", print_r($e));
                 throw $e;
             }
         } else {
             $log .= print_r($data, true) . "\n";
         }
     } catch (Exception $e) {
         $log .= "\n" . print_r($e, true);
     }
     Yii::log($log, 'info', 'BalancedCallback');
 }
<?php

// $bank_account_href_a is the stored href for the BankAccount for Person A
$bank_account_person_a = Balanced\BankAccount::get($bank_account_href_a);
$bank_account_person_a->credits->create(array("amount" => "50000", "description" => "Payout for order #1111"));
// $bank_account_href_b is the stored href for the BankAccount for Person B
$bank_account_person_b = Balanced\BankAccount::get($bank_account_href_b);
$bank_account_person_b->credits->create(array("amount" => "50000", "description" => "Payout for order #1111"));