Add product into cart, and press the PayPal Express Checkout button, will cause this problems:

PHP Fatal error: Call to undefined function uc_cart_get_contents() in /home/jian/src/drupal8/modules/ubercart/payment/uc_paypal/uc_paypal.module on line 683
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP Stack trace:
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 1. {main}() /home/jian/src/drupal8/index.php:0
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 2. Drupal\Core\DrupalKernel->handle() /home/jian/src/drupal8/index.php:22
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 3. Stack\StackedHttpKernel->handle() /home/jian/src/drupal8/core/lib/Drupal/Core/DrupalKernel.php:637
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 4. Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() /home/jian/src/drupal8/vendor/stack/builder/src/Stack/StackedHttpKernel.php:23
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 5. Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() /home/jian/src/drupal8/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php:55
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 6. Drupal\page_cache\StackMiddleware\PageCache->handle() /home/jian/src/drupal8/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php:51
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 7. Drupal\page_cache\StackMiddleware\PageCache->pass() /home/jian/src/drupal8/core/modules/page_cache/src/StackMiddleware/PageCache.php:82
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 8. Drupal\Core\StackMiddleware\KernelPreHandle->handle() /home/jian/src/drupal8/core/modules/page_cache/src/StackMiddleware/PageCache.php:103
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 9. Drupal\Core\StackMiddleware\Session->handle() /home/jian/src/drupal8/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php:53
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 10. Symfony\Component\HttpKernel\HttpKernel->handle() /home/jian/src/drupal8/core/lib/Drupal/Core/StackMiddleware/Session.php:62
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 11. Symfony\Component\HttpKernel\HttpKernel->handleRaw() /home/jian/src/drupal8/vendor/symfony/http-kernel/HttpKernel.php:62
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 12. call_user_func_array:{/home/jian/src/drupal8/vendor/symfony/http-kernel/HttpKernel.php:139}() /home/jian/src/drupal8/vendor/symfony/http-kernel/HttpKernel.php:139
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 13. Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() /home/jian/src/drupal8/vendor/symfony/http-kernel/HttpKernel.php:139
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 14. Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() /home/jian/src/drupal8/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:102
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 15. Drupal\Core\Render\Renderer->executeInRenderContext() /home/jian/src/drupal8/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:129
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 16. Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() /home/jian/src/drupal8/core/lib/Drupal/Core/Render/Renderer.php:577
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 17. call_user_func_array:{/home/jian/src/drupal8/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:128}() /home/jian/src/drupal8/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:128
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 18. Drupal\uc_cart\Controller\CartController->listing() /home/jian/src/drupal8/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:128
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 19. Drupal\Core\Form\FormBuilder->getForm() /home/jian/src/drupal8/modules/ubercart/uc_cart/src/Controller/CartController.php:67
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 20. Drupal\Core\Form\FormBuilder->buildForm() /home/jian/src/drupal8/core/lib/Drupal/Core/Form/FormBuilder.php:217
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 21. Drupal\Core\Form\FormBuilder->processForm() /home/jian/src/drupal8/core/lib/Drupal/Core/Form/FormBuilder.php:319
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 22. Drupal\Core\Form\FormSubmitter->doSubmitForm() /home/jian/src/drupal8/core/lib/Drupal/Core/Form/FormBuilder.php:588
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 23. Drupal\Core\Form\FormSubmitter->executeSubmitHandlers() /home/jian/src/drupal8/core/lib/Drupal/Core/Form/FormSubmitter.php:56
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 24. call_user_func_array:{/home/jian/src/drupal8/core/lib/Drupal/Core/Form/FormSubmitter.php:116}() /home/jian/src/drupal8/core/lib/Drupal/Core/Form/FormSubmitter.php:116
Nov 30 00:18:07 jian-ThinkPad-T420 apache2: PHP 25. uc_paypal_ec_form_submit() /home/jian/src/drupal8/core/lib/Drupal/Core/Form/FormSubmitter.php:116

Comments

jian he created an issue. See original summary.

tr’s picture

Title: PayPal Express Checkout not working » Port PayPal Express Checkout to D8
Category: Bug report » Task
Status: Active » Postponed
Issue tags: -Needs tests

We haven't ported anything but the internal payment methods (check, COD, other) to D8 yet. See #2621258: Decide on payment methods to ship with 8.x-4.x

I personally haven't put any effort into PayPal because I feel the effort is better spent integrating with Payment. I believe that our own Ubercart-specific version of PayPal is a dead end and it's a waste of time to work on it for D8.

jian he’s picture

Status: Postponed » Needs review
StatusFileSize
new15.23 KB

I personally haven't put any effort into PayPal because I feel the effort is better spent integrating with Payment.

I agree with the effort is better spent integrating with Payment, and integration with Payment is a must have feature.
But my situation is: My project need paypal working as soon as posible (better within 1 week), but the payment + plugin + currency project is not stable, and payment_ubercart project dos not ported to Drupal 8 yet, and payment_paypal project also does not ported to Drupal 8 yet. So it seems my wise choice is uc_paypal at my situation. Please let me know if I am wrong.

Status: Needs review » Needs work

The last submitted patch, 3: 2625276-paypal-ec-3.patch, failed testing.

tr’s picture

PayPal Express Checkout is a payment method in Ubercart, so you will have to implement an Ubercart PaymentMethod plugin. Yes, you can write this in 1 week. Normally I'd say 20 hours to do a payment method since it requires a lot of research and testing to make sure you're doing it right - you don't want bugs in a payment method! But it will probably take you longer than normal because there is some porting to D8 to do as well - variables to config etc.

Use uc_payment_pack (which implements 3 payment methods) as an example. PayPal WPS is also a payment method so the same advice applies. PayPal WPP is a payment *gateway* and we currently don't have a plugin definition for payment gateways, so that would require considerably more work.

tr’s picture

Oh and for the test fail above, the route to the admin page for your method is defined in uc_payment, and until you implement the plugin your test won't work. Again, see uc_payment_pack for an example.

One other thing, many of your patches show "\ No newline at end of file" - please make sure that the last character in each file is \n (newline) to prevent this from happening.

jian he’s picture

Status: Needs work » Needs review
StatusFileSize
new47.57 KB

It seems the patch is huge and hard to review. Does this need to split into small patches?

Status: Needs review » Needs work

The last submitted patch, 8: 2625276-paypal-ec-8.patch, failed testing.

tr’s picture

Assigned: Unassigned » tr
Status: Needs work » Needs review
StatusFileSize
new0 bytes

Well you're right, this was hard to review. Largely because it's only a partial port - there is still a huge amount of work to do. Part of the problem is that we've made extensive changes to Ubercart in the past month so a lot of the patch needed to be updated, and a lot will have to be reworked now that payment methods are plugins and not hooks.

I've made a lot of changes to the patch and took out some stuff (like the tests, since they no longer work). I'm just going to commit this, if it passes the tests, because it takes us part way there. But there's still a lot more to do which I hope to get done in the next few days.

Status: Needs review » Needs work

The last submitted patch, 10: paypal-ec.patch, failed testing.

tr’s picture

Status: Needs work » Needs review
StatusFileSize
new45.68 KB

Hmm, a 0 byte patch? How did that happen? Here it is again ...

Status: Needs review » Needs work

The last submitted patch, 12: paypal-ec.patch, failed testing.

tr’s picture

Ah that's the same old intermittent error we've been getting for a while. Let me just retest until it works ...

The last submitted patch, 12: paypal-ec.patch, failed testing.

tr’s picture

OK, so it worked. I'm committing this but leaving the issue at "Needs work" because there's still a lot to do.

tr’s picture

  • TR committed 6129bac on 8.x-4.x authored by jian he
    Issue #2625276 by jian he, TR: Port PayPal Express Checkout to D8
    
tr’s picture

Status: Needs work » Needs review
StatusFileSize
new124.58 KB

A very large patch for the testbot to look at. Still not done, but getting there fast ...

Status: Needs review » Needs work

The last submitted patch, 19: more-pp-porting.patch, failed testing.

tr’s picture

Status: Needs work » Needs review
StatusFileSize
new122.19 KB

I didn't mean to include the tests in that patch - I know they're not working yet ... Here's the patch without the tests.

  • TR committed edbdaca on 8.x-4.x
    More work on [#2625276].
    
tr’s picture

Status: Needs review » Needs work

Committed that hunk. Setting back to needs work again, until it's ready to use.

tr’s picture

Status: Needs work » Needs review
StatusFileSize
new24.47 KB

Both EC and WPS are payment methods, so the can both be ported.

Here's my latest patch for the testbot to look at.

  • TR committed f9b43d3 on 8.x-4.x
    Issue [#2625276]: More work on porting PayPal
    
tr’s picture

Title: Port PayPal Express Checkout to D8 » Port PayPal Express Checkout and Website Payments Standard to D8
Status: Needs review » Needs work

Back to work ...

  • TR committed 7e90409 on 8.x-4.x
    More work on [#2625276].
    
tr’s picture

Status: Needs work » Needs review
StatusFileSize
new12.22 KB

Remove $_SESSION

tr’s picture

Status: Needs review » Needs work

Committed, back to needs work.

  • TR committed dc319e3 on 8.x-4.x
    Issue [#2625276] by TR: Replace use of $_SESSION with session service.
    
longwave’s picture

Status: Needs work » Needs review
StatusFileSize
new11.33 KB

With this patch applied, I have successfully completed checkout through the PayPal WPS sandbox. The IPN isn't yet handled correctly but it's a start!

Status: Needs review » Needs work

The last submitted patch, 31: paypal-wps.patch, failed testing.

longwave’s picture

Status: Needs work » Needs review
StatusFileSize
new10.76 KB
new1.55 KB

We still use $_SESSION for do_complete.

  • longwave committed 3178836 on
    Issue #2625276: Continue porting PayPal Website Payments Standard to D8
    
tr’s picture

wps_no_shipping should be boolean. If you're getting a variable type conflict in config inspector it's because you had paypal installed before I pushed the schema yesterday and Drupal made an assumption about the type - you have to uninstall then reinstall paypal to make that go away. And in PayPalWebsitePaymentsStandard.php it should probably be initialized to TRUE instead of 1.

Instead of restoring the use of $_SESSION here, why not finish removing it in uc_cart? Most places have been switched to grabbing it from the session service rather than using the superglobal, so I'd rather not go back.

Otherwise looking real good ...

longwave’s picture

It's definitely a string (or perhaps an integer, if we change the keys):

    $form['wps_no_shipping'] = array(
      '#type' => 'radios',
      '#title' => $this->t('Shipping address prompt in PayPal'),
      '#options' => array(
        '1' => $this->t('Do not show shipping address prompt at PayPal.'),
        '0' => $this->t('Prompt customer to include a shipping address.'),
        '2' => $this->t('Require customer to provide a shipping address.'),
      ),
      '#default_value' => $this->configuration['wps_no_shipping'],
    );

The incorrect type took me some time to track down. With it set to boolean, sending <input name="no_shipping" value> (ie. with no value attribute at all) causes PayPal to throw a nondescript error.

I intend to finish the $_SESSION conversion elsewhere, I will open a new issue for that.

tr’s picture

Oh OK, thanks for catching that.

tr’s picture

Issue tags: +beta blocker

Let's start tagging ...

longwave’s picture

StatusFileSize
new17.7 KB

This patch converts the 'redirect' key to an interface so the form can be contained inside the plugin. This will break 2Checkout but that can be fixed later.

longwave’s picture

Assigned: tr » Unassigned
Status: Needs review » Needs work

Still to do for PayPal WPS:

  • Rename to PayPal Payments Standard (WPS is the old name)
  • Get IPN working
  • Check that the PayPal variables are up to date
  • Use currency from the order instead of configuration
  • Check whether we can simplify any of the other configuration options|
tr’s picture

Can you make the change to uc_2checkout while it's still fresh in your mind?

longwave’s picture

Fixed 2Checkout in http://cgit.drupalcode.org/ubercart/commit/?id=709e4e8, the form output looks okay but I have not done an end to end test.

longwave’s picture

Status: Needs work » Needs review
StatusFileSize
new9.75 KB

This patch removes the currency setting (as we have it stored against the order already), the cancel URL (we should just send the user back one page), and the stylesheet that contained a single rule and wasn't being applied anyway.

I think we should also remove wps_no_shipping and wps_address_override, and always send the address entered at checkout but never allow the user to override it at PayPal - I don't see the point in any other combination.

longwave’s picture

StatusFileSize
new12.23 KB

This patch additionally removes the address options from the WPS plugin configuration.

  • longwave committed 0239f02 on
    Issue #2625276: Simplify PayPal cancellation routes.
    
  • longwave committed 11d9836 on
    Issue #2625276: Use order currency for PayPal WPS.
    
  • longwave committed c314521 on
    Issue #2625276: Simplify PayPal WPS styling.
    
longwave’s picture

Not entirely sure yet whether we should remove the no_shipping and address_override options so I have left them in for now.

longwave’s picture

StatusFileSize
new22.95 KB

This patch cleans up the IPN listener so it POSTs back to PayPal without erroring first, however the PayPal response is still INVALID and I am yet to figure out why.

longwave’s picture

StatusFileSize
new6.83 KB

Another patch to send the order currency automatically for WPP and EC.

tr’s picture

  • longwave committed 852b635 on
    Issue #2625276: Use order currency for PayPal WPP and EC.
    
  • longwave committed d48c8bb on
    Issue #2625276: Fix PayPal IPN handling.
    
tr’s picture

Resetting issue "Last modified" which was messed up by #2664380: Wrong comment date in automated commit comments

hanniha’s picture

I'm not sure but I think I found problem why IPN verification not going throug.

Paypal's manual say: After receiving an IPN message from PayPal, you must respond to PayPal with a POST message that is an exact copy of the received message but with "cmd=_notify-validate" added to the end of the message

But what I understand programming that cmd=_notify-validate are added before IPN.

$response = \Drupal::httpClient()->request('POST', $host, [
        'form_params' => ['cmd' => '_notify-validate'] + $ipn,
      ]);
hanniha’s picture

StatusFileSize
new1.63 KB

I fix that validation like this...

hanniha’s picture

StatusFileSize
new524 bytes

Better fix. There was only one small mistake for that original code

tr’s picture

Status: Needs review » Needs work

Well, the $data variable isn't defined anywhere, and the 'test_ipn' key isn't defined anywhere either. A proper fix will be to figure out what this test was supposed to do (@longwave? this was added as part of your commit d48c8bbf) and make it work properly. Apparently all your patch does is to force the use of the sandbox server all the time, because you're testing a variable which will always be empty.

longwave’s picture

The test_ipn key is defined in the PayPal documentation but I am not sure it is entirely reliable, or maybe I misread how it is supposed to work. I thought it would be the right way to identify whether to send IPNs back to the live or sandbox site without necessarily needing to refer back to the payment method config, but maybe we need a different method for this.

tr’s picture

Then shouldn't it be $ipn['test_ipn'] instead of $data['test_ipn'] ? $data isn't defined anywhere ...

longwave’s picture

Ah, yeah, didn't spot that - could well be the issue! I will try that next time I get some free time to work on this.

  • longwave committed 3333e15 on 8.x-4.x
    Issue #2625276: Fix PayPal IPN verification.
    
longwave’s picture

PayPal sandbox is down but from reading the docs again I think this should work if I use the right variable name, so I committed this change. Express Checkout and WPP still need work.

longwave’s picture

Title: Port PayPal Express Checkout and Website Payments Standard to D8 » Port PayPal Express Checkout and Payments Standard to D8
Status: Needs work » Needs review
StatusFileSize
new5.59 KB

PayPal Payments Standard lost the "Website" part from its name some time ago.

  • longwave committed 5663ec5 on 8.x-4.x
    Issue #2625276: Rename PayPal Website Payments Standard to PayPal...
longwave’s picture

Status: Needs review » Active

Back to active to finish off Express Checkout, unfortunately I can't work on this until the PayPal sandbox is back up.

longwave’s picture

PayPal sandbox is back up and delivered an IPN (12 hours late!) that was successfully processed and verified for PayPal Payments Standard, which is good news.

longwave’s picture

Status: Active » Needs review
StatusFileSize
new11.2 KB

Work in progress for Express Checkout.

longwave’s picture

StatusFileSize
new48.14 KB

Express Checkout now works for both shortcut flow (cart > PayPal > review > complete) and mark flow (cart > checkout > review > PayPal > complete). We can improve things further later, but for now this is at least as good, if not better, than we had in D7.

longwave’s picture

Title: Port PayPal Express Checkout and Payments Standard to D8 » Port PayPal payment methods to D8

This only leaves Website Payments Pro, which still needs conversion.

longwave’s picture

StatusFileSize
new48.28 KB
new15.91 KB

Cleaned up version of #66. I have PayPal WPP almost ready to go as well.

  • longwave committed 4a59acf on 8.x-4.x
    Issue #2625276 by longwave: Port PayPal Express Checkout to D8
    
longwave’s picture

StatusFileSize
new17.97 KB

  • longwave committed 9adab90 on 8.x-4.x
    Issue #2625276 by longwave: Port PayPal Website Payments Pro to D8
    
longwave’s picture

Status: Needs review » Fixed

Committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.