cancel
Showing results for 
Search instead for 
Did you mean: 

Amount invalid

I am getting this error

The 'AnetApi/xml/v1/schema/AnetApiSchema.xsd:amount' element is invalid - The value '' is invalid according to its datatype 'Decimal' - The string '' is not a valid Decimal value.

 

From this code:

 

<?xml version="1.0" encoding="utf-8"?>
<getHostedPaymentPageRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
    <merchantAuthentication><name>myName</name><transactionKey>myKey</transactionKey></merchantAuthentication>
    <transactionRequest>
        <transactionType>authCaptureTransaction</transactionType>
        <amount>0.50</amount>
        <order>
            <invoiceNumber>INV-12345</invoiceNumber>
            <description>Product Description</description>
        </order>
        <lineItems>
            <lineItem>
                <itemId>1</itemId>
                <name>vase</name>
                <description>Cannes logo </description>
                <quantity>18</quantity>
                <unitPrice>45.00</unitPrice>
            </lineItem>
        </lineItems>
        <poNumber>456654</poNumber>
        <customer>
            <id>99999456654</id>
            <email>my@email.com</email>
        </customer>
        <billTo>
            <firstName>Ellen</firstName>
            <lastName>Johnson</lastName>
            <company>Souveniropolis</company>
            <address>14 Main Street</address>
            <city>Pecan Springs</city>
            <state>TX</state>
            <zip>44628</zip>
            <country>USA</country>
            <phoneNumber>1231231234</phoneNumber>
        </billTo>
        <customerIP>192.168.1.1</customerIP>
    <userFields>
          <userField>
             <name>sessionID</name>
             <value>ABC123</value>
          </userField>
        </userFields>
    </transactionRequest>
</getHostedPaymentPageRequest>

 

It runs fine when I test it on http://developer.authorize.net/api/reference/index.html#payment-transactions-get-an-accept-payment-p... but every time I run the code it comes back with an error.

 

Everything was working yesterday and now nothing works.

PcDudes524
Contributor
1 ACCEPTED SOLUTION

Accepted Solutions

In this case the response is XML, so it is even easier. Copy the source from the page at : https://nexwebhost.com/authorizenet/get-hosted.html, change the Ajax post url to your own PHP script, which I have already given you, as well as any other other domain specific variables. Done.

Powered by NexWebSites.com -
Certified Authorize.net developers

View solution in original post

17 REPLIES 17

How are you populating and posting the XML? Based on the error, it looks like the amount is apparently not getting populated in your XML and is being posted as an empty string.

Powered by NexWebSites.com -
Certified Authorize.net developers
NexusSoftware
Trusted Contributor

The XML is static, right now I am just trying to get the test XML to generate a token. I am sending it exactly as it came from Github examples just with the name and transaction key replaced.

Sending it how? Lets see your code that posts the static XML.
Powered by NexWebSites.com -
Certified Authorize.net developers

<?php

$xmlStr = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<getHostedPaymentPageRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
    <merchantAuthentication></merchantAuthentication>
    <transactionRequest>
        <transactionType>authCaptureTransaction</transactionType>
        <amount>0.50</amount>
        <order>
            <invoiceNumber>INV-12345</invoiceNumber>
            <description>Product Description</description>
        </order>
        <lineItems>
            <lineItem>
                <itemId>1</itemId>
                <name>vase</name>
                <description>Cannes logo </description>
                <quantity>18</quantity>
                <unitPrice>45.00</unitPrice>
            </lineItem>
        </lineItems>
        <poNumber>456654</poNumber>
        <customer>
            <id>99999456654</id>
            <email>my@email.com</email>
        </customer>
        <billTo>
            <firstName>Ellen</firstName>
            <lastName>Johnson</lastName>
            <company>Souveniropolis</company>
            <address>14 Main Street</address>
            <city>Pecan Springs</city>
            <state>TX</state>
            <zip>44628</zip>
            <country>USA</country>
            <phoneNumber>1231231234</phoneNumber>
        </billTo>
        <customerIP>192.168.1.1</customerIP>
    <userFields>
          <userField>
             <name>sessionID</name>
             <value>ABC123</value>
          </userField>
        </userFields>
    </transactionRequest>
</getHostedPaymentPageRequest>
XML;
$xml = simplexml_load_string($xmlStr, 'SimpleXMLElement', LIBXML_NOWARNING);
// $xml = new SimpleXMLElement($xmlStr);
$xml->merchantAuthentication->addChild('name', 'myName');
$xml->merchantAuthentication->addChild('transactionKey', 'myTransaction');


$url = "https://apitest.authorize.net/xml/v1/request.api";

try {   //setting the curl parameters.
        $ch = curl_init();
    if (false === $ch) {
        throw new Exception('failed to initialize');
    }
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml->asXML());
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
    // The following two curl SSL options are set to "false" for ease of development/debug purposes only.
    // Any code used in production should either remove these lines or set them to the appropriate
    // values to properly use secure connections for PCI-DSS compliance.
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);    //for production, set value to true or 1
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);    //for production, set value to 2
    curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
    //curl_setopt($ch, CURLOPT_PROXY, 'userproxy.visa.com:80');
    $content = curl_exec($ch);
    $content = str_replace('xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"', '', $content);

    $hostedPaymentResponse = new SimpleXMLElement($content);
    if (false === $content) {
            throw new Exception(curl_error($ch), curl_errno($ch));
    }
    curl_close($ch);
} catch (Exception $e) {
        trigger_error(sprintf('Curl failed with error #%d: %s', $e->getCode(), $e->getMessage()), E_USER_ERROR);
}

function thisPageURL()
{
    $pageURL = 'http';
    if ($_SERVER["HTTPS"] == "on") {
        $pageURL .= "s";
    }
    $pageURL .= "://";
    if ($_SERVER["SERVER_PORT"] != "80") {
        $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    } else {
        $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    }

    $pageLocation = str_replace('index.php', '', $pageURL);

    return $pageLocation;
}

I'm getting a successful response and a token, every time running that code.

<?xml version="1.0" encoding="utf-8"?><getHostedPaymentPageResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages><token>xO+JtNrIpVtdaGEl+...</token></getHostedPaymentPageResponse>

 Do you have another version, you may actually be running?

Powered by NexWebSites.com -
Certified Authorize.net developers

I am printing the XML to the screen so I can see the request so I am pretty sure that is what it is sending.

Try the following:

<?php

$xmlContent = '<getHostedPaymentPageRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
  <merchantAuthentication>
    <name>YOUR_LOGIN</name>
    <transactionKey>YOUR_TRANSACTION_KEY</transactionKey>
  </merchantAuthentication>
  <transactionRequest>
     <transactionType>authCaptureTransaction</transactionType>
        <amount>0.50</amount>
        <order>
            <invoiceNumber>INV-12345</invoiceNumber>
            <description>Product Description</description>
        </order>
        <lineItems>
            <lineItem>
                <itemId>1</itemId>
                <name>vase</name>
                <description>Cannes logo </description>
                <quantity>18</quantity>
                <unitPrice>45.00</unitPrice>
            </lineItem>
        </lineItems>
        <poNumber>456654</poNumber>
        <customer>
            <id>99999456654</id>
            <email>my@email.com</email>
        </customer>
        <billTo>
            <firstName>Ellen</firstName>
            <lastName>Johnson</lastName>
            <company>Souveniropolis</company>
            <address>14 Main Street</address>
            <city>Pecan Springs</city>
            <state>TX</state>
            <zip>44628</zip>
            <country>USA</country>
            <phoneNumber>1231231234</phoneNumber>
        </billTo>
        <customerIP>192.168.1.1</customerIP>
    <userFields>
          <userField>
             <name>sessionID</name>
             <value>ABC123</value>
          </userField>
        </userFields>
    </transactionRequest>
</getHostedPaymentPageRequest>';

$url = "https://apitest.authorize.net/xml/v1/request.api";

try {   //setting the curl parameters.
        $ch = curl_init();
    if (false === $ch) {
        throw new Exception('failed to initialize');
    }
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlContent);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
    $content = curl_exec($ch);
    $content = str_replace('xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"', '', $content);

    $hostedPaymentResponse = new SimpleXMLElement($content);
    echo $content;
    if (false === $content) {
            throw new Exception(curl_error($ch), curl_errno($ch));
    }
    curl_close($ch);
} catch (Exception $e) {
        trigger_error(sprintf('Curl failed with error #%d: %s', $e->getCode(), $e->getMessage()), E_USER_ERROR);
}

Powered by NexWebSites.com -
Certified Authorize.net developers

Ok, this is what was displayed when I used that code

 


OkI00001Successful./5Fg9pKUIZnb5Qnrvw3+DS0/HUwSDxvDNGOhJr+9jMBGPsVcxWsKiG5myspomGGPLBrENxuO/+ZP3PsKFiCkJJ7UJsXUQGUGYmJq47JarE2CJnnz5+bl8Cbt8v+t1/Hk2qiJ3c7IPFj9JnP3fShLQLL7mzyfXG9BW5+8cCRBiXHdHWNjUgZsnJWULASy7xLOmavkSjp5EVlTVmmfzVqf8DgKTEsxXzZfiFJZX90ahCJfZbA3U6/UPrQyCsTINdQm+4nt9UtFCSL22gVWgzyAEAIYwbTOUAU+lwqHkTmY+zJw6D+5HYdxrddjCuSZ7BBDE4+sBJMT/GC9OEkPQeFIrWOf2PHaXyUG/pdAC63UcGECpw4aQwOq+LKtE2Z5nyisuRoXjypZ8hDqOmdQTvAvVc4Fb1zivPf/4UnO3O/VxDiAfJXqazdhForDebn3R4GY49N1WoxTdc5OSuQOavMm9vMP9y0mWgTt/xqr9Sg6+G+YZJJy8jjwTIhbFMQCOG7EOjKEuAeMtaEret3rc3B+arjpjp4GgVfwD2DtamVeGYe0/DOOte6ABjiw3qtKD8090Vp8NnlgmosD6Dfh3guBUGzJOBE0i5Qx4b4wxGcyRi7yaNcjp5rnlHBeh0+MWYf/CWPDSGc6duUzp6F6uUHWmwly9/1sxbukC7jhSrcuVXm5xaTNgk9OViPVNj1iAq/xxCmjKe10eX/5fIxRme7AVtd6wxM96jfWBQq3ab/YgO77b8tFb0+L6l2JBkQLfexWp//W9l9mcumAJefSa38oXEvWlu02QbbuHy7R7a/N4Dx4rdte5BYQJbav6sHYedwKUK/GJxISRRf410/fiTK4VJQ0PcFFqoTHOG8briIYqcQC3IFEPoFMLL/zZ3kliGfNoM1T7Q0+N2UVke8e/u76f9RX7CFAksfnyF1rP0KwTOyuZtEFS13J1fiFMBte3brnZy1+hlDVkxMiIR3Vr7dtbfrddpTA6bVhqPwCqktBLrBGDhlII0U04apN59fSrv1oIrbFOEkYGx1iLegyUp26XycwIogUMIkAFItXgbsQZnQLHXH0qsx4/f0o9/5sz2QcDaI5HUwZ1hb3aYwbCuLACFN6E063AsUetPuZV4qsFQzw95l33UZ1En5LkjmROsDOqZbdhr6JtC6QZXU+7Iv4jC/n4vtE+jh47lIwYOb2plEIFIQ/Rqq6oI/OxD+WfHVy/aRkfu6vo5FG2WpxZl/lrdUmbsJFbE4X1ds5DTMj/1H/IAN3Z2GONuuT8oxbuYB7BdgMhg85hPJN0KKmTFf5+ET6M1pmvm7Npyc4PoZnYgFhbfwuzBBsRXERQe0NZs8fbZETPUxJnLLkJVEnyoFT1w==.6xSh8CL39

Great. It works, so maybe something to do with your PHP version or configuration related to asXML(). Because that is the only difference in your posted code and the one that works on your system.

Powered by NexWebSites.com -
Certified Authorize.net developers

Type a product name