omise PHP get all charges

699 Views Asked by At

Omise PHP get all charges ref : https://www.omise.co/charges-api

$charges = OmiseCharge::retrieve();

this code gives me 20 records which is okay.

$response = OmiseCharge::retrieve('',OMISE_PUBLIC_KEY,OMISE_SECRET_KEY);

this also gives me first 20 records.

but my requirement is fetch all charges with date params.

$param = array(

            'from' => '2014-10-20 00:00:00',
            'to' => '2014-09-25 00:00:00'
        );
    $response = OmiseCharge::retrieve($param);

this gives an error.

Fatal error: Uncaught exception 'OmiseNotFoundException' with message 'charge Array was not found' 

what i am doing wrong.

3

There are 3 best solutions below

0
On BEST ANSWER
$param = array(
            'from' => '2011-10-20 00:00:00',
            'to' => '2016-09-25 00:00:00'
        );
        $response = OmiseCharge::retrieve('?'.http_build_query($param));

worked for me.

0
On

currently Omise-PHP library doesn't support for passing array at the first parameter.

(As your solution) you have to pass it as string (including other filters, such as 'limit', 'offset').

$param = array(
    'limit'  => 40,
    'offset' => 40,
    'from'   => '2011-10-20 00:00:00',
    'to'     => '2016-09-25 00:00:00'
);

$charges = OmiseCharge::retrieve('?'.http_build_query($param));
0
On

I don't know this library but after quick search some tips: First of all (if you not already done this) read this doc about pagination.

  1. I found that date has different format: iso8601 what means for ex 2014-10-20T00:00:00Z.
  2. limit to 20 records you can change to 100, try to use pagination

BTW. Interesting API.