Permalink
Browse files

Factored out PayPal to lfs-paypal.

PayPal integration uses the default plugin mechanism now.
  • Loading branch information...
1 parent 9e207e7 commit 3c1982d51b0289e123275666b2e5b713eefaf530 @diefenbach committed May 18, 2012
@@ -10,23 +10,23 @@
</object>
<object pk="3" model="core.country">
<field type="CharField" name="name">USA</field>
- <field type="CharField" name="code">us</field>
+ <field type="CharField" name="code">us</field>
</object>
<object pk="4" model="core.country">
<field type="CharField" name="name">Netherlands</field>
- <field type="CharField" name="code">nl</field>
+ <field type="CharField" name="code">nl</field>
</object>
<object pk="5" model="core.country">
<field type="CharField" name="name">Ireland</field>
- <field type="CharField" name="code">ie</field>
+ <field type="CharField" name="code">ie</field>
</object>
<object pk="6" model="core.country">
<field type="CharField" name="name">Great Britain</field>
- <field type="CharField" name="code">gb</field>
+ <field type="CharField" name="code">gb</field>
</object>
<object pk="7" model="core.country">
<field type="CharField" name="name">France</field>
- <field type="CharField" name="code">fr</field>
+ <field type="CharField" name="code">fr</field>
</object>
<!-- Shop -->
<object pk="1" model="core.shop">
@@ -48,7 +48,7 @@
<object pk="4"></object>
<object pk="5"></object>
</field>
- </object>
+ </object>
<!-- Portlets -->
<object pk="1" model="portlets.slot">
@@ -57,8 +57,8 @@
<object pk="2" model="portlets.slot">
<field type="CharField" name="name">Right</field>
</object>
-
- <!-- Paymentmethod -->
+
+ <!-- Paymentmethod -->
<object pk="1" model="payment.paymentmethod">
<field type="CharField" name="name">Direct debit</field>
<field type="TextField" name="description"></field>
@@ -76,7 +76,7 @@
<field type="IntegerField" name="priority">2</field>
<field type="FileField" name="image"></field>
<field type="BooleanField" name="active">1</field>
- <field type="BooleanField" name="deletable">0</field>
+ <field type="BooleanField" name="deletable">0</field>
<field type="FloatField" name="price">17.9</field>
</object>
<object pk="3" model="payment.paymentmethod">
@@ -86,8 +86,9 @@
<field type="IntegerField" name="priority">3</field>
<field type="FileField" name="image"></field>
<field type="BooleanField" name="active">1</field>
- <field type="BooleanField" name="deletable">0</field>
+ <field type="BooleanField" name="deletable">0</field>
<field type="FloatField" name="price">0.0</field>
+ <field type="Textfield" name="module">lfs_paypal.PayPalProcessor</field>
</object>
<object pk="4" model="payment.paymentmethod">
<field type="CharField" name="name">Prepayment</field>
@@ -98,7 +99,7 @@
<field type="BooleanField" name="active">1</field>
<field type="BooleanField" name="deletable">0</field>
<field type="FloatField" name="price">0.0</field>
- </object>
+ </object>
<object pk="5" model="payment.paymentmethod">
<field type="CharField" name="name">By invoice</field>
<field type="TextField" name="description"></field>
@@ -108,5 +109,5 @@
<field type="BooleanField" name="active">1</field>
<field type="BooleanField" name="deletable">0</field>
<field type="FloatField" name="price">0.0</field>
- </object>
+ </object>
</django-objects>
@@ -88,7 +88,7 @@ def handle(self, *args, **options):
pm.id=1; pm.save()
pm = PaymentMethod.objects.create(name="Cash on delivery", priority=2, active=1, deletable=0)
pm.id=2; pm.save()
- pm = PaymentMethod.objects.create(name="PayPal", priority=3, active=1, deletable=0)
+ pm = PaymentMethod.objects.create(name="PayPal", priority=3, active=1, deletable=0, module="lfs_paypal.PayPalProcessor")
pm.id=3; pm.save()
pm = PaymentMethod.objects.create(name="Prepayment", priority=4, active=1, deletable=0)
pm.id=4; pm.save()
@@ -315,6 +315,11 @@ def migrate_to_08(self, application, version):
# Delivery Time
db.add_column('core_shop', 'delivery_time', models.ForeignKey(DeliveryTime, verbose_name=_(u"Delivery time"), blank=True, null=True))
+ # PayPal
+ paypal = PaymentMethod.objects.get(pk=3)
+ paypal.module = "lfs_paypal.PayPalProcessor"
+ paypal.save()
+
application.version = "0.8"
application.save()
View
@@ -13,7 +13,6 @@
from lfs.voucher.tests import *
from lfs.customer.tests import *
from lfs.checkout.tests import *
-from lfs.payment.tests import *
# from lfs.manage.tests import *
from lfs.gross_price.tests import *
from lfs.net_price.tests import *
@@ -24,6 +23,10 @@
except ImportError:
pass
+try:
+ from lfs_paypal.tests import *
+except ImportError:
+ pass
# django imports
from django.contrib.auth.models import User
View
@@ -5,6 +5,7 @@
# lfs imports
import lfs.payment.utils
+import lfs.core.utils
from lfs.catalog.models import Product
from lfs.catalog.models import Property
from lfs.catalog.models import PropertyOption
@@ -114,7 +115,15 @@ def __unicode__(self):
def get_pay_link(self, request):
"""Returns a pay link for the selected payment method.
"""
- return lfs.payment.utils.get_pay_link(request, self.payment_method, self)
+ if self.payment_method.module:
+ payment_class = lfs.core.utils.import_symbol(self.payment_method.module)
+ payment_instance = payment_class(request=request, order=self)
+ try:
+ return payment_instance.get_pay_link()
+ except AttributeError:
+ return ""
+ else:
+ return ""
def get_name(self):
order_name = ""
View
@@ -4,7 +4,6 @@
# lfs imports
from lfs.payment.models import PaymentMethod
from lfs.payment.models import PaymentMethodPrice
-from lfs.payment.models import PayPalOrderTransaction
class PaymentMethodAdmin(admin.ModelAdmin):
@@ -17,9 +16,3 @@ class PaymentMethodPriceAdmin(admin.ModelAdmin):
"""
"""
admin.site.register(PaymentMethodPrice, PaymentMethodPriceAdmin)
-
-
-class PayPalOrderTransactionAdmin(admin.ModelAdmin):
- """
- """
-admin.site.register(PayPalOrderTransaction, PayPalOrderTransactionAdmin)
View
@@ -1,84 +0,0 @@
-# django imports
-from django.conf import settings
-
-# lfs imports
-from lfs.order.models import Order
-from lfs.order.settings import PAID, PAYMENT_FAILED, PAYMENT_FLAGGED
-from lfs.mail import utils as mail_utils
-from models import PayPalOrderTransaction
-from lfs.core.signals import order_paid
-
-# other imports
-import logging
-from paypal.standard.ipn.signals import payment_was_successful, payment_was_flagged
-from paypal.standard.pdt.signals import pdt_failed, pdt_successful
-from paypal.standard.models import ST_PP_COMPLETED
-
-
-def mark_payment(pp_obj, order_state=PAID):
- order = None
- try:
- logging.info("getting order for uuid %s" % pp_obj.custom)
- order_uuid = pp_obj.custom
- order = Order.objects.get(uuid=order_uuid)
- if order is not None:
- if order.state != PAID and order_state == PAID:
- order_paid.send({"order": order, "request": None})
-
- if getattr(settings, 'LFS_SEND_ORDER_MAIL_ON_PAYMENT', False):
- mail_utils.send_order_received_mail(order)
-
- order.state = order_state
- order.save()
- except Order.DoesNotExist, e:
- logging.error(e)
- return order
-
-
-def successful_payment(sender, **kwargs):
- logging.info("successful ipn payment")
- ipn_obj = sender
- order = mark_payment(ipn_obj, PAID)
- if order is not None:
- transaction, created = PayPalOrderTransaction.objects.get_or_create(order=order)
- transaction.ipn.add(ipn_obj)
- transaction.save()
- else:
- logging.warning("successful ipn payment, no order found for uuid %s" % ipn_obj.custom)
-
-
-def unsuccessful_payment(sender, **kwargs):
- logging.info("unsuccessful ipn payment")
- ipn_obj = sender
- if ipn_obj:
- order = None
- if ipn_obj.payment_status == ST_PP_COMPLETED:
- order = mark_payment(ipn_obj, PAYMENT_FLAGGED)
- else:
- order = mark_payment(ipn_obj, PAYMENT_FAILED)
- if order is not None:
- transaction, created = PayPalOrderTransaction.objects.get_or_create(order=order)
- transaction.ipn.add(ipn_obj)
- transaction.save()
- else:
- logging.warning("unsuccessful ipn payment, no order found for uuid %s" % ipn_obj.custom)
- else:
- logging.warning("unsuccessful ipn payment signal with no ipn object")
-
-
-def successful_pdt(sender, **kwargs):
- logging.info("successful pdt payment")
- pdt_obj = sender
- order = mark_payment(pdt_obj, True)
-
-
-def unsuccesful_pdt(sender, **kwargs):
- logging.info("unsuccessful pdt payment")
- pdt_obj = sender
- order = mark_payment(pdt_obj, False)
-
-
-payment_was_successful.connect(successful_payment, dispatch_uid="Order.ipn_successful")
-payment_was_flagged.connect(unsuccessful_payment, dispatch_uid="Order.ipn_unsuccessful")
-pdt_successful.connect(successful_pdt, dispatch_uid="Order.pdt_successful")
-pdt_failed.connect(unsuccesful_pdt, dispatch_uid="Order.pdt_unsuccessful")
View
@@ -1,6 +1,5 @@
# django imports
from django.conf import settings
-from django.contrib.contenttypes import generic
from django.db import models
from django.utils.translation import ugettext_lazy as _
@@ -10,10 +9,6 @@
from lfs.tax.models import Tax
-# paypal imports
-from paypal.standard.ipn.models import PayPalIPN
-
-
class ActivePaymentMethodManager(models.Manager):
"""
A manager which return just valid shipping methods.
@@ -118,12 +113,3 @@ class Meta:
price = models.FloatField(_(u"Price"), default=0.0)
priority = models.IntegerField(_(u"Priority"), default=0)
active = models.BooleanField(_(u"Active"), default=False)
-
-
-from lfs.order.models import Order
-class PayPalOrderTransaction(models.Model):
- order = models.ForeignKey(Order, unique=True)
- ipn = models.ManyToManyField(PayPalIPN)
-
-
-from listeners import *
Oops, something went wrong.

0 comments on commit 3c1982d

Please sign in to comment.