Skip to content

Instantly share code, notes, and snippets.

@ajslaghu
Created June 12, 2014 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajslaghu/a5022f286ae71441dc54 to your computer and use it in GitHub Desktop.
Save ajslaghu/a5022f286ae71441dc54 to your computer and use it in GitHub Desktop.
Open Bank Project Example on parsing transaction data
<?php
define('DS', DIRECTORY_SEPARATOR);
$offset = 0;
$limit = 100;
$path = 'banking' . DS;
$url = 'https://api.openbankproject.com/obp/v1.2.1/banks/postbank/accounts/tesobe/public/transactions';
$gross_amount=0;
@mkdir($path);
while (true) {
$opts = array('http' => array('method' => "GET",
'header' => "obp_limit: $limit\r\n" . "obp_offset: $offset\r\n"));
$cache_fp = $path . md5($url) . "-$limit-$offset";
//echo $cache_fp . "\n";
if (!file_exists($cache_fp)) {
echo "Retrieving data from the web\n";
$file = file_get_contents($url, false, stream_context_create($opts));
file_put_contents($cache_fp, $file);
} else {
//echo "Retrieving data from cache\n";
$file = file_get_contents($cache_fp);
}
$data = json_decode($file);
foreach ($data->transactions as $item) {
print($item->details->completed . "\t");
print($item->other_account->holder->name . "\t");
print($item->details->value->amount . "\t");
$gross_amount +=$item->details->value->amount;
print($item->details->value->currency . "\t");
print("\n");
}
if (count($data->transactions) < $limit) {
break;
} else {
$offset+=$limit;
}
}
print("$gross_amount \n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment