Refund process (closes #26)

This commit is contained in:
Raphael Michel
2015-04-06 16:23:51 +02:00
parent f8322da3ad
commit 6d73267912
9 changed files with 170 additions and 15 deletions

View File

@@ -200,3 +200,37 @@ class Paypal(BasePaymentProvider):
ctx = {'request': request, 'event': self.event, 'settings': self.settings,
'payment_info': payment_info, 'order': order}
return template.render(ctx)
def order_control_refund_render(self, order) -> str:
return '<div class="alert alert-info">%s</div>' % _('The money will be automatically refunded.')
def order_control_refund_perform(self, request, order) -> "bool|str":
self.init_api()
if order.payment_info:
payment_info = json.loads(order.payment_info)
else:
payment_info = None
if not payment_info:
order.mark_refunded()
messages.warning(request, _('We were unable to transfer the money back automatically. '
'Please get in touch with the customer and transfer it back manually.'))
return
for res in payment_info['transactions'][0]['related_resources']:
for k, v in res.items():
if k == 'sale':
sale = paypalrestsdk.Sale.find(v['id'])
break
refund = sale.refund({})
if not refund.success():
order.mark_refunded()
messages.warning(request, _('We were unable to transfer the money back automatically. '
'Please get in touch with the customer and transfer it back manually.'))
else:
sale = paypalrestsdk.Payment.find(payment_info['id'])
order = order.mark_refunded()
order.payment_info = json.dumps(sale.to_dict())
order.save()