function cclite_contents() { $params = get_gateway_variables(); $user = $params['user']; $registry = $params['registry']; $arg_list = func_get_args(); $numargs = count($arg_list); $block_content = ''; $cclite_operation = ''; // debug arguments passed $stuff = "|" . implode("-", $arg_list) . "|"; // construct the payment url from configuration information $cclite_base_url = 'http://' . $params['domain']; $ch = curl_init(); // try and logon to cclite, return emptyhanded, if nothing... $logon_result = cclite_remote_logon(); if (strlen($logon_result[1])) { curl_setopt($ch, CURLOPT_COOKIE, $logon_result[1]); } else { return; } // log_debug("logon result 1", $logon_result[1]); curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE); curl_setopt($ch, CURLOPT_FAILONERROR, FALSE); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_FRESH_CONNECT, FALSE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); // this switch statement needs to map to the Rewrites in the cclite .htaccess file, so if you're // doing something custom-made, you need to think about: // -here-, .htaccess and various bits of login in the cclite motor switch ($arg_list[0]) { case 'recent': // $block_content = "case recent transactions : $arg_list[0]/$arg_list[1]" ; curl_setopt($ch, CURLOPT_URL, "{$cclite_base_url}/recent/transactions"); break; case 'summary': // $block_content = "case summary : $arg_list[0] $arg_list[1]/$arg_list[2]/$arg_list[3]/$arg_list[4]/$arg_list[5]" ; curl_setopt($ch, CURLOPT_URL, "{$cclite_base_url}/summary"); break; case 'block': // $block_content = "case summary : $arg_list[0] $arg_list[1]/$arg_list[2]/$arg_list[3]/$arg_list[4]/$arg_list[5]" ; curl_setopt($ch, CURLOPT_URL, "{$cclite_base_url}/summary"); break; case 'pay': if (!user_access('make payments')) { return "{$username} not authorised to make payments"; } // pay/test1/dalston/23/hack(s) using the merchant key // accept plural or singular version of currency name $pattern = '/(\\S+)s/i'; $replacement = '${1}'; $arg_list[4] = preg_replace($pattern, $replacement, $arg_list[4]); // $block_content = "case pay : $cclite_base_url/$arg_list[0]/$arg_list[1]/$arg_list[2]/$arg_list[3]/$arg_list[4]" ; curl_setopt($ch, CURLOPT_URL, "{$cclite_base_url}/pay/{$arg_list['1']}/{$arg_list['2']}/{$arg_list['3']}/{$arg_list['4']}"); break; case 'adduser': // direct/adduser/dalston/test1/email using the merchant key, without using individual logon $block_content = "case adduser : {$stuff}/{$key}"; // log_debug("in adduser ", "$cclite_base_url/direct/adduser/$arg_list[1]/$arg_list[2]/$arg_list[3]"); curl_setopt($ch, CURLOPT_URL, "{$cclite_base_url}/direct/adduser/{$arg_list['1']}/{$arg_list['2']}/{$arg_list['3']}"); break; case 'modifyuser': // direct/modifyuser/dalston/test1/email using the merchant key, without using individual logon // non-working at present... $block_content = "case modifyuser : {$stuff}/{$key}"; // log_debug("in modifyuser ", "$cclite_base_url/direct/modifyuser/$arg_list[1]/$arg_list[2]/$arg_list[3]"); curl_setopt($ch, CURLOPT_URL, "{$cclite_base_url}/direct/modifyuser/{$arg_list['1']}/{$arg_list['2']}/{$arg_list['3']}"); break; // nothing to display in // elgg specific show summary in spotlight // nothing to display in // elgg specific show summary in spotlight default: curl_setopt($ch, CURLOPT_URL, "{$cclite_base_url}/summary"); } $block_content = curl_exec($ch); curl_close($ch); return $block_content; }
function cclite_contents($input) { $params = get_gateway_variables(); $user = $params['user']; $registry = $params['registry']; $limit = $params['limit']; $block_content = ''; $cclite_operation = ''; $logon_result = ''; $url = ''; $ch = curl_init(); // try and logon to cclite, return emptyhanded, if nothing... if ($input[0] != 'adduser') { $logon_result = cclite_remote_logon(); if (strlen($logon_result[1])) { curl_setopt($ch, CURLOPT_COOKIE, $logon_result[1]); } else { // no need for logon to add user... return; } } // construct the payment url from configuration information $cclite_base_url = $params['protocol'] . "://" . $params['domain']; curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE); curl_setopt($ch, CURLOPT_FAILONERROR, FALSE); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_FRESH_CONNECT, FALSE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_POST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); // switch REST url depending on required cclite operation switch ($input[0]) { case 'recent': // $block_content = "case recent transactions : $input[0]/$input[1]" ; $url = "{$cclite_base_url}/recent/transactions/{$limit}"; curl_setopt($ch, CURLOPT_URL, $url); break; case 'recent.json': // $block_content = "case recent transactions : $input[0]/$input[1]" ; // recent transactions delivered as json format, will need post-processing.... $url = "{$cclite_base_url}/recent/transactions.json"; curl_setopt($ch, CURLOPT_URL, $url); break; case 'summary': // $block_content = "case summary : $input[0] $input[1]/$input[2]/$input[3]/$input[4]/$input[5]" ; $url = "{$cclite_base_url}/summary"; curl_setopt($ch, CURLOPT_URL, $url); break; case 'summary.json': // $block_content = "case summary : $input[0] $input[1]/$input[2]/$input[3]/$input[4]/$input[5]" ; $url = "{$cclite_base_url}/summary.json"; curl_setopt($ch, CURLOPT_URL, $url); break; case 'block': // $block_content = "case summary : $input[0] $input[1]/$input[2]/$input[3]/$input[4]/$input[5]" ; // note 'block' is a Drupal thing... $url = "{$cclite_base_url}/recent/transactions/{$limit}"; curl_setopt($ch, CURLOPT_URL, $url); break; case 'pay': // pay/test1/dalston/23/hack(s) using the merchant key // accept plural or singular version of currency name $pattern = '/(\\S+)s/i'; $replacement = '${1}'; $input[3] = preg_replace($pattern, $replacement, $input[3]); // $block_content = "case pay : $cclite_base_url/$input[0]/$input[1]/$input[2]/$input[3]/$input[4]" ; $url = "{$cclite_base_url}/pay/{$input['1']}/{$registry}/{$input['2']}/{$input['3']}"; // echo "pay url is $url" ; curl_setopt($ch, CURLOPT_URL, $url); break; case 'direct': // direct/adduser/dalston/test1/bogus@bogus.net using the merchant key, without using individual logon // non-working direct modify user if ($input[1] == 'adduser') { $url = "{$cclite_base_url}/direct/adduser/{$registry}/{$input['2']}/{$input['3']}"; curl_setopt($ch, CURLOPT_URL, $url); } elseif ($input[1] == 'modifyuser') { // non-working currently // $url = "$cclite_base_url/direct/adduser/$registry/$input[2]/$input[3]" ; // curl_setopt($ch, CURLOPT_URL, $url ); } break; case 'modifyuser': // direct/modifyuser/dalston/test1/email using the merchant key, without using individual logon // non-working at present... $block_content = "case modifyuser : {$stuff}/{$key}"; $url = "{$cclite_base_url}/direct/modifyuser/{$input['1']}/{$input['2']}/{$input['3']}"; curl_setopt($ch, CURLOPT_URL, $url); break; // nothing to display in // elgg specific show summary in spotlight, probably should return 'nothing' // nothing to display in // elgg specific show summary in spotlight, probably should return 'nothing' default: curl_setopt($ch, CURLOPT_URL, "{$cclite_base_url}/summary"); } $block_content = curl_exec($ch); // this version now logs off, gateway is 'transactional' and stateless doesn't stay connected... curl_setopt($ch, CURLOPT_URL, "{$cclite_base_url}/logoff"); $logoff = curl_exec($ch); curl_close($ch); // modify this at will to debug... if ($params['verbose']) { return "u:{$url}\n b:{$block_content} \n l:{$logoff}"; } else { return $block_content; } }