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
17 REPLIES 17

Ok, I am at a loss on where to go from here. I will reinstall the code from Github and start from scratch.

Okay, if that doesn't work for you, below is a very basic PHP example, that should be enable you to get started easily. Just replace the setting values with your own:

<?php
//Get your posted variables
if (is_numeric($_POST['amount']) && $_POST['amount']!="") {
$amount = $_POST['amount'];
} else {
  $amount = "10.27";
}
$xmlContent = '<getHostedPaymentPageRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
  <merchantAuthentication>
    <name>YOUR_API_LOGIN</name>
    <transactionKey>YOUR_TRANSACTION_KEY</transactionKey>
  </merchantAuthentication>
  <transactionRequest>
    <transactionType>authCaptureTransaction</transactionType>
    <amount>'.$amount.'</amount>
  </transactionRequest>
  <hostedPaymentSettings>
    <setting>
      <settingName>hostedPaymentIFrameCommunicatorUrl</settingName>
      <settingValue>{"url": "https://nexwebhost.com/authorizenet/iCommunicator.html"}</settingValue>
    </setting>
    <setting>
      <settingName>hostedPaymentBillingAddressOptions</settingName>
      <settingValue>{"show": false, "required":false}</settingValue>
    </setting>
    <setting>
      <settingName>hostedPaymentButtonOptions</settingName>
      <settingValue>{"text": "Pay"}</settingValue>
    </setting>
    <setting>
      <settingName>hostedPaymentReturnOptions</settingName>
      <settingValue>{"url":"https://nexwebsites.com/good","urlText":"Continue","cancelUrl":"https://nexwebsites.com/cancel","cancelUrlText":"Cancel"}</settingValue>
    </setting>
  </hostedPaymentSettings>
</getHostedPaymentPageRequest>';

  $url = 'https://apitest.authorize.net/xml/v1/request.api';
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
  curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlContent);
  $result = curl_exec($ch);
  echo $result;
  curl_close($ch);

 

Powered by NexWebSites.com -
Certified Authorize.net developers

Ok, this seems a bit easier but it doesn't look anything like the code from GitHub for the hosted payment page.

 

How do I read the response? I tried json_decode and a couple of other things but no luck.

 

How do I call the actual payment form into displaying? Should I use the iFrame code from the Github sample?

One way would be to do an Ajax post to the application and parse the response with Jquery, placing the token into the form's token input. An example of which is at http://go.javawebapp.com/
Powered by NexWebSites.com -
Certified Authorize.net developers

That looks like exactly what I want but I do not have any idea how to proceed after getting the token nd the source of the page does not tell me much.

The implementation will vary depending on your requirements, the important part is your success function:

success: function(data) {
var obj = $.parseJSON(data);
$("#token").val(obj['token']);
}

On the same page you would have your form that targets your iframe, which by the way, could be auto submitted : 

<form id="payform" target="payframe" action="https://test.authorize.net/payment/payment" method="post">
		<input type="hidden" id="token" name="token" value="">
		<input class="btn btn-primary" type="submit" value="Get Accept Hosted">
		</form>

Your iframe:

<iframe name="payframe" id="payframe"></iframe>
Powered by NexWebSites.com -
Certified Authorize.net developers

Ok, I tried combining all this code together and I get a message for 'Missing or Invalid token' and I'm not sure how to get the error messages to output.

 

Here is the code I have cobbled together:

 

<?php
//Get your posted variables
if (is_numeric($_POST['amount']) && $_POST['amount']!="") {
$amount = $_POST['amount'];
} else {
  $amount = "10.27";
}
$xmlContent = '<getHostedPaymentPageRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
  <merchantAuthentication>
    <name>5KP3u95bQpv</name>
    <transactionKey>346HZ32z3fP4hTG2</transactionKey>
  </merchantAuthentication>
  <transactionRequest>
    <transactionType>authCaptureTransaction</transactionType>
    <amount>'.$amount.'</amount>
  </transactionRequest>
  <hostedPaymentSettings>
    <setting>
      <settingName>hostedPaymentIFrameCommunicatorUrl</settingName>
      <settingValue>{"url": "https://nexwebhost.com/authorizenet/iCommunicator.html"}</settingValue>
    </setting>
    <setting>
      <settingName>hostedPaymentBillingAddressOptions</settingName>
      <settingValue>{"show": false, "required":false}</settingValue>
    </setting>
    <setting>
      <settingName>hostedPaymentButtonOptions</settingName>
      <settingValue>{"text": "Pay"}</settingValue>
    </setting>
    <setting>
      <settingName>hostedPaymentReturnOptions</settingName>
      <settingValue>{"url":"https://nexwebsites.com/good","urlText":"Continue","cancelUrl":"https://nexwebsites.com/cancel","can...>
    </setting>
  </hostedPaymentSettings>
</getHostedPaymentPageRequest>';

  $url = 'https://apitest.authorize.net/xml/v1/request.api';
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
  curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlContent);
  $result = curl_exec($ch);
  curl_close($ch);
?>


<script type="text/javascript">
  success: function(data) {
        var obj = $.parseJSON(data);
        $("#token").val(obj['token']);
    }
</script>

<form id="payform" name="payform" target="payframe" action="https://test.authorize.net/payment/payment" method="post">
    <input type="hidden" id="token" name="token" value="">
    <input class="btn btn-primary" type="submit" value="Get Accept Hosted">
</form>
        
<script type='text/javascript'>document.payform.submit();</script>    
    
    
<iframe name="payframe" id="payframe"></iframe>

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