public function __construct()
 {
     Httpful\Bootstrap::init();
     RESTful\Bootstrap::init();
     infiniteLabs\BalancedPayments\Bootstrap::init();
     infiniteLabs\BalancedPayments\Settings::$api_key = "ak-test-19GwHG7jYR8FFKR9rBIVyiY1uXBemYVov";
 }
Example #2
0
<?php

require __DIR__ . '/vendor/autoload.php';
Httpful\Bootstrap::init();
RESTful\Bootstrap::init();
Balanced\Bootstrap::init();
Balanced\Settings::$api_key = "ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY";
$callback = new Balanced\Callback(array("url" => "http://www.example.com/callback_test"));
$callback->save();
Example #3
0
 public function getUserAccount()
 {
     Yii::import('application.extensions.vendor.autoload', true);
     Httpful\Bootstrap::init();
     Balanced\Bootstrap::init();
     Balanced\Settings::$api_key = Yii::app()->params['balancedAPISecret'];
     $user = $this->getUser();
     if (!isset($user->AccountURI) || $user->AccountURI == null) {
         $account = Balanced\Marketplace::mine()->createAccount($user->Email);
         $user->AccountURI = $account->uri;
         $user->save(false);
     } else {
         $account = Balanced\Account::get($user->AccountURI);
     }
     return $account;
 }
Example #4
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');
 }