重定向页面仅显示订单摘要(authorize.net接受主机)

时间:2019-06-04 11:49:30

标签: php sdk authorize.net

我正在使用authorize.net提供的php SDK。特定的方法是使用重定向页面的可接受的宿主方法。 1)令牌与I00001成功消息一起返回 2)该页面仅在顶部显示订单摘要。 3)我也在Chrome控制台中收到以下错误。

我已经为此奋斗了2个多星期,但无济于事,我们所有人能给我的任何帮助将不胜感激。 吉姆

铬控制台上的错误消息:

payment:24 Uncaught SyntaxError:无效或意外的令牌

使用的代码:

function sdk_test()
 {
     //-----------------------------------------------------------
     //Create a merchantAuthenticationType object with authentication details
     //retrieved from the constants file
     //-----------------------------------------------------------
    $merchantAuthentication = new 
 AnetAPI\MerchantAuthenticationType();
    //$merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID);
    $merchantAuthentication->setName($this->anobj->get_field('login'));
    //$merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY);
    $merchantAuthentication->setTransactionKey($this->anobj->get_field('x_trans_key'));

    //-----------------------------------------------------------
    // Set the transaction's refId
    //-----------------------------------------------------------
    $refId = 'ref' . time();
    //-----------------------------------------------------------
    // Create the payment data for a credit card
    //-----------------------------------------------------------
    $creditCard = new AnetAPI\CreditCardType();
    $creditCard->setCardNumber("4111111111111111");
    $creditCard->setExpirationDate("2038-12");
    $creditCard->setCardCode("123");
    //-----------------------------------------------------------
    // Add the payment data to a paymentType object
    //-----------------------------------------------------------
    $paymentOne = new AnetAPI\PaymentType();
    $paymentOne->setCreditCard($creditCard);
    //-----------------------------------------------------------
    // Create order information
    //-----------------------------------------------------------
    $order = new AnetAPI\OrderType();
    $order->setInvoiceNumber("10101");
    $order->setDescription("Golf Shirts");
  //-----------------------------------------------------------
    // Set the customer's Bill To address
    //-----------------------------------------------------------
    $customerAddress = new AnetAPI\CustomerAddressType();
    $customerAddress->setFirstName("Ellen");
    $customerAddress->setLastName("Johnson");
    $customerAddress->setCompany("Souveniropolis");
    $customerAddress->setAddress("14 Main Street");
    $customerAddress->setCity("Pecan Springs");
    $customerAddress->setState("TX");
    $customerAddress->setZip("44628");
    $customerAddress->setCountry("USA");
    //-----------------------------------------------------------
    // Set the customer's identifying information
    //-----------------------------------------------------------
    $customerData = new AnetAPI\CustomerDataType();
    $customerData->setType("individual");
    $customerData->setId("99999456654");
    $customerData->setEmail("EllenJohnson@example.com");
    //-----------------------------------------------------------
    // Add values for transaction settings
    //-----------------------------------------------------------
    $duplicateWindowSetting = new AnetAPI\SettingType();
    $duplicateWindowSetting->setSettingName("duplicateWindow");
    $duplicateWindowSetting->setSettingValue("60");
    //-----------------------------------------------------------
    // Add some merchant defined fields. These fields won't be
    // stored with the transaction,but will be echoed back in the response.
    //-----------------------------------------------------------
    $merchantDefinedField1 = new AnetAPI\UserFieldType();
    $merchantDefinedField1->setName("customerLoyaltyNum");
    $merchantDefinedField1->setValue("1128836273");
    $merchantDefinedField2 = new AnetAPI\UserFieldType();
    $merchantDefinedField2->setName("favoriteColor");
    $merchantDefinedField2->setValue("blue");
    //-----------------------------------------------------------
    // Create a TransactionRequestType object and add the previous objects to it
    //-----------------------------------------------------------
    $transactionRequestType = new AnetAPI\TransactionRequestType();
    $transactionRequestType->setTransactionType("authOnlyTransaction");
    $transactionRequestType->setAmount($amount);
    $transactionRequestType->setOrder($order);
    $transactionRequestType->setPayment($paymentOne);
    $transactionRequestType->setBillTo($customerAddress);
    $transactionRequestType->setCustomer($customerData);
    $transactionRequestType->addToTransactionSettings($duplicateWindowSetting);
  $transactionRequestType->addToUserFields($merchantDefinedField1);
    $transactionRequestType->addToUserFields($merchantDefinedField2);
    //-----------------------------------------------------------
    // Assemble the complete transaction request
    //-----------------------------------------------------------
    $request = new AnetAPI\CreateTransactionRequest();
    $request->setMerchantAuthentication($merchantAuthentication);
    $request->setRefId($refId);
    $request->setTransactionRequest($transactionRequestType);
    //-----------------------------------------------------------
    // Create the controller and get the response
    //-----------------------------------------------------------
    $controller = new AnetController\CreateTransactionController($request);
    $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
    if ($response != null)
    {
        // Check to see if the API request was successfully received and acted upon
        if ($response->getMessages()->getResultCode() == "Ok")
        {
            // Since the API request was successful, look for a transaction response
            // and parse it to display the results of authorizing the card
            $tresponse = $response->getTransactionResponse();

            if ($tresponse != null && $tresponse->getMessages() != null)
            {
                echo " Successfully created transaction with Transaction ID: " .
                    $tresponse->getTransId() . "\n";
                echo " Transaction Response Code: " . $tresponse->getResponseCode() . "\n";
                echo " Message Code: " . $tresponse->getMessages()[0]->getCode() . "\n";
                echo " Auth Code: " . $tresponse->getAuthCode() . "\n";
                echo " Description: " . $tresponse->getMessages()[0]->getDescription() . "\n";
            }
            else
            {
                echo "Transaction Failed \n";
                if ($tresponse->getErrors() != null)
                {
                    echo " Error Code  : " .
                        $tresponse->getErrors()[0]->getErrorCode() . "\n";
                    echo " Error Message : " .
                        $tresponse->getErrors()[0]->getErrorText() . "\n";
                }
            }
   }
        else
        {
            echo "Transaction Failed \n";
            $tresponse = $response->getTransactionResponse();

            if ($tresponse != null && $tresponse->getErrors() != null)
            {
                echo " Error Code  : " .
                    $tresponse->getErrors()[0]->getErrorCode() . "\n";
                echo " Error Message : " .
                    $tresponse->getErrors()[0]->getErrorText() . "\n";
            }
            else
            {
                echo " Error Code  : " .
                    $response->getMessages()->getMessage()[0]->getCode() . "\n";
                echo " Error Message : " .
                    $response->getMessages()->getMessage()[0]->getText() . "\n";
            }
        }
    }
    else
    {
        echo  "No response returned \n";
    }
    return $response;
 }

返回的页面来源:

    <!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" xml:lang="en">

<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">

<head id="Head1"><title>
    Secure Information
</title>
          <!-- Google Tag Manager -->
            <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
            new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
            j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
            'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
            })(window,document,'script','dataLayer','GTM-KFWQGNC');</script>
          <!-- End Google Tag Manager -->
    <script src="https://sandbox-assets.secure.checkout.visa.com/checkout-widget/resources/js/integration/v1/sdk.js" type="text/javascript" > </script>
    <script type="text/javascript">
          var g_token = "null";
          var g_merchantData = null;
          var g_pageOptions = null;
          var g_paymentProfiles = null;
          var g_maxPaymentProfiles = false;
          var g_errorPanelMessage = "The page has timed out. Please go back to the beginning and try again.";
            var g_siteKey = "6Lc8tgYAAAAAAFfalsuPuIZ6bv_2dGT_Y9ZxURiK";
            var g_visaCheckoutUrl = "https://sandbox.secure.checkout.visa.com/wallet-services-web/xo/button.png";
        </script>

<script type="text/javascript">
  var g_EcheckEnabled = false;
var g_CreditEnabled = false;
  </script>
  <base href="./Scripts/v1/">
</head>
<body>
  <div class="PageOuter" id="divPageOuter">
    <div id="divPopupScreen" class="PopupScreen" style="display:none;"></div>
      <div class="Page" id="divPage">
      <div class="PageMain container" id="divPageMain container">

          <!-- Google Tag Manager (noscript) -->
            <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-KFWQGNC"
            height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
          <!-- End Google Tag Manager (noscript) -->
          <app-accept-payment></app-accept-payment>

          <link href="styles.bundle.css" rel="stylesheet"/>
          <script type="text/javascript" src="inline.bundle.js"></script>
          <script type="text/javascript" src="polyfills.bundle.js"></script>
          <script type="text/javascript" src="scripts.bundle.js"></script>
          <script type="text/javascript" src="main.bundle.js"></script>        

      </div>
      <div class="PageMainAfter"></div>
    </div>
  </div>
</body>
</html>

0 个答案:

没有答案
相关问题