function gocardless_confirm() { if (isset($_GET['resource_id']) && isset($_GET['resource_type'])) { // Get vars found so confirm payment // Load GoCardless gocardless_init(); // Params for confirming the resource $confirm_params = array('resource_id' => $_GET['resource_id'], 'resource_type' => $_GET['resource_type'], 'resource_uri' => $_GET['resource_uri'], 'signature' => $_GET['signature']); // State is optional if (isset($_GET['state'])) { $confirm_params['state'] = $_GET['state']; } // Confirm the resource $confirmed_resource = GoCardless::confirm_resource($confirm_params); } }
public function gocardless_complete() { $flash_success = $this->session->flashdata(__FUNCTION__ . '_success'); if ($flash_success) { $this->session->keep_flashdata('notice'); return redirect('order'); } //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')); //we've come back from Go Cardless //finalize the process $confirm_params = array('resource_uri' => $this->input->get('resource_uri'), 'resource_id' => $this->input->get('resource_id'), 'resource_type' => $this->input->get('resource_type'), 'signature' => $this->input->get('signature'), 'state' => $this->input->get('state')); // Returns the confirmed resource if successful, otherwise throws an exception $confirm_result = GoCardless::confirm_resource($confirm_params); if (!$confirm_result) { $this->flash->set('error', 'There was an error processing with Go Cardless.', TRUE); return redirect('bill/view/' . $this->input->get('state')); } //check what to do now //var_export($this->input->get()); die(); if ($this->input->get('resource_type') == 'bill') { //a single bill was paid, update it $this->load->model('order_model'); $result = $this->order_model->mark_bill_paid($this->input->get('state'), 'Go Cardless'); //send the user on if (!$result) { $this->flash->set('error', 'The payment was taken, but an error occured updating the bill. Please contact website staff.', TRUE); } else { $this->flash->set(__FUNCTION__ . '_success', TRUE, TRUE); $this->flash->set('notice', 'Thank you for paying with Go Cardless.', TRUE); } return redirect('order'); } else { if ($this->input->get('resource_type') == 'pre_authorization') { //Go Cardless is authorized to take payments. //make a note $this->load->model('order_model'); $this->order_model->gc_save_preauth_id($this->session->userdata('u_id'), $this->input->get('resource_id')); //Pay a bill we were on? if (is_numeric($this->input->get('state')) && $this->input->get('state') > 0) { //get the bill to pay. $this->load->model('order_model'); $bill = $this->order_model->get_bill($this->input->get('state')); if (isset($bill)) { //pay the bill we were on... $pre_auth = GoCardless_PreAuthorization::find($this->input->get('resource_id')); $gc_bill = $pre_auth->create_bill(array('name' => 'Bill #' . $bill['b_id'], 'amount' => $bill['b_price'])); } //send the user on if (!$gc_bill) { $this->flash->set('error', 'Go Cardless was authorised for futue payments, but an error occured paying this bill.', TRUE); } else { //after authorizing bill was paid, update it $this->load->model('order_model'); $result = $this->order_model->mark_bill_paid($this->input->get('state'), 'Go Cardless'); //send the user on if (!$result) { $this->flash->set('error', 'Payment was taken, but an error occured updating the bill. Please contact website staff.', TRUE); } else { $this->flash->set('notice', 'Thank you for paying with Go Cardless. Future payments will be made automatically.', TRUE); } } return redirect('order'); } else { $this->flash->set('success', 'Go Cardless has been set up for future bills.', TRUE); return redirect('order'); //send them where? } } else { $this->flash->set('error', 'Payment process not recognised.', TRUE); return redirect('order'); } } }
/** * Generate a URL to give a user to create a new bill * * @param array $params Parameters to use to generate the URL * * @return string The generated URL */ public static function confirm_resource($params) { return GoCardless::$client->confirm_resource($params); }
// Include library include_once '../lib/gocardless.php'; // Sandbox GoCardless::$environment = 'sandbox'; // Config vars $account_details = array('app_id' => null, 'app_secret' => null, 'merchant_id' => null, 'access_token' => null); // Initialize GoCardless GoCardless::set_account_details($account_details); if (isset($_GET['resource_id']) && isset($_GET['resource_type'])) { // Get vars found so let's try confirming payment $confirm_params = array('resource_id' => $_GET['resource_id'], 'resource_type' => $_GET['resource_type'], 'resource_uri' => $_GET['resource_uri'], 'signature' => $_GET['signature']); // State is optional if (isset($_GET['state'])) { $confirm_params['state'] = $_GET['state']; } $confirmed_resource = GoCardless::confirm_resource($confirm_params); echo '<p>Payment confirmed!</p>'; } echo '<h2>New payment URLs</h2>'; // New subscription $payment_details = array('amount' => '10.00', 'interval_length' => 1, 'interval_unit' => 'month'); $subscription_url = GoCardless::new_subscription_url($payment_details); echo '<p><a href="' . $subscription_url . '">New subscription</a>'; // New pre-authorization $payment_details = array('max_amount' => '20.00', 'interval_length' => 1, 'interval_unit' => 'month'); $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>';
require_once $whmcsdir . '/includes/invoicefunctions.php'; require_once $whmcsdir . '/modules/gateways/gocardless.php'; # get gateway params $gateway = getGatewayVariables('gocardless'); # sanity check to ensure module is active if (!$gateway['type']) { die("Module Not Activated"); } # set relevant API information for GoCardless module gocardless_set_account_details($gateway); # if the resource ID and resouce type are set, confirm it using the GoCardless API if (isset($_GET['resource_id']) && isset($_GET['resource_type'])) { # if GoCardless fails to confirm the resource, an exception will be thrown # we will handle the exception gracefully try { $confirmed_resource = GoCardless::confirm_resource(array('resource_id' => $_GET['resource_id'], 'resource_type' => $_GET['resource_type'], 'resource_uri' => $_GET['resource_uri'], 'signature' => $_GET['signature'], 'state' => $_GET['state'])); } catch (Exception $e) { # failed to verify the resource with GoCardless. Log transaction and ouput error message to client logTransaction($gateway['paymentmethod'], 'GoCardless Redirect Failed (Resource not verified) : ' . print_r($_GET, true) . 'Exception: ' . print_r($e, true), 'Unsuccessful'); header('HTTP/1.1 400 Bad Request'); exit('Your request could not be completed'); } } else { # failed to get resource ID and resource type, invalid request. Log transaction and ouput error message to client logTransaction($gateway['paymentmethod'], 'GoCardless Redirect Failed (No data provided) : ' . print_r($_GET, true), 'Unsuccessful'); header('HTTP/1.1 400 Bad Request'); exit('Your request could not be completed'); } # split invoice data into invoiceID and invoiceAmount list($invoiceID) = explode(':', $_GET['state']); # check we have the invoiceID
public function confirmResource($confirm_params) { return \GoCardless::confirm_resource($confirm_params); }