1

私は支払い処理ページに取り組んでいます。Authorize.net を使用してトランザクションを処理しています。Authorize の php ライブラリとそのすべての依存関係をインポートしました。

テスト トランザクションを処理しようとすると、次のエラーが発生します。

Fatal error: Using $this when not in object context in /home/ticketstroyfair/public_html/include/authorize/vendor/jms/serializer/src/JMS/Serializer/Serializer.php on line 99

最初は自分のコードに何かあると思ったので、Authorize の php サンプル トランザクションを実行してみましたが、同じエラーが発生しました。

シリアライザーは、昨日 GitHub からダウンロードされたばかりです。https://github.com/schmittjoh/serializer

Authorize のサンプル コードは次のとおりです。

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

define("AUTHORIZENET_LOG_FILE","phplog");

// Common setup for API credentials  
  $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();   
  $merchantAuthentication->setName("YOU_API_LOGIN_ID");   
  $merchantAuthentication->setTransactionKey("YOUR_TRANSACTION_KEY");   
  $refId = 'ref' . time();

// Create the payment data for a credit card
  $creditCard = new AnetAPI\CreditCardType();
  $creditCard->setCardNumber("4111111111111111" );  
  $creditCard->setExpirationDate( "2038-12");
  $paymentOne = new AnetAPI\PaymentType();
  $paymentOne->setCreditCard($creditCard);

// Create a transaction
  $transactionRequestType = new AnetAPI\TransactionRequestType();
  $transactionRequestType->setTransactionType("authCaptureTransaction");   
  $transactionRequestType->setAmount(151.51);
  $transactionRequestType->setPayment($paymentOne);
  $request = new AnetAPI\CreateTransactionRequest();
  $request->setMerchantAuthentication($merchantAuthentication);
  $request->setRefId( $refId);
  $request->setTransactionRequest($transactionRequestType);
  $controller = new AnetController\CreateTransactionController($request);
  $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);   

if ($response != null) 
{
  $tresponse = $response->getTransactionResponse();
  if (($tresponse != null) && ($tresponse->getResponseCode()=="1"))
  {
    echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n";
    echo "Charge Credit Card TRANS ID  : " . $tresponse->getTransId() . "\n";
  }
  else
  {
    echo "Charge Credit Card ERROR :  Invalid response\n";
  }
}  
else
{
  echo  "Charge Credit Card Null response returned";
}
?>

エラーの原因についてのアイデアはありますか?

4

1 に答える 1

2

おそらく、使用している PHP のバージョンは 5.4.0 よりも古いものですよね?

そのバージョンより下では、無名関数での $this の呼び出しはサポートされていません。無名関数での $this の使用を参照してください

そしてここhttp://php.net/manual/en/functions.anonymous.php

私が正しければ、少なくとも PHP 5.6.x に更新することを強くお勧めします。

少しでもお役に立てれば幸いです。

于 2016-02-11T19:02:55.587 に答える