django-oscar / django-oscar-paypal

PayPal integration for django-oscar. Can be used without Oscar too.

Home Page:https://django-oscar-paypal.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PayPal Express redirect fails when using DeferredTax mixin

nfletton opened this issue · comments

The following error occurs when clicking the PayPal icon at the payment step of the checkout process when using the DeferredTax mixin:

Can't calculate price.incl_tax as tax isn't known
Request Method: GET
Request URL:    http://127.0.0.1:5000/checkout/paypal/payment/
Django Version: 1.7.7
Exception Type: TaxNotKnown
Exception Value:    Can't calculate price.incl_tax as tax isn't known

Bearing in mind this is the first time I've used Oscar, the problem appears to be that the PayPal Express RedirectView uses the basket in the request object rather than the basket after it has had tax applied by the the overridden build_submission() method in CheckoutSessionMixin.

The solution that works in my scenario is to call build_submission() directly to get the basket with deferred taxes calculated.

Old code:

class RedirectView(CheckoutSessionMixin, RedirectView):
    ....
    def get_redirect_url(self, **kwargs):
        try:
            basket = self.request.basket
            url = self._get_redirect_url(basket, **kwargs)
        except PayPalError:
        ....

Patched code:

class RedirectView(CheckoutSessionMixin, RedirectView):
    ....
    def get_redirect_url(self, **kwargs):
        try:
            basket = self.build_submission()['basket']
            url = self._get_redirect_url(basket, **kwargs)
        except PayPalError:
        ....

Wow, I just wasted an entire day on this same exact problem, thinking something was wrong with my own CheckoutSessionMixin. @nfletton, thanks oodles for tracking it down. @maikhoepfel, it looks like this breaks pretty critical functionality -- any chance to get this issue reviewed?

I've added PR #121 which implements @nfletton's suggested fix, which I can confirm fixes the problem for me — unfortunately I don't really know what would be a good way to unit-test this.

Still a problem. Because using Express checkout means your not doing shipping parameters and when you don't do that means taxes isnt calculated. That's if your using an USstrategy. So what can we do about this situation?