cancel
Showing results for 
Search instead for 
Did you mean: 

Facing authorized dot. net (hosted) Form response error?

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>';

}
}

0 REPLIES 0