Quote Originally Posted by mc12345678 View Post
Seeing so many having difficulty using this added feature and while this (solution and addition to ZC) makes a plugin I offer obsolete, ZC 1.5.5x is missing an important part of the process outlined by PayPal to support In Context checkout. Namely the javascript code needed to support the operation.

The code needs to be incorporated first in the shopping_cart, and then anywhere from which the PayPal Express button can be applied and anywhere to which return from PayPal is expected in order to allow revisiting the in context operation and to "hold" the view in the original screen.

An easy solution that doesn't require any file overrides nor template modification is to place the following code in a file named jscript_paypal_incontext.php then place that file in the folders listed below:

jscript_paypal_incontext.php:
Code:
<?php
if (defined('MODULE_PAYMENT_PAYPALWPP_CHECKOUTSTYLE') && MODULE_PAYMENT_PAYPALWPP_CHECKOUTSTYLE == 'InContext' && defined('MODULE_PAYMENT_PAYPALWPP_MERCHANTID') && MODULE_PAYMENT_PAYPALWPP_MERCHANTID != '' && defined('MODULE_PAYMENT_PAYPALWPP_STATUS') && MODULE_PAYMENT_PAYPALWPP_STATUS == 'True') {
?><!-- merchant site HTML page --><script> (function(d, s, id){ var js, ref = d.getElementsByTagName(s)[0]; if (!d.getElementById(id)){ js = d.createElement(s); js.id = id; js.async = true; js.src = "//www.paypalobjects.com/js/external/paypal.js"; ref.parentNode.insertBefore(js, ref); } }(document, "script", "paypal-js")); </script><?php
}
Place the file in at least each of the folders in the path includes/modules/pages/

shopping_cart
login
checkout_shipping
checkout_payment
checkout_confirmation
checkout_success
time_out
index

Ie. includes/modules/pages/shopping_cart/jscript_paypal_incontext.php

And any other page that has the PayPal express checkout button or that is or could be a return page displayed to the customer in the checkout process as implemented by modifications made to your site to where a customer could return from PayPal express. (For example, the shipping page can be bypassed using PayPal Express, further the payment page can be bypassed also provided there is no possibility of a coupon being applied, which would deliver the customer to the checkout_confirmation page in a default ZC install.)
Revision to the above which so far has worked in all testing and uses more recent/locatable information.

An easy solution that doesn't require any file overrides nor template modification is to place the following code in a file named jscript_paypal_incontext.php then place that file in the folders listed below:

jscript_paypal_incontext.php:
Code:
<?php
if (defined('MODULE_PAYMENT_PAYPALWPP_CHECKOUTSTYLE') && MODULE_PAYMENT_PAYPALWPP_CHECKOUTSTYLE == 'InContext' && defined('MODULE_PAYMENT_PAYPALWPP_MERCHANTID') && MODULE_PAYMENT_PAYPALWPP_MERCHANTID != '' && defined('MODULE_PAYMENT_PAYPALWPP_STATUS') && MODULE_PAYMENT_PAYPALWPP_STATUS == 'True') {
  require_once(DIR_WS_CLASSES . 'payment.php');
  $paypalwpp_module = 'paypalwpp';
  // init the payment object
  $classPay = new payment($paypalwpp_module);
  ?><script>
  
  paypal.checkout.setup('<?php echo MODULE_PAYMENT_PAYPALWPP_MERCHANTID; ?>', {
    //locale: '<?php echo ${$paypalwpp_module}->getLanguageCode('incontext'); ?>',
<?php
  echo (MODULE_PAYMENT_PAYPALWPP_SERVER == 'live' ? '' : "\n          environment: 'sandbox',")?>
    container: 'PPecic',
    buttons: 'ecButton',
    click: function() {
      paypal.checkout.initXO();

      var action = $.post('/set-express-checkout');

      action.done(function (data) {
        paypal.checkout.startFlow(data.token);
      });

      action.fail(function () {
        paypal.checkout.closeFlow();
      });
    }
  });
</script>
<!-- merchant site HTML page --><script src = "//www.paypalobjects.com/api/checkout.js" async></script><?php
}
Place the file in at least each of the folders in the path includes/modules/pages/

shopping_cart
login
checkout_shipping
checkout_payment
checkout_confirmation
checkout_success
time_out
index

Ie. includes/modules/pages/shopping_cart/jscript_paypal_incontext.php

And any other page that has the PayPal express checkout button or that is or could be a return page displayed to the customer in the checkout process as implemented by modifications made to your site to where a customer could return from PayPal express. (For example, the shipping page can be bypassed using PayPal Express, further the payment page can be bypassed also provided there is no possibility of a coupon being applied, which would deliver the customer to the checkout_confirmation page in a default ZC install.)