forked from CGM_Public/pretix_original
PPv2 APM: Create referenced PPObjects for APM Orders; enable webhooks to capture them
This commit is contained in:
@@ -586,6 +586,9 @@ class PaypalMethod(BasePaymentProvider):
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
response = self.client.execute(paymentreq)
|
response = self.client.execute(paymentreq)
|
||||||
|
|
||||||
|
if payment:
|
||||||
|
ReferencedPayPalObject.objects.get_or_create(order=payment.order, payment=payment, reference=response.result.id)
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
if "RESOURCE_NOT_FOUND" in str(e):
|
if "RESOURCE_NOT_FOUND" in str(e):
|
||||||
messages.error(request, _('Your payment has failed due to a known issue within PayPal. Please try '
|
messages.error(request, _('Your payment has failed due to a known issue within PayPal. Please try '
|
||||||
|
|||||||
@@ -482,29 +482,32 @@ def webhook(request, *args, **kwargs):
|
|||||||
amount=payment.amount - known_sum
|
amount=payment.amount - known_sum
|
||||||
)
|
)
|
||||||
elif payment.state in (OrderPayment.PAYMENT_STATE_PENDING, OrderPayment.PAYMENT_STATE_CREATED,
|
elif payment.state in (OrderPayment.PAYMENT_STATE_PENDING, OrderPayment.PAYMENT_STATE_CREATED,
|
||||||
OrderPayment.PAYMENT_STATE_CANCELED, OrderPayment.PAYMENT_STATE_FAILED) \
|
OrderPayment.PAYMENT_STATE_CANCELED, OrderPayment.PAYMENT_STATE_FAILED):
|
||||||
and sale['status'] == 'COMPLETED':
|
if sale['status'] == 'COMPLETED':
|
||||||
any_captures = False
|
any_captures = False
|
||||||
all_captures_completed = True
|
all_captures_completed = True
|
||||||
for purchaseunit in sale['purchase_units']:
|
for purchaseunit in sale['purchase_units']:
|
||||||
for capture in purchaseunit['payments']['captures']:
|
for capture in purchaseunit['payments']['captures']:
|
||||||
try:
|
try:
|
||||||
ReferencedPayPalObject.objects.get_or_create(order=payment.order, payment=payment,
|
ReferencedPayPalObject.objects.get_or_create(order=payment.order, payment=payment,
|
||||||
reference=capture['id'])
|
reference=capture['id'])
|
||||||
except ReferencedPayPalObject.MultipleObjectsReturned:
|
except ReferencedPayPalObject.MultipleObjectsReturned:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if capture['status'] not in ('COMPLETED', 'REFUNDED', 'PARTIALLY_REFUNDED'):
|
if capture['status'] not in ('COMPLETED', 'REFUNDED', 'PARTIALLY_REFUNDED'):
|
||||||
all_captures_completed = False
|
all_captures_completed = False
|
||||||
else:
|
else:
|
||||||
any_captures = True
|
any_captures = True
|
||||||
if any_captures and all_captures_completed:
|
if any_captures and all_captures_completed:
|
||||||
try:
|
try:
|
||||||
payment.info = json.dumps(sale.dict())
|
payment.info = json.dumps(sale.dict())
|
||||||
payment.save(update_fields=['info'])
|
payment.save(update_fields=['info'])
|
||||||
payment.confirm()
|
payment.confirm()
|
||||||
except Quota.QuotaExceededException:
|
except Quota.QuotaExceededException:
|
||||||
pass
|
pass
|
||||||
|
elif sale['status'] == 'APPROVED':
|
||||||
|
request.session['payment_paypal_oid'] = payment.info_data['id']
|
||||||
|
payment.payment_provider.execute_payment(request, payment)
|
||||||
|
|
||||||
return HttpResponse(status=200)
|
return HttpResponse(status=200)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user