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

@@ -8,6 +8,7 @@ from django.utils.timezone import now
from pretix.base.models import (
Event, Order, Organizer, RequiredAction, Team, User,
)
from pretix.plugins.stripe.models import ReferencedStripeObject
@pytest.fixture
@@ -185,6 +186,46 @@ def test_webhook_all_good(env, client, monkeypatch):
assert order.status == Order.STATUS_PAID
@pytest.mark.django_db
def test_webhook_global(env, client, monkeypatch):
order = env[1]
order.status = Order.STATUS_PENDING
order.save()
charge = get_test_charge(env[1])
monkeypatch.setattr("paypalrestsdk.Sale.find", lambda *args: charge)
monkeypatch.setattr("pretix.plugins.paypal.payment.Paypal.init_api", lambda *args: None)
ReferencedStripeObject.objects.create(order=order, reference="PAY-5YK922393D847794YKER7MUI")
client.post('/_paypal/webhook/', json.dumps(
{
"id": "WH-2WR32451HC0233532-67976317FL4543714",
"create_time": "2014-10-23T17:23:52Z",
"resource_type": "sale",
"event_type": "PAYMENT.SALE.COMPLETED",
"summary": "A successful sale payment was made for $ 0.48 USD",
"resource": {
"amount": {
"total": "-0.01",
"currency": "USD"
},
"id": "36C38912MN9658832",
"parent_payment": "PAY-5YK922393D847794YKER7MUI",
"update_time": "2014-10-31T15:41:51Z",
"state": "completed",
"create_time": "2014-10-31T15:41:51Z",
"links": [],
"sale_id": "9T0916710M1105906"
},
"links": [],
"event_version": "1.0"
}
), content_type='application_json')
order.refresh_from_db()
assert order.status == Order.STATUS_PAID
@pytest.mark.django_db
def test_webhook_mark_paid(env, client, monkeypatch):
order = env[1]

View File

@@ -219,7 +219,7 @@ def test_webhook_partial_refund(env, client, monkeypatch):
@pytest.mark.django_db
def test_webhook_organizer_level(env, client, monkeypatch):
def test_webhook_global(env, client, monkeypatch):
order = env[1]
order.status = Order.STATUS_PENDING
order.save()