Showing results for 
Search instead for 
Did you mean: 

php Hosted API, not getting any response


We are working on sandbox and using example given in


With below code payment is processsed, token is alos generated but on return url not getting any response. Want to process the payment related to tables when payment is sucessful.


following is the code


$xmlStr = '<getHostedPaymentPageRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<address>14 Main Street</address>
<city>Pecan Springs</city>
<settingValue>{"showReceipt": true, "url": "", "urlText": "Continue", "cancelUrl": "", "cancelUrlText": "Cancel"}</settingValue>
<settingValue>{"text": "Pay"}</settingValue>
<settingValue>{"bgColor": "blue"}</settingValue>
<settingValue>{"cardCodeRequired": false, "showCreditCard": true, "showBankAccount": true}</settingValue>
<settingValue>{"captcha": false}</settingValue>
<settingValue>{"show": false, "required": false}</settingValue>
<settingValue>{"show": true, "required":false}</settingValue>
<settingValue>{"showEmail": false, "requiredEmail": false, "addPaymentProfile": true}</settingValue>
<settingValue>{"show": true, "merchantName": "G and S Questions Inc."}</settingValue>
<settingValue>{"url": ""}</settingValue>


$xml = new SimpleXMLElement($xmlStr);


$ch = curl_init();
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, 10000);
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);

$content = curl_exec($ch);

$hostedPaymentResponse = new SimpleXMLElement($content);
$hostedPaymentToken = $hostedPaymentResponse->token;

<form id="send_hptoken" name="authForm" action="" method="post">
<input type="text" name="token" value="<?php echo $hostedPaymentToken; ?>" />
<b>Please click to accept the <a class='medLinksOrangeBold' href='javascript&colon;newwindowterms()'><u>Terms and Conditions</u></a>?</b> &nbsp; <input type='checkbox' name='terms'>
<br><br><input name='sub_but' type='submit' value='Submit'>


You won't use the response if you're using the redirect method. You use webhooks. I also like webhooks better even if you're using iframe. Search reference files for webhooks and you'll see all the details of how that works. 



Here is the process my app uses:


1. When the API call is made, the invoice number is passed
2. If transaction succeeds. Webhook comes in
3. The json payload is captured and the transaction id is programmatically extracted
4. The transaction id is passed as a parameter in the gettransactiondetails method call
5. This will return a response object that has the entire transaction that relates to that transaction id, including the invoice
6. I extract the invoice number from the response object
7. The invoice number is used to locate the appropriate record in the dB to insert the transaction Id



Note that the invoice number is in the payload now, I think. So you could skip the method call and just extract it, if the only data you need is the invoice number and transId. 

All Star


Ok got it. Do you have any examples. I did search and there are different examples. One I tried with iframe, fire the webhook when iframe is loaded and when pay button is clicked nothing is send to webhook.


I may be doing something wrong.


Complete working example in php will help.

How is it that you are verifying nothing is sent to the webhook? You have to get your endpoint working before you can do anything with it. You can test fire the webhook in the merchant interface. It will tell you if you’re connecting. From there you just need to make sure that your are subscribed to the correct events in your interface. You also want to turn on transaction reporting.