PayPal: Event-independent webhooks

This commit is contained in:
Raphael Michel
2017-07-23 12:38:41 +02:00
parent 5f529817ef
commit 1d2d9d8b99
8 changed files with 112 additions and 15 deletions

View File

@@ -12,7 +12,9 @@ from pretix.base.models import Order, Quota, RequiredAction
from pretix.base.payment import BasePaymentProvider, PaymentException
from pretix.base.services.mail import SendMailException
from pretix.base.services.orders import mark_order_paid, mark_order_refunded
from pretix.helpers.urls import build_absolute_uri as build_global_uri
from pretix.multidomain.urlreverse import build_absolute_uri
from pretix.plugins.paypal.models import ReferencedPayPalObject
logger = logging.getLogger('pretix.plugins.paypal')
@@ -55,7 +57,7 @@ class Paypal(BasePaymentProvider):
return "<div class='alert alert-info'>%s<br /><code>%s</code></div>" % (
_('Please configure a PayPal Webhook to the following endpoint in order to automatically cancel orders '
'when payments are refunded externally.'),
build_absolute_uri(self.event, 'plugins:paypal:webhook')
build_global_uri('plugins:paypal:webhook')
)
def init_api(self):
@@ -154,6 +156,7 @@ class Paypal(BasePaymentProvider):
self.init_api()
payment = paypalrestsdk.Payment.find(request.session.get('payment_paypal_id'))
ReferencedPayPalObject.objects.get_or_create(order=order, reference=payment.id)
if str(payment.transactions[0].amount.total) != str(order.total) or payment.transactions[0].amount.currency != \
self.event.currency:
logger.error('Value mismatch: Order %s vs payment %s' % (order.id, str(payment)))