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); }