Zen Cart Logo
Forums / Addon Payment Modules / Having trouble with order total in Authnet CIM

Having trouble with order total in Authnet CIM

Locked

Views: 2,595

Results 1 to 2 of 2
This thread is locked. New replies are disabled.
9 Mar 2010, 7:08 PM
#1
chrismarie avatar

chrismarie

New Zenner

Join Date:
Apr 2009
Location:
Chicago, IL
Posts:
45
Plugin Contributions:
0

Having trouble with order total in Authnet CIM

Hi all,
I'm running 1.3.8a and trying to get my own Authorize.net CIM module off the ground. I've managed to piece it together and I'm getting hung up on this final issue.

The xml that I submit to authorize.net has to have the order total in it. I created the variable transactionAmount and copied the order total code from the authorize.net aim module to end up with this:

$this->transactionAmount = number_format($order->info['total'], 2);

So that this is what I have for the submit data:

   $submit_data = "<?xml version='1.0' encoding='utf-8'?>
	<createCustomerProfileTransactionRequest xmlns='AnetApi/xml/v1/schema/AnetApiSchema.xsd'>
	<merchantAuthentication>
		<name>" . MODULE_PAYMENT_AUTHORIZENET_CIM_LOGIN . "</name>
		<transactionKey>" . MODULE_PAYMENT_AUTHORIZENET_CIM_TXNKEY . "</transactionKey>
	</merchantAuthentication>
	<transaction>
		<profileTransAuthCapture>
			<amount>".$this->transactionAmount."</amount>
			<customerProfileId>" .$this->customerProfileID. "</customerProfileId>
			<customerPaymentProfileId>" .$this->customerPaymentProfileID. "</customerPaymentProfileId>
			<taxExempt>false</taxExempt>
			<recurringBilling>false</recurringBilling>
		</profileTransAuthCapture>
	</transaction>
	</createCustomerProfileTransactionRequest>";

Everything else comes through okay, but when I try to send the transaction request for an order of $1.00, I get the following error: The 'AnetApi/xml/v1/schema/AnetApiSchema.xsd:amount' element is invalid - The value '0.00' is invalid according to its datatype 'Decimal' - The MinInclusive constraint failed.

I don't know why the transactionAmount is coming out as 0.00. When I added $this->transactionAmount as a field to the selection array, the value came out correctly as 1.00

When I replaced the code with the value 1.00 in the xml and sent the payment request, it went through to authorize.net without any error. I'm soooo confused and any help would be much appreciated.

Here's the whole before_process function:

  function before_process() {
    global $response, $db, $order, $messageStack, $cimInfo;

    // DATA PREPARATION SECTION
    unset($submit_data);  // Cleans out any previous data stored in the variable

    // Create a string that contains a listing of products ordered for the description field
    $description = '';
    for ($i=0; $i<sizeof($order->products); $i++) {
      $description .= $order->products[$i]['name'] . ' (qty: ' . $order->products[$i]['qty'] . ') + ';
    }
    // Remove the last "\n" from the string
    $description = substr($description, 0, -2);

    // Create a variable that holds the order time
    $order_time = date("F j, Y, g:i a");

    // Calculate the next expected order id (adapted from code written by Eric Stamper - 01/30/2004 Released under GPL)
    $last_order_id = $db->Execute("select * from " . TABLE_ORDERS . " order by orders_id desc limit 1");
    $new_order_id = $last_order_id->fields['orders_id'];
    $new_order_id = ($new_order_id + 1);

    // add randomized suffix to order id to produce uniqueness ... since it's unwise to submit the same order-number twice to authorize.net
    $new_order_id = (string)$new_order_id . '-' . zen_create_random_value(6);

    // Populate an array that contains all of the data to be sent to Authorize.net
    $submit_data = "<?xml version='1.0' encoding='utf-8'?>
	<createCustomerProfileTransactionRequest xmlns='AnetApi/xml/v1/schema/AnetApiSchema.xsd'>
	<merchantAuthentication>
		<name>" . MODULE_PAYMENT_AUTHORIZENET_CIM_LOGIN . "</name>
		<transactionKey>" . MODULE_PAYMENT_AUTHORIZENET_CIM_TXNKEY . "</transactionKey>
	</merchantAuthentication>
	<transaction>
		<profileTransAuthCapture>
			<amount>".$this->transactionAmount."</amount>
			<customerProfileId>" .$this->customerProfileID. "</customerProfileId>
			<customerPaymentProfileId>" .$this->customerPaymentProfileID. "</customerPaymentProfileId>
			<taxExempt>false</taxExempt>
			<recurringBilling>false</recurringBilling>
		</profileTransAuthCapture>
	</transaction>
	</createCustomerProfileTransactionRequest>";

    unset($response);
    $response = $this->_sendRequest($submit_data);
    $response_code = $this->resultCode;
    $response_text = $this->text;
    $this->auth_code = $this->directResponse[5];
    $this->transaction_id = $this->transactionApprovalCode;
    $response_msg_to_customer = $response_text;


    // If the response code is not 1 (approved) then redirect back to the payment page with the appropriate error message
    if ($this->resultCode != "Ok") {
      $messageStack->add_session('checkout_payment', $response_msg_to_customer . ' - ' . MODULE_PAYMENT_AUTHORIZENET_CIM_TEXT_DECLINED_MESSAGE, 'error');
      zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
    }
  }

Also, this is where I define the other variables:

  function authorizenet_cim() {
    global $order, $db;

    $cim_query = "select customers_profileID, customers_profile_paymentID
                         	from " . TABLE_CUSTOMERS . "
                         	where customers_id = '" . $_SESSION['customer_id'] . "'";
    $cimInfo = $db->Execute($cim_query);
    $this->customerProfileID = $cimInfo->fields['customers_profileID'];
    $this->customerPaymentProfileID = $cimInfo->fields['customers_profile_paymentID'];
    $this->transactionAmount = number_format($order->info['total'], 2);
    $this->code = 'authorizenet_cim';

edit: oh yeah, I apologize in advance if any of my php lingo is incorrect :)

9 Mar 2010, 7:29 PM
#2
chrismarie avatar

chrismarie

New Zenner

Join Date:
Apr 2009
Location:
Chicago, IL
Posts:
45
Plugin Contributions:
0

Re: Having trouble with order total in Authnet CIM

Nevermind! I just replaced the this->transactionAmount with the actual value of number_format($order->info['total'], 2)

I had tried it that way originally and it wasn't working, but that was because I closed it with <amount> instead of </amount>

Silly rabbit!