Integration and Testing

Authorize.Net API questions and help with your payment integration.

Posts: 17
Registered: ‎12-30-2018

Unexpected '$opaqueData when using PHP SDK sample code

I'm having trouble, and I think it is the way I'm deploying the code. I'm thinking it can't find the SDK or something. Here is the code snippet, which is based on the sample PHP code for doing a payment transaction:



require './sdk-php/autoload.php';

require_once './credentials.php';

use net\authorize\api\contract\v1 as AnetAPI;

use net\authorize\api\controller as AnetController;



define("AUTHORIZENET_LOG_FILE", "phplog");



function createAnAcceptPaymentTransaction($amount)



/* Create a merchantAuthenticationType object with authentication details


retrieved from the constants file */

$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();





// Set the transaction's refId

$refId = 'ref' . time();

$dataDesc = $_POST['dataDescriptor'];

$dataVal = $_POST['dataValue'];

$Amount = $_POST['Amount']



// Create the payment object for a payment nonce

$opaqueData = new AnetAPI\OpaqueDataType();






I get the following error referring to the line above where it creates the $opaqueData object:


Parse error: syntax error, unexpected '$opaqueData' (T_VARIABLE) in .../test_auth_process.php on line 24.


What I have is my code in the root of my website. I've copied the SDK-PHP folder to that same folder, and I reference the Autoload, as instructed. I did rename the top level folder from sdk-php-2.0.0 to just sdk-php, as I'm thinking there might be updates at some point. I've tried it looking just for Require 'sdk-php/autoload.php' and './sdk-php/autoload.php', with the same error.


Can anybody spot what I'm doing wrong?


Thanks in advance.

Posts: 17
Registered: ‎12-30-2018

Re: Unexpected '$opaqueData when using PHP SDK sample code

Can anybody tell me what support files are needed when using PHP sample code? Is there a complete sample application that can be copied, so I can see what support files are needed, and where they need to be put?


Thank you.

All Star
Posts: 733
Registered: ‎11-05-2018

Re: Unexpected '$opaqueData when using PHP SDK sample code

Post[‘amount’] needs a semicolon after it. This isn’t an api error it is a straight php syntax error. FYI you are passing the amount as a parameter in the method call and then pulling the amount charged from a post variable inside the function. You’re doing double work. You could save a step and just include the post variable as an argument when you do the method call.
All Star
Posts: 733
Registered: ‎11-05-2018

Re: Unexpected '$opaqueData when using PHP SDK sample code

Your include/require paths are correct, otherwise you would get an error for that as well. Renaming the folder for the sdk will have no effect on anything as long as you rename the include/require path as well. What you never do is rename the files or sub folders in the api sub folder within the sdk package.