Last active
September 20, 2016 07:42
-
-
Save nimid/fe24e1eb076b10ae25e201954745db8d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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