[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
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("[email protected]", $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('[email protected]', 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 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |