cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Authorized dot net hosted Form response issues.

I am trying to integrate Authrize.net's hosted gateway and I have successfully generated a token for the same.

But after computing the payment how can I get payment status.
Currently, I am using a local server and also let me how to redirect page will success or fail payment status.

I have also added a webhook but didn't get any response.

Please assist me with the above-mentioned issues.

Note : Below is script that I am currently using.
=================================================

<?php
  require 'vendor/autoload.php';
  require_once 'SampleCodeConstants.php';
  use net\authorize\api\contract\v1 as AnetAPI;
  use net\authorize\api\controller as AnetController;

  define("AUTHORIZENET_LOG_FILE", "phplog");
 
function getAnAcceptPaymentPage()
{
    /* Create a merchantAuthenticationType object with authentication details
       retrieved from the constants file */
    $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
    $merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID);
    $merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY);
   
    // Set the transaction's refId
    $refId = 'ref' . time();

    //create a transaction
    $transactionRequestType = new AnetAPI\TransactionRequestType();
    $transactionRequestType->setTransactionType("authCaptureTransaction");
    $transactionRequestType->setAmount("12.23");

    // Set Hosted Form options
    $setting1 = new AnetAPI\SettingType();
    $setting1->setSettingName("hostedPaymentButtonOptions");
    $setting1->setSettingValue("{\"text\": \"Pay\"}");

    $setting2 = new AnetAPI\SettingType();
    $setting2->setSettingName("hostedPaymentOrderOptions");
    $setting2->setSettingValue("{\"show\": false}");

    $setting3 = new AnetAPI\SettingType();
    $setting3->setSettingName("hostedPaymentReturnOptions");
    $setting3->setSettingValue(
        "{\"url\": \"http://localhost/Test/authorized/auth-receipt.php\", \"cancelUrl\": \"https://mysite.com/cancel\", \"showReceipt\": true}"
    );

    // Build transaction request
    $request = new AnetAPI\GetHostedPaymentPageRequest();
    $request->setMerchantAuthentication($merchantAuthentication);
    $request->setRefId($refId);
    $request->setTransactionRequest($transactionRequestType);

    $request->addToHostedPaymentSettings($setting1);
    $request->addToHostedPaymentSettings($setting2);
    $request->addToHostedPaymentSettings($setting3);
   
    //execute request
    $controller = new AnetController\GetHostedPaymentPageController($request);
    $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
   
    if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) {
//echo 'Token Created';
       // echo $response->getToken()."\n";
    } else {
       // echo "ERROR :  Failed to get hosted payment page token\n";
        $errorMessages = $response->getMessages()->getMessage();
        //echo "RESPONSE : " . $errorMessages[0]->getCode() . "  " .$errorMessages[0]->getText() . "\n";
    }
    return $response;
}
if (!defined('DONT_RUN_SAMPLES')) {
    $responce = getAnAcceptPaymentPage();
if(isset($responce))
{
//echo $responce->getToken();
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<head>
<title>Authrized dot net redirect</title>
</head>
<body>
<form action="https://test.authorize.net/payment/payment" method="post" id="frmPaymentRedirect">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="token" value="'.$responce->getToken().'" />
</form>
<script type="text/javascript">document.getElementById("frmPaymentRedirect").submit();</script>
</body>
</html>';

}
}



Thank you,
Amit
ArtWork
Member
6 REPLIES 6

Hello,

I just yesterday asked a similar question

 

https://community.developer.authorize.net/t5/Integration-and-Testing/Accept-Hosted-how-to-get-Transa...

 

 

I have not figured out the way to pass refId into AZ via their API,

 

but once that' is passed in, you would have to create a event subscription notification receiver

(basically a separate app or a separate REST end point in your existing backend.

And 'listen' to events comming from authorize.net, in there with event payload, there will be merchantReferenceId (which is the refId that we are somehow supposed to pass in (this is part I still do not know) )

 

And that's how you will be able to get status and details of the CC Payment.

 

you will not be able to get it 'inline' when AZ redirects User's webbrowser from their Hosted Payment page back to your http://localhost/Test/authorized/auth-receipt.php

 

erdz1
Contributor

If your issue regarding Authorized dot net hosted Form response issues is not yet resolved then you can contact me...

 

I can help in that matter just hit me up at my personal email stromy@mynstrom.com

We are using Redirect module to capture payments, that is a token is generated by calling getHostedPaymentPageRequest, after receiving the token we do a form post to authorize.net/payment page, for authorize.net to capture the payment details.

We are able to successfully implement the above process, however upon clicking on "Pay" on payments page it is redirecting to receipt page, even if we set "showReceipt\": false for hostedPaymentReturnOptions settings.

Also, after clicking on โ€˜Continue to siteโ€™ button on receipt page, its successfully redirected to desired custom โ€˜AuthorizeNetReturn.aspxโ€™ page of our application but we are unable to get or read receipt/transaction response data i.e. responseCode,AuthorizationCode and TransactionID on โ€˜AuthorizeNetReturn.aspxโ€™ page

Below is the code

ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.SANDBOX;

           ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()

           {

               name = loginID,

               ItemElementName = ItemChoiceType.transactionKey,

               Item = transactionKey,

           };

settingType[] settings = new settingType[7];

 

string returnURL = CommonHelper.GetStoreLocation(false) + "AuthorizeNetReturn.aspx";

settings[0] = new settingType();

settings[0].settingName = settingNameEnum.hostedPaymentButtonOptions.ToString();

settings[0].settingValue = "{\"text\": \"Pay\"}";

 

settings[1] = new settingType();

settings[1].settingName = settingNameEnum.hostedPaymentOrderOptions.ToString(); settings[1].settingValue = "{\"show\": true}";

 

settings[2] = new settingType();

settings[2].settingName = settingNameEnum.hostedPaymentReturnOptions.ToString();

          

settings[2].settingValue = "{\"url\": \"" + returnURL + "\",\"urlText\":\"Continue to site\",\"cancelUrl\": \"" + returnURL+"\", \"showReceipt\": false}";

 

settings[3] = new settingType();

settings[3].settingName = settingNameEnum.hostedPaymentPaymentOptions.ToString();

settings[3].settingValue = "{\"cardCodeRequired\": true, \"showCreditCard\": true, \"showBankAccount\": false}";

 

settings[4] = new settingType();

settings[4].settingName = settingNameEnum.hostedPaymentBillingAddressOptions.ToString();

settings[4].settingValue = "{\"show\": false}";

 

settings[5] = new settingType();

settings[5].settingName = settingNameEnum.hostedPaymentShippingAddressOptions.ToString();

           settings[5].settingValue = "{\"show\": false}";

 

settings[6] = new settingType();

settings[6].settingName = settingNameEnum.hostedPaymentIFrameCommunicatorUrl.ToString();

           settings[6].settingValue = "{\"url\": \"" + returnURL+"?mode=post" + "\"}";

 

var billTo = new customerAddressType

           {

               firstName = order.BillingFirstName,

               lastName = order.BillingLastName,

               address = order.BillingAddress1,

               city = order.BillingCity,

               state = order.BillingStateProvince,

               zip = order.BillingZipPostalCode,

               country=order.BillingCountry,

               phoneNumber=order.BillingPhoneNumber              

           };

 

var shipTo = new customerAddressType

           {

               firstName = order.ShippingFirstName,

               lastName = order.ShippingLastName,

               address = order.ShippingAddress1,

               city = order.ShippingCity,

               state = order.ShippingStateProvince,

               zip = order.ShippingZipPostalCode,

               country = order.ShippingCountry,

               phoneNumber = order.ShippingPhoneNumber

           };

var transactionRequest = new transactionRequestType

           {

               transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),  

               amount = Convert.ToDecimal(order.OrderTotal.ToString("####.00", new CultureInfo("en-US", false).NumberFormat)),

               billTo = billTo,

               shipTo=shipTo

              

           };

 

           var request = new getHostedPaymentPageRequest();

           request.transactionRequest = transactionRequest;

           request.hostedPaymentSettings = settings;

 

           // instantiate the controller that will call the service

           var controller = new getHostedPaymentPageController(request);

           controller.Execute();

 

           // get the response from the service (errors contained if any)

           var response = controller.GetApiResponse();

           if (response != null)

           {

               if (response.messages.resultCode == messageTypeEnum.Ok)

               {

                  

                   remotePostHelper.Add("token", response.token.ToString());

                  remotePostHelper.Post();

               }

       }

We went through the documentation of Authorize.net and as per that we tried using both hostedPaymentIFrameCommunicatorUrl and hostedPaymentReturnOptions, but with none we could acheive the desired result. 

 

One more thing which we wanted to mention here is that we are not using iframe, but instead doing a form post to authorize.net/payments to capture credit card details and return back data to our application. 

 

Kindly advise if we were missing out anything, any help will be much appreciated. 

shkula
Member

Sorry I cannot see what exactly the problem might be in your code.

However below is a portion of my Java code that setups the the call to receive the token.

 

May it will be of some help.

I always see the receipt page, but then, once the button there clicked, the user is redirected to the appropriate route on my site.

 

In my experience (this was mostly last year). AuthorizeNet APIs are not always match documentation. And unless it is a 'show stopper', it might never get improved.  So if there is a plausable workaround,  share it here, and use it! 

 

------------ java --------

 

 

 


SettingType sett_payBtnOptions = new SettingType();
sett_payBtnOptions.setSettingName("hostedPaymentButtonOptions");
sett_payBtnOptions.setSettingValue("{\"text\": \"Pay\"}");

SettingType sett_payOrderOptions = new SettingType();
sett_payOrderOptions.setSettingName("hostedPaymentOrderOptions");
sett_payOrderOptions.setSettingValue(String.format("{\"show\": true," +
"\"merchantName\":\"%s\"}",
otherCFG.getBusinessName()));


SettingType sett_returnOptions= new SettingType();
sett_returnOptions.setSettingName("hostedPaymentReturnOptions");
sett_returnOptions.setSettingValue(String.format("{\"showReceipt\": true, " + /* Note: If you do not embed the payment form in an iframe, the receipt page is displayed regardless of the value of showReceipt. */
"\"url\":\"%s\"," +
" \"urlText\": \"Continue\"," +
" \"cancelUrl\": \"%s\"," +
" \"cancelUrlText\": \"Cancel\"}",
replyCFG.getFullURL__Accepted(THIS_PPID),
replyCFG.getFullURL__Cancelled(THIS_PPID)));


SettingType sett_CustomerOptions = new SettingType();
sett_CustomerOptions.setSettingName("hostedPaymentCustomerOptions");
sett_CustomerOptions.setSettingValue("{\"showEmail\": true, " +
"\"requiredEmail\": false, \"addPaymentProfile\": false}");


SettingType sett_BillingAdrOptions = new SettingType();
sett_BillingAdrOptions.setSettingName("hostedPaymentBillingAddressOptions");
sett_BillingAdrOptions.setSettingValue("{\"show\": true, " +
"\"required\": false}");


ArrayOfSetting alist = new ArrayOfSetting();
alist.getSetting().add(sett_returnOptions);
alist.getSetting().add(sett_payBtnOptions);
alist.getSetting().add(sett_CustomerOptions);
alist.getSetting().add(sett_BillingAdrOptions);
alist.getSetting().add(sett_payOrderOptions);

GetHostedPaymentPageRequest apiRequest = new GetHostedPaymentPageRequest();
apiRequest.setTransactionRequest(txnRequest);
apiRequest.setHostedPaymentSettings(alist);

GetHostedPaymentPageController controller = new GetHostedPaymentPageController(apiRequest);
controller.execute();

GetHostedPaymentPageResponse //response = new GetHostedPaymentPageResponse();
response = controller.getApiResponse();

if (response!=null) {
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
System.out.println(response.getMessages().getMessage().get(0).getCode());
System.out.println(response.getMessages().getMessage().get(0).getText());
System.out.println(response.getToken());
}
else {
System.out.println("Failed to get hosted payment page: " + response.getMessages().getResultCode());
}
}
return response;

I think you miss out one or two steps of coding I would do suggest to you please relook your coding where you have left one or two line I am sharing the exactly code here                                Mynordstrom Employee Portal

SettingType sett_payBtnOptions = new SettingType();
sett_payBtnOptions.setSettingName("hostedPaymentButtonOptions");
sett_payBtnOptions.setSettingValue("{\"text\": \"Pay\"}");

SettingType sett_payOrderOptions = new SettingType();
sett_payOrderOptions.setSettingName("hostedPaymentOrderOptions");
sett_payOrderOptions.setSettingValue(String.format("{\"show\": true," +
"\"merchantName\":\"%s\"}",
otherCFG.getBusinessName()));


SettingType sett_returnOptions= new SettingType();
sett_returnOptions.setSettingName("hostedPaymentReturnOptions");
sett_returnOptions.setSettingValue(String.format("{\"showReceipt\": true, " + /* Note: If you do not embed the payment form in an iframe, the receipt page is displayed regardless of the value of showReceipt. */
"\"url\":\"%s\"," +
" \"urlText\": \"Continue\"," +
" \"cancelUrl\": \"%s\"," +
" \"cancelUrlText\": \"Cancel\"}",
replyCFG.getFullURL__Accepted(THIS_PPID),
replyCFG.getFullURL__Cancelled(THIS_PPID)));


SettingType sett_CustomerOptions = new SettingType();
sett_CustomerOptions.setSettingName("hostedPaymentCustomerOptions");
sett_CustomerOptions.setSettingValue("{\"showEmail\": true, " +
"\"requiredEmail\": false, \"addPaymentProfile\": false}");


SettingType sett_BillingAdrOptions = new SettingType();
sett_BillingAdrOptions.setSettingName("hostedPaymentBillingAddressOptions");
sett_BillingAdrOptions.setSettingValue("{\"show\": true, " +
"\"required\": false}");


ArrayOfSetting alist = new ArrayOfSetting();
alist.getSetting().add(sett_returnOptions);
alist.getSetting().add(sett_payBtnOptions);
alist.getSetting().add(sett_CustomerOptions);
alist.getSetting().add(sett_BillingAdrOptions);
alist.getSetting().add(sett_payOrderOptions);

GetHostedPaymentPageRequest apiRequest = new GetHostedPaymentPageRequest();
apiRequest.setTransactionRequest(txnRequest);
apiRequest.setHostedPaymentSettings(alist);

GetHostedPaymentPageController controller = new GetHostedPaymentPageController(apiRequest);
controller.execute();

GetHostedPaymentPageResponse //response = new GetHostedPaymentPageResponse();
response = controller.getApiResponse();

if (response!=null) {
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
System.out.println(response.getMessages().getMessage().get(0).getCode());
System.out.println(response.getMessages().getMessage().get(0).getText());
System.out.println(response.getToken());
}
else {
System.out.println("Failed to get hosted payment page: " + response.getMessages().getResultCode());
}
}

I ensure you there is minors mistake what I have seen in your coding you can please rectify you blends on coding because you missing any one minor mistake you code won't be accepted for further procedure.

SettingType sett_payBtnOptions = new SettingType();
sett_payBtnOptions.setSettingName("hostedPaymentButtonOptions");
sett_payBtnOptions.setSettingValue("{\"text\": \"Pay\"}");

SettingType sett_payOrderOptions = new SettingType();
sett_payOrderOptions.setSettingName("hostedPaymentOrderOptions");
sett_payOrderOptions.setSettingValue(String.format("{\"show\": true," +
"\"merchantName\":\"%s\"}",
otherCFG.getBusinessName()));


SettingType sett_returnOptions= new SettingType();
sett_returnOptions.setSettingName("hostedPaymentReturnOptions");
sett_returnOptions.setSettingValue(String.format("{\"showReceipt\": true, " + /* Note: If you do not embed the payment form in an iframe, the receipt page is displayed regardless of the value of showReceipt. */
"\"url\":\"%s\"," +
" \"urlText\": \"Continue\"," +
" \"cancelUrl\": \"%s\"," +
" \"cancelUrlText\": \"Cancel\"}",
replyCFG.getFullURL__Accepted(THIS_PPID),
replyCFG.getFullURL__Cancelled(THIS_PPID)));


SettingType sett_CustomerOptions = new SettingType();
sett_CustomerOptions.setSettingName("hostedPaymentCustomerOptions");
sett_CustomerOptions.setSettingValue("{\"showEmail\": true, " +
"\"requiredEmail\": false, \"addPaymentProfile\": false}");


SettingType sett_BillingAdrOptions = new SettingType();
sett_BillingAdrOptions.setSettingName("hostedPaymentBillingAddressOptions");
sett_BillingAdrOptions.setSettingValue("{\"show\": true, " +
"\"required\": false}");


ArrayOfSetting alist = new ArrayOfSetting();
alist.getSetting().add(sett_returnOptions);
alist.getSetting().add(sett_payBtnOptions);
alist.getSetting().add(sett_CustomerOptions);
alist.getSetting().add(sett_BillingAdrOptions);
alist.getSetting().add(sett_payOrderOptions);

GetHostedPaymentPageRequest apiRequest = new GetHostedPaymentPageRequest();
apiRequest.setTransactionRequest(txnRequest);
apiRequest.setHostedPaymentSettings(alist);

GetHostedPaymentPageController controller = new GetHostedPaymentPageController(apiRequest);
controller.execute();

GetHostedPaymentPageResponse //response = new GetHostedPaymentPageResponse();
response = controller.getApiResponse();

if (response!=null) {
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
System.out.println(response.getMessages().getMessage().get(0).getCode());
System.out.println(response.getMessages().getMessage().get(0).getText());
System.out.println(response.getToken());
}
else {
System.out.println("Failed to get hosted payment page: " + response.getMessages().getResultCode());
}
}

 

jeniferloras
Member