Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Code errors for Paypal API 2.0 upgrade


Thomas789

Recommended Posts

In the official instruction for the manual install of Paypal API 2.0 in osCommerce 2.2. , the following is asked to be added in /classes/payment.php

 

c) about line 142 (156) find
and insert before
function pre_confirmation_check() {
/// paypal_rest (from osc23)

 function checkout_initialization_method() {

 $initialize_array = array();


 if (is_array($this->modules)) {

 reset($this->modules);

 while (list(, $value) = each($this->modules)) {

 $class = substr($value, 0, strrpos($value, '.'));

 if ($GLOBALS[$class]->enabled && method_exists($GLOBALS[$class],

'checkout_initialization_method')) {

 $initialize_array[] = $GLOBALS[$class]->checkout_initialization_method();

 }

 }

 }

return $initialize_array;

 }

The highlighted line is invaild PHP since PHP8 and fails with fatal error. It should be replaced by

 

foreach ($this->modules as $value) {

 

Of course, the original code for osC 2.2. is invalid in many places these days as well, but our cart has always been upgraded to the latest PHP and mySQL versions over the years, and one should expect that the new installation instructions for apps should reflect the present status of PHP.

 

 

 

Edited by Thomas789
Link to comment
Share on other sites

As you mentioned, that package is for oscommerce 2.2. That oscommerce version is not qualified to run on any version above php 5.4, if that. So if the code in the paypal package was coded with code that works for php 8x, it would probably fail since some php code is not backward compatible.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

Posted (edited)
21 hours ago, Jack_mcs said:

As you mentioned, that package is for oscommerce 2.2. That oscommerce version is not qualified to run on any version above php 5.4, if that. So if the code in the paypal package was coded with code that works for php 8x, it would probably fail since some php code is not backward compatible.

 

The PHP foreach() construct is backward compatible with PHP 4 even.

 

Another issue I noticed is the missing class constructor in classes where the function name is identical to the class name. So it should be for instance


 

class paypal_rest extends PaypalPartnerTrait {

    var $code, $title, $description, $enabled;
    
         // class constructor
    function __construct() {
          $this->paypal_rest();
    }  
    

    function paypal_rest() {

Without the added class constructor method, this fails with fatal error in PHP8.  This is backward compatible with PHP5 at least as well.

Edited by Thomas789
Link to comment
Share on other sites

You're looking at it backwards. If i am coding an addon for a 2.2 shop, I would code it using php for that version - 5.3, maybe 5.4. To try to code it for some future version of php is just asking for problems. The parts you mention are compatible, but some other function may not be. So, I would need to create two versions: one for the intended shops and one for those like you, assuming I used code that was not compatible between the various versions. Since my imaginary addon is being written for free, why should I go to so much effort to cover cases where the shops code has been altered? Look at just about any old addon and the instructions will mention that the changes are for a stock shop. This is no different.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

×
×
  • Create New...