$key->save(); Balanced\Settings::$api_key = $key->secret; $marketplace = new Balanced\Marketplace(); $marketplace->save(); // Create a bank account $bank_account = new \Balanced\BankAccount(array("account_number" => "9900000001", "name" => "Johann Bernoulli", "routing_number" => "121000358", "type" => "checking")); $bank_account->save(); print "The BankAccount: " . $bank_account->uri; // Create a Customer $customer = new \Balanced\Customer(array("name" => "William Henry Cavendish III", "email" => "*****@*****.**")); $customer->save(); // Add the bank account to the Customer $customer->addBankAccount($bank_account); print "You can't debit from a bank account until you verify it\n"; try { $customer->debit(100); } catch (Exception $e) { printf("Debit failed, %s\n", $e->description); } // Initiate a bank account verification $verification = $bank_account->verify(); // Verify the bank account try { $verification->confirm(1, 2); } catch (Balanced\Errors\BankAccountVerificationFailure $e) { printf("Verification error , %s\n", $e->description); print "PROTIP: for TEST bank accounts the valid amount is always 1 and 1\n"; } $verification->confirm(1, 1); $debit = $customer->debit(100); printf("Debited the bank account %s for %d cents\n", $debit->source->uri, $debit->amount);
// Create a requestb.in $ch = curl_init("http://requestb.in/api/v1/bins"); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . 0)); $result = json_decode(curl_exec($ch)); $bin_name = $result->name; $callback_url = "http://requestb.in/" . $bin_name; $requests_url = "http://requestb.in/api/v1/bins/" . $bin_name . "/requests"; // Create a Callback printf("Create a callback\n"); $callback = new Balanced\Callback(array("url" => $callback_url)); $callback->save(); print "The callback: " . $callback->uri . "\n"; // Create a Customer $customer = new \Balanced\Customer(array("name" => "William Henry Cavendish III", "email" => "*****@*****.**")); $customer->save(); print "The customer: " . $customer->uri . "\n"; // Create a Card printf("Create a Card\n"); $card = $marketplace->cards->create(array("card_number" => "5105105105105100", "expiration_month" => "12", "expiration_year" => "2015")); // Add Card to Customer print "Add Card to Customer\n"; $customer->addCard($card->uri); // Debit the Customer printf("Create a debit (which implicitly creates and captures a hold)\n"); $customer->debit(100); foreach ($marketplace->events as $event) { printf("Received Event:\n Type - %s\n Occurred at - %s\n\n", $event->type, $event->occurred_at); } printf("Examine event payloads at http://requestb.in/%s?inspect\n", $bin_name);
require __DIR__ . '/vendor/autoload.php'; Httpful\Bootstrap::init(); RESTful\Bootstrap::init(); Balanced\Bootstrap::init(); $API_KEY_SECRET = '5f4db668a5ec11e1b908026ba7e239a9'; Balanced\Settings::$api_key = $API_KEY_SECRET; $marketplace = Balanced\Marketplace::mine(); // Create a Card print "Create a card\n"; $card = $marketplace->cards->create(array("card_number" => "5105105105105100", "expiration_month" => "12", "expiration_year" => "2015")); print "The card: " . $card->uri . "\n"; // Create a Customer $customer = new \Balanced\Customer(array("name" => "William Henry Cavendish III", "email" => "*****@*****.**")); $customer->save(); print "The customer: " . $customer->uri . "\n"; // Add the Card to the Customer print "Add the Card to the Customer\n"; $customer->addCard($card->uri); // Debit the Customer print "Debit the customer \$15\n"; try { $debit = $customer->debit(1500); print "The debit: " . $debit->uri . "\n"; print "Debited Customer " . $customer->uri . " for " . $debit->amount . " cents.\n"; } catch (Balanced\Errors\Declined $e) { print "Oh no, the processor declined the debit!\n"; } catch (Balanced\Errors\NoFundingSource $e) { print "Oh no, the buyer has not active funding sources!\n"; } catch (Balanced\Errors\CannotDebit $e) { print "Oh no, the buyer has no debitable funding sources!\n"; }
print "The customer: " . $customer->uri . "\n"; // Add Card to Customer $customer->addCard($card->uri); // Hold some funds print "Create a Hold for some funds, \$15\n"; $hold = $marketplace->holds->create(array("amount" => 1500, "description" => "Some descriptive text for the debit in the dashboard", "source_uri" => $card->uri)); // Capture the hold print "Capture the Hold (for the full amount)\n"; $debit = $hold->capture(); // Check escrow for new funds from debit $marketplace = Balanced\Marketplace::mine(); if ($marketplace->in_escrow != 1500) { throw new Exception("1500 is not in escrow! This is wrong"); } print "Escrow amount: " . $marketplace->in_escrow . " \n"; print "Refund the full amount\n"; $refund = $debit->refund(); // Create a bank account $bank_account = new \Balanced\BankAccount(array("account_number" => "9900000001", "name" => "Johann Bernoulli", "routing_number" => "121000358", "type" => "checking")); $bank_account->save(); // Create a Customer who is the seller $seller = new \Balanced\Customer(array("name" => "Billy Jones", "email" => "*****@*****.**", "street_address" => "801 High St", "postal_code" => "94301", "country" => "USA", "dob" => "1979-02")); $seller->save(); // Add bank account to seller $seller->addBankAccount($bank_account->uri); print "Debit the customer for \$130\n"; $debit = $customer->debit(13000, "MARKETPLACE.COM"); print "Credit the seller \$110\n"; $credit = $seller->credit(11000, "Buyer purchased something on Marketplace.com"); print "The marketplace charges 15%, so it earned \$20\n"; $mp_credit = $marketplace->owner_customer->credit(2000, "Commission from MARKETPLACE.COM");