Exemplo n.º 1
0
/**
 * Checks whether test mode is enabled or disabled
 * and sets appropriate details against GoCardless object
 * @param array $params Array of parameters that contains gateway details
 */
function gocardless_set_account_details($params = null)
{
    # check if params have been supplied, if not attempt
    # to use global params
    if (is_null($params)) {
        unset($params);
        global $params;
    }
    global $CONFIG;
    # check we have been able to obtain the correct params
    if (!isset($params['app_id'])) {
        throw new Exception('Could not get GoCardless params');
    }
    if (!empty($CONFIG['SystemSSLURL']) && $CONFIG['SystemSSLURL'] != "") {
        $systemUrl = $CONFIG['SystemSSLURL'];
    } else {
        $systemUrl = $CONFIG['SystemURL'];
    }
    # check if we are running in Sandbox mode (test_mode)
    if ($params['test_mode'] == 'on') {
        # Initialise SANDBOX Account Details
        GoCardless::$environment = 'sandbox';
        GoCardless::set_account_details(array('app_id' => $params['dev_app_id'], 'app_secret' => $params['dev_app_secret'], 'merchant_id' => $params['dev_merchant_id'], 'access_token' => $params['dev_access_token'], 'redirect_uri' => $systemUrl . '/modules/gateways/gocardless/redirect.php', 'ua_tag' => 'gocardless-whmcs/v' . GC_VERSION));
    } else {
        # Initialise LIVE Account Details
        GoCardless::$environment = 'production';
        GoCardless::set_account_details(array('app_id' => $params['app_id'], 'app_secret' => $params['app_secret'], 'merchant_id' => $params['merchant_id'], 'access_token' => $params['access_token'], 'redirect_uri' => $systemUrl . '/modules/gateways/gocardless/redirect.php', 'ua_tag' => 'gocardless-whmcs/v' . GC_VERSION));
    }
}
 public function setup()
 {
     $this->account_details = array('app_id' => env('GOCARDLESS_APP_ID', ''), 'app_secret' => env('GOCARDLESS_APP_SECRET', ''), 'merchant_id' => env('GOCARDLESS_MERCHANT_ID', ''), 'access_token' => env('GOCARDLESS_ACCESS_TOKEN', ''));
     // Initialize GoCardless
     if (\App::environment() == 'production') {
         \GoCardless::$environment = 'production';
     }
     \GoCardless::set_account_details($this->account_details);
 }
Exemplo n.º 3
0
function gocardless_init()
{
    define('GC_WP_VERSION', '0.1.1');
    global $gocardless_config;
    global $gocardless_limit;
    $gocardless_config = get_option('gocardless_config');
    $gocardless_limit = get_option('gocardless_limit');
    if (is_array($gocardless_limit)) {
        $gocardless_limit = array_map('stripslashes', $gocardless_limit);
    }
    // Check to see if already instantiated
    if (!class_exists('GoCardless') && isset($gocardless_config['app_id']) && isset($gocardless_config['app_secret']) && isset($gocardless_config['merchant_id']) && isset($gocardless_config['access_token'])) {
        // Include GoCardless PHP library
        require_once dirname(__FILE__) . '/lib/GoCardless.php';
        // Sandbox mode? Defaults to production
        if ($gocardless_config['sandbox']) {
            GoCardless::$environment = 'sandbox';
        }
        // Initialize library
        GoCardless::set_account_details(array('app_id' => $gocardless_config['app_id'], 'app_secret' => $gocardless_config['app_secret'], 'merchant_id' => $gocardless_config['merchant_id'], 'access_token' => $gocardless_config['access_token'], 'ua_tag' => 'gocardless-wp/v' . GC_WP_VERSION));
    }
}
 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');
         }
     }
 }
Exemplo n.º 5
0
<?php

// First create your application in the GoCardless sandbox:
// https://sandbox.gocardless.com
// Then grab your application id and secret and paste them in below
// You'll also need to to change the various ids throughout this demo
// 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');
 function doTransferCheckout(&$params, $component)
 {
     $paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(false, null, 'name');
     $paymentProcessorTypeId = CRM_Utils_Array::key('Gocardless', $paymentProcessorType);
     $domainID = CRM_Core_Config::domainID();
     $sql = " SELECT user_name ";
     $sql .= " ,      password ";
     $sql .= " ,      signature ";
     $sql .= " ,      subject ";
     $sql .= " FROM civicrm_payment_processor ";
     $sql .= " WHERE payment_processor_type_id = %1 ";
     $sql .= " AND is_test= %2 ";
     $sql .= " AND domain_id = %3 ";
     $isTest = 0;
     if ($this->_mode == 'test') {
         $isTest = 1;
     }
     $sql_params = array(1 => array($paymentProcessorTypeId, 'Integer'), 2 => array($isTest, 'Int'), 3 => array($domainID, 'Int'));
     $dao = CRM_Core_DAO::executeQuery($sql, $sql_params);
     if ($dao->fetch()) {
         $app_id = $dao->user_name;
         $app_secret = $dao->password;
         $merchant_id = $dao->signature;
         $access_token = $dao->subject;
     }
     $account_details = array('app_id' => $app_id, 'app_secret' => $app_secret, 'merchant_id' => $merchant_id, 'access_token' => $access_token);
     // Fail nicely if no account details set
     if (!$account_details['app_id'] && !$account_details['app_secret']) {
         echo '<p>First sign up to <a href="http://gocardless.com">GoCardless</a> and
     copy your sandbox API credentials from the \'Developer\' tab into the top of
     this script.</p>';
         exit;
     }
     // Set $environment to 'production' if live. Default is 'sandbox'
     if ($this->_mode == 'live') {
         GoCardless::$environment = 'production';
     }
     // Initialize GoCardless
     GoCardless::set_account_details($account_details);
     $goCardLessParams = array();
     $goCardLessParams['amount'] = $params['amount'];
     $goCardLessParams['interval_length'] = $params['frequency_interval'];
     $goCardLessParams['interval_unit'] = $params['frequency_unit'];
     if (!empty($params['preferred_collection_day'])) {
         $preferredCollectionDay = $params['preferred_collection_day'];
         $collectionDate = UK_Direct_Debit_Form_Main::firstCollectionDate($preferredCollectionDay, null);
         // ISO8601 format.
         $goCardLessParams['start_at'] = $collectionDate->format('c');
     }
     $url = $component == 'event' ? 'civicrm/event/register' : 'civicrm/contribute/transact';
     $cancel = $component == 'event' ? '_qf_Register_display' : '_qf_Main_display';
     $returnURL = CRM_Utils_System::url($url, "_qf_ThankYou_display=1&qfKey={$params['qfKey']}" . "&cid={$params['contactID']}", true, null, false);
     $goCardLessParams['redirect_uri'] = $returnURL;
     $goCardLessParams['user'] = array('email' => isset($params['email-5']) ? $params['email-5'] : NULL, 'first_name' => isset($params['first_name']) ? $params['first_name'] : NULL, 'last_name' => isset($params['last_name']) ? $params['last_name'] : NULL, 'billing_address1' => isset($params['street_address']) ? $params['street_address'] : NULL, 'billing_town' => isset($params['city']) ? $params['city'] : NULL, 'billing_postcode' => isset($params['postal_code']) ? $params['postal_code'] : NULL, 'country_code' => 'GB');
     // Allow further manipulation of the arguments via custom hooks ..
     CRM_Utils_Hook::alterPaymentProcessorParams($this, $params, $goCardLessParams);
     $subscription_url = GoCardless::new_subscription_url($goCardLessParams);
     CRM_Utils_System::redirect($subscription_url);
 }
 /**
  * Tries to auto pay a bill with Go Cardless, o e-mails the user, and updates the bill status as relevant
  *
  * @author GM
  * @param $b_id	int	the id of the bill
  * @param $u_id	int	the id of the user that needs to pay
  * @param $b_price	float	the price of the bill that we want to debit from them
  */
 public function make_bill_due_and_pay($b_id, $u_id, $b_price)
 {
     //error avoidance
     if ($b_price <= 0) {
         return array('success' => FALSE, 'description' => 'Amount due must be positive, Bill #' . $b_id . ' not marked as due.');
     }
     //have they authorised Go Cardless in the past?
     $pre_auth_id = $this->gc_get_preauth_id($u_id);
     if (!$pre_auth_id) {
         //set bill as due, e-mail them asking to pay
         $result = $this->change_bill_status($b_id, "Pending");
         if ($result) {
             //email them about it
             $this->load->model('users_model');
             $member = $this->users_model->get_user($u_id);
             $subject = config_item('site_name') . ' Payment is due. ';
             $message = '<p>Hello ' . $member['u_title'] . ' ' . $member['u_fname'] . ' ' . $member['u_sname'] . ',</p>';
             $message .= '<p>Bill #' . $b_id . ', is now ready for you to pay.';
             $message .= '<br />The amount for your recent delivery is <em>&pound;' . $b_price . '</em>.';
             $message .= '<br />You can view details of this bill and pay online at <a href="' . site_url('bill/view/' . $b_id) . '">' . site_url('bill/view/' . $b_id) . '</a>.</p>';
             $message .= '<p>Thank you, <br /> ' . config_item('site_name') . '</p>';
             $eq[] = array('eq_email' => $member['u_email'], 'eq_subject' => $subject, 'eq_body' => $message);
             // load emails queue model
             $this->load->model('emails_queue_model');
             $this->emails_queue_model->set_queue($eq);
             return array('success' => TRUE, 'description' => 'The member has been notified that the bill is due.');
         } else {
             return array('success' => FALSE, 'description' => 'The bill status could not be updated.');
         }
     } else {
         //is Go Cardless working & enough?
         require_once APPPATH . '/third_party/GoCardless.php';
         GoCardless::$environment = config_item('gocardless_environment');
         GoCardless::set_account_details(config_item('gocardless_account'));
         $pre_auth = GoCardless_PreAuthorization::find($pre_auth_id);
         if (isset($pre_auth) && $pre_auth->status == 'active' && $pre_auth->remaining_amount >= $b_price) {
             //try paying it
             $bill_details = array('name' => 'Bill #' . $b_id, 'amount' => $b_price);
             $gc_bill = $pre_auth->create_bill($bill_details);
             if ($gc_bill) {
                 //mark it as paid
                 $result = $this->mark_bill_paid($b_id, 'Go Cardless Pre-Auth');
                 if (!$result) {
                     return array('success' => FALSE, 'description' => 'Bill ' . $b_id . ' was paid, but an error caused it not to be marked as such.');
                 } else {
                     return array('success' => TRUE, 'description' => 'The bill was paid through Go Cardless pre-authorisation.');
                 }
             }
         }
         //set bill as due, e-mail them asking to pay, because GC couldn't be used (or was not enough)
         $result = $this->change_bill_status($b_id, "Pending");
         if ($result) {
             //email them about it
             $this->load->model('users_model');
             $member = $this->users_model->get_user($u_id);
             $subject = config_item('site_name') . ' Payment is due. ';
             $message = '<p>Hello ' . $member['u_title'] . ' ' . $member['u_fname'] . ' ' . $member['u_sname'] . ',</p>';
             $message .= '<p>Bill #' . $b_id . ', is now ready for you to pay.';
             $message .= '<br />The amount for your recent delivery is <em>&pound;' . $b_price . '</em>.';
             $message .= '<br />On this occasion, we were unable to debit the amount from your bank through the Go Cardless system.';
             $message .= '<br />You can view details of this bill and pay online at <a href="' . site_url('bill/view/' . $b_id) . '">' . site_url('bill/view/' . $b_id) . '</a>.</p>';
             $message .= '<p>Thank you, <br /> ' . config_item('site_name') . '</p>';
             $eq[] = array('eq_email' => $member['u_email'], 'eq_subject' => $subject, 'eq_body' => $message);
             // load emails queue model
             $this->load->model('emails_queue_model');
             $this->emails_queue_model->set_queue($eq);
             return array('success' => TRUE, 'description' => 'The member has been notified that the bill is due.');
         } else {
             return array('success' => FALSE, 'description' => 'The bill status could not be updated.');
         }
     }
 }
Exemplo n.º 8
0
require_once "{$root}/user.php";
require_once "{$root}/transaction.php";
require_once "{$root}/card.php";
require_once "{$root}/usersprofile.php";
require_once "{$root}/learning.php";
require_once "{$root}/alias.php";
require_once "{$root}/interest.php";
require_once "{$root}/calendar.php";
require_once "{$root}/project.php";
require_once "{$root}/gocardless-php/lib/GoCardless.php";
$db = new fDatabase('postgresql', $DB_NAME, $DB_USER, $DB_PASSWORD);
fORMDatabase::attach($db);
fSession::setLength('30 minutes', '10 weeks');
fSession::setPath(dirname(__FILE__) . '/../var/session');
if (isset($GOCARDLESS_CREDENTIALS)) {
    GoCardless::set_account_details($GOCARDLESS_CREDENTIALS);
}
if ($uid = fSession::get('user')) {
    $user = new User($uid);
} else {
    $user = null;
}
function ensureLogin()
{
    global $user;
    if (!isset($user)) {
        fURL::redirect("/login.php?forward={$_SERVER['REQUEST_URI']}");
    }
}
function ensureMember()
{
Exemplo n.º 9
-1
 /**
  * Caller Magic Method
  *
  * @param	string
  * @param	array
  * @return	object
  */
 public function __call($method, $params)
 {
     GoCardless::$environment = $this->_config['mode'] == 'test' ? 'sandbox' : 'production';
     $account_details = array('app_id' => $this->_config['app_identifier'], 'app_secret' => $this->_config['app_secret'], 'merchant_id' => $this->_config['id'], 'access_token' => $this->_config['access_token']);
     GoCardless::set_account_details($account_details);
     $args = $params[0];
     $this->_lib_method = $method;
     list($api, $api_method, $params_ready) = $this->_build_request($args);
     try {
         $raw = $api::$api_method($params_ready);
         return $this->_parse_response($raw);
     } catch (Exception $e) {
         return Payment_Response::instance()->gateway_response('failure', $method . '_gateway_failure', $e->getMessage());
     }
 }