Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102131478
events-and-callbacks.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
Mon, Feb 17, 10:04
Size
1 KB
Mime Type
text/x-php
Expires
Wed, Feb 19, 10:04 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
24289243
Attached To
rPH Phabricator
events-and-callbacks.php
View Options
<?php
/*
* Welcome weary traveller. Sick of polling for state changes? Well today have
* I got good news for you. Run this example below to see how to get yourself
* some callback goodness and to understand how events work.
*/
require
(
__DIR__
.
"/vendor/autoload.php"
);
Httpful\Bootstrap
::
init
();
RESTful\Bootstrap
::
init
();
Balanced\Bootstrap
::
init
();
// create a new marketplace
$key
=
new
Balanced\APIKey
();
$key
->
save
();
Balanced\Settings
::
$api_key
=
$key
->
secret
;
$marketplace
=
new
Balanced\Marketplace
();
$marketplace
->
save
();
// let"s 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"
;
printf
(
"let's create a callback
\n
"
);
$marketplace
->
createCallback
(
$callback_url
);
printf
(
"let's create a card and associate it with a new account
\n
"
);
$card
=
$marketplace
->
cards
->
create
(
array
(
"card_number"
=>
"5105105105105100"
,
"expiration_month"
=>
"12"
,
"expiration_year"
=>
"2015"
));
$buyer
=
$marketplace
->
createBuyer
(
"buyer@example.org"
,
$card
->
uri
);
printf
(
"generate a debit (which implicitly creates and captures a hold)
\n
"
);
$buyer
->
debit
(
100
);
foreach
(
$marketplace
->
events
as
$event
)
{
printf
(
"this was a %s event, it occurred at %s
\n
"
,
$event
->
type
,
$event
->
occurred_at
);
}
printf
(
"ok, let's check with requestb.in to see if our callbacks fired at %s
\n
"
,
$callback_url
);
printf
(
"we received callbacks, you can view them at http://requestb.in/%s?inspect
\n
"
,
$bin_name
);
?>
Event Timeline
Log In to Comment