Jump to content
Smoky Barnable

PayPal App timing out?

Recommended Posts

How does the PayPal App connect to the PayPal servers?  In other words, I notice occasionally the connection times out on the shopping cart page and the express payment button is not displayed. Same issue if using PayPal login, none of the login methods load if a connection to PayPal can't be established. Does the PayPal App cycle through all ip/domain addresses as described here?

https://www.paypal.com/us/smarthelp/article/what-are-the-ip-addresses-for-live-paypal-servers-ts1056

The long timeouts are the concern to me. Perhaps something more robust can be coded up.


The water in a vessel is sparkling; the water in the sea is dark. The small truth has words which are clear; the great truth has great silence.

- Rabindranath Tagore

Share this post


Link to post
Share on other sites

Hey @Smoky Barnable,

Think I can help you with this too.

The Express button and the Login button are two different beasts. 

As always please backup before making any changes and test all changes after.

Express Button

The Express button specifics vary depending on how you have it configured, whether it's dynamic or static.

If it's static then it is an image that's loaded from paypalobjects.com but is done in the old fashioned way of <img src="https://www.paypalobjects.com/...."> so not much can be done about that other than to save the image and then upload it to your server so it's served locally which will speed up display.  You'll need to change the definition for this URL found in includes/apps/paypal/languages/english/modules/EC/EC.php on line 22 approx.

All of these changes are based on 5.018 of the stock osC PayPal App (not Frozen etc)

From:

module_ec_button_url = https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-medium.png

To (as an example):

module_ec_button_url = https://www.mydomainname.com/images/buttons/checkout-logo-medium.png

However any auto-updates applied in the future will revert it back to stock.

IF it's being loaded dynamically then it could be because it's trying to render before the page has fully loaded all resources and this is the same problem I've found with the Login button also suffers from.

For the next part to work, jQuery must be called on the page before the output of this script in paypal_express.php

In includes/modules/payment/paypal_express.php approx line 220 find:

$string .= <<<EOD
<span id="ppECButton"></span>
<script>
paypal.Button.render({
  env: '{$server}',
  style: {
    size: '${button_size}',
    color: '${button_color}',
    shape: '${button_shape}'
  },
  payment: function(resolve, reject) {
    paypal.request.post('${ppecset_url}')
      .then(function(data) {
        if ((data.token !== undefined) && (data.token.length > 0)) {
          resolve(data.token);
        } else {
          window.location = '${ppecerror_url}';
        }
      })
      .catch(function(err) {
        reject(err);

        window.location = '${ppecerror_url}';
      });
  },
  onAuthorize: function(data, actions) {
    return actions.redirect();
  },
  onCancel: function(data, actions) {
    return actions.redirect();
  }
}, '#ppECButton');
</script>
EOD;

And replace with:

$string .= <<<EOD
<span id="ppECButton"></span>
<script>
$( document ).ready(function() {
paypal.Button.render({
  env: '{$server}',
  style: {
    size: '${button_size}',
    color: '${button_color}',
    shape: '${button_shape}'
  },
  payment: function(resolve, reject) {
    paypal.request.post('${ppecset_url}')
      .then(function(data) {
        if ((data.token !== undefined) && (data.token.length > 0)) {
          resolve(data.token);
        } else {
          window.location = '${ppecerror_url}';
        }
      })
      .catch(function(err) {
        reject(err);

        window.location = '${ppecerror_url}';
      });
  },
  onAuthorize: function(data, actions) {
    return actions.redirect();
  },
  onCancel: function(data, actions) {
    return actions.redirect();
  }
}, '#ppECButton');
});
</script>
EOD;

 

PayPal Login

THE CHANGES BELOW ARE ONLY FOR THOSE WHO HAVE SWAPPED OVER TO https://www.paypalobjects.com/js/external/connect/api.js LIKE SMOKY HAS (SEE OTHER POST REGARDING PAYPAL LOGIN UPDATE 

In includes/modules/content/login/templates/paypal_login.php find:

<script type="text/javascript" src="https://www.paypalobjects.com/js/external/connect/api.js"></script>
<script type="text/javascript">
paypal.use( ["login"], function(login) {
  login.render ({

<?php
  if ( OSCOM_APP_PAYPAL_LOGIN_STATUS == '0' ) {
    echo '    "authend": "sandbox",';
  }

  if ( OSCOM_APP_PAYPAL_LOGIN_THEME == 'Neutral' ) {
    echo '    "theme": "neutral",';
  }
?>

    "responseType" : "code id_Token",
    "locale": "<?php echo $cm_paypal_login->_app->getDef('module_login_language_locale'); ?>",
    "appid": "<?php echo (OSCOM_APP_PAYPAL_LOGIN_STATUS == '1') ? OSCOM_APP_PAYPAL_LOGIN_LIVE_CLIENT_ID : OSCOM_APP_PAYPAL_LOGIN_SANDBOX_CLIENT_ID; ?>",
    "scopes": "<?php echo implode(' ', $use_scopes); ?>",
    "buttonType" : "CWP",
    "buttonShape" : "rectangle",
    "buttonSize" : "md",
    "fullPage" : "false",
    "containerid": "PayPalLoginButton",
    "returnurl": "<?php echo str_replace('&amp;', '&', tep_href_link(FILENAME_LOGIN, 'action=paypal_login', 'SSL', false)); ?>"
  });
});
</script>

And replace with:

<script type="text/javascript" src="https://www.paypalobjects.com/js/external/connect/api.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
paypal.use( ["login"], function(login) {
  login.render ({

<?php
  if ( OSCOM_APP_PAYPAL_LOGIN_STATUS == '0' ) {
    echo '    "authend": "sandbox",';
  }

  if ( OSCOM_APP_PAYPAL_LOGIN_THEME == 'Neutral' ) {
    echo '    "theme": "neutral",';
  }
?>

    "responseType" : "code id_Token",
    "locale": "<?php echo $cm_paypal_login->_app->getDef('module_login_language_locale'); ?>",
    "appid": "<?php echo (OSCOM_APP_PAYPAL_LOGIN_STATUS == '1') ? OSCOM_APP_PAYPAL_LOGIN_LIVE_CLIENT_ID : OSCOM_APP_PAYPAL_LOGIN_SANDBOX_CLIENT_ID; ?>",
    "scopes": "<?php echo implode(' ', $use_scopes); ?>",
    "buttonType" : "CWP",
    "buttonShape" : "rectangle",
    "buttonSize" : "md",
    "fullPage" : "false",
    "containerid": "PayPalLoginButton",
    "returnurl": "<?php echo str_replace('&amp;', '&', tep_href_link(FILENAME_LOGIN, 'action=paypal_login', 'SSL', false)); ?>"
  });
});
});
</script>

 

Again, any changes made to the above files will be overwritten if the PayPal auto-update button is used at anypoint in the future.


If it still don't work, hit it again!

Senior PHP Dev with 18+ years of commercial experience for hire, all requirements considered, see profile for more information.

Is your version of osC up to date? You'll find the latest osC version (the community-supported responsive version) here.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×