Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92758857
iterate-example.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Nov 23, 11:56
Size
1 KB
Mime Type
text/x-php
Expires
Mon, Nov 25, 11:56 (2 d)
Engine
blob
Format
Raw Data
Handle
22493043
Attached To
rPH Phabricator
iterate-example.php
View Options
<?
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
"
;
?>
Event Timeline
Log In to Comment