[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/externals/balanced-php/example/ -> bank-account-debits.php (source)

   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("[email protected]");
  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  ?>


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