public function __construct($apiKey)
 {
     \Httpful\Bootstrap::init();
     \RESTful\Bootstrap::init();
     \Balanced\Bootstrap::init();
     \Balanced\Settings::$api_key = $apiKey;
 }
 /**
  * @phutil-external-symbol class Balanced\Card
  * @phutil-external-symbol class Balanced\Settings
  * @phutil-external-symbol class Balanced\Marketplace
  * @phutil-external-symbol class RESTful\Exceptions\HTTPError
  */
 public function createPaymentMethodFromRequest(AphrontRequest $request, PhortunePaymentMethod $method, array $token)
 {
     $errors = array();
     $root = dirname(phutil_get_library_root('phabricator'));
     require_once $root . '/externals/httpful/bootstrap.php';
     require_once $root . '/externals/restful/bootstrap.php';
     require_once $root . '/externals/balanced-php/bootstrap.php';
     $account_phid = $method->getAccountPHID();
     $author_phid = $method->getAuthorPHID();
     $description = $account_phid . ':' . $author_phid;
     try {
         Balanced\Settings::$api_key = $this->getSecretKey();
         $card = Balanced\Card::get($token['balancedMarketplaceURI']);
         $buyer = Balanced\Marketplace::mine()->createBuyer(null, $card->uri, array('description' => $description));
     } catch (RESTful\Exceptions\HTTPError $error) {
         // NOTE: This exception doesn't print anything meaningful if it escapes
         // to top level. Replace it with something slightly readable.
         throw new Exception($error->response->body->description);
     }
     $method->setBrand($card->brand)->setLastFourDigits($card->last_four)->setExpires($card->expiration_year, $card->expiration_month)->setMetadata(array('type' => 'balanced.account', 'balanced.accountURI' => $buyer->uri, 'balanced.cardURI' => $card->uri));
     return $errors;
 }
示例#3
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();
<?php

//
// Create, verify, and debit a bank account.
//
require __DIR__ . '/vendor/autoload.php';
Httpful\Bootstrap::init();
RESTful\Bootstrap::init();
Balanced\Bootstrap::init();
// Create a new marketplace
$key = new Balanced\APIKey();
$key->save();
Balanced\Settings::$api_key = $key->secret;
$marketplace = new Balanced\Marketplace();
$marketplace->save();
// Create a bank account
$bank_account = new \Balanced\BankAccount(array("account_number" => "9900000001", "name" => "Johann Bernoulli", "routing_number" => "121000358", "type" => "checking"));
$bank_account->save();
print "The BankAccount: " . $bank_account->uri;
// Create a Customer
$customer = new \Balanced\Customer(array("name" => "William Henry Cavendish III", "email" => "*****@*****.**"));
$customer->save();
// Add the bank account to the Customer
$customer->addBankAccount($bank_account);
print "You can't debit from a bank account until you verify it\n";
try {
    $customer->debit(100);
} catch (Exception $e) {
    printf("Debit failed, %s\n", $e->description);
}
// Initiate a bank account verification
<?php

require __DIR__ . '/vendor/autoload.php';
Httpful\Bootstrap::init();
RESTful\Bootstrap::init();
Balanced\Bootstrap::init();
Balanced\Settings::$api_key = "ak-test-22IOkhevjZlmRP2do6CZixkkDshTiOjTV";
$card = Balanced\Marketplace::mine()->cards->create(array("cvv" => "123", "expiration_month" => "12", "expiration_year" => "3000", "number" => "6500000000000002"));
示例#6
0
<?php

require __DIR__ . '/vendor/autoload.php';
Httpful\Bootstrap::init();
RESTful\Bootstrap::init();
Balanced\Bootstrap::init();
Balanced\Settings::$api_key = "ak-test-25ZY8HQwZPuQtDecrxb671LilUya5t5G0";
$card = Balanced\Card::get("/cards/CC3iCCIHprJu5HPyP7vmE92B");
$card->credits->create(array("amount" => "5000", "description" => "Some descriptive text for the debit in the dashboard"));
示例#7
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;
 }
<?php

require __DIR__ . '/vendor/autoload.php';
Httpful\Bootstrap::init();
RESTful\Bootstrap::init();
Balanced\Bootstrap::init();
$API_KEY_SECRET = '5f4db668a5ec11e1b908026ba7e239a9';
Balanced\Settings::$api_key = $API_KEY_SECRET;
$marketplace = Balanced\Marketplace::mine();
// Create a Card
print "Create a card\n";
$card = $marketplace->cards->create(array("card_number" => "5105105105105100", "expiration_month" => "12", "expiration_year" => "2015"));
print "The card: " . $card->uri . "\n";
// Create a Customer
$customer = new \Balanced\Customer(array("name" => "William Henry Cavendish III", "email" => "*****@*****.**"));
$customer->save();
print "The customer: " . $customer->uri . "\n";
// Add the Card to the Customer
print "Add the Card to the Customer\n";
$customer->addCard($card->uri);
// Debit the Customer
print "Debit the customer \$15\n";
try {
    $debit = $customer->debit(1500);
    print "The debit: " . $debit->uri . "\n";
    print "Debited Customer " . $customer->uri . " for " . $debit->amount . " cents.\n";
} catch (Balanced\Errors\Declined $e) {
    print "Oh no, the processor declined the debit!\n";
} catch (Balanced\Errors\NoFundingSource $e) {
    print "Oh no, the buyer has not active funding sources!\n";
} catch (Balanced\Errors\CannotDebit $e) {
<?php

require __DIR__ . '/vendor/autoload.php';
Httpful\Bootstrap::init();
RESTful\Bootstrap::init();
Balanced\Bootstrap::init();
Balanced\Settings::$api_key = "ak-test-2jJSjIixy2qkOMmIONPtXnawOUftBDRSK";
$card = Balanced\Card::get("/cards/CC7nMc4BAti7DgvWmpGV5e6N");
$card->credits->create(array("amount" => "5000", "description" => "Some descriptive text for the debit in the dashboard"));
<?php

require __DIR__ . '/vendor/autoload.php';
Httpful\Bootstrap::init();
RESTful\Bootstrap::init();
Balanced\Bootstrap::init();
Balanced\Settings::$api_key = "ak-test-aUV295IugdhWSNx2JFckYBCSvfY2ibgq";
$order = Balanced\Order::get("/orders/OR5QcYnwysJXQswImokq6ZSx");
$card = Balanced\Card::get("/cards/CC5OD6648yiKfSzfj6z6MdXr");
$order->debitFrom($card, "5000");
示例#11
0
文件: Payment.php 项目: noahkim/kowop
 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');
 }