Skip to content

Instantly share code, notes, and snippets.

@nimid
Last active September 20, 2016 07:42
Show Gist options
  • Save nimid/fe24e1eb076b10ae25e201954745db8d to your computer and use it in GitHub Desktop.
Save nimid/fe24e1eb076b10ae25e201954745db8d to your computer and use it in GitHub Desktop.
<?php
// how to run:
// php download_disputes.php
// Works on Mac OS X
// It will generate (and overwrite) a csv file with name disputes.csv
// Update your valid Live Secret Key, this is only a test key:
$skey = 'skey_';
// Output file name
$filename = './disputes.csv';
// Dates to retrieve data
$from = '2016-01-01';
$to = '2016-12-31';
// Miximum limit for API is 100 records
$limit = '100';
$response = shell_exec("curl -s https://api.omise.co/disputes -X GET -u $skey: -d 'from=$from' -d 'to=$to' -d 'offset=0' -d 'limit=$limit'");
$disputes = json_decode($response, true);
if ($disputes['object'] === 'error') {
echo $disputes['code'] . ', ' . $disputes['message'];
die();
}
if ($disputes['total'] === 0) {
echo 'No data found';
}
$csv_header = array(
'id',
'amount',
'currency',
'status',
'transaction',
'message',
'reason_code',
'reason_message',
'charge',
'created',
);
$file = fopen($filename, 'w');
fputcsv($file, $csv_header);
foreach ($disputes['data'] as $dispute) {
unset($dispute['object']);
unset($dispute['livemode']);
unset($dispute['location']);
fputcsv($file, $dispute);
}
fclose($file);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment