public function getSubscriptionFirstBill($id) { $bills = \GoCardless_Merchant::find($this->account_details['merchant_id'])->bills(array('source_id' => $id)); if (count($bills) > 0) { return $bills[0]; } return false; }
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>'; } }
public function gocardless_test() { if (ENVIRONMENT !== 'development') { show_404(); } //get going with Go Cardless require_once APPPATH . '/third_party/GoCardless.php'; GoCardless::$environment = config_item('gocardless_environment'); GoCardless::set_account_details(config_item('gocardless_account')); header('Content-Type: text/plain'); var_dump(GoCardless_Merchant::find($this->config->item('merchant_id', 'gocardless_account'))); exit; }
$pre_auth_url = GoCardless::new_pre_authorization_url($payment_details); echo ' · <a href="' . $pre_auth_url . '">New pre-authorized payment</a>'; // New bill $payment_details = array('amount' => '30.00', 'name' => 'Donation', 'user' => array('first_name' => 'Tom', 'last_name' => 'Blomfield', 'email' => '*****@*****.**')); $bill_url = GoCardless::new_bill_url($payment_details); echo ' · <a href="' . $bill_url . '">New bill</a></p>'; echo 'NB. The \'new bill\' link is also a demo of pre-populated user data'; echo '<h2>API calls</h2>'; echo 'GoCardless_Merchant::find(\'258584\')'; echo '<blockquote><pre>'; $merchant = GoCardless_Merchant::find('258584'); print_r($merchant); echo '</pre></blockquote>'; echo 'GoCardless_Merchant::find(\'258584\')->pre_authorizations()'; echo '<blockquote><pre>'; $preauths = GoCardless_Merchant::find('258584')->pre_authorizations(); print_r($preauths); echo '</pre></blockquote>'; echo 'GoCardless_PreAuthorization::find(\'992869\')->create_bill($bill_details)'; echo '<blockquote><pre>'; $pre_auth = GoCardless_PreAuthorization::find('013M018V0K'); $bill_details = array('amount' => '15.00'); $bill = $pre_auth->create_bill($bill_details); print_r($bill); echo '</pre></blockquote>'; echo 'validate webhook:'; echo '<blockquote><pre>'; $webhook_json = '{"payload":{"bills":[{"id":"880807"},{"status":"pending"},{"source_type":"subscription"},{"source_id":"21"},{"uri":"https:\\/\\/sandbox.gocardless.com\\/api\\/v1\\/bills\\/880807"}],"action":"created","resource_type":"bill","signature":"f25a611fb9afbc272ab369ead52109edd8a88cbb29a3a00903ffbce0ec6be5cb"}}'; $webhook = json_decode($webhook_json, true); var_dump(GoCardless::validate_webhook($webhook['payload'])); echo '</pre></blockquote>';