mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-27 15:58:06 -05:00
refund_campaign handles refund calculation.
This commit is contained in:
committed by
Neil Williams
parent
7a515b0f98
commit
61e4e4a849
@@ -372,7 +372,7 @@ class PromoteController(ListingController):
|
||||
billable_impressions = promote.get_billable_impressions(campaign)
|
||||
billable_amount = promote.get_billable_amount(campaign,
|
||||
billable_impressions)
|
||||
refund_amount = campaign.bid - billable_amount
|
||||
refund_amount = promote.get_refund_amount(campaign, billable_amount)
|
||||
if refund_amount > 0:
|
||||
promote.refund_campaign(link, campaign, billable_amount,
|
||||
billable_impressions)
|
||||
|
||||
@@ -3481,7 +3481,7 @@ class RefundPage(Reddit):
|
||||
billable_impressions = promote.get_billable_impressions(campaign)
|
||||
billable_amount = promote.get_billable_amount(campaign,
|
||||
billable_impressions)
|
||||
refund_amount = campaign.bid - billable_amount
|
||||
refund_amount = promote.get_refund_amount(campaign, billable_amount)
|
||||
self.billable_impressions = billable_impressions
|
||||
self.billable_amount = billable_amount
|
||||
self.refund_amount = refund_amount
|
||||
|
||||
@@ -24,6 +24,7 @@ from __future__ import with_statement
|
||||
|
||||
from collections import defaultdict, OrderedDict, namedtuple
|
||||
from datetime import datetime, timedelta
|
||||
from decimal import Decimal, ROUND_UP
|
||||
import itertools
|
||||
import json
|
||||
import math
|
||||
@@ -838,8 +839,20 @@ def finalize_completed_campaigns(daysago=1):
|
||||
set_underdelivered_campaigns(underdelivered_campaigns)
|
||||
|
||||
|
||||
def get_refund_amount(camp, billable):
|
||||
existing_refund = getattr(camp, 'refund_amount', 0.)
|
||||
charge = camp.bid - existing_refund
|
||||
refund_amount = charge - billable
|
||||
refund_amount = Decimal(refund_amount).quantize(Decimal('.01'),
|
||||
rounding=ROUND_UP)
|
||||
return max(float(refund_amount), 0.)
|
||||
|
||||
|
||||
def refund_campaign(link, camp, billable_amount, billable_impressions):
|
||||
refund_amount = camp.bid - billable_amount
|
||||
refund_amount = get_refund_amount(camp, billable_amount)
|
||||
if refund_amount <= 0:
|
||||
return
|
||||
|
||||
owner = Account._byID(camp.owner_id, data=True)
|
||||
try:
|
||||
success = authorize.refund_transaction(owner, camp.trans_id,
|
||||
|
||||
Reference in New Issue
Block a user