function create_buyer($email_address, $card_uri) { $marketplace = Balanced\Marketplace::mine(); try { # new buyer $buyer = $marketplace->createBuyer($email_address, $card_uri); } catch (Balanced\Errors\DuplicateAccountEmailAddress $e) { # oops, account for $email_address already exists so just add the card $buyer = Balanced\Account::get($e->extras->account_uri); $buyer->addCard($card_uri); } return $buyer; }
function create_buyer($email_address, $card_uri) { $marketplace = Balanced\Marketplace::mine(); try { # new buyer $buyer = $marketplace->createBuyer($email_address, $card_uri); } catch (Balanced\Exceptions\HTTPError $e) { if ($e->category_code == 'duplicate-email-address') { # oops, account for $email_address already exists so just add the card $buyer = $marketplace->accounts->query()->filter(Balanced\Account::$f->email_address->eq($email_address))->one(); $buyer->addCard($card_uri); } else { throw $e; } } return $buyer; }
/** * @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; }
<?php $bank_account = Balanced\Marketplace::mine()->bank_accounts->create(array("account_number" => "0987654321", "name" => "Henry Ford", "routing_number" => "321174851", "type" => "checking")); $bank_account->associateToCustomer($merchant);
<?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"));
<?php $card = Balanced\Marketplace::mine()->cards->create(array("expiration_month" => "12", "expiration_year" => "2020", "number" => "5105105105105100", "security_code" => "123"));
<?php require __DIR__ . '/vendor/autoload.php'; Httpful\Bootstrap::init(); RESTful\Bootstrap::init(); Balanced\Bootstrap::init(); Balanced\Settings::$api_key = "ak-test-22IOkhevjZlmRP2do6CZixkkDshTiOjTV"; $marketplace = Balanced\Marketplace::mine(); $marketplace->reversals->query()->all();
<?php /* * Welcome weary traveller. Sick of polling for state changes? Well today have * I got good news for you. Run this example below to see how to get yourself * some callback goodness and to understand how events work. */ 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(); // let"s create a requestb.in $ch = curl_init("http://requestb.in/api/v1/bins"); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . 0)); $result = json_decode(curl_exec($ch)); $bin_name = $result->name; $callback_url = "http://requestb.in/" . $bin_name; $requests_url = "http://requestb.in/api/v1/bins/" . $bin_name . "/requests"; printf("let's create a callback\n"); $marketplace->createCallback($callback_url); printf("let's create a card and associate it with a new account\n"); $card = $marketplace->cards->create(array("card_number" => "5105105105105100", "expiration_month" => "12", "expiration_year" => "2015")); $buyer = $marketplace->createBuyer("*****@*****.**", $card->uri);
<?php Balanced\Marketplace::mine()->owner_customer->bank_accounts->query()->first()->credits->create(array("amount" => "2000000", "description" => "Credit from Balanced escrow"));
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; }
<? require('vendor/autoload.php'); Httpful\Bootstrap::init(); Balanced\Bootstrap::init(); $key = new Balanced\APIKey(); $key->save(); Balanced\Settings::$api_key = $key->secret; $marketplace = new Balanced\Marketplace(); $marketplace->save(); $card = $marketplace->cards->create(array( "card_number" => "5105105105105100", "expiration_month" => "12", "expiration_year" => "2015" )); $buyer = $marketplace->createBuyer("*****@*****.**", $card->uri); $debit = $buyer->debit(1500); $debit->refund(100); $debit->refund(100); $debit->refund(100); echo $debit->refunds->total() . " refunds" . "\n"; $total = 0; foreach ($debit->refunds as $r) { $total += $r->amount;
<?php // // Learn how to authenticate a bank account so you can debit with it. // 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 = $marketplace->createBankAccount("Jack Q Merchant", "123123123", "123123123"); $buyer = $marketplace->createAccount("*****@*****.**"); $buyer->addBankAccount($bank_account); print "you can't debit from a bank account until you verify it\n"; try { $buyer->debit(100); } catch (Exception $e) { printf("Debit failed, %s\n", $e->getMessage()); } // authenticate $verification = $bank_account->verify(); try { $verification->confirm(1, 2); } catch (Balanced\Errors\BankAccountVerificationFailure $e) { printf('Authentication error , %s\\n', $e->getMessage());
<?php $bank_account = Balanced\Marketplace::mine()->bank_accounts->create(array("account_number" => "9900000001", "name" => "Johann Bernoulli", "routing_number" => "121000358", "type" => "checking"));
<?php require __DIR__ . '/vendor/autoload.php'; Httpful\Bootstrap::init(); RESTful\Bootstrap::init(); Balanced\Bootstrap::init(); Balanced\Settings::$api_key = "ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY"; $card = Balanced\Marketplace::mine()->cards->create(array("expiration_month" => "05", "expiration_year" => "2020", "name" => "Johannes Bach", "number" => "4342561111111118"));
<?php $marketplace_bank_account = Balanced\Marketplace::mine()->owner_customer->bank_accounts->query()->first(); $order->creditTo($marketplace_bank_account, "2000");