cancel
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 https://developer.authorize.net/api/reference/features/accept_hosted.html#Integrating_the_Form_using...

 

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">
<merchantAuthentication>
<name>API_LOGIN_ID</name>
<transactionKey>API_TRANSACTION_KEY</transactionKey>
</merchantAuthentication>
<transactionRequest>
<transactionType>authCaptureTransaction</transactionType>
<amount>12.00</amount>
<profile>
<customerProfileId>123456789</customerProfileId>
</profile>
<customer>
<email>ellen@mail.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>
</billTo>
</transactionRequest>
<hostedPaymentSettings>
<setting>
<settingName>hostedPaymentReturnOptions</settingName>
<settingValue>{"showReceipt": true, "url": "https://mysite.com/receipt", "urlText": "Continue", "cancelUrl": "https://mysite.com/cancel", "cancelUrlText": "Cancel"}</settingValue>
</setting>
<setting>
<settingName>hostedPaymentButtonOptions</settingName>
<settingValue>{"text": "Pay"}</settingValue>
</setting>
<setting>
<settingName>hostedPaymentStyleOptions</settingName>
<settingValue>{"bgColor": "blue"}</settingValue>
</setting>
<setting>
<settingName>hostedPaymentPaymentOptions</settingName>
<settingValue>{"cardCodeRequired": false, "showCreditCard": true, "showBankAccount": true}</settingValue>
</setting>
<setting>
<settingName>hostedPaymentSecurityOptions</settingName>
<settingValue>{"captcha": false}</settingValue>
</setting>
<setting>
<settingName>hostedPaymentShippingAddressOptions</settingName>
<settingValue>{"show": false, "required": false}</settingValue>
</setting>
<setting>
<settingName>hostedPaymentBillingAddressOptions</settingName>
<settingValue>{"show": true, "required":false}</settingValue>
</setting>
<setting>
<settingName>hostedPaymentCustomerOptions</settingName>
<settingValue>{"showEmail": false, "requiredEmail": false, "addPaymentProfile": true}</settingValue>
</setting>
<setting>
<settingName>hostedPaymentOrderOptions</settingName>
<settingValue>{"show": true, "merchantName": "G and S Questions Inc."}</settingValue>
</setting>
<setting>
<settingName>hostedPaymentIFrameCommunicatorUrl</settingName>
<settingValue>{"url": "https://mysite.com/special"}</settingValue>
</setting>
</hostedPaymentSettings>
</getHostedPaymentPageRequest>';

 

$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="https://test.authorize.net/payment/payment" 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'>
</form>

pr_75
Member
3 REPLIES 3

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. 

Renaissance
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.