forked from CGM_Public/pretix_original
Stripe: Do not duplicate refunds of migrated payments
This commit is contained in:
@@ -233,18 +233,31 @@ def charge_webhook(event, event_json, charge_id, rso):
|
||||
is_refund = charge['refunds']['total_count'] or charge['dispute']
|
||||
if is_refund:
|
||||
known_refunds = [r.info_data.get('id') for r in payment.refunds.all()]
|
||||
migrated_refund_amounts = [r.amount for r in payment.refunds.all() if not r.info_data.get('id')]
|
||||
for r in charge['refunds']['data']:
|
||||
a = prov._amount_to_decimal(r['amount'])
|
||||
if r['status'] in ('failed', 'canceled'):
|
||||
continue
|
||||
|
||||
if a in migrated_refund_amounts:
|
||||
migrated_refund_amounts.remove(a)
|
||||
continue
|
||||
|
||||
if r['id'] not in known_refunds:
|
||||
payment.create_external_refund(
|
||||
amount=prov._amount_to_decimal(r['amount']),
|
||||
amount=a,
|
||||
info=str(r)
|
||||
)
|
||||
if charge['dispute']:
|
||||
if charge['dispute']['status'] != 'won' and charge['dispute']['id'] not in known_refunds:
|
||||
payment.create_external_refund(
|
||||
amount=prov._amount_to_decimal(charge['dispute']['amount']),
|
||||
info=str(charge['dispute'])
|
||||
)
|
||||
a = prov._amount_to_decimal(charge['dispute']['amount'])
|
||||
if a in migrated_refund_amounts:
|
||||
migrated_refund_amounts.remove(a)
|
||||
else:
|
||||
payment.create_external_refund(
|
||||
amount=a,
|
||||
info=str(charge['dispute'])
|
||||
)
|
||||
elif payment.state in (OrderPayment.PAYMENT_STATE_PENDING, OrderPayment.PAYMENT_STATE_CREATED):
|
||||
if charge['status'] == 'succeeded':
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user