[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/externals/balanced-php/tests/Balanced/ -> SuiteTest.php (source)

   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+%[email protected]', 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+%[email protected]', 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+%[email protected]', 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('[email protected]');
 191          self::_createBuyer('[email protected]');
 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('[email protected]');
 213          $account2 = self::$marketplace->findOrCreateAccountByEmailAddress('[email protected]');
 214          $this->assertEquals($account2->id, $account2->id);
 215          $account3 = self::$marketplace->findOrCreateAccountByEmailAddress('[email protected]');
 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+%[email protected]', 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('[email protected]'))
 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  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1