1

I am working on a payment processing page. We are using Authorize.net to process the transactions. I have imported Authorize's php library and all of its dependencies.

When I try to process a test transaction I get the following error:

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

At first I thought it was something in my code so I tried running Authorize's php sample transaction and get the same error.

The serializer was just downloaded yesterday from GitHub. https://github.com/schmittjoh/serializer

Here is the Authorize Sample Code:

<?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";
}
?>

Any ideas on what is causing the error?

Josh Curren
  • 10,171
  • 17
  • 62
  • 73

1 Answers1

2

My bet is, the PHP version you are using is older then 5.4.0, right?

Calling $this in an anonymous function is not supported below that version. See Using $this in anonymous function

and here http://php.net/manual/en/functions.anonymous.php

If I am correct, I highly advice to update to at least PHP 5.6.x

Hope I could help bit.

Community
  • 1
  • 1
MrMagix
  • 116
  • 1
  • 4