forked from CGM_Public/pretix_original
Paypal2: handle incomming capture webhooks (Z#23240966) (#6456)
* store the state of the payment regardless of the state control.html shows the banner that the payment is in review depending on payment.info * handle capture ressource * Update src/pretix/plugins/paypal2/views.py Co-authored-by: Phin Wolkwitz <wolkwitz@pretix.eu> * add test * cleanup logic regarding uninteresting resource_type * store payment.info during _execute_payment asap --------- Co-authored-by: Phin Wolkwitz <wolkwitz@pretix.eu>
This commit is contained in:
co-authored by
Phin Wolkwitz
parent
ea792e76b2
commit
4d9dfa88fe
@@ -677,6 +677,8 @@ class PaypalMethod(BasePaymentProvider):
|
||||
raise PaymentException(_('We had trouble communicating with PayPal'))
|
||||
else:
|
||||
pp_captured_order = response.result
|
||||
payment.info = json.dumps(pp_captured_order.dict())
|
||||
payment.save()
|
||||
|
||||
try:
|
||||
ReferencedPayPalObject.objects.get_or_create(order=payment.order, payment=payment, reference=pp_captured_order.id)
|
||||
|
||||
@@ -357,14 +357,13 @@ def webhook(request, *args, **kwargs):
|
||||
if 'resource_type' not in event_json:
|
||||
return HttpResponse("Invalid body, no resource_type given", status=400)
|
||||
|
||||
if event_json['resource_type'] not in ["checkout-order", "refund", "capture"]:
|
||||
return HttpResponse("Not interested in this resource type", status=200)
|
||||
|
||||
# Retrieve the Charge ID of the refunded payment
|
||||
if event_json['resource_type'] == 'refund':
|
||||
if event_json['resource_type'] == 'checkout-order':
|
||||
payloadid = event_json['resource']['id']
|
||||
elif event_json['resource_type'] == 'refund' or event_json['resource_type'] == 'capture':
|
||||
payloadid = get_link(event_json['resource']['links'], 'up')['href'].split('/')[-1]
|
||||
else:
|
||||
payloadid = event_json['resource']['id']
|
||||
return HttpResponse("Not interested in this resource type", status=200)
|
||||
|
||||
refs = [payloadid]
|
||||
if event_json['resource'].get('supplementary_data', {}).get('related_ids', {}).get('order_id'):
|
||||
@@ -424,6 +423,8 @@ def webhook(request, *args, **kwargs):
|
||||
**event_json,
|
||||
'_order_state': sale.dict(),
|
||||
})
|
||||
payment.info = json.dumps(sale.dict())
|
||||
payment.save()
|
||||
|
||||
if payment.state == OrderPayment.PAYMENT_STATE_CONFIRMED and sale['status'] in ('PARTIALLY_REFUNDED', 'REFUNDED', 'COMPLETED'):
|
||||
if event_json['resource_type'] == 'refund':
|
||||
|
||||
Reference in New Issue
Block a user