Esempio n. 1
0
function gocardless_admin_dashboard()
{
    global $gocardless_config;
    global $gocardless_limit;
    // Grab timestamp for measuring API data load time
    $start_time = microtime(true);
    // Fetch subscriptions
    try {
        $raw_subscriptions = GoCardless_Merchant::find($gocardless_config['merchant_id'])->subscriptions();
    } catch (GoCardless_ApiException $e) {
        // Do something here (display error notice)
        $raw_subscriptions = null;
    }
    if (count($raw_subscriptions) > 0) {
        // Sort subscriptions, most recent first
        $index = array();
        foreach ($raw_subscriptions as $key => $value) {
            $index[$key] = $value->created_at;
        }
        arsort($index);
        $subscriptions = array();
        foreach ($index as $key => $value) {
            $subscriptions[$raw_subscriptions[$key]->id] = $raw_subscriptions[$key];
        }
        // End sorting
        // Fetch bills
        $raw_bills = GoCardless_Merchant::find($gocardless_config['merchant_id'])->bills();
        // Add bill count to each subscription
        foreach ($raw_bills as $key => $value) {
            if (is_object($subscriptions[$value->source_id])) {
                $subscriptions[$value->source_id]->bill_count++;
            }
        }
        // Fetch user list
        $user_list = GoCardless_Merchant::find($gocardless_config['merchant_id'])->users();
        // Fetch individual user as index function doesn't contain full info
        $users = array();
        foreach ($user_list as $key => $value) {
            $users[$value->id] = GoCardless_User::find($value->id);
        }
        // Add user object to subscriptions
        foreach ($subscriptions as $key => $value) {
            $subscriptions[$key]->user = $users[$value->user_id];
        }
        // Load dashboard view, requires $subscriptions
        include 'view_dashboard.php';
        // Show API data load time
        $finish_time = microtime(true);
        $total_time = round($finish_time - $start_time, 2);
        echo '<p class="description">Data fetched in ' . $total_time . ' seconds.</p>';
    }
}
Esempio n. 2
0
 /**
  * Get a specific user
  *
  * @param string $id The id of the user to fetch
  *
  * @return object The user object matching the id requested
  */
 public function user($id)
 {
     return GoCardless_User::find_with_client($this, $id);
 }
Esempio n. 3
0
 /**
  * Get a specific user
  *
  * @param string $id The id of the user to fetch
  *
  * @return object The user object matching the id requested
  */
 public function user($id)
 {
     if (!isset($this->account_details['access_token'])) {
         throw new GoCardless_ClientException('Access token missing');
     }
     return GoCardless_User::find_with_client($this, $id);
 }