1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 06:20:56 +01:00
phorge-phorge/externals/balanced-php/example/iterate-example.php
epriestley 23786784ef Add Balanced Payments API
Summary: Adds the Balanced PHP API to externals/. Ref T2787.

Test Plan: Used in next diff.

Reviewers: btrahan, chad

Reviewed By: chad

CC: aran, aurelijus

Maniphest Tasks: T2787

Differential Revision: https://secure.phabricator.com/D5764
2013-04-25 09:47:30 -07:00

71 lines
1.5 KiB
PHP

<?
require('vendor/autoload.php');
Httpful\Bootstrap::init();
RESTful\Bootstrap::init();
Balanced\Bootstrap::init();
$key = new Balanced\APIKey();
$key->save();
Balanced\Settings::$api_key = $key->secret;
$marketplace = new Balanced\Marketplace();
$marketplace->save();
$card = $marketplace->cards->create(array(
"card_number" => "5105105105105100",
"expiration_month" => "12",
"expiration_year" => "2015"
));
$buyer = $marketplace->createBuyer("buyer@example.com", $card->uri);
$debit = $buyer->debit(1500);
$debit->refund(100);
$debit->refund(100);
$debit->refund(100);
echo $debit->refunds->total() . " refunds" . "\n";
$total = 0;
foreach ($debit->refunds as $r) {
$total += $r->amount;
print "refund = " . $r->amount . "\n";
}
print $total . "\n";
# bigger pagination example
print "Create 60 **buyer** with cards accounts\n";
for ($i = 0; $i < 60; $i++) {
$card = $marketplace->cards->create(array(
"card_number" => "5105105105105100",
"expiration_month" => "12",
"expiration_year" => "2015"
));
$buyer = $marketplace->createBuyer("buyer" . $i . "@example.org", $card->uri);
print '.';
}
print "\n";
$cards = $marketplace->cards;
print $cards->total() . " cards in Marketplace\n";
foreach ($cards as $c) {
print "card " . $c->uri . "\n";
}
# let's iterate through cards for just a single account
foreach ($buyer->cards as $c) {
print "buyer's card " . $c->uri . "\n";
}
print "and there you have it :)\n";
?>