@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remove support for Balanced payments

Summary: See <https://www.balancedpayments.com/stripe>. Just get rid of support since Phortune is a prototype anyway.

Test Plan: `grep`, poked around Phortune.

Reviewers: btrahan, chad

Reviewed By: chad

Subscribers: aurelijus, epriestley

Differential Revision: https://secure.phabricator.com/D12074

+2 -4122
-14
externals/balanced-php/.gitignore
··· 1 - # composer 2 - .buildpath 3 - composer.lock 4 - composer.phar 5 - vendor 6 - *~ 7 - *# 8 - # phar 9 - *.phar 10 - 11 - # eclipse-pdt 12 - .settings 13 - .project 14 - *.iml
-8
externals/balanced-php/.travis.yml
··· 1 - language: php 2 - before_script: 3 - - curl -s http://getcomposer.org/installer | php 4 - - php composer.phar install 5 - script: phpunit --bootstrap vendor/autoload.php --exclude-group suite tests/ 6 - php: 7 - - 5.3 8 - - 5.4
-22
externals/balanced-php/LICENSE
··· 1 - Copyright (c) 2012 Balanced 2 - 3 - MIT License 4 - 5 - Permission is hereby granted, free of charge, to any person obtaining 6 - a copy of this software and associated documentation files (the 7 - "Software"), to deal in the Software without restriction, including 8 - without limitation the rights to use, copy, modify, merge, publish, 9 - distribute, sublicense, and/or sell copies of the Software, and to 10 - permit persons to whom the Software is furnished to do so, subject to 11 - the following conditions: 12 - 13 - The above copyright notice and this permission notice shall be 14 - included in all copies or substantial portions of the Software. 15 - 16 - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-156
externals/balanced-php/README.md
··· 1 - # Balanced 2 - 3 - Online Marketplace Payments 4 - 5 - [![Build Status](https://secure.travis-ci.org/balanced/balanced-php.png)](http://travis-ci.org/balanced/balanced-php) 6 - 7 - The design of this library was heavily influenced by [Httpful](https://github.com/nategood/httpful). 8 - 9 - ## Requirements 10 - 11 - - [PHP](http://www.php.net) >= 5.3 **with** [cURL](http://www.php.net/manual/en/curl.installation.php) 12 - - [RESTful](https://github.com/bninja/restful) >= 0.1 13 - - [Httpful](https://github.com/nategood/httpful) >= 0.1 14 - 15 - ## Issues 16 - 17 - Please use appropriately tagged github [issues](https://github.com/balanced/balanced-php/issues) to request features or report bugs. 18 - 19 - ## Installation 20 - 21 - You can install using [composer](#composer), a [phar](#phar) package or from [source](#source). Note that Balanced is [PSR-0](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md) compliant: 22 - 23 - ### Composer 24 - 25 - If you don't have Composer [install](http://getcomposer.org/doc/00-intro.md#installation) it: 26 - 27 - $ curl -s https://getcomposer.org/installer | php 28 - 29 - Add this to your `composer.json`: 30 - 31 - { 32 - "require": { 33 - "balanced/balanced": "*" 34 - } 35 - } 36 - 37 - Refresh your dependencies: 38 - 39 - $ php composer.phar update 40 - 41 - 42 - Then make sure to `require` the autoloader and initialize all: 43 - 44 - <?php 45 - require(__DIR__ . '/vendor/autoload.php'); 46 - 47 - \Httpful\Bootstrap::init(); 48 - \RESTful\Bootstrap::init(); 49 - \Balanced\Bootstrap::init(); 50 - ... 51 - 52 - ### Phar 53 - 54 - Download an Httpful [phar](http://php.net/manual/en/book.phar.php) file, which are all [here](https://github.com/nategood/httpful/downloads): 55 - 56 - $ curl -s -L -o httpful.phar https://github.com/downloads/nategood/httpful/httpful.phar 57 - 58 - Download a RESTful [phar](http://php.net/manual/en/book.phar.php) file, which are all [here](https://github.com/bninja/restful/downloads): 59 - 60 - $ curl -s -L -o restful.phar https://github.com/bninja/restful/downloads/restful.phar 61 - 62 - Download a Balanced [phar](http://php.net/manual/en/book.phar.php) file, which are all [here](https://github.com/balanced/balanced-php/downloads): 63 - 64 - $ curl -s -L -o balanced.phar https://github.com/balanced/balanced-php/downloads/balanced-{VERSION}.phar 65 - 66 - And then `include` all: 67 - 68 - <?php 69 - include(__DIR__ . '/httpful.phar'); 70 - include(__DIR__ . '/restful.phar'); 71 - include(__DIR__ . '/balanced.phar'); 72 - ... 73 - 74 - ### Source 75 - 76 - Download [Httpful](https://github.com/nategood/httpful) source: 77 - 78 - $ curl -s -L -o httpful.zip https://github.com/nategood/httpful/zipball/master; 79 - $ unzip httpful.zip; mv nategood-httpful* httpful; rm httpful.zip 80 - 81 - Download [RESTful](https://github.com/bninja/restful) source: 82 - 83 - $ curl -s -L -o restful.zip https://github.com/bninja/restful/zipball/master; 84 - $ unzip restful.zip; mv bninja-restful* restful; rm restful.zips 85 - 86 - Download the Balanced source: 87 - 88 - $ curl -s -L -o balanced.zip https://github.com/balanced/balanced-php/zipball/master 89 - $ unzip balanced.zip; mv balanced-balanced-php-* balanced; rm balanced.zip 90 - 91 - And then `require` all bootstrap files: 92 - 93 - <?php 94 - require(__DIR__ . "/httpful/bootstrap.php") 95 - require(__DIR__ . "/restful/bootstrap.php") 96 - require(__DIR__ . "/balanced/bootstrap.php") 97 - ... 98 - 99 - ## Quickstart 100 - 101 - curl -s http://getcomposer.org/installer | php 102 - 103 - echo '{ 104 - "require": { 105 - "balanced/balanced": "*" 106 - } 107 - }' > composer.json 108 - 109 - php composer.phar install 110 - 111 - curl https://raw.github.com/balanced/balanced-php/master/example/example.php > example.php 112 - 113 - php example.php 114 - 115 - curl https://raw.github.com/balanced/balanced-php/master/example/buyer-example.php > buyer-example.php 116 - 117 - php -S 127.0.0.1:9321 buyer-example.php 118 - # now open a browser and go to http://127.0.0.1:9321/ to view how to tokenize cards and add to a buyer 119 - 120 - ## Usage 121 - 122 - See https://www.balancedpayments.com/docs/overview?language=php for tutorials and documentation. 123 - 124 - ## Testing 125 - 126 - $ phpunit --bootstrap vendor/autoload.php tests/ 127 - 128 - Or if you'd like to skip network calls: 129 - 130 - $ phpunit --exclude-group suite --bootstrap vendor/autoload.php tests/ 131 - 132 - ## Publishing 133 - 134 - 1. Ensure that **all** [tests](#testing) pass 135 - 2. Increment minor `VERSION` in `src/Balanced/Settings` and `composer.json` (`git commit -am 'v{VERSION} release'`) 136 - 3. Tag it (`git tag -a v{VERSION} -m 'v{VERSION} release'`) 137 - 4. Push the tag (`git push --tag`) 138 - 5. [Packagist](http://packagist.org/packages/balanced/balanced) will see the new tag and take it from there 139 - 6. Build (`build-phar`) and upload a [phar](http://php.net/manual/en/book.phar.php) file 140 - 141 - ## Contributing 142 - 143 - 1. Fork it 144 - 2. Create your feature branch (`git checkout -b my-new-feature`) 145 - 3. Write your code **and [tests](#testing)** 146 - 4. Ensure all tests still pass (`phpunit --bootstrap vendor/autoload.php tests/`) 147 - 5. Commit your changes (`git commit -am 'Add some feature'`) 148 - 6. Push to the branch (`git push origin my-new-feature`) 149 - 7. Create new pull request 150 - 151 - ## Contributors 152 - 153 - * [Jacob Rus](https://github.com/jrus) 154 - * [Leon Smith](https://github.com/leonsmith) 155 - * [Matt Drollette](https://github.com/MDrollette) 156 - * [You](https://github.com/balanced/balanced-php/issues)!
-4
externals/balanced-php/bootstrap.php
··· 1 - <?php 2 - 3 - require(__DIR__ . '/src/Balanced/Bootstrap.php'); 4 - \Balanced\Bootstrap::init();
-36
externals/balanced-php/build-phar
··· 1 - #!/usr/bin/php 2 - <?php 3 - include('src/Balanced/Settings.php'); 4 - 5 - function exit_unless($condition, $msg = null) { 6 - if ($condition) 7 - return; 8 - echo "[FAIL] $msg"; 9 - exit(1); 10 - } 11 - 12 - echo "Building Phar... "; 13 - $base_dir = dirname(__FILE__); 14 - $source_dir = $base_dir . '/src/Balanced/'; 15 - $phar_name = 'balanced.phar'; 16 - $phar_path = $base_dir . '/' . $phar_name; 17 - $phar = new Phar($phar_path, 0, $phar_name); 18 - $stub = <<<HEREDOC 19 - <?php 20 - // Phar Stub File 21 - Phar::mapPhar('balanced.phar'); 22 - include('phar://balanced.phar/Balanced/Bootstrap.php'); 23 - \Balanced\Bootstrap::pharInit(); 24 - 25 - __HALT_COMPILER(); 26 - HEREDOC; 27 - $phar->setStub($stub); 28 - exit_unless($phar, "Unable to create a phar. Make sure you have phar.readonly=0 set in your ini file."); 29 - $phar->buildFromDirectory(dirname($source_dir)); 30 - echo "[ OK ]\n"; 31 - 32 - echo "Renaming Phar... "; 33 - $phar_versioned_name = 'balanced-' . \Balanced\Settings::VERSION . '.phar'; 34 - $phar_versioned_path = $base_dir . '/' . $phar_versioned_name; 35 - rename($phar_path, $phar_versioned_path); 36 - echo "[ OK ]\n";
-24
externals/balanced-php/composer.json
··· 1 - { 2 - "name": "balanced/balanced", 3 - "description": "Client for Balanced API", 4 - "homepage": "http://github.com/balanced/balanced-php", 5 - "license": "MIT", 6 - "keywords": ["payments", "api"], 7 - "version": "0.7.1", 8 - "authors": [ 9 - { 10 - "name": "Balanced", 11 - "email": "dev@balancedpayments.com", 12 - "homepage": "http://www.balancedpayments.com" 13 - } 14 - ], 15 - "require": { 16 - "nategood/httpful": "*", 17 - "bninja/restful": "*" 18 - }, 19 - "autoload": { 20 - "psr-0": { 21 - "Balanced": "src/" 22 - } 23 - } 24 - }
-54
externals/balanced-php/example/bank-account-debits.php
··· 1 - <?php 2 - // 3 - // Learn how to authenticate a bank account so you can debit with it. 4 - // 5 - 6 - require(__DIR__ . '/vendor/autoload.php'); 7 - 8 - Httpful\Bootstrap::init(); 9 - RESTful\Bootstrap::init(); 10 - Balanced\Bootstrap::init(); 11 - 12 - // create a new marketplace 13 - $key = new Balanced\APIKey(); 14 - $key->save(); 15 - Balanced\Settings::$api_key = $key->secret; 16 - $marketplace = new Balanced\Marketplace(); 17 - $marketplace->save(); 18 - 19 - // create a bank account 20 - $bank_account = $marketplace->createBankAccount("Jack Q Merchant", 21 - "123123123", 22 - "123123123" 23 - ); 24 - $buyer = $marketplace->createAccount("buyer@example.org"); 25 - $buyer->addBankAccount($bank_account); 26 - 27 - print("you can't debit from a bank account until you verify it\n"); 28 - try { 29 - $buyer->debit(100); 30 - } catch (Exception $e) { 31 - printf("Debit failed, %s\n", $e->getMessage()); 32 - } 33 - 34 - // authenticate 35 - $verification = $bank_account->verify(); 36 - 37 - try { 38 - $verification->confirm(1, 2); 39 - } catch (Balanced\Errors\BankAccountVerificationFailure $e) { 40 - printf('Authentication error , %s\n', $e->getMessage()); 41 - print("PROTIP: for TEST bank accounts the valid amount is always 1 and 1\n"); 42 - 43 - } 44 - 45 - $verification->confirm(1, 1); 46 - 47 - $debit = $buyer->debit(100); 48 - printf("debited the bank account %s for %d cents\n", 49 - $debit->source->uri, 50 - $debit->amount 51 - ); 52 - print("and there you have it"); 53 - 54 - ?>
-157
externals/balanced-php/example/buyer-example.php
··· 1 - <?php 2 - 3 - require(__DIR__ . '/vendor/autoload.php'); 4 - 5 - Httpful\Bootstrap::init(); 6 - RESTful\Bootstrap::init(); 7 - Balanced\Bootstrap::init(); 8 - 9 - $API_KEY_SECRET = '5f4db668a5ec11e1b908026ba7e239a9'; 10 - $page = $_SERVER['REQUEST_URI']; 11 - Balanced\Settings::$api_key = $API_KEY_SECRET; 12 - $marketplace = Balanced\Marketplace::mine(); 13 - 14 - if ($page == '/') { 15 - // do nothing 16 - } elseif ($page == '/buyer') { 17 - if (isset($_POST['uri']) and isset($_POST['email_address'])) { 18 - // create in balanced 19 - $email_address = $_POST['email_address']; 20 - $card_uri = $_POST['uri']; 21 - try { 22 - echo create_buyer($email_address, $card_uri)->uri; 23 - return; 24 - } catch (Balanced\Errors\Error $e) { 25 - echo $e->getMessage(); 26 - return; 27 - } 28 - } 29 - } 30 - 31 - function create_buyer($email_address, $card_uri) { 32 - $marketplace = Balanced\Marketplace::mine(); 33 - try { 34 - # new buyer 35 - $buyer = $marketplace->createBuyer( 36 - $email_address, 37 - $card_uri); 38 - } 39 - catch (Balanced\Errors\DuplicateAccountEmailAddress $e) { 40 - # oops, account for $email_address already exists so just add the card 41 - $buyer = Balanced\Account::get($e->extras->account_uri); 42 - $buyer->addCard($card_uri); 43 - } 44 - return $buyer; 45 - } 46 - 47 - ?> 48 - <html> 49 - <head> 50 - <link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" type="text/css"> 51 - <style type="text/css"> 52 - [name="marketplace_eid"] { 53 - width: 300px; 54 - } 55 - [name^="expiration"] { 56 - width: 50px; 57 - } 58 - [name="security_code"] { 59 - width: 50px; 60 - } 61 - code { display: block; } 62 - pre { color: green; } 63 - </style> 64 - </head> 65 - <body> 66 - <h1>Balanced Sample - Collect Credit Card Information</h1> 67 - <div class="row"> 68 - <div class="span6"> 69 - <form id="payment"> 70 - <div> 71 - <label>Email Address</label> 72 - <input name="email_address" value="bob@example.com"> 73 - </div> 74 - <div> 75 - <label>Card Number</label> 76 - <input name="card_number" value="4111111111111111" autocomplete="off"> 77 - </div> 78 - <div> 79 - <label>Expiration</label> 80 - <input name="expiration_month" value="1"> / <input name="expiration_year" value="2020"> 81 - </div> 82 - <div> 83 - <label>Security Code</label> 84 - <input name="security_code" value="123" autocomplete="off"> 85 - </div> 86 - <button>Submit Payment Data</button> 87 - </form> 88 - </div> 89 - </div> 90 - <div id="result"></div> 91 - <script type="text/javascript" src="https://js.balancedpayments.com/v1/balanced.js"></script> 92 - <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 93 - <script type="text/javascript"> 94 - var marketplaceUri = '<?php echo $marketplace->uri; ?>'; 95 - 96 - var debug = function (tag, content) { 97 - $('<' + tag + '>' + content + '</' + tag + '>').appendTo('#result'); 98 - }; 99 - 100 - try { 101 - balanced.init(marketplaceUri); 102 - } catch (e) { 103 - debug('code', 'You need to set the marketplaceUri variable'); 104 - } 105 - 106 - function accountCreated(response) { 107 - debug('code', 'account create result: ' + response); 108 - } 109 - 110 - function balancedCallback(response) { 111 - var tag = (response.status < 300) ? 'pre' : 'code'; 112 - debug(tag, JSON.stringify(response)); 113 - switch (response.status) { 114 - case 201: 115 - // response.data.uri == uri of the card resource, submit to your server 116 - $.post('/buyer', { 117 - uri: response.data.uri, 118 - email_address: $('[name="email_address"]').val() 119 - }, accountCreated); 120 - case 400: 121 - case 403: 122 - // missing/malformed data - check response.error for details 123 - break; 124 - case 402: 125 - // we couldn't authorize the buyer's credit card - check response.error for details 126 - break; 127 - case 404: 128 - // your marketplace URI is incorrect 129 - break; 130 - default: 131 - // we did something unexpected - check response.error for details 132 - break; 133 - } 134 - } 135 - 136 - var tokenizeCard = function(e) { 137 - e.preventDefault(); 138 - 139 - var $form = $('form#payment'); 140 - var cardData = { 141 - card_number: $form.find('[name="card_number"]').val(), 142 - expiration_month: $form.find('[name="expiration_month"]').val(), 143 - expiration_year: $form.find('[name="expiration_year"]').val(), 144 - security_code: $form.find('[name="security_code"]').val() 145 - }; 146 - 147 - balanced.card.create(cardData, balancedCallback); 148 - }; 149 - 150 - $('#payment').submit(tokenizeCard); 151 - 152 - if (window.location.protocol === 'file:') { 153 - alert("balanced.js does not work when included in pages served over file:// URLs. Try serving this page over a webserver. Contact support@balancedpayments.com if you need assistance."); 154 - } 155 - </script> 156 - </body> 157 - </html>
-5
externals/balanced-php/example/composer.json
··· 1 - { 2 - "require": { 3 - "balanced/balanced": "*" 4 - } 5 - }
-42
externals/balanced-php/example/debit-example.php
··· 1 - <?php 2 - 3 - require('vendor/autoload.php'); 4 - 5 - Httpful\Bootstrap::init(); 6 - RESTful\Bootstrap::init(); 7 - Balanced\Bootstrap::init(); 8 - 9 - $API_KEY_SECRET = '5f4db668a5ec11e1b908026ba7e239a9'; 10 - Balanced\Settings::$api_key = $API_KEY_SECRET; 11 - $marketplace = Balanced\Marketplace::mine(); 12 - 13 - print "create a card\n"; 14 - $card = $marketplace->cards->create(array( 15 - "card_number" => "5105105105105100", 16 - "expiration_month" => "12", 17 - "expiration_year" => "2015" 18 - )); 19 - print "our card: " . $card->uri . "\n"; 20 - 21 - print "create a **buyer** account with that card\n"; 22 - $buyer = $marketplace->createBuyer(null, $card->uri); 23 - print "our buyer account: " . $buyer->uri . "\n"; 24 - 25 - print "debit our buyer, let's say $15\n"; 26 - try { 27 - $debit = $buyer->debit(1500); 28 - print "our buyer debit: " . $debit->uri . "\n"; 29 - } 30 - catch (Balanced\Errors\Declined $e) { 31 - print "oh no, the processor declined the debit!\n"; 32 - } 33 - catch (Balanced\Errors\NoFundingSource $e) { 34 - print "oh no, the buyer has not active funding sources!\n"; 35 - } 36 - catch (Balanced\Errors\CannotDebit $e) { 37 - print "oh no, the buyer has no debitable funding sources!\n"; 38 - } 39 - 40 - print "and there you have it 8)\n"; 41 - 42 - ?>
-59
externals/balanced-php/example/events-and-callbacks.php
··· 1 - <?php 2 - /* 3 - * Welcome weary traveller. Sick of polling for state changes? Well today have 4 - * I got good news for you. Run this example below to see how to get yourself 5 - * some callback goodness and to understand how events work. 6 - */ 7 - require(__DIR__ . "/vendor/autoload.php"); 8 - 9 - Httpful\Bootstrap::init(); 10 - RESTful\Bootstrap::init(); 11 - Balanced\Bootstrap::init(); 12 - 13 - // create a new marketplace 14 - $key = new Balanced\APIKey(); 15 - $key->save(); 16 - Balanced\Settings::$api_key = $key->secret; 17 - $marketplace = new Balanced\Marketplace(); 18 - $marketplace->save(); 19 - 20 - // let"s create a requestb.in 21 - $ch = curl_init("http://requestb.in/api/v1/bins"); 22 - curl_setopt($ch, CURLOPT_POST, true); 23 - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 24 - curl_setopt($ch, CURLOPT_HTTPHEADER, array( 25 - 'Content-Type: application/json', 26 - 'Content-Length: ' . 0) 27 - ); 28 - $result = json_decode(curl_exec($ch)); 29 - $bin_name = $result->name; 30 - $callback_url = "http://requestb.in/" . $bin_name; 31 - $requests_url = "http://requestb.in/api/v1/bins/" . $bin_name . "/requests"; 32 - 33 - printf("let's create a callback\n"); 34 - $marketplace->createCallback($callback_url); 35 - 36 - printf("let's create a card and associate it with a new account\n"); 37 - $card = $marketplace->cards->create(array( 38 - "card_number" => "5105105105105100", 39 - "expiration_month" => "12", 40 - "expiration_year" => "2015" 41 - )); 42 - $buyer = $marketplace->createBuyer("buyer@example.org", $card->uri); 43 - 44 - printf("generate a debit (which implicitly creates and captures a hold)\n"); 45 - $buyer->debit(100); 46 - 47 - foreach ($marketplace->events as $event) { 48 - printf("this was a %s event, it occurred at %s\n", 49 - $event->type, 50 - $event->occurred_at 51 - ); 52 - } 53 - 54 - printf("ok, let's check with requestb.in to see if our callbacks fired at %s\n", $callback_url); 55 - printf("we received callbacks, you can view them at http://requestb.in/%s?inspect\n", 56 - $bin_name 57 - ); 58 - 59 - ?>
-120
externals/balanced-php/example/example.php
··· 1 - <?php 2 - 3 - require('vendor/autoload.php'); 4 - 5 - Httpful\Bootstrap::init(); 6 - RESTful\Bootstrap::init(); 7 - Balanced\Bootstrap::init(); 8 - 9 - print "create our new api key\n"; 10 - $key = new Balanced\APIKey(); 11 - $key->save(); 12 - print "Our secret is " . $key->secret . "\n"; 13 - 14 - print "configure with our secret " . $key->secret . "\n"; 15 - Balanced\Settings::$api_key = $key->secret; 16 - 17 - print "create our marketplace"; 18 - $marketplace = new Balanced\Marketplace(); 19 - $marketplace->save(); 20 - 21 - if (Balanced\Merchant::me() == null) { 22 - throw new Exception("Balanced\Merchant::me() should not be null"); 23 - } 24 - 25 - print "What's my merchant? Easy: Balanced\Merchant::me(): " . Balanced\Merchant::me()->uri . "\n"; 26 - 27 - if (Balanced\Marketplace::mine() == null) { 28 - throw new Exception("Balanced\Marketplace::mine() should never be null"); 29 - } 30 - 31 - print "What's my marketplace? Easy: Balanced\Marketplace::mine(): " .Balanced\Marketplace::mine()->uri . "\n"; 32 - 33 - print "My marketplace's name is " . $marketplace->name . "\n"; 34 - print "Changing it to TestFooey\n"; 35 - $marketplace->name = "TestFooey"; 36 - $marketplace->save(); 37 - print "My marketplace name is now " . $marketplace->name . "\n"; 38 - 39 - if ($marketplace->name != "TestFooey") { 40 - throw new Exception("Marketplace name is NOT TestFooey"); 41 - } 42 - 43 - print "Cool, let's create a card\n"; 44 - $card = $marketplace->cards->create(array( 45 - "card_number" => "5105105105105100", 46 - "expiration_month" => "12", 47 - "expiration_year" => "2015" 48 - )); 49 - 50 - print "Our card: " . $card->uri . "\n"; 51 - 52 - print "Create out **buyer** account\n"; 53 - $buyer = $marketplace->createBuyer("buyer@example.org", $card->uri); 54 - print "our buyer account: " . $buyer->uri . "\n"; 55 - 56 - print "hold some amount of funds on the buyer, let's say $15\n"; 57 - $the_hold = $buyer->hold(1500); 58 - 59 - print "ok, no more holds! let's capture it (for the full amount)\n"; 60 - $debit = $the_hold->capture(); 61 - 62 - print "hmm, ho much money do i have in escrow? it should equal the debit amount\n"; 63 - $marketplace = Balanced\Marketplace::mine(); 64 - if ($marketplace->in_escrow != 1500) { 65 - throw new Exception("1500 is not in escrow! This is wrong"); 66 - } 67 - print "I have " . $marketplace->in_escrow . " in escrow!\n"; 68 - 69 - print "Cool. now let me refund the full amount"; 70 - $refund = $debit->refund(); 71 - 72 - print "ok, we have a merchant that's signing up, let's create an account for them first, let's create their bank account\n"; 73 - 74 - $bank_account = $marketplace->createBankAccount("Jack Q Merchant", 75 - "123123123", /* account_number */ 76 - "123123123" /* bank_code (routing number is USA)*/ 77 - ); 78 - 79 - $identity = array( 80 - "type" => "person", 81 - "name" => "Billy Jones", 82 - "street_address" => "801 High St", 83 - "postal_code" => "94301", 84 - "country" => "USA", 85 - "dob" => "1979-02", 86 - "phone_number" => "+16505551234" 87 - ); 88 - 89 - $merchant = $marketplace->createMerchant('merchant@example.org', 90 - $identity, 91 - $bank_account->uri 92 - ); 93 - 94 - print "our buyer is interested in buying something for $130\n"; 95 - $another_debit = $buyer->debit(13000, "MARKETPLACE.COM"); 96 - 97 - print "let's credit our merchant $110\n"; 98 - $credit = $merchant->credit(11000, "Buyer purchase something on Marketplace.com"); 99 - 100 - print "let's assume the marketplace charges 15%, so it earned $20\n"; 101 - $mp_credit = $marketplace->owner_account->credit(2000, 102 - "Commission from MARKETPLACE.COM"); 103 - 104 - print "ok, let's invalidate the card used so it cannot be used again\n"; 105 - $card->is_valid = false; 106 - $card->save(); 107 - 108 - print "how do we look up an existing object from the URI?\n"; 109 - $the_buyer = Balanced\Account::get($buyer->uri); 110 - print "we got the buyer " . $the_buyer->email_address . "\n"; 111 - 112 - $the_debit = Balanced\Debit::get($debit->uri); 113 - print "we got the debit: " . $the_debit->uri . "\n"; 114 - 115 - $the_credit = Balanced\Credit::get($credit->uri); 116 - print "we got the credit: " . $the_credit->uri . "\n"; 117 - 118 - print "and there you have it :)\n"; 119 - 120 - ?>
-71
externals/balanced-php/example/iterate-example.php
··· 1 - <? 2 - require('vendor/autoload.php'); 3 - 4 - Httpful\Bootstrap::init(); 5 - RESTful\Bootstrap::init(); 6 - Balanced\Bootstrap::init(); 7 - 8 - $key = new Balanced\APIKey(); 9 - $key->save(); 10 - Balanced\Settings::$api_key = $key->secret; 11 - $marketplace = new Balanced\Marketplace(); 12 - $marketplace->save(); 13 - 14 - $card = $marketplace->cards->create(array( 15 - "card_number" => "5105105105105100", 16 - "expiration_month" => "12", 17 - "expiration_year" => "2015" 18 - )); 19 - 20 - $buyer = $marketplace->createBuyer("buyer@example.com", $card->uri); 21 - 22 - $debit = $buyer->debit(1500); 23 - $debit->refund(100); 24 - $debit->refund(100); 25 - $debit->refund(100); 26 - 27 - echo $debit->refunds->total() . " refunds" . "\n"; 28 - 29 - $total = 0; 30 - 31 - foreach ($debit->refunds as $r) { 32 - $total += $r->amount; 33 - print "refund = " . $r->amount . "\n"; 34 - } 35 - 36 - print $total . "\n"; 37 - 38 - # bigger pagination example 39 - 40 - print "Create 60 **buyer** with cards accounts\n"; 41 - 42 - for ($i = 0; $i < 60; $i++) { 43 - $card = $marketplace->cards->create(array( 44 - "card_number" => "5105105105105100", 45 - "expiration_month" => "12", 46 - "expiration_year" => "2015" 47 - )); 48 - $buyer = $marketplace->createBuyer("buyer" . $i . "@example.org", $card->uri); 49 - print '.'; 50 - } 51 - 52 - print "\n"; 53 - 54 - $cards = $marketplace->cards; 55 - 56 - print $cards->total() . " cards in Marketplace\n"; 57 - 58 - foreach ($cards as $c) { 59 - print "card " . $c->uri . "\n"; 60 - } 61 - 62 - # let's iterate through cards for just a single account 63 - 64 - foreach ($buyer->cards as $c) { 65 - print "buyer's card " . $c->uri . "\n"; 66 - } 67 - 68 - print "and there you have it :)\n"; 69 - 70 - 71 - ?>
-14
externals/balanced-php/example/test-composer.php
··· 1 - <?php 2 - 3 - // run this file to test your composer install of Balanced 4 - 5 - require(__DIR__ . '/vendor/autoload.php'); 6 - 7 - \Httpful\Bootstrap::init(); 8 - \RESTful\Bootstrap::init(); 9 - \Balanced\Bootstrap::init(); 10 - 11 - echo "[ OK ]\n"; 12 - echo "balanced version -- " . \Balanced\Settings::VERSION . " \n"; 13 - echo "restful version -- " . \RESTful\Settings::VERSION . " \n"; 14 - echo "httpful version -- " . \Httpful\Httpful::VERSION . " \n";
-12
externals/balanced-php/example/test-phar.php
··· 1 - <?php 2 - 3 - // run this file to test your phar install of Balanced 4 - 5 - include(__DIR__ . '/httpful.phar'); 6 - include(__DIR__ . '/restful.phar'); 7 - include(__DIR__ . '/balanced.phar'); 8 - 9 - echo "[ OK ]\n"; 10 - echo "balanced version -- " . \Balanced\Settings::VERSION . " \n"; 11 - echo "restful version -- " . \RESTful\Settings::VERSION . " \n"; 12 - echo "httpful version -- " . \Httpful\Httpful::VERSION . " \n";
-12
externals/balanced-php/example/test-source.php
··· 1 - <?php 2 - 3 - // run this file to test your source install of Balanced 4 - 5 - require(__DIR__ . "/httpful/bootstrap.php"); 6 - require(__DIR__ . "/restful/bootstrap.php"); 7 - require(__DIR__ . "/balanced/bootstrap.php"); 8 - 9 - echo "[ OK ]\n"; 10 - echo "balanced version -- " . \Balanced\Settings::VERSION . " \n"; 11 - echo "restful version -- " . \RESTful\Settings::VERSION . " \n"; 12 - echo "httpful version -- " . \Httpful\Httpful::VERSION . " \n";
-55
externals/balanced-php/src/Balanced/APIKey.php
··· 1 - <?php 2 - 3 - namespace Balanced; 4 - 5 - use Balanced\Resource; 6 - use Balanced\Settings; 7 - use \RESTful\URISpec; 8 - 9 - /** 10 - * Represents an api key. These are used to authenticate you with the api. 11 - * 12 - * Typically you create an initial api key: 13 - * 14 - * <code> 15 - * print \Balanced\Settings::$api_key == null; 16 - * $api_key = new \Balanced\APIKey(); 17 - * $api_key = api_key->save(); 18 - * $secret = $api_key->secret; 19 - * print $secret; 20 - * </code> 21 - * 22 - * Then save the returned secret (we don't store it) and configure the client 23 - * to use it: 24 - * 25 - * <code> 26 - * \Balanced\Settings::$api_key = 'my-api-key-secret'; 27 - * </code> 28 - * 29 - * You can later add another api key if you'd like to rotate or expire old 30 - * ones: 31 - * 32 - * <code> 33 - * $api_key = new \Balanced\APIKey(); 34 - * $api_key = api_key->save(); 35 - * $new_secret = $api_key->secret; 36 - * print $new_secret; 37 - * 38 - * \Balanced\Settings::$api_key = $new_secret; 39 - * 40 - * \Balanced\APIKey::query() 41 - * ->sort(\Balanced\APIKey::f->created_at->desc()) 42 - * ->first() 43 - * ->delete(); 44 - * </code> 45 - */ 46 - class APIKey extends Resource 47 - { 48 - protected static $_uri_spec = null; 49 - 50 - public static function init() 51 - { 52 - self::$_uri_spec = new URISpec('api_keys', 'id', '/v1'); 53 - self::$_registry->add(get_called_class()); 54 - } 55 - }
-217
externals/balanced-php/src/Balanced/Account.php
··· 1 - <?php 2 - 3 - namespace Balanced; 4 - 5 - use Balanced\Resource; 6 - use \RESTful\URISpec; 7 - 8 - /** 9 - * Represent a buyer or merchant account on a marketplace. 10 - * 11 - * You create these using Balanced\Marketplace->createBuyer or 12 - * Balanced\Marketplace->createMerchant. 13 - * 14 - * <code> 15 - * $marketplace = \Balanced\Marketplace::mine(); 16 - * 17 - * $card = $marketplace->cards->create(array( 18 - * 'street_address' => $street_address, 19 - * 'city' => 'Jollywood', 20 - * 'region' => 'CA', 21 - * 'postal_code' => '90210', 22 - * 'name' => 'Captain Chunk', 23 - * 'card_number' => '4111111111111111', 24 - * 'expiration_month' => 7, 25 - * 'expiration_year' => 2015 26 - * )); 27 - * 28 - * $buyer = $marketplace->createBuyer( 29 - * 'buyer@example.com', 30 - * $card->uri, 31 - * array( 32 - * 'my_id' => '1212121', 33 - * ) 34 - * ); 35 - * </code> 36 - * 37 - * @see Balanced\Marketplace->createBuyer 38 - * @see Balanced\Marketplace->createMerchant 39 - */ 40 - class Account extends Resource 41 - { 42 - protected static $_uri_spec = null; 43 - 44 - public static function init() 45 - { 46 - self::$_uri_spec = new URISpec('accounts', 'id'); 47 - self::$_registry->add(get_called_class()); 48 - } 49 - 50 - /** 51 - * Credit the account. 52 - * 53 - * @param int amount Amount to credit the account in USD pennies. 54 - * @param string description Optional description of the credit. 55 - * @param array[string]string meta Optional metadata to associate with the credit. 56 - * @param mixed destination Optional URI of a funding destination (i.e. \Balanced\BankAccount) associated with this account to credit. If not specified the funding destination most recently added to the account is used. 57 - * @param string appears_on_statement_as Optional description of the credit as it will appears on the customer's billing statement. 58 - * 59 - * @return \Balanced\Credit 60 - */ 61 - public function credit( 62 - $amount, 63 - $description = null, 64 - $meta = null, 65 - $destination = null, 66 - $appears_on_statement_as = null) 67 - { 68 - if ($destination == null) 69 - $destination_uri = null; 70 - else 71 - $destination_uri = is_string($destination) ? $destination : $destination->uri; 72 - return $this->credits->create(array( 73 - 'amount' => $amount, 74 - 'description' => $description, 75 - 'meta' => $meta, 76 - 'destination_uri' => $destination_uri, 77 - 'appears_on_statement_as' => $appears_on_statement_as 78 - )); 79 - } 80 - 81 - /** 82 - * Debit the account. 83 - * 84 - * @param int amount Amount to debit the account in USD pennies. 85 - * @param string appears_on_statement_as Optional description of the debit as it will appears on the customer's billing statement. 86 - * @param string description Optional description of the debit. 87 - * @param array[string]string meta Optional metadata to associate with the debit. 88 - * @param mixed Optional funding source (i.e. \Balanced\Card) or URI of a funding source associated with this account to debit. If not specified the funding source most recently added to the account is used. 89 - * 90 - * @return \Balanced\Debit 91 - */ 92 - public function debit( 93 - $amount, 94 - $appears_on_statement_as = null, 95 - $description = null, 96 - $meta = null, 97 - $source = null, 98 - $on_behalf_of = null) 99 - { 100 - if ($source == null) { 101 - $source_uri = null; 102 - } else if (is_string($source)) { 103 - $source_uri = $source; 104 - } else { 105 - $source_uri = $source->uri; 106 - } 107 - 108 - if ($on_behalf_of == null) { 109 - $on_behalf_of_uri = null; 110 - } else if (is_string($on_behalf_of)) { 111 - $on_behalf_of_uri = $on_behalf_of; 112 - } else { 113 - $on_behalf_of_uri = $on_behalf_of->uri; 114 - } 115 - 116 - if (isset($this->uri) && $on_behalf_of_uri == $this->uri) 117 - throw new \InvalidArgumentException( 118 - 'The on_behalf_of parameter MAY NOT be the same account as the account you are debiting!' 119 - ); 120 - 121 - return $this->debits->create(array( 122 - 'amount' => $amount, 123 - 'description' => $description, 124 - 'meta' => $meta, 125 - 'source_uri' => $source_uri, 126 - 'on_behalf_of_uri' => $on_behalf_of_uri, 127 - 'appears_on_statement_as' => $appears_on_statement_as 128 - )); 129 - } 130 - 131 - /** 132 - * Create a hold (i.e. a guaranteed pending debit) for account funds. You 133 - * can later capture or void. A hold is associated with a account funding 134 - * source (i.e. \Balanced\Card). If you don't specify the source then the 135 - * current primary funding source for the account is used. 136 - * 137 - * @param int amount Amount of the hold in USD pennies. 138 - * @param string Optional description Description of the hold. 139 - * @param string Optional URI referencing the card to use for the hold. 140 - * @param array[string]string meta Optional metadata to associate with the hold. 141 - * 142 - * @return \Balanced\Hold 143 - */ 144 - public function hold( 145 - $amount, 146 - $description = null, 147 - $source_uri = null, 148 - $meta = null) 149 - { 150 - return $this->holds->create(array( 151 - 'amount' => $amount, 152 - 'description' => $description, 153 - 'source_uri' => $source_uri, 154 - 'meta' => $meta 155 - )); 156 - } 157 - 158 - /** 159 - * Creates or associates a created card with the account. The default 160 - * funding source for the account will be this card. 161 - * 162 - * @see \Balanced\Marketplace->createCard 163 - * 164 - * @param mixed card \Balanced\Card or URI referencing a card to associate with the account. Alternatively it can be an associative array describing a card to create and associate with the account. 165 - * 166 - * @return \Balanced\Account 167 - */ 168 - public function addCard($card) 169 - { 170 - if (is_string($card)) 171 - $this->card_uri = $card; 172 - else if (is_array($card)) 173 - $this->card = $card; 174 - else 175 - $this->card_uri = $card->uri; 176 - return $this->save(); 177 - } 178 - 179 - /** 180 - * Creates or associates a created bank account with the account. The 181 - * new default funding destination for the account will be this bank account. 182 - * 183 - * @see \Balanced\Marketplace->createBankAccount 184 - * 185 - * @param mixed bank_account \Balanced\BankAccount or URI for a bank account to associate with the account. Alternatively it can be an associative array describing a bank account to create and associate with the account. 186 - * 187 - * @return \Balanced\Account 188 - */ 189 - public function addBankAccount($bank_account) 190 - { 191 - if (is_string($bank_account)) 192 - $this->bank_account_uri = $bank_account; 193 - else if (is_array($bank_account)) 194 - $this->bank_account = $bank_account; 195 - else 196 - $this->bank_account_uri = $bank_account->uri; 197 - return $this->save(); 198 - } 199 - 200 - /** 201 - * Promotes a role-less or buyer account to a merchant. 202 - * 203 - * @see Balanced\Marketplace::createMerchant 204 - * 205 - * @param mixed merchant Associative array describing the merchants identity or a URI referencing a created merchant. 206 - * 207 - * @return \Balanced\Account 208 - */ 209 - public function promoteToMerchant($merchant) 210 - { 211 - if (is_string($merchant)) 212 - $this->merchant_uri = $merchant; 213 - else 214 - $this->merchant = $merchant; 215 - return $this->save(); 216 - } 217 - }
-127
externals/balanced-php/src/Balanced/BankAccount.php
··· 1 - <?php 2 - 3 - namespace Balanced; 4 - 5 - use Balanced\Resource; 6 - use \RESTful\URISpec; 7 - 8 - /** 9 - * Represents an account bank account. 10 - * 11 - * You can create these via Balanced\Marketplace::bank_accounts::create or 12 - * Balanced\Marketplace::createBankAccount. Associate them with a buyer or 13 - * merchant one creation via Balanced\Marketplace::createBuyer or 14 - * Balanced\Marketplace::createMerchant and with an existing buyer or merchant 15 - * use Balanced\Account::addBankAccount. 16 - * 17 - * <code> 18 - * $marketplace = \Balanced\Marketplace::mine(); 19 - * 20 - * $bank_account = $marketplace->bank_accounts->create(array( 21 - * 'name' => 'name', 22 - * 'account_number' => '11223344', 23 - * 'bank_code' => '1313123', 24 - * )); 25 - * 26 - * $account = $marketplace 27 - * ->accounts 28 - * ->query() 29 - * ->filter(Account::f->email_address->eq('merchant@example.com')) 30 - * ->one(); 31 - * $account->addBankAccount($bank_account->uri); 32 - * </code> 33 - */ 34 - class BankAccount extends Resource 35 - { 36 - protected static $_uri_spec = null; 37 - 38 - public static function init() 39 - { 40 - self::$_uri_spec = new URISpec('bank_accounts', 'id', '/v1'); 41 - self::$_registry->add(get_called_class()); 42 - } 43 - 44 - /** 45 - * Credit a bank account. 46 - * 47 - * @param int amount Amount to credit in USD pennies. 48 - * @param string description Optional description of the credit. 49 - * @param string appears_on_statement_as Optional description of the credit as it will appears on the customer's billing statement. 50 - * 51 - * @return \Balanced\Credit 52 - * 53 - * <code> 54 - * $bank_account = new \Balanced\BankAccount(array( 55 - * 'account_number' => '12341234', 56 - * 'name' => 'Fit Finlay', 57 - * 'bank_code' => '325182797', 58 - * 'type' => 'checking', 59 - * )); 60 - * 61 - * $credit = $bank_account->credit(123, 'something descriptive'); 62 - * </code> 63 - */ 64 - public function credit( 65 - $amount, 66 - $description = null, 67 - $meta = null, 68 - $appears_on_statement_as = null) 69 - { 70 - if (!property_exists($this, 'account') || $this->account == null) { 71 - $credit = $this->credits->create(array( 72 - 'amount' => $amount, 73 - 'description' => $description, 74 - )); 75 - } else { 76 - $credit = $this->account->credit( 77 - $amount, 78 - $description, 79 - $meta, 80 - $this->uri, 81 - $appears_on_statement_as 82 - ); 83 - } 84 - return $credit; 85 - } 86 - 87 - public function verify() 88 - { 89 - $response = self::getClient()->post( 90 - $this->verifications_uri, null 91 - ); 92 - $verification = new BankAccountVerification(); 93 - $verification->_objectify($response->body); 94 - return $verification; 95 - } 96 - } 97 - 98 - /** 99 - * Represents an verification for a bank account which is a pre-requisite if 100 - * you want to create debits using the associated bank account. The side-effect 101 - * of creating a verification is that 2 random amounts will be deposited into 102 - * the account which must then be confirmed via the confirm method to ensure 103 - * that you have access to the bank account in question. 104 - * 105 - * You can create these via Balanced\Marketplace::bank_accounts::verify. 106 - * 107 - * <code> 108 - * $marketplace = \Balanced\Marketplace::mine(); 109 - * 110 - * $bank_account = $marketplace->bank_accounts->create(array( 111 - * 'name' => 'name', 112 - * 'account_number' => '11223344', 113 - * 'bank_code' => '1313123', 114 - * )); 115 - * 116 - * $verification = $bank_account->verify(); 117 - * </code> 118 - */ 119 - class BankAccountVerification extends Resource { 120 - 121 - public function confirm($amount1, $amount2) { 122 - $this->amount_1 = $amount1; 123 - $this->amount_2 = $amount2; 124 - $this->save(); 125 - return $this; 126 - } 127 - }
-79
externals/balanced-php/src/Balanced/Bootstrap.php
··· 1 - <?php 2 - 3 - namespace Balanced; 4 - 5 - /** 6 - * Bootstrapper for Balanced does autoloading and resource initialization. 7 - */ 8 - class Bootstrap 9 - { 10 - const DIR_SEPARATOR = DIRECTORY_SEPARATOR; 11 - const NAMESPACE_SEPARATOR = '\\'; 12 - 13 - public static $initialized = false; 14 - 15 - 16 - public static function init() 17 - { 18 - spl_autoload_register(array('\Balanced\Bootstrap', 'autoload')); 19 - self::initializeResources(); 20 - } 21 - 22 - public static function autoload($classname) 23 - { 24 - self::_autoload(dirname(dirname(__FILE__)), $classname); 25 - } 26 - 27 - public static function pharInit() 28 - { 29 - spl_autoload_register(array('\Balanced\Bootstrap', 'pharAutoload')); 30 - self::initializeResources(); 31 - } 32 - 33 - public static function pharAutoload($classname) 34 - { 35 - self::_autoload('phar://balanced.phar', $classname); 36 - } 37 - 38 - private static function _autoload($base, $classname) 39 - { 40 - if (!strncmp($classname, 'Balanced\Errors\\', strlen('Balanced\Errors\\'))) 41 - $classname = 'Balanced\Errors'; 42 - $parts = explode(self::NAMESPACE_SEPARATOR, $classname); 43 - $path = $base . self::DIR_SEPARATOR. implode(self::DIR_SEPARATOR, $parts) . '.php'; 44 - if (file_exists($path)) { 45 - require_once($path); 46 - } 47 - } 48 - 49 - /** 50 - * Initializes resources (i.e. registers them with Resource::_registry). Note 51 - * that if you add a Resource then you must initialize it here. 52 - * 53 - * @internal 54 - */ 55 - private static function initializeResources() 56 - { 57 - if (self::$initialized) 58 - return; 59 - 60 - \Balanced\Errors\Error::init(); 61 - 62 - \Balanced\Resource::init(); 63 - 64 - \Balanced\APIKey::init(); 65 - \Balanced\Marketplace::init(); 66 - \Balanced\Account::init(); 67 - \Balanced\Credit::init(); 68 - \Balanced\Debit::init(); 69 - \Balanced\Refund::init(); 70 - \Balanced\Card::init(); 71 - \Balanced\BankAccount::init(); 72 - \Balanced\Hold::init(); 73 - \Balanced\Merchant::init(); 74 - \Balanced\Callback::init(); 75 - \Balanced\Event::init(); 76 - 77 - self::$initialized = true; 78 - } 79 - }
-24
externals/balanced-php/src/Balanced/Callback.php
··· 1 - <?php 2 - 3 - namespace Balanced; 4 - 5 - use Balanced\Resource; 6 - use \RESTful\URISpec; 7 - 8 - /* 9 - * A Callback is a publicly accessible location that can receive POSTed JSON 10 - * data whenever an Event is generated. 11 - * 12 - * You create these using Balanced\Marketplace->createCallback. 13 - * 14 - */ 15 - class Callback extends Resource 16 - { 17 - protected static $_uri_spec = null; 18 - 19 - public static function init() 20 - { 21 - self::$_uri_spec = new URISpec('callbacks', 'id'); 22 - self::$_registry->add(get_called_class()); 23 - } 24 - }
-61
externals/balanced-php/src/Balanced/Card.php
··· 1 - <?php 2 - 3 - namespace Balanced; 4 - 5 - use Balanced\Resource; 6 - use \RESTful\URISpec; 7 - 8 - /** 9 - * Represents an account card. 10 - * 11 - * You can create these via Balanced\Marketplace::cards::create or 12 - * Balanced\Marketplace::createCard. Associate them with a buyer or merchant 13 - * one creation via Marketplace::createBuyer or 14 - * Balanced\Marketplace::createMerchant and with an existing buyer or merchant 15 - * use Balanced\Account::addCard. 16 - * 17 - * <code> 18 - * $marketplace = \Balanced\Marketplace::mine(); 19 - * 20 - * $card = $marketplace->cards->create(array( 21 - * 'name' => 'name', 22 - * 'account_number' => '11223344', 23 - * 'bank_code' => '1313123' 24 - * )); 25 - * 26 - * $account = $marketplace 27 - * ->accounts 28 - * ->query() 29 - * ->filter(Account::f->email_address->eq('buyer@example.com')) 30 - * ->one(); 31 - * $account->addCard($card->uri); 32 - * </code> 33 - */ 34 - class Card extends Resource 35 - { 36 - protected static $_uri_spec = null; 37 - 38 - public static function init() 39 - { 40 - self::$_uri_spec = new URISpec('cards', 'id', '/v1'); 41 - self::$_registry->add(get_called_class()); 42 - } 43 - 44 - public function debit( 45 - $amount, 46 - $appears_on_statement_as = null, 47 - $description = null, 48 - $meta = null, 49 - $source = null) 50 - { 51 - if ($this->account == null) { 52 - throw new \UnexpectedValueException('Card is not associated with an account.'); 53 - } 54 - return $this->account->debit( 55 - $amount, 56 - $appears_on_statement_as, 57 - $description, 58 - $meta, 59 - $this->uri); 60 - } 61 - }
-75
externals/balanced-php/src/Balanced/Credit.php
··· 1 - <?php 2 - 3 - namespace Balanced; 4 - 5 - use Balanced\Resource; 6 - use \RESTful\URISpec; 7 - 8 - /** 9 - * Represents an account credit transaction. 10 - * 11 - * You create these using Balanced\Account::credit. 12 - * 13 - * <code> 14 - * $marketplace = \Balanced\Marketplace::mine(); 15 - * 16 - * $account = $marketplace 17 - * ->accounts 18 - * ->query() 19 - * ->filter(Account::f->email_address->eq('merchant@example.com')) 20 - * ->one(); 21 - * 22 - * $credit = $account->credit( 23 - * 100, 24 - * 'how it ' 25 - * array( 26 - * 'my_id': '112233' 27 - * ) 28 - * ); 29 - * </code> 30 - */ 31 - class Credit extends Resource 32 - { 33 - protected static $_uri_spec = null; 34 - 35 - public static function init() 36 - { 37 - self::$_uri_spec = new URISpec('credits', 'id', '/v1'); 38 - self::$_registry->add(get_called_class()); 39 - } 40 - 41 - /** 42 - * Credit an unstored bank account. 43 - * 44 - * @param int amount Amount to credit in USD pennies. 45 - * @param string description Optional description of the credit. 46 - * @param mixed bank_account Associative array describing a bank account to credit. The bank account will *not* be stored. 47 - * 48 - * @return \Balanced\Credit 49 - * 50 - * <code> 51 - * $credit = \Balanced\Credit::bankAccount( 52 - * 123, 53 - * array( 54 - * 'account_number' => '12341234', 55 - * 'name' => 'Fit Finlay', 56 - * 'bank_code' => '325182797', 57 - * 'type' => 'checking', 58 - * ), 59 - * 'something descriptive'); 60 - * </code> 61 - */ 62 - public static function bankAccount( 63 - $amount, 64 - $bank_account, 65 - $description = null) 66 - { 67 - $credit = new Credit(array( 68 - 'amount' => $amount, 69 - 'bank_account' => $bank_account, 70 - 'description' => $description 71 - )); 72 - $credit->save(); 73 - return $credit; 74 - } 75 - }
-64
externals/balanced-php/src/Balanced/Debit.php
··· 1 - <?php 2 - 3 - namespace Balanced; 4 - 5 - use Balanced\Resource; 6 - use \RESTful\URISpec; 7 - 8 - /** 9 - * Represents an account debit transaction. 10 - * 11 - * You create these using Balanced\Account::debit. 12 - * 13 - * <code> 14 - * $marketplace = \Balanced\Marketplace::mine(); 15 - * 16 - * $account = $marketplace 17 - * ->accounts 18 - * ->query() 19 - * ->filter(Account::f->email_address->eq('buyer@example.com')) 20 - * ->one(); 21 - * 22 - * $debit = $account->debit( 23 - * 100, 24 - * 'how it appears on the statement', 25 - * 'a description', 26 - * array( 27 - * 'my_id': '443322' 28 - * ) 29 - * ); 30 - * </code> 31 - */ 32 - class Debit extends Resource 33 - { 34 - protected static $_uri_spec = null; 35 - 36 - public static function init() 37 - { 38 - self::$_uri_spec = new URISpec('debits', 'id'); 39 - self::$_registry->add(get_called_class()); 40 - } 41 - 42 - /** 43 - * Create a refund for this debit. You can create multiple refunds for a 44 - * debit but the total amount of the refunds must be less than the debit 45 - * amount. 46 - * 47 - * @param int amount Optional amount of the refund in USD pennies. If unspecified then the full debit amount is used. 48 - * @param string description Optional description of the refund. 49 - * @param array[string]string meta Optional metadata to associate with the refund. 50 - * 51 - * @return \Balanced\Refund 52 - */ 53 - public function refund( 54 - $amount = null, 55 - $description = null, 56 - $meta = null) 57 - { 58 - return $this->refunds->create(array( 59 - 'amount' => $amount, 60 - 'description' => $description, 61 - 'meta' => $meta 62 - )); 63 - } 64 - }
-135
externals/balanced-php/src/Balanced/Errors.php
··· 1 - <?php 2 - 3 - namespace Balanced\Errors; 4 - 5 - use RESTful\Exceptions\HTTPError; 6 - 7 - class Error extends HTTPError 8 - { 9 - public static $codes = array(); 10 - 11 - public static function init() 12 - { 13 - foreach (get_declared_classes() as $class) { 14 - $parent_class = get_parent_class($class); 15 - if ($parent_class != 'Balanced\Errors\Error') 16 - continue; 17 - foreach ($class::$codes as $type) 18 - self::$codes[$type] = $class; 19 - } 20 - } 21 - } 22 - 23 - class DuplicateAccountEmailAddress extends Error 24 - { 25 - public static $codes = array('duplicate-email-address'); 26 - } 27 - 28 - class InvalidAmount extends Error 29 - { 30 - public static $codes = array('invalid-amount'); 31 - } 32 - 33 - class InvalidRoutingNumber extends Error 34 - { 35 - public static $codes = array('invalid-routing-number'); 36 - } 37 - 38 - class InvalidBankAccountNumber extends Error 39 - { 40 - public static $codes = array('invalid-bank-account-number'); 41 - } 42 - 43 - class Declined extends Error 44 - { 45 - public static $codes = array('funding-destination-declined', 'authorization-failed'); 46 - } 47 - 48 - class CannotAssociateMerchantWithAccount extends Error 49 - { 50 - public static $codes = array('cannot-associate-merchant-with-account'); 51 - } 52 - 53 - class AccountIsAlreadyAMerchant extends Error 54 - { 55 - public static $codes = array('account-already-merchant'); 56 - } 57 - 58 - class NoFundingSource extends Error 59 - { 60 - public static $codes = array('no-funding-source'); 61 - } 62 - 63 - class NoFundingDestination extends Error 64 - { 65 - public static $codes = array('no-funding-destination'); 66 - } 67 - 68 - class CardAlreadyAssociated extends Error 69 - { 70 - public static $codes = array('card-already-funding-src'); 71 - } 72 - 73 - class CannotAssociateCard extends Error 74 - { 75 - public static $codes = array('cannot-associate-card'); 76 - } 77 - 78 - class BankAccountAlreadyAssociated extends Error 79 - { 80 - public static $codes = array('bank-account-already-associated'); 81 - } 82 - 83 - class AddressVerificationFailed extends Error 84 - { 85 - public static $codes = array('address-verification-failed'); 86 - } 87 - 88 - class HoldExpired extends Error 89 - { 90 - public static $codes = array('authorization-expired'); 91 - } 92 - 93 - class MarketplaceAlreadyCreated extends Error 94 - { 95 - public static $codes = array('marketplace-already-created'); 96 - } 97 - 98 - class IdentityVerificationFailed extends Error 99 - { 100 - public static $codes = array('identity-verification-error', 'business-principal-kyc', 'business-kyc', 'person-kyc'); 101 - } 102 - 103 - class InsufficientFunds extends Error 104 - { 105 - public static $codes = array('insufficient-funds'); 106 - } 107 - 108 - class CannotHold extends Error 109 - { 110 - public static $codes = array('funding-source-not-hold'); 111 - } 112 - 113 - class CannotCredit extends Error 114 - { 115 - public static $codes = array('funding-destination-not-creditable'); 116 - } 117 - 118 - class CannotDebit extends Error 119 - { 120 - public static $codes = array('funding-source-not-debitable'); 121 - } 122 - 123 - class CannotRefund extends Error 124 - { 125 - public static $codes = array('funding-source-not-refundable'); 126 - } 127 - 128 - class BankAccountVerificationFailure extends Error 129 - { 130 - public static $codes = array( 131 - 'bank-account-authentication-not-pending', 132 - 'bank-account-authentication-failed', 133 - 'bank-account-authentication-already-exists' 134 - ); 135 - }
-23
externals/balanced-php/src/Balanced/Event.php
··· 1 - <?php 2 - 3 - namespace Balanced; 4 - 5 - use Balanced\Resource; 6 - use \RESTful\URISpec; 7 - 8 - /* 9 - * An Event is a snapshot of another resource at a point in time when 10 - * something significant occurred. Events are created when resources are 11 - * created, updated, deleted or otherwise change state such as a Credit 12 - * being marked as failed. 13 - */ 14 - class Event extends Resource 15 - { 16 - protected static $_uri_spec = null; 17 - 18 - public static function init() 19 - { 20 - self::$_uri_spec = new URISpec('events', 'id', '/v1'); 21 - self::$_registry->add(get_called_class()); 22 - } 23 - }
-77
externals/balanced-php/src/Balanced/Hold.php
··· 1 - <?php 2 - 3 - namespace Balanced; 4 - 5 - use Balanced\Resource; 6 - use \RESTful\URISpec; 7 - 8 - /** 9 - * Represents pending debit of funds for an account. The funds for that debit 10 - * are held by the processor. You can later capture the hold, which results in 11 - * debit, or void it, which releases the held funds. 12 - * 13 - * Note that a hold can expire so you should always check 14 - * Balanced\Hold::expires_at. 15 - * 16 - * You create these using \Balanced\Account::hold. 17 - * 18 - * <code> 19 - * $marketplace = \Balanced\Marketplace::mine(); 20 - * 21 - * $account = $marketplace 22 - * ->accounts 23 - * ->query() 24 - * ->filter(Account::f->email_address->eq('buyer@example.com')) 25 - * ->one(); 26 - * 27 - * $hold = $account->hold( 28 - * 100, 29 - * 'a description', 30 - * null, 31 - * array( 32 - * 'my_id': '1293712837' 33 - * ) 34 - * ); 35 - * 36 - * $debit = $hold->capture(); 37 - * </code> 38 - */ 39 - class Hold extends Resource 40 - { 41 - protected static $_uri_spec = null; 42 - 43 - public static function init() 44 - { 45 - self::$_uri_spec = new URISpec('holds', 'id'); 46 - self::$_registry->add(get_called_class()); 47 - } 48 - 49 - /** 50 - ** Voids a pending hold. This releases the held funds. Once voided a hold 51 - * is not longer pending can cannot be re-captured or re-voided. 52 - * 53 - * @return \Balanced\Hold 54 - */ 55 - public function void() 56 - { 57 - $this->is_void = true; 58 - return $this->save(); 59 - } 60 - 61 - /** 62 - * Captures a pending hold. This results in a debit. Once captured a hold 63 - * is not longer pending can cannot be re-captured or re-voided. 64 - * 65 - * @param int amount Optional Portion of the pending hold to capture. If not specified the full amount associated with the hold is captured. 66 - * 67 - * @return \Balanced\Debit 68 - */ 69 - public function capture($amount = null) 70 - { 71 - $this->debit = $this->account->debits->create(array( 72 - 'hold_uri' => $this->uri, 73 - 'amount' => $amount, 74 - )); 75 - return $this->debit; 76 - } 77 - }
-325
externals/balanced-php/src/Balanced/Marketplace.php
··· 1 - <?php 2 - 3 - namespace Balanced; 4 - 5 - use Balanced\Resource; 6 - use Balanced\Errors; 7 - use Balanced\Account; 8 - use \RESTful\URISpec; 9 - 10 - /** 11 - * Represents a marketplace. 12 - * 13 - * To get started you create an api key and then create a marketplace: 14 - * 15 - * <code> 16 - * $api_key = new \Balanced\APIKey(); 17 - * $api_key->save(); 18 - * $secret = $api_key->secret // better save this somewhere 19 - * print $secret; 20 - * \Balanced\Settings::$api_key = $secret; 21 - * 22 - * $marketplace = new \Balanced\Marketplace(); 23 - * $marketplace->save(); 24 - * var_dump($marketplace); 25 - * </code> 26 - * 27 - * Each api key is uniquely associated with an api key so once you've created a 28 - * marketplace: 29 - * 30 - * <code> 31 - * \Balanced\Settings::$api_key = $secret; 32 - * $marketplace = \Balanced\Marketplace::mine(); // this is the marketplace associated with $secret 33 - * </code> 34 - */ 35 - class Marketplace extends Resource 36 - { 37 - protected static $_uri_spec = null; 38 - 39 - public static function init() 40 - { 41 - self::$_uri_spec = new URISpec('marketplaces', 'id', '/v1'); 42 - self::$_registry->add(get_called_class()); 43 - } 44 - 45 - /** 46 - * Get the marketplace associated with the currently configured 47 - * \Balanced\Settings::$api_key. 48 - * 49 - * @throws \RESTful\Exceptions\NoResultFound 50 - * @return \Balanced\Marketplace 51 - */ 52 - public static function mine() 53 - { 54 - return self::query()->one(); 55 - } 56 - 57 - /** 58 - * Create a card. These can later be associated with an account using 59 - * \Balanced\Account->addCard or \Balanced\Marketplace->createBuyer. 60 - * 61 - * @param string street_address Street address. Use null if there is no address for the card. 62 - * @param string city City. Use null if there is no address for the card. 63 - * @param string postal_code Postal code. Use null if there is no address for the card. 64 - * @param string name Name as it appears on the card. 65 - * @param string card_number Card number. 66 - * @param string security_code Card security code. Use null if it is no available. 67 - * @param int expiration_month Expiration month. 68 - * @param int expiration_year Expiration year. 69 - * 70 - * @return \Balanced\Card 71 - */ 72 - public function createCard( 73 - $street_address, 74 - $city, 75 - $region, 76 - $postal_code, 77 - $name, 78 - $card_number, 79 - $security_code, 80 - $expiration_month, 81 - $expiration_year) 82 - { 83 - if ($region != null && strlen($region) > 0) { 84 - trigger_error("The region parameter will be deprecated in the next minor version of balanced-php", E_USER_NOTICE); 85 - } 86 - 87 - return $this->cards->create(array( 88 - 'street_address' => $street_address, 89 - 'city' => $city, 90 - 'region' => $region, 91 - 'postal_code' => $postal_code, 92 - 'name' => $name, 93 - 'card_number' => $card_number, 94 - 'security_code' => $security_code, 95 - 'expiration_month' => $expiration_month, 96 - 'expiration_year' => $expiration_year 97 - )); 98 - } 99 - 100 - /** 101 - * Create a bank account. These can later be associated with an account 102 - * using \Balanced\Account->addBankAccount. 103 - * 104 - * @param string name Name of the account holder. 105 - * @param string account_number Account number. 106 - * @param string routing_number Bank code or routing number. 107 - * @param string type checking or savings 108 - * @param array meta Single level mapping from string keys to string values. 109 - * 110 - * @return \Balanced\BankAccount 111 - */ 112 - public function createBankAccount( 113 - $name, 114 - $account_number, 115 - $routing_number, 116 - $type, 117 - $meta = null 118 - ) 119 - { 120 - return $this->bank_accounts->create(array( 121 - 'name' => $name, 122 - 'account_number' => $account_number, 123 - 'routing_number' => $routing_number, 124 - 'type' => $type, 125 - 'meta' => $meta 126 - )); 127 - } 128 - 129 - /** 130 - * Create a role-less account. You can later turn this into a buyer by 131 - * adding a funding source (e.g a card) or a merchant using 132 - * \Balanced\Account->promoteToMerchant. 133 - * 134 - * @param string email_address Optional email address. There can only be one account with this email address. 135 - * @param array[string]string meta Optional metadata to associate with the account. 136 - * 137 - * @return \Balanced\Account 138 - */ 139 - public function createAccount($email_address = null, $meta = null) 140 - { 141 - return $this->accounts->create(array( 142 - 'email_address' => $email_address, 143 - 'meta' => $meta, 144 - )); 145 - } 146 - 147 - /** 148 - * Find or create a role-less account by email address. You can later turn 149 - * this into a buyer by adding a funding source (e.g a card) or a merchant 150 - * using \Balanced\Account->promoteToMerchant. 151 - * 152 - * @param string email_address Email address. There can only be one account with this email address. 153 - * 154 - * @return \Balanced\Account 155 - */ 156 - function findOrCreateAccountByEmailAddress($email_address) 157 - { 158 - $marketplace = Marketplace::mine(); 159 - try { 160 - $account = $this->accounts->create(array( 161 - 'email_address' => $email_address 162 - )); 163 - } 164 - catch (Errors\DuplicateAccountEmailAddress $e) { 165 - $account = Account::get($e->extras->account_uri); 166 - } 167 - return $account; 168 - } 169 - 170 - /** 171 - * Create a buyer account. 172 - * 173 - * @param string email_address Optional email address. There can only be one account with this email address. 174 - * @param string card_uri URI referencing a card to associate with the account. 175 - * @param array[string]string meta Optional metadata to associate with the account. 176 - * @param string name Optional name of the account. 177 - * 178 - * @return \Balanced\Account 179 - */ 180 - public function createBuyer($email_address, $card_uri, $meta = null, $name = null) 181 - { 182 - return $this->accounts->create(array( 183 - 'email_address' => $email_address, 184 - 'card_uri' => $card_uri, 185 - 'meta' => $meta, 186 - 'name' => $name 187 - )); 188 - } 189 - 190 - /** 191 - * Create a merchant account. 192 - * 193 - * Unlike buyers the identity of a merchant must be established before 194 - * the account can function as a merchant (i.e. be credited). A merchant 195 - * can be either a person or a business. Either way that information is 196 - * represented as an associative array and passed as the merchant parameter 197 - * when creating the merchant account. 198 - * 199 - * For a person the array looks like this: 200 - * 201 - * <code> 202 - * array( 203 - * 'type' => 'person', 204 - * 'name' => 'William James', 205 - * 'tax_id' => '393-48-3992', 206 - * 'street_address' => '167 West 74th Street', 207 - * 'postal_code' => '10023', 208 - * 'dob' => '1842-01-01', 209 - * 'phone_number' => '+16505551234', 210 - * 'country_code' => 'USA' 211 - * ) 212 - * </code> 213 - * 214 - * For a business the array looks like this: 215 - * 216 - * <code> 217 - * array( 218 - * 'type' => 'business', 219 - * 'name' => 'Levain Bakery', 220 - * 'tax_id' => '253912384', 221 - * 'street_address' => '167 West 74th Street', 222 - * 'postal_code' => '10023', 223 - * 'phone_number' => '+16505551234', 224 - * 'country_code' => 'USA', 225 - * 'person' => array( 226 - * 'name' => 'William James', 227 - * 'tax_id' => '393483992', 228 - * 'street_address' => '167 West 74th Street', 229 - * 'postal_code' => '10023', 230 - * 'dob' => '1842-01-01', 231 - * 'phone_number' => '+16505551234', 232 - * 'country_code' => 'USA', 233 - * ) 234 - * ) 235 - * </code> 236 - * 237 - * In some cases the identity of the merchant, person or business, cannot 238 - * be verified in which case a \Balanced\Exceptions\HTTPError is thrown: 239 - * 240 - * <code> 241 - * $identity = array( 242 - * 'type' => 'business', 243 - * 'name' => 'Levain Bakery', 244 - * 'tax_id' => '253912384', 245 - * 'street_address' => '167 West 74th Street', 246 - * 'postal_code' => '10023', 247 - * 'phone_number' => '+16505551234', 248 - * 'country_code' => 'USA', 249 - * 'person' => array( 250 - * 'name' => 'William James', 251 - * 'tax_id' => '393483992', 252 - * 'street_address' => '167 West 74th Street', 253 - * 'postal_code' => '10023', 254 - * 'dob' => '1842-01-01', 255 - * 'phone_number' => '+16505551234', 256 - * 'country_code' => 'USA', 257 - * ), 258 - * ); 259 - * 260 - * try { 261 - * $merchant = \Balanced\Marketplace::mine()->createMerchant( 262 - * 'merchant@example.com', 263 - * $identity, 264 - * ); 265 - * catch (\Balanced\Exceptions\HTTPError $e) { 266 - * if ($e->code != 300) { 267 - * throw $e; 268 - * } 269 - * print e->response->header['Location'] // this is where merchant must signup 270 - * } 271 - * </code> 272 - * 273 - * Once the merchant has completed signup you can use the resulting URI to 274 - * create an account for them on your marketplace: 275 - * 276 - * <code> 277 - * $merchant = self::$marketplace->createMerchant( 278 - * 'merchant@example.com', 279 - * null, 280 - * null, 281 - * $merchant_uri 282 - * ); 283 - * </coe> 284 - * 285 - * @param string email_address Optional email address. There can only be one account with this email address. 286 - * @param array[string]mixed merchant Associative array describing the merchants identity. 287 - * @param string $bank_account_uri Optional URI referencing a bank account to associate with this account. 288 - * @param string $merchant_uri URI of a merchant created via the redirection sign-up flow. 289 - * @param string $name Optional name of the merchant. 290 - * @param array[string]string meta Optional metadata to associate with the account. 291 - * 292 - * @return \Balanced\Account 293 - */ 294 - public function createMerchant( 295 - $email_address = null, 296 - $merchant = null, 297 - $bank_account_uri = null, 298 - $merchant_uri = null, 299 - $name = null, 300 - $meta = null) 301 - { 302 - return $this->accounts->create(array( 303 - 'email_address' => $email_address, 304 - 'merchant' => $merchant, 305 - 'merchant_uri' => $merchant_uri, 306 - 'bank_account_uri' => $bank_account_uri, 307 - 'name' => $name, 308 - 'meta' => $meta, 309 - )); 310 - } 311 - 312 - /* 313 - * Create a callback. 314 - * 315 - * @param string url URL of callback. 316 - */ 317 - public function createCallback( 318 - $url 319 - ) 320 - { 321 - return $this->callbacks->create(array( 322 - 'url' => $url 323 - )); 324 - } 325 - }
-51
externals/balanced-php/src/Balanced/Merchant.php
··· 1 - <?php 2 - 3 - namespace Balanced; 4 - 5 - use Balanced\Resource; 6 - use \RESTful\URISpec; 7 - 8 - /** 9 - * Represents a merchant identity. 10 - * 11 - * These are optionally created and associated with an account via 12 - * \Balanced\Marketplace::createMerchant which establishes a merchant account 13 - * on a marketplace. 14 - * 15 - * In some cases a merchant may need to be redirected to create a identity (e.g. the 16 - * information provided cannot be verified, more information is needed, etc). That 17 - * redirected signup results in a merchant_uri which is then associated with an 18 - * account on the marketplace via \Balanced\Marketplace::createMerchant. 19 - * 20 - * @see \Balanced\Marketplace 21 - */ 22 - class Merchant extends Resource 23 - { 24 - protected static $_uri_spec = null; 25 - 26 - public static function init() 27 - { 28 - self::$_uri_spec = new URISpec('merchants', 'id', '/v1'); 29 - self::$_registry->add(get_called_class()); 30 - } 31 - 32 - /** 33 - * Return the merchant identity associated with the current 34 - * Balanced\Settings::$api_key. If you are not authenticated (i.e. 35 - * ) then Balanced\Exceptions\NoResult 36 - * will be thrown. 37 - * 38 - * <code> 39 - * $merchant = \Balanced\Merchant::me(); 40 - * $owner_account = \Balanced\Marketplace::mine()->owner_account; 41 - * assert($merchant->id == $owner_account->merchant->id); 42 - * </code> 43 - * 44 - * @throws \RESTful\Exceptions\NoResultFound 45 - * @return \Balanced\Merchant 46 - */ 47 - public static function me() 48 - { 49 - return self::query()->one(); 50 - } 51 - }
-50
externals/balanced-php/src/Balanced/Refund.php
··· 1 - <?php 2 - 3 - namespace Balanced; 4 - 5 - use Balanced\Resource; 6 - use \RESTful\URISpec; 7 - 8 - /** 9 - * Represents a refund of an account debit transaction. 10 - * 11 - * You create these via Balanced\Debit::refund. 12 - * 13 - * <code> 14 - * $marketplace = \Balanced\Marketplace::mine(); 15 - * 16 - * $account = $marketplace 17 - * ->accounts 18 - * ->query() 19 - * ->filter(Account::f->email_address->eq('buyer@example.com')) 20 - * ->one(); 21 - * 22 - * $debit = $account->debit( 23 - * 100, 24 - * 'how it appears on the statement', 25 - * 'a description', 26 - * array( 27 - * 'my_id': '443322' 28 - * ) 29 - * ); 30 - * 31 - * $debit->refund( 32 - * 99, 33 - * 'some description', 34 - * array( 35 - * 'my_id': '123123' 36 - * ) 37 - * ); 38 - * </code> 39 - */ 40 - class Refund extends Resource 41 - { 42 - protected static $_uri_spec = null; 43 - 44 - public static function init() 45 - { 46 - self::$_uri_spec = new URISpec('refunds', 'id'); 47 - self::$_registry->add(get_called_class()); 48 - } 49 - } 50 -
-48
externals/balanced-php/src/Balanced/Resource.php
··· 1 - <?php 2 - 3 - namespace Balanced; 4 - 5 - use Balanced\Errors\Error; 6 - use RESTful\Exceptions\HTTPError; 7 - 8 - class Resource extends \RESTful\Resource 9 - { 10 - public static $fields, $f; 11 - 12 - protected static $_client, $_registry, $_uri_spec; 13 - 14 - public static function init() 15 - { 16 - self::$_client = new \RESTful\Client('\Balanced\Settings', null, __NAMESPACE__ .'\Resource::convertError'); 17 - self::$_registry = new \RESTful\Registry(); 18 - self::$f = self::$fields = new \RESTful\Fields(); 19 - } 20 - 21 - public static function convertError($response) 22 - { 23 - if (property_exists($response->body, 'category_code') && 24 - array_key_exists($response->body->category_code, Error::$codes)) 25 - $error = new Error::$codes[$response->body->category_code]($response); 26 - else 27 - $error = new HTTPError($response); 28 - return $error; 29 - } 30 - 31 - public static function getClient() 32 - { 33 - $class = get_called_class(); 34 - return $class::$_client; 35 - } 36 - 37 - public static function getRegistry() 38 - { 39 - $class = get_called_class(); 40 - return $class::$_registry; 41 - } 42 - 43 - public static function getURISpec() 44 - { 45 - $class = get_called_class(); 46 - return $class::$_uri_spec; 47 - } 48 - }
-43
externals/balanced-php/src/Balanced/Settings.php
··· 1 - <?php 2 - 3 - namespace Balanced; 4 - 5 - /** 6 - * Configurable settings. 7 - * 8 - * You can either set these settings individually: 9 - * 10 - * <code> 11 - * \Balanced\Settngs::api_key = 'my-api-key-secret'; 12 - * </code> 13 - * 14 - * or all at once: 15 - * 16 - * <code> 17 - * \Balanced\Settngs::configure( 18 - * 'https://api.balancedpayments.com', 19 - * 'my-api-key-secret' 20 - * ); 21 - * </code> 22 - */ 23 - class Settings 24 - { 25 - const VERSION = '0.7.1'; 26 - 27 - public static $url_root = 'https://api.balancedpayments.com', 28 - $api_key = null, 29 - $agent = 'balanced-php', 30 - $version = Settings::VERSION; 31 - 32 - /** 33 - * Configure all settings. 34 - * 35 - * @param string url_root The root (schema://hostname[:port]) to use when constructing api URLs. 36 - * @param string api_key The api key secret to use for authenticating when talking to the api. If null then api usage is limited to uauthenticated endpoints. 37 - */ 38 - public static function configure($url_root, $api_key) 39 - { 40 - self::$url_root= $url_root; 41 - self::$api_key = $api_key; 42 - } 43 - }
-614
externals/balanced-php/tests/Balanced/ResourceTest.php
··· 1 - <?php 2 - 3 - namespace Balanced\Test; 4 - 5 - \Balanced\Bootstrap::init(); 6 - \RESTful\Bootstrap::init(); 7 - \Httpful\Bootstrap::init(); 8 - 9 - use Balanced\Resource; 10 - use Balanced\Settings; 11 - use Balanced\APIKey; 12 - use Balanced\Marketplace; 13 - use Balanced\Credit; 14 - use Balanced\Debit; 15 - use Balanced\Refund; 16 - use Balanced\Account; 17 - use Balanced\Merchant; 18 - use Balanced\BankAccount; 19 - use Balanced\Card; 20 - use Balanced\Hold; 21 - 22 - use \RESTful\Collection; 23 - 24 - 25 - class APIKeyTest extends \PHPUnit_Framework_TestCase 26 - { 27 - 28 - function testRegistry() 29 - { 30 - $this->expectOutputString(''); 31 - $result = Resource::getRegistry()->match('/v1/api_keys'); 32 - return; 33 - $expected = array( 34 - 'collection' => true, 35 - 'class' => 'Balanced\APIKey', 36 - ); 37 - $this->assertEquals($expected, $result); 38 - $result = Resource::getRegistry()->match('/v1/api_keys/1234'); 39 - $expected = array( 40 - 'collection' => false, 41 - 'class' => 'Balanced\APIKey', 42 - 'ids' => array('id' => '1234'), 43 - ); 44 - $this->assertEquals($expected, $result); 45 - } 46 - } 47 - 48 - class MarketplaceTest extends \PHPUnit_Framework_TestCase 49 - { 50 - function testRegistry() 51 - { 52 - $result = Resource::getRegistry()->match('/v1/marketplaces'); 53 - $expected = array( 54 - 'collection' => true, 55 - 'class' => 'Balanced\Marketplace', 56 - ); 57 - $this->assertEquals($expected, $result); 58 - $result = Resource::getRegistry()->match('/v1/marketplaces/1122'); 59 - $expected = array( 60 - 'collection' => false, 61 - 'class' => 'Balanced\Marketplace', 62 - 'ids' => array('id' => '1122'), 63 - ); 64 - $this->assertEquals($expected, $result); 65 - } 66 - 67 - function testCreateCard() 68 - { 69 - $collection = $this->getMock( 70 - '\RESTful\Collection', 71 - array('create'), 72 - array('\Balanced\Card', 'some/uri', null) 73 - ); 74 - 75 - $collection->expects($this->once()) 76 - ->method('create') 77 - ->with(array( 78 - 'street_address' => '123 Fake Street', 79 - 'city' => 'Jollywood', 80 - 'region' => '', 81 - 'postal_code' => '90210', 82 - 'name' => 'khalkhalash', 83 - 'card_number' => '4112344112344113', 84 - 'security_code' => '123', 85 - 'expiration_month' => 12, 86 - 'expiration_year' => 2013, 87 - )); 88 - 89 - $marketplace = new Marketplace(array('cards' => $collection)); 90 - $marketplace->createCard( 91 - '123 Fake Street', 92 - 'Jollywood', 93 - '', 94 - '90210', 95 - 'khalkhalash', 96 - '4112344112344113', 97 - '123', 98 - 12, 99 - 2013); 100 - } 101 - 102 - function testCreateBankAccount() 103 - { 104 - $collection = $this->getMock( 105 - '\RESTful\Collection', 106 - array('create'), 107 - array('\Balanced\BankAccount', 'some/uri', null) 108 - ); 109 - 110 - $collection->expects($this->once()) 111 - ->method('create') 112 - ->with(array( 113 - 'name' => 'Homer Jay', 114 - 'account_number' => '112233a', 115 - 'routing_number' => '121042882', 116 - 'type' => 'savings', 117 - 'meta' => null 118 - )); 119 - 120 - $marketplace = new Marketplace(array('bank_accounts' => $collection)); 121 - $marketplace->createBankAccount( 122 - 'Homer Jay', 123 - '112233a', 124 - '121042882', 125 - 'savings'); 126 - } 127 - 128 - function testCreateAccount() 129 - { 130 - $collection = $this->getMock( 131 - '\RESTful\Collection', 132 - array('create'), 133 - array('\Balanced\Account', 'some/uri', null) 134 - ); 135 - 136 - $collection->expects($this->once()) 137 - ->method('create') 138 - ->with(array( 139 - 'email_address' => 'role-less@example.com', 140 - 'meta' => array('test#' => 'test_d') 141 - )); 142 - 143 - $marketplace = new Marketplace(array('accounts' => $collection)); 144 - $marketplace->createAccount( 145 - 'role-less@example.com', 146 - array('test#' => 'test_d') 147 - ); 148 - } 149 - 150 - function testCreateBuyer() 151 - { 152 - $collection = $this->getMock( 153 - '\RESTful\Collection', 154 - array('create'), 155 - array('\Balanced\Account', 'some/uri', null) 156 - ); 157 - 158 - $collection->expects($this->once()) 159 - ->method('create') 160 - ->with(array( 161 - 'email_address' => 'buyer@example.com', 162 - 'card_uri' => '/some/card/uri', 163 - 'meta' => array('test#' => 'test_d'), 164 - 'name' => 'Buy Er' 165 - )); 166 - 167 - $marketplace = new Marketplace(array('accounts' => $collection)); 168 - $marketplace->createBuyer( 169 - 'buyer@example.com', 170 - '/some/card/uri', 171 - array('test#' => 'test_d'), 172 - 'Buy Er' 173 - ); 174 - } 175 - } 176 - 177 - class AccountTest extends \PHPUnit_Framework_TestCase 178 - { 179 - function testRegistry() 180 - { 181 - $result = Resource::getRegistry()->match('/v1/accounts'); 182 - $expected = array( 183 - 'collection' => true, 184 - 'class' => 'Balanced\Account', 185 - ); 186 - $this->assertEquals($expected, $result); 187 - $result = Resource::getRegistry()->match('/v1/accounts/0099'); 188 - $expected = array( 189 - 'collection' => false, 190 - 'class' => 'Balanced\Account', 191 - 'ids' => array('id' => '0099'), 192 - ); 193 - $this->assertEquals($expected, $result); 194 - } 195 - 196 - function testCredit() 197 - { 198 - $collection = $this->getMock( 199 - '\RESTful\Collection', 200 - array('create'), 201 - array('\Balanced\Credit', 'some/uri', null) 202 - ); 203 - 204 - $collection 205 - ->expects($this->once()) 206 - ->method('create') 207 - ->with(array( 208 - 'amount' => 101, 209 - 'description' => 'something sweet', 210 - 'meta' => null, 211 - 'destination_uri' => null, 212 - 'appears_on_statement_as' => null 213 - )); 214 - 215 - $account = new Account(array('credits' => $collection)); 216 - $account->credit(101, 'something sweet'); 217 - } 218 - 219 - function testDebit() 220 - { 221 - $collection = $this->getMock( 222 - '\RESTful\Collection', 223 - array('create'), 224 - array('\Balanced\Debit', 'some/uri', null) 225 - ); 226 - 227 - $collection 228 - ->expects($this->once()) 229 - ->method('create') 230 - ->with(array( 231 - 'amount' => 9911, 232 - 'description' => 'something tangy', 233 - 'appears_on_statement_as' => 'BAL*TANG', 234 - 'meta' => null, 235 - 'source_uri' => null, 236 - 'on_behalf_of_uri' => null, 237 - )); 238 - 239 - $account = new Account(array('debits' => $collection)); 240 - $account->debit(9911, 'BAL*TANG', 'something tangy'); 241 - } 242 - 243 - function testHold() 244 - { 245 - $collection = $this->getMock( 246 - '\RESTful\Collection', 247 - array('create'), 248 - array('\Balanced\Hold', 'some/uri', null) 249 - ); 250 - 251 - $collection 252 - ->expects($this->once()) 253 - ->method('create') 254 - ->with(array( 255 - 'amount' => 1243, 256 - 'description' => 'something crispy', 257 - 'source_uri' => '/some/card/uri', 258 - 'meta' => array('test#' => 'test_d') 259 - )); 260 - 261 - $account = new Account(array('holds' => $collection)); 262 - $account->hold( 263 - 1243, 264 - 'something crispy', 265 - '/some/card/uri', 266 - array('test#' => 'test_d') 267 - ); 268 - } 269 - 270 - function testAddCard() 271 - { 272 - $account = $this->getMock( 273 - '\Balanced\Account', 274 - array('save') 275 - ); 276 - 277 - $account 278 - ->expects($this->once()) 279 - ->method('save') 280 - ->with(); 281 - 282 - $account->addCard('/my/new/card/121212'); 283 - $this->assertEquals($account->card_uri, '/my/new/card/121212'); 284 - } 285 - 286 - function testAddBankAccount() 287 - { 288 - $account = $this->getMock( 289 - '\Balanced\Account', 290 - array('save') 291 - ); 292 - 293 - $account 294 - ->expects($this->once()) 295 - ->method('save') 296 - ->with(); 297 - 298 - $account->addBankAccount('/my/new/bank_account/121212'); 299 - $this->assertEquals($account->bank_account_uri, '/my/new/bank_account/121212'); 300 - } 301 - 302 - function testPromotToMerchant() 303 - { 304 - $account = $this->getMock( 305 - '\Balanced\Account', 306 - array('save') 307 - ); 308 - 309 - $account 310 - ->expects($this->once()) 311 - ->method('save') 312 - ->with(); 313 - 314 - $merchant = array( 315 - 'type' => 'person', 316 - 'name' => 'William James', 317 - 'tax_id' => '393-48-3992', 318 - 'street_address' => '167 West 74th Street', 319 - 'postal_code' => '10023', 320 - 'dob' => '1842-01-01', 321 - 'phone_number' => '+16505551234', 322 - 'country_code' => 'USA' 323 - ); 324 - 325 - $account->promoteToMerchant($merchant); 326 - $this->assertEquals($account->merchant, $merchant); 327 - } 328 - } 329 - 330 - class HoldTest extends \PHPUnit_Framework_TestCase 331 - { 332 - function testRegistry() 333 - { 334 - $result = Resource::getRegistry()->match('/v1/holds'); 335 - $expected = array( 336 - 'collection' => true, 337 - 'class' => 'Balanced\Hold', 338 - ); 339 - $this->assertEquals($expected, $result); 340 - $result = Resource::getRegistry()->match('/v1/holds/112233'); 341 - $expected = array( 342 - 'collection' => false, 343 - 'class' => 'Balanced\Hold', 344 - 'ids' => array('id' => '112233'), 345 - ); 346 - $this->assertEquals($expected, $result); 347 - } 348 - 349 - function testVoid() 350 - { 351 - $hold = $this->getMock( 352 - '\Balanced\Hold', 353 - array('save') 354 - ); 355 - 356 - $hold 357 - ->expects($this->once()) 358 - ->method('save') 359 - ->with(); 360 - 361 - $hold->void(); 362 - $this->assertTrue($hold->is_void); 363 - } 364 - 365 - function testCapture() 366 - { 367 - $collection = $this->getMock( 368 - '\RESTful\Collection', 369 - array('create'), 370 - array('\Balanced\Debit', 'some/uri', null) 371 - ); 372 - 373 - $collection 374 - ->expects($this->once()) 375 - ->method('create') 376 - ->with(array( 377 - 'hold_uri' => 'some/hold/uri', 378 - 'amount' => 2211, 379 - )); 380 - 381 - $account = new Account(array('debits' => $collection)); 382 - 383 - $hold = new Hold(array('uri' => 'some/hold/uri', 'account' => $account)); 384 - 385 - $hold->capture(2211); 386 - } 387 - } 388 - 389 - class CreditTest extends \PHPUnit_Framework_TestCase 390 - { 391 - function testRegistry() 392 - { 393 - $result = Resource::getRegistry()->match('/v1/credits'); 394 - $expected = array( 395 - 'collection' => true, 396 - 'class' => 'Balanced\Credit', 397 - ); 398 - $this->assertEquals($expected, $result); 399 - $result = Resource::getRegistry()->match('/v1/credits/9988'); 400 - $expected = array( 401 - 'collection' => false, 402 - 'class' => 'Balanced\Credit', 403 - 'ids' => array('id' => '9988'), 404 - ); 405 - $this->assertEquals($expected, $result); 406 - } 407 - } 408 - 409 - class DebitTest extends \PHPUnit_Framework_TestCase 410 - { 411 - function testRegistry() 412 - { 413 - $result = Resource::getRegistry()->match('/v1/debits'); 414 - $expected = array( 415 - 'collection' => true, 416 - 'class' => 'Balanced\Debit', 417 - ); 418 - $this->assertEquals($expected, $result); 419 - $result = Resource::getRegistry()->match('/v1/debits/4545'); 420 - $expected = array( 421 - 'collection' => false, 422 - 'class' => 'Balanced\Debit', 423 - 'ids' => array('id' => '4545'), 424 - ); 425 - $this->assertEquals($expected, $result); 426 - } 427 - 428 - function testRefund() 429 - { 430 - $collection = $this->getMock( 431 - '\RESTful\Collection', 432 - array('create'), 433 - array('\Balanced\Refund', 'some/uri', null) 434 - ); 435 - 436 - $collection 437 - ->expects($this->once()) 438 - ->method('create') 439 - ->with(array( 440 - 'amount' => 5645, 441 - 'description' => null, 442 - 'meta' => array('test#' => 'test_d') 443 - )); 444 - 445 - $debit = new Debit(array('refunds' => $collection)); 446 - 447 - $debit->refund(5645, null, array('test#' => 'test_d')); 448 - } 449 - } 450 - 451 - class RefundTest extends \PHPUnit_Framework_TestCase 452 - { 453 - function testRegistry() 454 - { 455 - $result = Resource::getRegistry()->match('/v1/refunds'); 456 - $expected = array( 457 - 'collection' => true, 458 - 'class' => 'Balanced\Refund', 459 - ); 460 - $this->assertEquals($expected, $result); 461 - $result = Resource::getRegistry()->match('/v1/refunds/1287'); 462 - $expected = array( 463 - 'collection' => false, 464 - 'class' => 'Balanced\Refund', 465 - 'ids' => array('id' => '1287'), 466 - ); 467 - $this->assertEquals($expected, $result); 468 - } 469 - } 470 - 471 - class BankAccountTest extends \PHPUnit_Framework_TestCase 472 - { 473 - function testRegistry() 474 - { 475 - $result = Resource::getRegistry()->match('/v1/bank_accounts'); 476 - $expected = array( 477 - 'collection' => true, 478 - 'class' => 'Balanced\BankAccount', 479 - ); 480 - $this->assertEquals($expected, $result); 481 - $result = Resource::getRegistry()->match('/v1/bank_accounts/887766'); 482 - $expected = array( 483 - 'collection' => false, 484 - 'class' => 'Balanced\BankAccount', 485 - 'ids' => array('id' => '887766'), 486 - ); 487 - $this->assertEquals($expected, $result); 488 - } 489 - 490 - function testCreditAccount() 491 - { 492 - $collection = $this->getMock( 493 - '\RESTful\Collection', 494 - array('create'), 495 - array('\Balanced\Credit', 'some/uri', null) 496 - ); 497 - 498 - $collection 499 - ->expects($this->once()) 500 - ->method('create') 501 - ->with(array( 502 - 'amount' => 101, 503 - 'description' => 'something super sweet', 504 - 'meta' => null, 505 - 'destination_uri' => '/some/other/uri', 506 - 'appears_on_statement_as' => null 507 - )); 508 - 509 - $account = new Account(array('credits' => $collection)); 510 - $bank_account = new BankAccount(array('uri' => '/some/other/uri', 'account' => $account)); 511 - 512 - $bank_account->credit(101, 'something super sweet'); 513 - } 514 - 515 - function testCreditAccountless() 516 - { 517 - $collection = $this->getMock( 518 - '\RESTful\Collection', 519 - array('create'), 520 - array('\Balanced\Credit', 'some/uri', null) 521 - ); 522 - 523 - $collection 524 - ->expects($this->once()) 525 - ->method('create') 526 - ->with(array( 527 - 'amount' => 101, 528 - 'description' => 'something super sweet', 529 - )); 530 - $bank_account = new BankAccount(array( 531 - 'uri' => '/some/other/uri', 532 - 'account' => null, 533 - 'credits' => $collection, 534 - )); 535 - 536 - $bank_account->credit(101, 'something super sweet'); 537 - } 538 - } 539 - 540 - class CardTest extends \PHPUnit_Framework_TestCase 541 - { 542 - function testRegistry() 543 - { 544 - $result = Resource::getRegistry()->match('/v1/cards'); 545 - $expected = array( 546 - 'collection' => true, 547 - 'class' => 'Balanced\Card', 548 - ); 549 - $this->assertEquals($expected, $result); 550 - $result = Resource::getRegistry()->match('/v1/cards/136asd6713'); 551 - $expected = array( 552 - 'collection' => false, 553 - 'class' => 'Balanced\Card', 554 - 'ids' => array('id' => '136asd6713'), 555 - ); 556 - $this->assertEquals($expected, $result); 557 - } 558 - 559 - function testDebit() 560 - { 561 - $collection = $this->getMock( 562 - '\RESTful\Collection', 563 - array('create'), 564 - array('\Balanced\Debit', 'some/uri', null) 565 - ); 566 - 567 - $account = new Account(array('debits' => $collection)); 568 - $card = new Card(array('uri' => '/some/uri', 'account' => $account )); 569 - 570 - $collection 571 - ->expects($this->once()) 572 - ->method('create') 573 - ->with(array( 574 - 'amount' => 9911, 575 - 'description' => 'something tangy', 576 - 'appears_on_statement_as' => 'BAL*TANG', 577 - 'meta' => null, 578 - 'source_uri' => '/some/uri', 579 - 'on_behalf_of_uri' => null, 580 - )); 581 - 582 - $card->debit(9911, 'BAL*TANG', 'something tangy'); 583 - } 584 - 585 - /** 586 - * @expectedException \UnexpectedValueException 587 - */ 588 - function testNotAssociatedDebit() 589 - { 590 - $card = new Card(array('uri' => '/some/uri', 'account' => null )); 591 - $card->debit(9911, 'BAL*TANG', 'something tangy'); 592 - } 593 - } 594 - 595 - 596 - class MerchantTest extends \PHPUnit_Framework_TestCase 597 - { 598 - function testRegistry() 599 - { 600 - $result = Resource::getRegistry()->match('/v1/merchants'); 601 - $expected = array( 602 - 'collection' => true, 603 - 'class' => 'Balanced\Merchant', 604 - ); 605 - $this->assertEquals($expected, $result); 606 - $result = Resource::getRegistry()->match('/v1/merchants/136asd6713'); 607 - $expected = array( 608 - 'collection' => false, 609 - 'class' => 'Balanced\Merchant', 610 - 'ids' => array('id' => '136asd6713'), 611 - ); 612 - $this->assertEquals($expected, $result); 613 - } 614 - }
-798
externals/balanced-php/tests/Balanced/SuiteTest.php
··· 1 - <?php 2 - 3 - namespace Balanced\Test; 4 - 5 - \Balanced\Bootstrap::init(); 6 - \RESTful\Bootstrap::init(); 7 - \Httpful\Bootstrap::init(); 8 - 9 - use Balanced\Settings; 10 - use Balanced\APIKey; 11 - use Balanced\Marketplace; 12 - use Balanced\Credit; 13 - use Balanced\Debit; 14 - use Balanced\Refund; 15 - use Balanced\Account; 16 - use Balanced\Merchant; 17 - use Balanced\BankAccount; 18 - use Balanced\Card; 19 - 20 - 21 - /** 22 - * Suite test cases. These talk to an API server and so make network calls. 23 - * 24 - * Environment variables can be used to control client settings: 25 - * 26 - * <ul> 27 - * <li>$BALANCED_URL_ROOT If set applies to \Balanced\Settings::$url_root. 28 - * <li>$BALANCED_API_KEY If set applies to \Balanced\Settings::$api_key. 29 - * </ul> 30 - */ 31 - class SuiteTest extends \PHPUnit_Framework_TestCase 32 - { 33 - static $key, 34 - $marketplace, 35 - $email_counter = 0; 36 - 37 - static function _createBuyer($email_address = null, $card = null) 38 - { 39 - if ($email_address == null) 40 - $email_address = sprintf('m+%d@poundpay.com', self::$email_counter++); 41 - if ($card == null) 42 - $card = self::_createCard(); 43 - return self::$marketplace->createBuyer( 44 - $email_address, 45 - $card->uri, 46 - array('test#' => 'test_d'), 47 - 'Hobo Joe' 48 - ); 49 - } 50 - 51 - static function _createCard($account = null) 52 - { 53 - $card = self::$marketplace->createCard( 54 - '123 Fake Street', 55 - 'Jollywood', 56 - null, 57 - '90210', 58 - 'khalkhalash', 59 - '4112344112344113', 60 - null, 61 - 12, 62 - 2013); 63 - if ($account != null) { 64 - $account->addCard($card); 65 - $card = Card::get($card->uri); 66 - } 67 - return $card; 68 - } 69 - 70 - static function _createBankAccount($account = null) 71 - { 72 - $bank_account = self::$marketplace->createBankAccount( 73 - 'Homer Jay', 74 - '112233a', 75 - '121042882', 76 - 'checking' 77 - ); 78 - if ($account != null) { 79 - $account->addBankAccount($bank_account); 80 - $bank_account = $account->bank_accounts[0]; 81 - } 82 - return $bank_account; 83 - } 84 - 85 - public static function _createPersonMerchant($email_address = null, $bank_account = null) 86 - { 87 - if ($email_address == null) 88 - $email_address = sprintf('m+%d@poundpay.com', self::$email_counter++); 89 - if ($bank_account == null) 90 - $bank_account = self::_createBankAccount(); 91 - $merchant = array( 92 - 'type' => 'person', 93 - 'name' => 'William James', 94 - 'tax_id' => '393-48-3992', 95 - 'street_address' => '167 West 74th Street', 96 - 'postal_code' => '10023', 97 - 'dob' => '1842-01-01', 98 - 'phone_number' => '+16505551234', 99 - 'country_code' => 'USA' 100 - ); 101 - return self::$marketplace->createMerchant( 102 - $email_address, 103 - $merchant, 104 - $bank_account->uri 105 - ); 106 - } 107 - 108 - public static function _createBusinessMerchant($email_address = null, $bank_account = null) 109 - { 110 - if ($email_address == null) 111 - $email_address = sprintf('m+%d@poundpay.com', self::$email_counter++); 112 - if ($bank_account == null) 113 - $bank_account = self::_createBankAccount(); 114 - $merchant = array( 115 - 'type' => 'business', 116 - 'name' => 'Levain Bakery', 117 - 'tax_id' => '253912384', 118 - 'street_address' => '167 West 74th Street', 119 - 'postal_code' => '10023', 120 - 'phone_number' => '+16505551234', 121 - 'country_code' => 'USA', 122 - 'person' => array( 123 - 'name' => 'William James', 124 - 'tax_id' => '393483992', 125 - 'street_address' => '167 West 74th Street', 126 - 'postal_code' => '10023', 127 - 'dob' => '1842-01-01', 128 - 'phone_number' => '+16505551234', 129 - 'country_code' => 'USA', 130 - ), 131 - ); 132 - return self::$marketplace->createMerchant( 133 - $email_address, 134 - $merchant, 135 - $bank_account->uri 136 - ); 137 - } 138 - 139 - public static function setUpBeforeClass() 140 - { 141 - // url root 142 - $url_root = getenv('BALANCED_URL_ROOT'); 143 - if ($url_root != '') { 144 - Settings::$url_root = $url_root; 145 - } 146 - else 147 - Settings::$url_root = 'https://api.balancedpayments.com'; 148 - 149 - // api key 150 - $api_key = getenv('BALANCED_API_KEY'); 151 - if ($api_key != '') { 152 - Settings::$api_key = $api_key; 153 - } 154 - else { 155 - self::$key = new APIKey(); 156 - self::$key->save(); 157 - Settings::$api_key = self::$key->secret; 158 - } 159 - 160 - // marketplace 161 - try { 162 - self::$marketplace = Marketplace::mine(); 163 - } 164 - catch(\RESTful\Exceptions\NoResultFound $e) { 165 - self::$marketplace = new Marketplace(); 166 - self::$marketplace->save(); 167 - } 168 - } 169 - 170 - function testMarketplaceMine() 171 - { 172 - $marketplace = Marketplace::mine(); 173 - $this->assertEquals($this::$marketplace->id, $marketplace->id); 174 - } 175 - 176 - /** 177 - * @expectedException \RESTful\Exceptions\HTTPError 178 - */ 179 - function testAnotherMarketplace() 180 - { 181 - $marketplace = new Marketplace(); 182 - $marketplace->save(); 183 - } 184 - 185 - /** 186 - * @expectedException \RESTful\Exceptions\HTTPError 187 - */ 188 - function testDuplicateEmailAddress() 189 - { 190 - self::_createBuyer('dupe@poundpay.com'); 191 - self::_createBuyer('dupe@poundpay.com'); 192 - } 193 - 194 - function testIndexMarketplace() 195 - { 196 - $marketplaces = Marketplace::query()->all(); 197 - $this->assertEquals(count($marketplaces), 1); 198 - } 199 - 200 - function testCreateBuyer() 201 - { 202 - self::_createBuyer(); 203 - } 204 - 205 - function testCreateAccountWithoutEmailAddress() 206 - { 207 - self::$marketplace->createAccount(); 208 - } 209 - 210 - function testFindOrCreateAccountByEmailAddress() 211 - { 212 - $account1 = self::$marketplace->createAccount('foc@example.com'); 213 - $account2 = self::$marketplace->findOrCreateAccountByEmailAddress('foc@example.com'); 214 - $this->assertEquals($account2->id, $account2->id); 215 - $account3 = self::$marketplace->findOrCreateAccountByEmailAddress('foc2@example.com'); 216 - $this->assertNotEquals($account3->id, $account1->id); 217 - } 218 - 219 - function testGetBuyer() 220 - { 221 - $buyer1 = self::_createBuyer(); 222 - $buyer2 = Account::get($buyer1->uri); 223 - $this->assertEquals($buyer1->id, $buyer2->id); 224 - } 225 - 226 - 227 - function testMe() 228 - { 229 - $marketplace = Marketplace::mine(); 230 - $merchant = Merchant::me(); 231 - $this->assertEquals($marketplace->id, $merchant->marketplace->id); 232 - } 233 - 234 - function testDebitAndRefundBuyer() 235 - { 236 - $buyer = self::_createBuyer(); 237 - $debit = $buyer->debit( 238 - 1000, 239 - 'Softie', 240 - 'something i bought', 241 - array('hi' => 'bye') 242 - ); 243 - $refund = $debit->refund(100); 244 - } 245 - 246 - /** 247 - * @expectedException \RESTful\Exceptions\HTTPError 248 - */ 249 - function testDebitZero() 250 - { 251 - $buyer = self::_createBuyer(); 252 - $debit = $buyer->debit( 253 - 0, 254 - 'Softie', 255 - 'something i bought' 256 - ); 257 - } 258 - 259 - function testMultipleRefunds() 260 - { 261 - $buyer = self::_createBuyer(); 262 - $debit = $buyer->debit( 263 - 1500, 264 - 'Softie', 265 - 'something tart', 266 - array('hi' => 'bye')); 267 - $refunds = array( 268 - $debit->refund(100), 269 - $debit->refund(100), 270 - $debit->refund(100), 271 - $debit->refund(100)); 272 - $expected_refund_ids = array_map( 273 - function($x) { 274 - return $x->id; 275 - }, $refunds); 276 - sort($expected_refund_ids); 277 - $this->assertEquals($debit->refunds->total(), 4); 278 - 279 - // itemization 280 - $total = 0; 281 - $refund_ids = array(); 282 - foreach ($debit->refunds as $refund) { 283 - $total += $refund->amount; 284 - array_push($refund_ids, $refund->id); 285 - } 286 - sort($refund_ids); 287 - $this->assertEquals($total, 400); 288 - $this->assertEquals($expected_refund_ids, $refund_ids); 289 - 290 - // pagination 291 - $total = 0; 292 - $refund_ids = array(); 293 - foreach ($debit->refunds->paginate() as $page) { 294 - foreach ($page->items as $refund) { 295 - $total += $refund->amount; 296 - array_push($refund_ids, $refund->id); 297 - } 298 - } 299 - sort($refund_ids); 300 - $this->assertEquals($total, 400); 301 - $this->assertEquals($expected_refund_ids, $refund_ids); 302 - } 303 - 304 - function testDebitSource() 305 - { 306 - $buyer = self::_createBuyer(); 307 - $card1 = self::_createCard($buyer); 308 - $card2 = self::_createCard($buyer); 309 - 310 - $credit = $buyer->debit( 311 - 1000, 312 - 'Softie', 313 - 'something i bought' 314 - ); 315 - $this->assertEquals($credit->source->id, $card2->id); 316 - 317 - $credit = $buyer->debit( 318 - 1000, 319 - 'Softie', 320 - 'something i bought', 321 - null, 322 - $card1 323 - ); 324 - $this->assertEquals($credit->source->id, $card1->id); 325 - } 326 - 327 - function testDebitOnBehalfOf() 328 - { 329 - $buyer = self::_createBuyer(); 330 - $merchant = self::$marketplace->createAccount(null); 331 - $card1 = self::_createCard($buyer); 332 - 333 - $debit = $buyer->debit(1000, null, null, null, null, $merchant); 334 - $this->assertEquals($debit->amount, 1000); 335 - // for now just test the debit succeeds. 336 - // TODO: once the on_behalf_of actually shows up on the response, test it. 337 - } 338 - 339 - /** 340 - * @expectedException \InvalidArgumentException 341 - */ 342 - function testDebitOnBehalfOfFailsForBuyer() 343 - { 344 - $buyer = self::_createBuyer(); 345 - $card1 = self::_createCard($buyer); 346 - $debit = $buyer->debit(1000, null, null, null, null, $buyer); 347 - } 348 - 349 - function testCreateAndVoidHold() 350 - { 351 - $buyer = self::_createBuyer(); 352 - $hold = $buyer->hold(1000); 353 - $this->assertEquals($hold->is_void, false); 354 - $hold->void(); 355 - $this->assertEquals($hold->is_void, true); 356 - } 357 - 358 - function testCreateAndCaptureHold() 359 - { 360 - $buyer = self::_createBuyer(); 361 - $hold = $buyer->hold(1000); 362 - $debit = $hold->capture(909); 363 - $this->assertEquals($debit->account->id, $buyer->id); 364 - $this->assertEquals($debit->hold->id, $hold->id); 365 - $this->assertEquals($hold->debit->id, $debit->id); 366 - } 367 - 368 - function testCreatePersonMerchant() 369 - { 370 - $merchant = self::_createPersonMerchant(); 371 - } 372 - 373 - function testCreateBusinessMerchant() 374 - { 375 - $merchant = self::_createBusinessMerchant(); 376 - } 377 - 378 - /** 379 - * @expectedException \RESTful\Exceptions\HTTPError 380 - */ 381 - function testCreditRequiresNonZeroAmount() 382 - { 383 - $buyer = self::_createBuyer(); 384 - $buyer->debit( 385 - 1000, 386 - 'Softie', 387 - 'something i bought' 388 - ); 389 - $merchant = self::_createBusinessMerchant(); 390 - $merchant->credit(0); 391 - } 392 - 393 - /** 394 - * @expectedException \RESTful\Exceptions\HTTPError 395 - */ 396 - function testCreditMoreThanEscrowBalanceFails() 397 - { 398 - $buyer = self::_createBuyer(); 399 - $buyer->credit( 400 - 1000, 401 - 'something i bought', 402 - null, 403 - null, 404 - 'Softie' 405 - ); 406 - $merchant = self::_createBusinessMerchant(); 407 - $merchant->credit(self::$marketplace->in_escrow + 1); 408 - } 409 - 410 - function testCreditDestiation() 411 - { 412 - $buyer = self::_createBuyer(); 413 - $buyer->debit(3000); # NOTE: build up escrow balance to credit 414 - 415 - $merchant = self::_createPersonMerchant(); 416 - $bank_account1 = self::_createBankAccount($merchant); 417 - $bank_account2 = self::_createBankAccount($merchant); 418 - 419 - $credit = $merchant->credit( 420 - 1000, 421 - 'something i sold', 422 - null, 423 - null, 424 - 'Softie' 425 - ); 426 - $this->assertEquals($credit->destination->id, $bank_account2->id); 427 - 428 - $credit = $merchant->credit( 429 - 1000, 430 - 'something i sold', 431 - null, 432 - $bank_account1, 433 - 'Softie' 434 - ); 435 - $this->assertEquals($credit->destination->id, $bank_account1->id); 436 - } 437 - 438 - function testAssociateCard() 439 - { 440 - $merchant = self::_createPersonMerchant(); 441 - $card = self::_createCard(); 442 - $merchant->addCard($card->uri); 443 - } 444 - 445 - function testAssociateBankAccount() 446 - { 447 - $merchant = self::_createPersonMerchant(); 448 - $bank_account = self::_createBankAccount(); 449 - $merchant->addBankAccount($bank_account->uri); 450 - } 451 - 452 - function testCardMasking() 453 - { 454 - $card = self::$marketplace->createCard( 455 - '123 Fake Street', 456 - 'Jollywood', 457 - null, 458 - '90210', 459 - 'khalkhalash', 460 - '4112344112344113', 461 - '123', 462 - 12, 463 - 2013); 464 - $this->assertEquals($card->last_four, '4113'); 465 - $this->assertFalse(property_exists($card, 'number')); 466 - } 467 - 468 - function testBankAccountMasking() 469 - { 470 - $bank_account = self::$marketplace->createBankAccount( 471 - 'Homer Jay', 472 - '112233a', 473 - '121042882', 474 - 'checking' 475 - ); 476 - $this->assertEquals($bank_account->last_four, '233a'); 477 - $this->assertEquals($bank_account->account_number, 'xxx233a'); 478 - } 479 - 480 - function testFilteringAndSorting() 481 - { 482 - $buyer = self::_createBuyer(); 483 - $debit1 = $buyer->debit(1122, null, null, array('tag' => '1')); 484 - $debit2 = $buyer->debit(3322, null, null, array('tag' => '1')); 485 - $debit3 = $buyer->debit(2211, null, null, array('tag' => '2')); 486 - 487 - $getId = function($o) { 488 - return $o->id; 489 - }; 490 - 491 - $debits = ( 492 - self::$marketplace->debits->query() 493 - ->filter(Debit::$f->meta->tag->eq('1')) 494 - ->sort(Debit::$f->created_at->asc()) 495 - ->all()); 496 - $debit_ids = array_map($getId, $debits); 497 - $this->assertEquals($debit_ids, array($debit1->id, $debit2->id)); 498 - 499 - $debits = ( 500 - self::$marketplace->debits->query() 501 - ->filter(Debit::$f->meta->tag->eq('2')) 502 - ->all()); 503 - $debit_ids = array_map($getId, $debits); 504 - $this->assertEquals($debit_ids, array($debit3->id)); 505 - 506 - $debits = ( 507 - self::$marketplace->debits->query() 508 - ->filter(Debit::$f->meta->contains('tag')) 509 - ->sort(Debit::$f->created_at->asc()) 510 - ->all()); 511 - $debit_ids = array_map($getId, $debits); 512 - $this->assertEquals($debit_ids, array($debit1->id, $debit2->id, $debit3->id)); 513 - 514 - $debits = ( 515 - self::$marketplace->debits->query() 516 - ->filter(Debit::$f->meta->contains('tag')) 517 - ->sort(Debit::$f->amount->desc()) 518 - ->all()); 519 - $debit_ids = array_map($getId, $debits); 520 - $this->assertEquals($debit_ids, array($debit2->id, $debit3->id, $debit1->id)); 521 - } 522 - 523 - function testMerchantIdentityFailure() 524 - { 525 - // NOTE: postal_code == '99999' && region == 'EX' triggers identity failure 526 - $identity = array( 527 - 'type' => 'business', 528 - 'name' => 'Levain Bakery', 529 - 'tax_id' => '253912384', 530 - 'street_address' => '167 West 74th Street', 531 - 'postal_code' => '99999', 532 - 'region' => 'EX', 533 - 'phone_number' => '+16505551234', 534 - 'country_code' => 'USA', 535 - 'person' => array( 536 - 'name' => 'William James', 537 - 'tax_id' => '393483992', 538 - 'street_address' => '167 West 74th Street', 539 - 'postal_code' => '99999', 540 - 'region' => 'EX', 541 - 'dob' => '1842-01-01', 542 - 'phone_number' => '+16505551234', 543 - 'country_code' => 'USA', 544 - ), 545 - ); 546 - 547 - try { 548 - self::$marketplace->createMerchant( 549 - sprintf('m+%d@poundpay.com', self::$email_counter++), 550 - $identity); 551 - } 552 - catch(\RESTful\Exceptions\HTTPError $e) { 553 - $this->assertEquals($e->response->code, 300); 554 - $expected = sprintf('https://www.balancedpayments.com/marketplaces/%s/kyc', self::$marketplace->id); 555 - $this->assertEquals($e->redirect_uri, $expected); 556 - $this->assertEquals($e->response->headers['Location'], $expected); 557 - return; 558 - } 559 - $this->fail('Expected exception HTTPError not raised.'); 560 - } 561 - 562 - function testInternationalCard() 563 - { 564 - $payload = array( 565 - 'card_number' => '4111111111111111', 566 - 'city' => '\xe9\x83\xbd\xe7\x95\x99\xe5\xb8\x82', 567 - 'country_code' => 'JPN', 568 - 'expiration_month' => 12, 569 - 'expiration_year' => 2014, 570 - 'name' => 'Johnny Fresh', 571 - 'postal_code' => '4020054', 572 - 'street_address' => '\xe7\x94\xb0\xe5\x8e\x9f\xef\xbc\x93\xe3\x83\xbc\xef\xbc\x98\xe3\x83\xbc\xef\xbc\x91' 573 - ); 574 - $card = self::$marketplace->cards->create($payload); 575 - $this->assertEquals($card->street_address, $payload['street_address']); 576 - } 577 - 578 - /** 579 - * @expectedException \RESTful\Exceptions\NoResultFound 580 - */ 581 - function testAccountWithEmailAddressNotFound() 582 - { 583 - self::$marketplace->accounts->query() 584 - ->filter(Account::$f->email_address->eq('unlikely@address.com')) 585 - ->one(); 586 - } 587 - 588 - function testDebitACard() 589 - { 590 - $buyer = self::_createBuyer(); 591 - $card = self::_createCard($buyer); 592 - $debit = $card->debit( 593 - 1000, 594 - 'Softie', 595 - 'something i bought', 596 - array('hi' => 'bye')); 597 - $this->assertEquals($debit->source->uri, $card->uri); 598 - } 599 - 600 - /** 601 - * @expectedException \UnexpectedValueException 602 - */ 603 - function testDebitAnUnassociatedCard() 604 - { 605 - $card = self::_createCard(); 606 - $card->debit(1000, 'Softie'); 607 - } 608 - 609 - function testCreditABankAccount() 610 - { 611 - $buyer = self::_createBuyer(); 612 - $buyer->debit(101); # NOTE: build up escrow balance to credit 613 - 614 - $merchant = self::_createPersonMerchant(); 615 - $bank_account = self::_createBankAccount($merchant); 616 - $credit = $bank_account->credit(55, 'something sour'); 617 - $this->assertEquals($credit->destination->uri, $bank_account->uri); 618 - } 619 - 620 - function testQuery() 621 - { 622 - $buyer = self::_createBuyer(); 623 - $tag = '123123123123'; 624 - $debit1 = $buyer->debit(1122, null, null, array('tag' => $tag)); 625 - $debit2 = $buyer->debit(3322, null, null, array('tag' => $tag)); 626 - $debit3 = $buyer->debit(2211, null, null, array('tag' => $tag)); 627 - $expected_debit_ids = array($debit1->id, $debit2->id, $debit3->id); 628 - 629 - $query = ( 630 - self::$marketplace->debits->query() 631 - ->filter(Debit::$f->meta->tag->eq($tag)) 632 - ->sort(Debit::$f->created_at->asc()) 633 - ->limit(1)); 634 - 635 - $this->assertEquals($query->total(), 3); 636 - 637 - $debit_ids = array(); 638 - foreach ($query as $debits) { 639 - array_push($debit_ids, $debits->id); 640 - } 641 - $this->assertEquals($debit_ids, $expected_debit_ids); 642 - 643 - $debit_ids = array($query[0]->id, $query[1]->id, $query[2]->id); 644 - $this->assertEquals($debit_ids, $expected_debit_ids); 645 - } 646 - 647 - function testBuyerPromoteToMerchant() 648 - { 649 - $merchant = array( 650 - 'type' => 'person', 651 - 'name' => 'William James', 652 - 'tax_id' => '393-48-3992', 653 - 'street_address' => '167 West 74th Street', 654 - 'postal_code' => '10023', 655 - 'dob' => '1842-01-01', 656 - 'phone_number' => '+16505551234', 657 - 'country_code' => 'USA' 658 - ); 659 - $buyer = self::_createBuyer(); 660 - $buyer->promoteToMerchant($merchant); 661 - } 662 - 663 - function testCreditAccountlessBankAccount() 664 - { 665 - $buyer = self::_createBuyer(); 666 - $buyer->debit(101); # NOTE: build up escrow balance to credit 667 - 668 - $bank_account = self::_createBankAccount(); 669 - $credit = $bank_account->credit(55, 'something sour'); 670 - $this->assertEquals($credit->bank_account->id, $bank_account->id); 671 - $bank_account = $bank_account->get($bank_account->id); 672 - $this->assertEquals($bank_account->credits->total(), 1); 673 - } 674 - 675 - function testCreditUnstoredBankAccount() 676 - { 677 - $buyer = self::_createBuyer(); 678 - $buyer->debit(101); # NOTE: build up escrow balance to credit 679 - 680 - $credit = Credit::bankAccount( 681 - 55, 682 - array( 683 - 'name' => 'Homer Jay', 684 - 'account_number' => '112233a', 685 - 'routing_number' => '121042882', 686 - 'type' => 'checking', 687 - ), 688 - 'something sour'); 689 - $this->assertFalse(property_exists($credit->bank_account, 'uri')); 690 - $this->assertFalse(property_exists($credit->bank_account, 'id')); 691 - $this->assertEquals($credit->bank_account->name, 'Homer Jay'); 692 - $this->assertEquals($credit->bank_account->account_number, 'xxx233a'); 693 - $this->assertEquals($credit->bank_account->type, 'checking'); 694 - } 695 - 696 - function testDeleteBankAccount() 697 - { 698 - $buyer = self::_createBuyer(); 699 - $buyer->debit(101); # NOTE: build up escrow balance to credit 700 - 701 - $bank_account = self::_createBankAccount(); 702 - $credit = $bank_account->credit(55, 'something sour'); 703 - $this->assertTrue(property_exists($credit->bank_account, 'uri')); 704 - $this->assertTrue(property_exists($credit->bank_account, 'id')); 705 - $bank_account = BankAccount::get($bank_account->id); 706 - $bank_account->delete(); 707 - $credit = Credit::get($credit->uri); 708 - $this->assertFalse(property_exists($credit->bank_account, 'uri')); 709 - $this->assertFalse(property_exists($credit->bank_account, 'id')); 710 - } 711 - 712 - function testGetBankAccounById() 713 - { 714 - $bank_account = self::_createBankAccount(); 715 - $bank_account_2 = BankAccount::get($bank_account->id); 716 - $this->assertEquals($bank_account_2->id, $bank_account->id); 717 - } 718 - 719 - /** 720 - * @expectedException \Balanced\Errors\InsufficientFunds 721 - */ 722 - function testInsufficientFunds() 723 - { 724 - $marketplace = Marketplace::get(self::$marketplace->uri); 725 - $amount = $marketplace->in_escrow + 100; 726 - $credit = Credit::bankAccount( 727 - $amount, 728 - array( 729 - 'name' => 'Homer Jay', 730 - 'account_number' => '112233a', 731 - 'routing_number' => '121042882', 732 - 'type' => 'checking', 733 - ), 734 - 'something sour'); 735 - } 736 - 737 - function testCreateCallback() { 738 - $callback = self::$marketplace->createCallback( 739 - 'http://example.com/php' 740 - ); 741 - $this->assertEquals($callback->url, 'http://example.com/php'); 742 - } 743 - 744 - /** 745 - * @expectedException \Balanced\Errors\BankAccountVerificationFailure 746 - */ 747 - function testBankAccountVerificationFailure() { 748 - $bank_account = self::_createBankAccount(); 749 - $buyer = self::_createBuyer(); 750 - $buyer->addBankAccount($bank_account); 751 - $verification = $bank_account->verify(); 752 - $verification->confirm(1, 2); 753 - } 754 - 755 - /** 756 - * @expectedException \Balanced\Errors\BankAccountVerificationFailure 757 - */ 758 - function testBankAccountVerificationDuplicate() { 759 - $bank_account = self::_createBankAccount(); 760 - $buyer = self::_createBuyer(); 761 - $buyer->addBankAccount($bank_account); 762 - $bank_account->verify(); 763 - $bank_account->verify(); 764 - } 765 - 766 - function testBankAccountVerificationSuccess() { 767 - $bank_account = self::_createBankAccount(); 768 - $buyer = self::_createBuyer(); 769 - $buyer->addBankAccount($bank_account); 770 - $verification = $bank_account->verify(); 771 - $verification->confirm(1, 1); 772 - 773 - // this will fail if the bank account is not verified 774 - $debit = $buyer->debit( 775 - 1000, 776 - 'Softie', 777 - 'something i bought', 778 - array('hi' => 'bye'), 779 - $bank_account 780 - ); 781 - $this->assertTrue(strpos($debit->source->uri, 'bank_account') > 0); 782 - } 783 - 784 - function testEvents() { 785 - $prev_num_events = Marketplace::mine()->events->total(); 786 - $account = self::_createBuyer(); 787 - $account->debit(123); 788 - $cur_num_events = Marketplace::mine()->events->total(); 789 - $count = 0; 790 - while ($cur_num_events == $prev_num_events && $count < 10) { 791 - printf("waiting for events - %d, %d == %d\n", $count + 1, $cur_num_events, $prev_num_events); 792 - sleep(2); // 2 seconds 793 - $cur_num_events = Marketplace::mine()->events->total(); 794 - $count += 1; 795 - } 796 - $this->assertTrue($cur_num_events > $prev_num_events); 797 - } 798 - }
-8
externals/balanced-php/tests/phpunit.xml
··· 1 - <phpunit> 2 - <testsuite name="Balanced"> 3 - <directory>.</directory> 4 - </testsuite> 5 - <logging> 6 - <log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/> 7 - </logging> 8 - </phpunit>
+2 -9
resources/celerity/map.php
··· 44 44 'rsrc/css/application/config/config-welcome.css' => '6abd79be', 45 45 'rsrc/css/application/config/setup-issue.css' => '22270af2', 46 46 'rsrc/css/application/config/unhandled-exception.css' => '37d4f9a2', 47 - 'rsrc/css/application/conpherence/durable-column.css' => '8c951609', 47 + 'rsrc/css/application/conpherence/durable-column.css' => '1f5c64e8', 48 48 'rsrc/css/application/conpherence/menu.css' => 'c6ac5299', 49 49 'rsrc/css/application/conpherence/message-pane.css' => '5930260a', 50 50 'rsrc/css/application/conpherence/notification.css' => '04a6e10a', ··· 404 404 'rsrc/js/application/phame/phame-post-preview.js' => 'be807912', 405 405 'rsrc/js/application/pholio/behavior-pholio-mock-edit.js' => '9c2623f4', 406 406 'rsrc/js/application/pholio/behavior-pholio-mock-view.js' => 'e58bf807', 407 - 'rsrc/js/application/phortune/behavior-balanced-payment-form.js' => 'b2c03e60', 408 407 'rsrc/js/application/phortune/behavior-stripe-payment-form.js' => '3f5d6dbf', 409 408 'rsrc/js/application/phortune/behavior-test-payment-form.js' => 'fc91ab6c', 410 409 'rsrc/js/application/phortune/phortune-credit-card-form.js' => '2290aeef', ··· 514 513 'changeset-view-manager' => '88be0133', 515 514 'config-options-css' => '7fedf08b', 516 515 'config-welcome-css' => '6abd79be', 517 - 'conpherence-durable-column-view' => '8c951609', 516 + 'conpherence-durable-column-view' => '1f5c64e8', 518 517 'conpherence-menu-css' => 'c6ac5299', 519 518 'conpherence-message-pane-css' => '5930260a', 520 519 'conpherence-notification-css' => '04a6e10a', ··· 554 553 'javelin-behavior-aphront-more' => 'a80d0378', 555 554 'javelin-behavior-audio-source' => '59b251eb', 556 555 'javelin-behavior-audit-preview' => 'd835b03a', 557 - 'javelin-behavior-balanced-payment-form' => 'b2c03e60', 558 556 'javelin-behavior-boards-dropdown' => '0ec56e1d', 559 557 'javelin-behavior-choose-control' => '6153c708', 560 558 'javelin-behavior-config-reorder-fields' => '14a827de', ··· 1669 1667 'javelin-dom', 1670 1668 'javelin-uri', 1671 1669 'javelin-request', 1672 - ), 1673 - 'b2c03e60' => array( 1674 - 'javelin-behavior', 1675 - 'javelin-dom', 1676 - 'phortune-credit-card-form', 1677 1670 ), 1678 1671 'b3a4b884' => array( 1679 1672 'javelin-behavior',
resources/sprite/login_1x/Balanced.png

This is a binary file and will not be displayed.

resources/sprite/login_2x/Balanced.png

This is a binary file and will not be displayed.

-2
src/__phutil_library_map__.php
··· 2779 2779 'PhortuneAccountTransaction' => 'applications/phortune/storage/PhortuneAccountTransaction.php', 2780 2780 'PhortuneAccountTransactionQuery' => 'applications/phortune/query/PhortuneAccountTransactionQuery.php', 2781 2781 'PhortuneAccountViewController' => 'applications/phortune/controller/PhortuneAccountViewController.php', 2782 - 'PhortuneBalancedPaymentProvider' => 'applications/phortune/provider/PhortuneBalancedPaymentProvider.php', 2783 2782 'PhortuneCart' => 'applications/phortune/storage/PhortuneCart.php', 2784 2783 'PhortuneCartAcceptController' => 'applications/phortune/controller/PhortuneCartAcceptController.php', 2785 2784 'PhortuneCartCancelController' => 'applications/phortune/controller/PhortuneCartCancelController.php', ··· 6176 6175 'PhortuneAccountTransaction' => 'PhabricatorApplicationTransaction', 6177 6176 'PhortuneAccountTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 6178 6177 'PhortuneAccountViewController' => 'PhortuneController', 6179 - 'PhortuneBalancedPaymentProvider' => 'PhortunePaymentProvider', 6180 6178 'PhortuneCart' => array( 6181 6179 'PhortuneDAO', 6182 6180 'PhabricatorApplicationTransactionInterface',
-370
src/applications/phortune/provider/PhortuneBalancedPaymentProvider.php
··· 1 - <?php 2 - 3 - final class PhortuneBalancedPaymentProvider extends PhortunePaymentProvider { 4 - 5 - const BALANCED_MARKETPLACE_ID = 'balanced.marketplace-id'; 6 - const BALANCED_SECRET_KEY = 'balanced.secret-key'; 7 - 8 - public function isAcceptingLivePayments() { 9 - return !preg_match('/-test-/', $this->getSecretKey()); 10 - } 11 - 12 - public function getName() { 13 - return pht('Balanced Payments'); 14 - } 15 - 16 - public function getConfigureName() { 17 - return pht('Add Balanced Payments Account'); 18 - } 19 - 20 - public function getConfigureDescription() { 21 - return pht( 22 - 'Allows you to accept credit or debit card payments with a '. 23 - 'balancedpayments.com account.'); 24 - } 25 - 26 - public function getConfigureProvidesDescription() { 27 - return pht( 28 - 'This merchant accepts credit and debit cards via Balanced Payments.'); 29 - } 30 - 31 - public function getConfigureInstructions() { 32 - return pht( 33 - "To configure Balacned, register or log in to an existing account on ". 34 - "[[https://balancedpayments.com | balancedpayments.com]]. Once logged ". 35 - "in:\n\n". 36 - " - Choose a marketplace.\n". 37 - " - Find the **Marketplace ID** in {nav My Marketplace > Settings} and ". 38 - " copy it into the field above.\n". 39 - " - On the same screen, under **API keys**, choose **Add a key**, then ". 40 - " **Show key secret**. Copy the value into the field above.\n\n". 41 - "You can either use a test marketplace to add this provider in test ". 42 - "mode, or use a live marketplace to accept live payments."); 43 - } 44 - 45 - public function getAllConfigurableProperties() { 46 - return array( 47 - self::BALANCED_MARKETPLACE_ID, 48 - self::BALANCED_SECRET_KEY, 49 - ); 50 - } 51 - 52 - public function getAllConfigurableSecretProperties() { 53 - return array( 54 - self::BALANCED_SECRET_KEY, 55 - ); 56 - } 57 - 58 - public function processEditForm( 59 - AphrontRequest $request, 60 - array $values) { 61 - 62 - $errors = array(); 63 - $issues = array(); 64 - 65 - if (!strlen($values[self::BALANCED_MARKETPLACE_ID])) { 66 - $errors[] = pht('Balanced Marketplace ID is required.'); 67 - $issues[self::BALANCED_MARKETPLACE_ID] = pht('Required'); 68 - } 69 - 70 - if (!strlen($values[self::BALANCED_SECRET_KEY])) { 71 - $errors[] = pht('Balanced Secret Key is required.'); 72 - $issues[self::BALANCED_SECRET_KEY] = pht('Required'); 73 - } 74 - 75 - return array($errors, $issues, $values); 76 - } 77 - 78 - public function extendEditForm( 79 - AphrontRequest $request, 80 - AphrontFormView $form, 81 - array $values, 82 - array $issues) { 83 - 84 - $form 85 - ->appendChild( 86 - id(new AphrontFormTextControl()) 87 - ->setName(self::BALANCED_MARKETPLACE_ID) 88 - ->setValue($values[self::BALANCED_MARKETPLACE_ID]) 89 - ->setError(idx($issues, self::BALANCED_MARKETPLACE_ID, true)) 90 - ->setLabel(pht('Balanced Marketplace ID'))) 91 - ->appendChild( 92 - id(new AphrontFormTextControl()) 93 - ->setName(self::BALANCED_SECRET_KEY) 94 - ->setValue($values[self::BALANCED_SECRET_KEY]) 95 - ->setError(idx($issues, self::BALANCED_SECRET_KEY, true)) 96 - ->setLabel(pht('Balanced Secret Key'))); 97 - 98 - } 99 - 100 - public function canRunConfigurationTest() { 101 - return true; 102 - } 103 - 104 - public function runConfigurationTest() { 105 - $this->loadBalancedAPILibraries(); 106 - 107 - // TODO: This only tests that the secret key is correct. It's not clear 108 - // how to test that the marketplace is correct. 109 - 110 - try { 111 - Balanced\Settings::$api_key = $this->getSecretKey(); 112 - Balanced\APIKey::query()->first(); 113 - } catch (RESTful\Exceptions\HTTPError $error) { 114 - // NOTE: This exception doesn't print anything meaningful if it escapes 115 - // to top level. Replace it with something slightly readable. 116 - throw new Exception($error->response->body->description); 117 - } 118 - } 119 - 120 - public function getPaymentMethodDescription() { 121 - return pht('Add Credit or Debit Card'); 122 - } 123 - 124 - public function getPaymentMethodIcon() { 125 - return 'Balanced'; 126 - } 127 - 128 - public function getPaymentMethodProviderDescription() { 129 - return pht('Processed by Balanced'); 130 - } 131 - 132 - public function getDefaultPaymentMethodDisplayName( 133 - PhortunePaymentMethod $method) { 134 - return pht('Credit/Debit Card'); 135 - } 136 - 137 - protected function executeCharge( 138 - PhortunePaymentMethod $method, 139 - PhortuneCharge $charge) { 140 - $this->loadBalancedAPILibraries(); 141 - 142 - $price = $charge->getAmountAsCurrency(); 143 - 144 - // Build the string which will appear on the credit card statement. 145 - $charge_as = new PhutilURI(PhabricatorEnv::getProductionURI('/')); 146 - $charge_as = $charge_as->getDomain(); 147 - $charge_as = id(new PhutilUTF8StringTruncator()) 148 - ->setMaximumBytes(22) 149 - ->setTerminator('') 150 - ->truncateString($charge_as); 151 - 152 - try { 153 - Balanced\Settings::$api_key = $this->getSecretKey(); 154 - $card = Balanced\Card::get($method->getMetadataValue('balanced.cardURI')); 155 - $debit = $card->debit($price->getValueInUSDCents(), $charge_as); 156 - } catch (RESTful\Exceptions\HTTPError $error) { 157 - // NOTE: This exception doesn't print anything meaningful if it escapes 158 - // to top level. Replace it with something slightly readable. 159 - throw new Exception($error->response->body->description); 160 - } 161 - 162 - $expect_status = 'succeeded'; 163 - if ($debit->status !== $expect_status) { 164 - throw new Exception( 165 - pht( 166 - 'Debit failed, expected "%s", got "%s".', 167 - $expect_status, 168 - $debit->status)); 169 - } 170 - 171 - $charge->setMetadataValue('balanced.debitURI', $debit->uri); 172 - $charge->save(); 173 - } 174 - 175 - protected function executeRefund( 176 - PhortuneCharge $charge, 177 - PhortuneCharge $refund) { 178 - $this->loadBalancedAPILibraries(); 179 - 180 - $debit_uri = $charge->getMetadataValue('balanced.debitURI'); 181 - if (!$debit_uri) { 182 - throw new Exception(pht('No Balanced debit URI!')); 183 - } 184 - 185 - $refund_cents = $refund 186 - ->getAmountAsCurrency() 187 - ->negate() 188 - ->getValueInUSDCents(); 189 - 190 - $params = array( 191 - 'amount' => $refund_cents, 192 - ); 193 - 194 - try { 195 - Balanced\Settings::$api_key = $this->getSecretKey(); 196 - $balanced_debit = Balanced\Debit::get($debit_uri); 197 - $balanced_refund = $balanced_debit->refunds->create($params); 198 - } catch (RESTful\Exceptions\HTTPError $error) { 199 - throw new Exception($error->response->body->description); 200 - } 201 - 202 - $refund->setMetadataValue('balanced.refundURI', $balanced_refund->uri); 203 - $refund->save(); 204 - } 205 - 206 - public function updateCharge(PhortuneCharge $charge) { 207 - $this->loadBalancedAPILibraries(); 208 - 209 - $debit_uri = $charge->getMetadataValue('balanced.debitURI'); 210 - if (!$debit_uri) { 211 - throw new Exception(pht('No Balanced debit URI!')); 212 - } 213 - 214 - try { 215 - Balanced\Settings::$api_key = $this->getSecretKey(); 216 - $balanced_debit = Balanced\Debit::get($debit_uri); 217 - } catch (RESTful\Exceptions\HTTPError $error) { 218 - throw new Exception($error->response->body->description); 219 - } 220 - 221 - // TODO: Deal with disputes / chargebacks / surprising refunds. 222 - } 223 - 224 - private function getMarketplaceID() { 225 - return $this 226 - ->getProviderConfig() 227 - ->getMetadataValue(self::BALANCED_MARKETPLACE_ID); 228 - } 229 - 230 - private function getSecretKey() { 231 - return $this 232 - ->getProviderConfig() 233 - ->getMetadataValue(self::BALANCED_SECRET_KEY); 234 - } 235 - 236 - private function getMarketplaceURI() { 237 - return '/v1/marketplaces/'.$this->getMarketplaceID(); 238 - } 239 - 240 - 241 - /* -( Adding Payment Methods )--------------------------------------------- */ 242 - 243 - 244 - public function canCreatePaymentMethods() { 245 - return true; 246 - } 247 - 248 - public function validateCreatePaymentMethodToken(array $token) { 249 - return isset($token['balancedMarketplaceURI']); 250 - } 251 - 252 - 253 - /** 254 - * @phutil-external-symbol class Balanced\Card 255 - * @phutil-external-symbol class Balanced\Debit 256 - * @phutil-external-symbol class Balanced\Settings 257 - * @phutil-external-symbol class Balanced\Marketplace 258 - * @phutil-external-symbol class Balanced\APIKey 259 - * @phutil-external-symbol class RESTful\Exceptions\HTTPError 260 - */ 261 - public function createPaymentMethodFromRequest( 262 - AphrontRequest $request, 263 - PhortunePaymentMethod $method, 264 - array $token) { 265 - $this->loadBalancedAPILibraries(); 266 - 267 - $errors = array(); 268 - 269 - $account_phid = $method->getAccountPHID(); 270 - $author_phid = $method->getAuthorPHID(); 271 - $description = $account_phid.':'.$author_phid; 272 - 273 - try { 274 - Balanced\Settings::$api_key = $this->getSecretKey(); 275 - 276 - $card = Balanced\Card::get($token['balancedMarketplaceURI']); 277 - 278 - $buyer = Balanced\Marketplace::mine()->createBuyer( 279 - null, 280 - $card->uri, 281 - array( 282 - 'description' => $description, 283 - )); 284 - 285 - } catch (RESTful\Exceptions\HTTPError $error) { 286 - // NOTE: This exception doesn't print anything meaningful if it escapes 287 - // to top level. Replace it with something slightly readable. 288 - throw new Exception($error->response->body->description); 289 - } 290 - 291 - $method 292 - ->setBrand($card->brand) 293 - ->setLastFourDigits($card->last_four) 294 - ->setExpires($card->expiration_year, $card->expiration_month) 295 - ->setMetadata( 296 - array( 297 - 'type' => 'balanced.account', 298 - 'balanced.accountURI' => $buyer->uri, 299 - 'balanced.cardURI' => $card->uri, 300 - )); 301 - 302 - return $errors; 303 - } 304 - 305 - public function renderCreatePaymentMethodForm( 306 - AphrontRequest $request, 307 - array $errors) { 308 - 309 - $ccform = id(new PhortuneCreditCardForm()) 310 - ->setUser($request->getUser()) 311 - ->setErrors($errors) 312 - ->addScript('https://js.balancedpayments.com/v1/balanced.js'); 313 - 314 - Javelin::initBehavior( 315 - 'balanced-payment-form', 316 - array( 317 - 'balancedMarketplaceURI' => $this->getMarketplaceURI(), 318 - 'formID' => $ccform->getFormID(), 319 - )); 320 - 321 - return $ccform->buildForm(); 322 - } 323 - 324 - private function getBalancedShortErrorCode($error_code) { 325 - $prefix = 'cc:balanced:'; 326 - if (strncmp($error_code, $prefix, strlen($prefix))) { 327 - return null; 328 - } 329 - return substr($error_code, strlen($prefix)); 330 - } 331 - 332 - public function translateCreatePaymentMethodErrorCode($error_code) { 333 - $short_code = $this->getBalancedShortErrorCode($error_code); 334 - 335 - if ($short_code) { 336 - static $map = array( 337 - ); 338 - 339 - if (isset($map[$short_code])) { 340 - return $map[$short_code]; 341 - } 342 - } 343 - 344 - return $error_code; 345 - } 346 - 347 - public function getCreatePaymentMethodErrorMessage($error_code) { 348 - $short_code = $this->getBalancedShortErrorCode($error_code); 349 - if (!$short_code) { 350 - return null; 351 - } 352 - 353 - switch ($short_code) { 354 - 355 - default: 356 - break; 357 - } 358 - 359 - 360 - return null; 361 - } 362 - 363 - private function loadBalancedAPILibraries() { 364 - $root = dirname(phutil_get_library_root('phabricator')); 365 - require_once $root.'/externals/httpful/bootstrap.php'; 366 - require_once $root.'/externals/restful/bootstrap.php'; 367 - require_once $root.'/externals/balanced-php/bootstrap.php'; 368 - } 369 - 370 - }
-57
webroot/rsrc/js/application/phortune/behavior-balanced-payment-form.js
··· 1 - /** 2 - * @provides javelin-behavior-balanced-payment-form 3 - * @requires javelin-behavior 4 - * javelin-dom 5 - * phortune-credit-card-form 6 - */ 7 - 8 - JX.behavior('balanced-payment-form', function(config) { 9 - balanced.init(config.balancedMarketplaceURI); 10 - 11 - function onsubmit(card_data) { 12 - var errors = []; 13 - 14 - if (!balanced.card.isCardNumberValid(card_data.number)) { 15 - errors.push('cc:invalid:number'); 16 - } 17 - 18 - if (!balanced.card.isSecurityCodeValid(card_data.number, card_data.cvc)) { 19 - errors.push('cc:invalid:cvc'); 20 - } 21 - 22 - if (!balanced.card.isExpiryValid(card_data.month, card_data.year)) { 23 - errors.push('cc:invalid:expiry'); 24 - } 25 - 26 - if (errors.length) { 27 - ccform.submitForm(errors); 28 - return; 29 - } 30 - 31 - var data = { 32 - card_number: card_data.number, 33 - security_code: card_data.cvc, 34 - expiration_month: card_data.month, 35 - expiration_year: card_data.year 36 - }; 37 - 38 - balanced.card.create(data, onresponse); 39 - } 40 - 41 - function onresponse(response) { 42 - var token = null; 43 - var errors = []; 44 - 45 - if (response.error) { 46 - errors = ['cc:balanced:error:' + response.error.type]; 47 - } else if (response.status != 201) { 48 - errors = ['cc:balanced:http:' + response.status]; 49 - } else { 50 - token = response.data.uri; 51 - } 52 - 53 - ccform.submitForm(errors, {balancedMarketplaceURI: token}); 54 - } 55 - 56 - var ccform = new JX.PhortuneCreditCardForm(JX.$(config.formID), onsubmit); 57 - });