Ejemplo n.º 1
0
function trustcommerce_refund($params)
{
    if (!extension_loaded("tclink")) {
        $extfname = "tclink.so";
        if (!dl($extfname)) {
            $msg = "Please check to make sure the module TCLink is properly built";
            return array("status" => "error", "rawdata" => array("error" => $msg));
        }
    }
    $tc_params = array("action" => "credit");
    $tc_params['custid'] = $params['username'];
    $tc_params['password'] = $params['password'];
    $tc_params['demo'] = $params['testmode'] ? "y" : "n";
    $tc_params['transid'] = $params['transid'];
    $tc_params['amount'] = $params['amount'] * 100;
    $tc_result = tclink_send($tc_params);
    if ($tc_result['status'] == "approved" || $tc_result['status'] == "accepted") {
        $result = array("status" => "success", "transid" => $tc_result['transid'], "rawdata" => $tc_result);
    } else {
        if ($tc_result['status'] == "decline" || $tc_result['status'] == "rejected") {
            $result = array("status" => "declined", "rawdata" => $tc_result);
        } else {
            if ($tc_result['status'] == "baddata") {
                $result = array("status" => "baddata", "rawdata" => $tc_result);
            } else {
                $result = array("status" => "error", "rawdata" => $tc_result);
            }
        }
    }
    return $result;
}
Ejemplo n.º 2
0
 public function process()
 {
     if ($this->test_mode) {
         $this->fields['demo'] = 'y';
     }
     $this->fields['name'] = $this->fields['first_name'] . ' ' . $this->fields['last_name'];
     $this->fields['shipto_name'] = $this->fields['ship_to_first_name'] . ' ' . $this->fields['ship_to_last_name'];
     unset($this->fields['first_name'], $this->fields['last_name'], $this->fields['ship_to_first_name'], $this->fields['ship_to_last_name']);
     // Check for required fields
     if (in_array(FALSE, $this->required_fields)) {
         $fields = array();
         foreach ($this->required_fields as $key => $field) {
             if (!$field) {
                 $fields[] = $key;
             }
         }
         throw new Kohana_Exception('payment.required', implode(', ', $fields));
     }
     $result = tclink_send($this->fields);
     // Report status
     if ($result['status'] == 'approved') {
         return TRUE;
     } elseif ($result['status'] == 'decline') {
         return Kohana::lang('payment.error', 'payment_Trustcommerce.decline.' . $result[$result['status'] . 'type']);
     } else {
         return Kohana::lang('payment.error', Kohana::lang('payment_Trustcommerce.' . $result['status'] . '.' . $result['error']));
     }
 }
Ejemplo n.º 3
0
 /**
  * Process the transaction.
  *
  * @return mixed Payment_Process_Result on success, PEAR_Error on failure
  */
 function &process()
 {
     // Sanity check
     $result = $this->validate();
     if (PEAR::isError($result)) {
         return $result;
     }
     // Prepare the data
     $result = $this->_prepare();
     if (PEAR::isError($result)) {
         return $result;
     }
     // Don't die partway through
     PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
     $fields = $this->_prepareQueryString();
     if (function_exists('tclink_send')) {
         /** USE TCLINK **/
         $result = tclink_send($fields);
         $r_keys = array_keys($result);
         for ($i = 0; $i < sizeof($r_keys); $i++) {
             $key = $r_keys[$i];
             $value = $result[$key];
             $result_string .= $key . '=' . $value . "\n";
         }
         if (PEAR::isError($result_string)) {
             PEAR::popErrorHandling();
             return $result_string;
         } else {
             $result = $result_string;
         }
     } else {
         /** USE CURL **/
         $curl = new Net_Curl('https://vault.trustcommerce.com/trans/');
         if (PEAR::isError($curl)) {
             PEAR::popErrorHandling();
             return $curl;
         }
         $curl->type = 'PUT';
         $curl->fields = $fields;
         $curl->userAgent = 'PEAR Payment_Process_TrustCommerce 0.1a';
         $result =& $curl->execute();
         if (PEAR::isError($result)) {
             PEAR::popErrorHandling();
             return $result;
         } else {
             $curl->close();
         }
     }
     /** END TCLINK/CURL CASE STATEMENT **/
     $this->_responseBody = trim($result);
     $this->_processed = true;
     // Restore error handling
     PEAR::popErrorHandling();
     $response = Payment_Process_Result::factory($this->_driver, $this->_responseBody, $this);
     if (!PEAR::isError($response)) {
         $response->parse();
     }
     return $response;
 }
Ejemplo n.º 4
0
		if (!dl($extfname)) {
			echo "FAILED!\nAborting this test script, please check to make sure the module is properly built.\n";
			exit(1);
		}
		echo "success.\n";
	}

	print "\nTCLink version " . tclink_getversion() . "\n";
	print "Sending transaction...";

	// Build a hash containing our parameters
	$params['custid'] = 'TestMerchant';
	$params['password'] = '******';
	$params['action'] = 'sale';
	$params['media'] = 'cc';
	$params['cc'] = '4111111111111111';
	$params['exp'] = '0110';
	$params['amount'] = '100';
	$params['name'] = 'Joe PHP';

	// Send the hash to TrustCommerce for processing
	$result = tclink_send($params);

	print "done!\n\nTransaction results:\n";

	// Print out all parameters returned
	while (list($key, $val) = each($result))
		print "\t$key=$val\n";
?>

Ejemplo n.º 5
0
			$tclink['action'] = $action;
			if (is_numeric($amount))
				$tclink['amount'] = $amount;

			if ($action == 'sale' || $action == 'preauth')
			{
				$tclink['name'] = $name;
				$tclink['cc'] = $cc;
				$tclink['exp'] = $mm . $yy;
			}
			else if ($action == 'credit' || $action == 'postauth')
			{
				$tclink['transid'] = $transid;
			}

			$result = tclink_send($tclink);

			print "<tr><td colspan=2><hr></td></tr>";
			print "<tr bgcolor=blue><th colspan=2 align=center><font color=white>Transaction Results:</font></td></tr>";

			if ($result['transid'])
				printf("<tr><th>Transaction ID:</th><td>%s</td></tr>\n", $result['transid']);

			printf("<tr><th>Status:</td><td>%s</td></tr>\n", $result['status']);
			switch($result['status'])
			{
				case 'accepted':
				case 'approved':
					break;

				case 'decline':