Showing results for 
Search instead for 
Did you mean: 

accept.js - SO CLOSE! One small thing and it will work ... $dataValue ??

Using code from github, I've finally gotten (mostly) accept.js to work, except for ONE thing ...

If I get the value from the returned nonce and paste it into the block below, the transaction will clear. So, I know that everything up to this point is correct:

    $opaqueData = new AnetAPI\OpaqueDataType();

BUT, I need to get that into the block as a variable. Nothing seems to work at the moment.
Checking to see if I've got a variable assigned.

echo 'dataValue '.$dataValue;
This correctly displays the returned value ( eyJjb2RlIjoiNTBfMl8wNjAwMDUyNkE5QzdDRUE2Q0E3QUFBMDAyQTkyMjc1OUEyNEFDMDM0NUJFNEUzOUM0RjYwQjlDMzBFMkJBN0U4NjA4QzE1QzQ5OUVBN0FGMDE2NTJBRjYzMkU1REQ2RUI5NkFEREVDIiwidG9rZW4iOiI5NTYxNDcxMDQyMTc4NjQxMDAzNTAxIiwidiI6IjEuMSJ9 ) so it seems my variable is set.
So back to my code block - trying this:
    $opaqueData = new AnetAPI\OpaqueDataType();


This generates an error: 

Notice: Undefined variable: dataValue in /order_receipt.php on line 109
Transaction Failed Error Code : E00003 Error Message : The element 'opaqueData' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has incomplete content. List of possible elements expected: 'dataValue' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'.

Hmmm - right above is my display block, and it's still outputting the correct value.

Just to be SURE I'm not an idiot (and I can be) ... single or double quotes don't work either
Notice: Undefined variable: dataValue in /order_receipt.php on line 109
Transaction Failed Error Code : E00076 Error Message : dataValue contains invalid value.

What have I got wrong? I'm an idiot, yes?

Actually, trying to get ANY variables into the code generates the same problem.
For example, I have $firstNAME and $lastNAME set ...

If the names are hard coded in, it works



But, trying to get that to work using the variables - ain't working ....






This sounds like a scope issue.  If so, there are several ways around it. The first, which will work but is bad practice is to use the global keyword for all the variables you want to use inside that function. So inside the function before you assign those object properties type-


global $firstName, $lastName;

//comma separate as many variables as you need. 

Since you have a small project this would probably be fine. Using global variables excessively in larger projects will cause bugs that are very difficult to track down. I still advise against it.  Another way is to pass all of those variables as parameters in your function.


function createAnAcceptPaymentTransaction($amount, $firstName, $lastName)

//use the above when defining the function then call it as in the below. You will 
// add the rest of your variables as needed

if (!defined('DONT_RUN_SAMPLES')) {

Regardless of what I try, I can't get it to include the $dataValue from the nonce


Adding $dataValue to the globel doesn't help ....

I'm experimenting with it, but no go so far ...
Also, is there a list of the returned data somewhere? Damned docs are convoluted ...

Also, THIS works and when the receipt comes back, is shown as the correct invoice number:



So why doesn't it work for the names? Or $dataValue??



This works too:


$order->setDescription("Enrollment Payment $enrID");

... and in the receipt email:

========= ORDER INFORMATION =========
Invoice : 1804875
Description : Enrollment Payment 1804875
Amount : 2.23 (USD)
Payment Method: Visa xxxx1111
Transaction Type: Authorization and Capture


Post your entire script
And using double quotes isn’t necessary and may be what’s causing your issue.

The nonce is a client side output and you and putting it through the server side. How are you assigning the value to the $dataValue variable? Are you posting it with a form? I’m on a phone waiting for my car to get inspected. I may be missing details.

Sounds like you are requesting a hosted pay web page where clients can sign in and store their card statistics, generating a relaxed token link, which you could then use for destiny variable expenses. That itself is quite simple.