Skip to content

Commit

Permalink
Merge pull request #817 from xzzy/master
Browse files Browse the repository at this point in the history
Allow Ledger to send callbacks to your app on approved refund
  • Loading branch information
xzzy committed Aug 20, 2020
2 parents d56ec8a + a5f03dc commit 4b37168
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 7 additions & 1 deletion ledger/checkout/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ def create_basket_session(request, parameters):
else:
product_serializer = serializers.CheckoutProductSerializer(data=serializer.initial_data.get('products'), many=True)
product_serializer.is_valid(raise_exception=True)

# Cleaning up stale Baskets
if request.user:
if request.user.__class__.__name__ == 'EmailUser':
ba = Basket.objects.filter(owner=request.user).exclude(status='Submitted')
for b in ba:
b.status='Frozen'
b.save()
# validate basket
if serializer.validated_data.get('vouchers'):
if custom:
Expand Down
11 changes: 10 additions & 1 deletion ledger/payments/bpoint/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def refund(self,info,user,matched=True):
from ledger.payments.facade import bpoint_facade
from ledger.payments.models import TrackRefund, Invoice
LEDGER_REFUND_EMAIL = env('LEDGER_REFUND_EMAIL', False)

LEDGER_REFUND_TRANSACTION_CALLBACK_MODULE =env('LEDGER_REFUND_TRANSACTION_CALLBACK_MODULE', '')

with transaction.atomic():
amount = info['amount']
Expand Down Expand Up @@ -193,6 +193,15 @@ def refund(self,info,user,matched=True):
except BpointToken.DoesNotExist:
UsedBpointToken.objects.create(DVToken=txn.dvtoken)
TrackRefund.objects.create(user=user,type=2,refund_id=txn.id,details=details)
if len(LEDGER_REFUND_TRANSACTION_CALLBACK_MODULE) != 0:
try:
ltc = LEDGER_REFUND_TRANSACTION_CALLBACK_MODULE.split(":")
exec('import '+str(ltc[0]))
exec(ltc[1]+"('"+self.crn1+"',"+str(self.id)+")")
except Exception as e:
print (e)


if LEDGER_REFUND_EMAIL is True:
# Disabled as requested by Walter and then enabled again for parkstay
send_refund_email(Invoice.objects.get(reference=self.crn1),'card',txn.amount,card_ending=self.last_digits)
Expand Down

0 comments on commit 4b37168

Please sign in to comment.