Skip to content

PayPal Express redirect fails when using DeferredTax mixin #98

Closed
@nfletton

Description

@nfletton

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:
        ....

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions