function gocardless_shortcode($attrs) { global $gocardless_config; global $gocardless_limit; // Load GoCardless gocardless_init(); // Create $payment_details array $payment_details = array(); // Array of expected vars $expected_vars = array('name', 'description', 'amount', 'interval_length', 'interval_unit', 'calendar_intervals'); // Loop through expected vars, setting $payment_details foreach ($expected_vars as $key) { // Only set $payment_details if value is not null if ($gocardless_limit['limit_' . $key] != null) { $payment_details[$key] = $gocardless_limit['limit_' . $key]; } } // Uncomment the following to inspect the payment vars //echo '<pre>'; //print_r($payment_details); //echo '</pre>'; // Generate paylink $paylink = GoCardless::new_subscription_url($payment_details); if ($attrs['url']) { // Return raw url return $paylink; } else { // Return link w/text if (isset($payment_details['name'])) { // Use the link name if available $link_text = $payment_details['name']; } else { // Otherwise show default text $link_text = 'New subscription'; } return '<a href="' . $paylink . '">' . $link_text . '</a>'; } }
/** * Generate a URL to give a user to create a new subscription * * @param array $params Parameters to use to generate the URL * * @return string The generated URL */ public static function new_subscription_url($params) { return GoCardless::$client->new_subscription_url($params); }
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); }
// 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>'; 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);
public function newSubUrl($payment_details) { return \GoCardless::new_subscription_url($payment_details); }