Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi Larry,

 

Hope you are well.

 

I have hit a brick wall on page 336 on Effortless Ecommerce 2nd edition.

 

I have written all the code up to this point. The only modification I have made is changing the  urls beginning with 'https' to 'http' in the billing.php page

 

eg:

$location = 'https://' . BASE_URL . 'checkout.php';

to
$location = 'http://' . BASE_URL . 'checkout.php';

 

and

$location = 'http://' . BASE_URL . 'final.php';

to
$location = '/final.php';

 

These are temporary adjustments because I don't have a ssl certificate installed yet.

 

When I get to the billing.php page and fill out all the form details which are all correct. I then click the 'place order' button to process the payment, and absolutely nothing happens. My 'API_LOGIN_ID'   id and 'TRANSACTION_KEY' are both correct. The billing.php page just refreshes with the same values in the fields, and not going to the 'final.php' page.

 

I debugged the program and when I got to the billing.php page, when I got  to the 'Process payment section'

// Process the payment!
        if (isset($order_id, $order_total)) {

 

 

I encountered an error at the following line:

 

'$response = $aim->authorizeOnly();'

 

all the values contained in the '$response' variable came back as null,

ie:

_response_array = null

approved = (bool) false

declined = null

error = (bool)true

response_code = null

transaction_id = null

invoice_number = null

description = null

customer_id = null

first_name = null

last_name = null

etc

 

so the following line:

$r = mysqli_query($dbc, "CALL add_transaction($order_id, '{$response->transaction_type}', $order_total, {$response->response_code}, '$reason', {$response->transaction_id}, '$full_response')");                
           

came back as false

so

if ($response->approved) 

returned false

 

I don't understand what happened because all the entered fields in the 'billing.php' page were correct, but for some reason, when passed to Authorize.net, the values are failing and returning null values.

I have tried for 3 full days to work this out but no luck.

Can you please help

Thank you

regards

 

Link to post
Share on other sites

Upon further research, the problem happens in the billing.php page, specifically at the line:

 

$response = $aim->authorizeOnly();

All my entered values are entered correctly, but when the following class is called in the 'anet_php_sdk' folder:

class AuthorizeNetAIM extends AuthorizeNetRequest()

and then the following method inside the class is called:

 

public function authorizeOnly($amount = false, $card_num = false, $exp_date = false)
    {
        ($amount ? $this->amount = $amount : null);
        ($card_num ? $this->card_num = $card_num : null);
        ($exp_date ? $this->exp_date = $exp_date : null);
        $this->type = "AUTH_ONLY";
        return $this->_sendRequest();
    }

 

The following variable parameters:

 

'$amount',  '$card_num', and  '$exp_date'

all return null values

 

Up until then, all the variables '$amount',  '$card_num', and  '$exp_date' all have valid values, but for some reason, they are not being passed into the parameters inside the above

'authorizeOnly($amount = false, $card_num = false, $exp_date = false)'  function

 

So the values that have been entered for the credit card details, are never passed into the above method because the boolean 'false' is assigned to these values.

I tried to take away all the 'false' values in the parameter in the 'authorizeOnly()' function, but all I got back was a blank 'billing.php' page.

 

So because all 'null' values are returned in the above 'authorizeOnly()' method, the following method in the 'billing.php' page, returns false, and the payment is never processed.

if ($response->approved) {)

 

Can you help me solve this problem please.

 

Thank you.

 

regards

 

Link to post
Share on other sites

Hmmm...it's been a long while since I've looked at this code. What version of the Authorize.NET PHP library are you using? This could be a change in their library since the book was written. 

Link to post
Share on other sites

Hi Larry,

 

I am using the following version which can be found at:

 

https://github.com/objco/anet_php_sdk

 

It's called

anet_php_sdk-master

 

The reason I am using this version is because the link developer.authorize.net/downloads  where you said we could download the version you are using on page 325, is  obsolete, so I had no choice but to find another link where there was another version.

 

I believe I am using a slightly different version from the one you are using.

 

regards

 

Link to post
Share on other sites

Okay, so the code is the same as in the book and the library is roughly the same and the code examples in GitHub are roughly the same. This is going to be hard to debug! 

My inclination is that either the library doesn't work on HTTP or it has something to do with the sandbox. I would first log into Authorize.net and see if I can view the requests being made. First check that the requests are getting there. Then, if so, check that the requests are receiving the CC dummy values. 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...