我正在處理付款處理頁面。我們正在使用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
起初我還以爲這東西在我的代碼,所以我試圖運行授權的PHP樣本交易,並得到同樣的錯誤。
該串行器昨天剛剛從GitHub下載。 https://github.com/schmittjoh/serializer
這裏是授權示例代碼:
<?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";
}
?>
是什麼原因造成的錯誤任何想法?
那麼,你在哪個代碼中爲串行器調用? –
我剛剛添加了我試圖運行的授權示例代碼。 Authorize庫中的一種方法是調用Serializer。 –