Skip to content

Commit

Permalink
fix #4: Cancel payment return: Page not found
Browse files Browse the repository at this point in the history
  • Loading branch information
jrief committed May 10, 2017
1 parent 09b1090 commit 96524a6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This integrates the PayPal for django-shop version 0.9 and above.

## Installation

for django-shop version 0.9.x:
for django-shop version 0.10.x:

```
pip install djangoshop-paypal==0.1.4
Expand Down Expand Up @@ -50,3 +50,10 @@ Add ``'shop_paypal.modifiers.PaymentModifier'`` to the list of ``SHOP_CART_MODIF
Add ``'shop_paypal.payment.OrderWorkflowMixin'`` to the list of ``SHOP_ORDER_WORKFLOWS``.

When rendering the payment method form, "PayPal" shall appear in the list of possible payments.

Successful payments are redirected onto the CMS page with the ID ``shop-order-last``. If no such
CMS page exists, the URL which resolves to ``shop-order-last`` is returned.

If a payment was rejected by PayPal, **djangoshop-paypal** redirects onto the CMS page with the ID
``shop-cancel-payment``. If no such CMS page exists, the URL which resolves to
``shop-cancel-payment`` is returned.
18 changes: 13 additions & 5 deletions shop_paypal/payment.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import json
import paypalrestsdk
import warnings

from django.conf import settings
from django.conf.urls import url
from django.core.serializers.json import DjangoJSONEncoder
from django.core.urlresolvers import resolve, reverse
from django.core.exceptions import ImproperlyConfigured
from django.http.response import HttpResponseRedirect, HttpResponseBadRequest
from django.urls import resolve, reverse, NoReverseMatch
from django.utils.translation import ugettext_lazy as _

from cms.models import Page

from django_fsm import transition

from shop.models.cart import CartModel
from shop.models.order import BaseOrder, OrderModel, OrderPayment
from shop.payment.base import PaymentProvider
from django_fsm import transition


class PayPalPayment(PaymentProvider):
Expand Down Expand Up @@ -114,10 +119,13 @@ def return_view(cls, request):
@classmethod
def cancel_view(cls, request):
try:
cancel_url = Page.objects.public().get(reverse_id='cancel-payment').get_absolute_url()
cancel_url = Page.objects.public().get(reverse_id='shop-cancel-payment').get_absolute_url()
except Page.DoesNotExist:
warnings.warn("Please add a page with an id `cancel-payment` to the CMS.")
cancel_url = '/page__cancel-payment__not-found-in-cms'
try:
cancel_url = reverse('shop-cancel-payment')
except NoReverseMatch:
warnings.warn("Please add a page with an id `cancel-payment` to the CMS.")
cancel_url = '/page__shop-cancel-payment__not-found-in-cms'
return HttpResponseRedirect(cancel_url)


Expand Down

0 comments on commit 96524a6

Please sign in to comment.