Forum

Thread tagged as: Question, Problem, Shop

How to route the checkout page for PayPal Express in Runway?

When the Checkout Now link on my cart page is clicked, it goes to an empty/blank page. I have debug on but I'm not sure how to get the correct route from it. Please help me route this correctly.

My current template setup and debug info (admin = the perch folder) is below, it's more or less copied direct from the documentation so I can make sure everything works at its most basic...

Master page: cart.php located in admin/pages/

<?php perch_shop_cart(); ?>


Master page: checkout.php located in admin/pages/

<?php
if (perch_member_logged_in()) {

  // your 'success' return URL
  $return_url = '/shop/payment';
  $cancel_url = '/';

  perch_shop_checkout('paypal-express', [
    'return_url' => $return_url,
    'cancel_url' => $cancel_url,
  ]);
}
?>

Master page: payment.php located in admin/pages/

<?php
  perch_shop_complete_payment('paypal-express');

  if (perch_shop_order_successful()) {
      echo '<h1>Thank you for your order!</h1>';
    }else{
      echo '<h1>Sorry!</h1>';
    }
?>

The location path for my Payment page is /shop/payment


My config for PayPal Express is set up in admin/config/shop.php like this:

<?php
    return [

        /*
        |--------------------------------------------------------------------------
        | Gateway settings
        |--------------------------------------------------------------------------
        */

        'gateways' => [

            'default' => [
                'enabled'   => false,
                'test_mode' => false,
                'live' => [
                    'api_key'      => 'abc123',
                ],
                'test' => [
                    'api_key'      => 'abc123',
                ],
            ],

            'paypal-express' => [
                    'enabled'   => true,
                    'test_mode' => true,
                    'live' => [
                      'username'  => 'paypal_api_username',
                      'password'  => 'paypal_api_password',
                      'signature' => 'paypal_api_signature',
                    ],
                    'test' => [
                      'username'  => '43ranch_api1.lmlgraphics.com',
                      'password'  => '5JFMNSXS6773DHN7',
                      'signature' => 'AFcWxV21C7fd0v3bYYYRCpSSRl31Az9U8FhOSoCZdIHQiXqolF1CweiO',
                    ],
                ],
            ],

        ],

    ];

My understanding from this docs page is that the Checkout page should link directly to PayPal if the config file is set up, but I must be missing something.

You can add products to the cart on the development server / see the issue live here: https://138.197.208.91/shop

Here is the debug from the blank checkout page:

Debug Message - Perch Runway 3.0.10
[11] SELECT p.pagePath, pr.routePattern, pr.routeRegExp, p.pageTemplate, pr.routeOrder, s.settingValue AS siteOffline FROM perch3_pages p LEFT JOIN perch3_page_routes pr ON p.pageID=pr.pageID LEFT JOIN perch3_settings s ON s.settingID='siteOffline' UNION SELECT NULL AS pagePath, pr2.routePattern, pr2.routeRegExp, pr2.templatePath AS pageTemplate, pr2.routeOrder, NULL AS siteOffline FROM perch3_page_routes pr2 WHERE templateID!=0 ORDER BY routeOrder ASC, pagePath ASC
Matched page: /shop/checkout, so not using routes.
Using master page: /templates/pages/checkout.php
[41] SELECT DISTINCT settingID, settingValue FROM perch3_settings WHERE userID=0
[1] SELECT * FROM perch3_pages WHERE pagePath='/shop/checkout' LIMIT 1
[1] SELECT * FROM perch3_shop_cart WHERE cartID=7493
[1] SELECT * FROM perch3_shop_cart WHERE cartID=7493
[nil] SELECT * FROM perch3_shop_sales WHERE saleFrom<='2017-10-17 04:54:00' AND saleTo>'2017-10-17 04:54:00' AND saleActive=1 AND saleDeleted IS NULL ORDER BY saleOrder ASC
Request time: 0.0098
Process time: 0.0092
Memory: 0.9013
Lindsay Masten

Lindsay Masten 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you checked your error log?

Hi Drew, thanks for helping. I'm so stumped!

My error log—you mean in browser developer tools?—isn't showing anything, just a little message saying Navigated to https://138.197.208.91/shop/checkout which is unfortunately a blank page.

Is there a debug I should look at besides the one I'm seeing on at shop/checkout included above? Everything up to that point seems to be working and I didn't notice any red error messages.

If I type the payment page URL into the browser, I see it's sort of working (I get the "Sorry!" message): https://138.197.208.91/shop/payment

My site diagnostics show I'm healthy, here's the summary readout:

Perch Runway: 3.0.10, PHP: 7.1.10, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: b396954eeb2d1d9ed7902b8bae237b287f21ad9e $, with PDO
Server OS: Linux, fpm-fcgi
Installed apps: content (3.0.10), assets (3.0.10), categories (3.0.10), perch_blog (5.6.1), perch_shop_orders (1.2.5), perch_shop_products (1.2.5), perch_shop (1.2.5), perch_members (1.6.2)
App runtimes: <?php $apps_list = [ 'content', 'categories', 'perch_blog', 'perch_members', 'perch_shop', ];
PERCH_LOGINPATH: /admin
PERCH_PATH: /srv/users/serverpilot/apps/43-ranch/public/admin
PERCH_CORE: /srv/users/serverpilot/apps/43-ranch/public/admin/core
PERCH_RESFILEPATH: /srv/users/serverpilot/apps/43-ranch/public/admin/resources
Image manipulation: GD
PHP limits: Max upload 512M, Max POST 1024M, Memory: 256M, Total max file upload: 256M
F1: 3b606135b33e6a102526838f4152a807
Resource folder writeable: Yes
SCRIPT_NAME: /admin/core/settings/diagnostics/index.php
REQUEST_URI: /admin/core/settings/diagnostics/
DOCUMENT_ROOT: /srv/users/serverpilot/apps/43-ranch/public
HTTP_HOST: 138.197.208.91
Drew McLellan

Drew McLellan 2638 points
Perch Support

I mean your PHP error log on the web server. If you're getting a blank page it sounds like the process is exiting with an error.

Sorry, of course, so many places to look for errors.

Here's the most recent php error log, the only one from today.

[17-Oct-2017 06:48:26 UTC] PHP Parse error:  syntax error, unexpected end of file in /srv/users/serverpilot/apps/43-ranch/public/admin/config/config.production.php on line 1
[17-Oct-2017 07:34:08 UTC] PHP Warning:  include(admin/runtime.php): failed to open stream: No such file or directory in /srv/users/serverpilot/apps/43-ranch/public/admin/templates/layouts/home/content_home.php on line 1
[17-Oct-2017 07:34:08 UTC] PHP Warning:  include(): Failed opening 'admin/runtime.php' for inclusion (include_path='.:/opt/sp/php7.1/lib/php') in /srv/users/serverpilot/apps/43-ranch/public/admin/templates/layouts/home/content_home.php on line 1
[17-Oct-2017 07:39:53 UTC] PHP Parse error:  syntax error, unexpected '<', expecting end of file in /srv/users/serverpilot/apps/43-ranch/public/admin/templates/pages/home.php on line 9
[17-Oct-2017 08:01:55 UTC] PHP Parse error:  syntax error, unexpected end of file in /srv/users/serverpilot/apps/43-ranch/public/admin/config/config.production.php on line 1
[17-Oct-2017 08:18:42 UTC] PHP Parse error:  syntax error, unexpected end of file in /srv/users/serverpilot/apps/43-ranch/public/admin/config/config.production.php on line 1

Hi, sorry to pester the forum, but my PHP is not strong enough to know what issue the above error log is pointing me toward. Does anyone have any insight?

ETA: To my eyes it looks like an unrelated error involving my homepage. But it's the only error from today, so if it doesn't help I'm back to square one with the checkout problem. :(

There is an error in your php on your home.php or the layout code.

I am on my phone so I can’t really read the error easily. But it is a php error, not likely a perch one.

Hi Robert, thanks for taking a look. There was an error on my home.php layout code, but I think now that it's probably a red herring unrelated to my main problem. I only shared that error text because Drew asked if there were any errors logged and it was the only error logged today/yesterday.

My main issue with having my checkout page show up blank during PayPal Express checkout doesn't seem to be logging any errors. :-/ It's probably difficult to see on a phone, but I have my template code and debug info loaded into my initial post above. I'd really appreciate if you took a look, if you have time. Thanks so much.

Duncan Revell

Duncan Revell 78 points
Registered Developer

Hi Lindsay,

when you get to the checkout page, are you logged in as a member?

Hi Duncan, I'm not, I haven't set any of the member stuff up yet at all. I'm guessing by your question that maybe I should? Ideally, I would like people to be able to check out without signing in.

Duncan Revell

Duncan Revell 78 points
Registered Developer

Your checkout page has code that is wrapped in code that checks if the member is logged in:

<?php if (perch_member_logged_in()) 
{  
// your 'success' return URL 
$return_url = '/shop/payment'; 
$cancel_url = '/';  
perch_shop_checkout('paypal-express', 
[ 'return_url' => $return_url, 
'cancel_url' => $cancel_url, 
]); 
} 
?>

That code currently won't run.

Thank you, Duncan, that's a great catch. I modified the code to get rid of the if/logged in check:

<?php perch_shop_checkout('paypal-express', [ 'return_url' => '/shop/payment', 'cancel_url' => '/', ]); ?>

Now I am getting this error, which seems to imply that I do need the membership features turned on:

Fatal error: Uncaught Error: Call to a member function id() on null in /srv/users/serverpilot/apps/43-ranch/public/admin/addons/apps/perch_shop/lib/PerchShop_Runtime.class.php:910 Stack trace: #0 /srv/users/serverpilot/apps/43-ranch/public/admin/addons/apps/perch_shop/lib/PerchShop_Runtime.class.php(603): PerchShop_Runtime->get_address(NULL, 'default') #1 /srv/users/serverpilot/apps/43-ranch/public/admin/addons/apps/perch_shop/runtime/cart.php(186): PerchShop_Runtime->checkout('paypal-express', Array, 'default') #2 /srv/users/serverpilot/apps/43-ranch/public/admin/templates/pages/checkout.php(4): perch_shop_checkout('paypal-express', Array) #3 /srv/users/serverpilot/apps/43-ranch/public/admin/core/runway/start.php(43): include('/srv/users/serv...') #4 /srv/users/serverpilot/apps/43-ranch/public/admin/core/runway/start.php(47): perch_runway_dispatch_page(Object(PerchRoutedPage)) #5 {main} thrown in /srv/users/serverpilot/apps/43-ranch/public/admin/addons/apps/perch_shop/lib/PerchShop_Runtime.class.php on line 910
Duncan Revell

Duncan Revell 78 points
Registered Developer

I don't think you can go that far without a member - you still need a name, email and postal address in order to be able to process a payment.

Look through this link to see how to create a password-less member:
https://docs.grabaperch.com/addons/shop/examples/no-account/