mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-05 03:00:15 -04:00
Refunds for authorize.net transactions.
This commit is contained in:
committed by
Brian Simpson
parent
2be7bf01e8
commit
776755b9df
@@ -25,6 +25,9 @@ For talking to authorize.net credit card payments via their XML api.
|
||||
|
||||
This file consists mostly of wrapper classes for dealing with their
|
||||
API, while the actual useful functions live in interaction.py
|
||||
|
||||
NOTE: This is using the Customer Information Manager (CIM) API
|
||||
http://developer.authorize.net/api/cim/
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
@@ -38,6 +38,7 @@ from r2.lib.authorize.api import (
|
||||
Order,
|
||||
ProfileTransAuthOnly,
|
||||
ProfileTransPriorAuthCapture,
|
||||
ProfileTransRefund,
|
||||
ProfileTransVoid,
|
||||
UpdateCustomerPaymentProfileRequest,
|
||||
)
|
||||
@@ -205,3 +206,22 @@ def charge_transaction(user, trans_id, campaign, test=None):
|
||||
|
||||
# already charged
|
||||
return True
|
||||
|
||||
|
||||
@export
|
||||
def refund_transaction(user, trans_id, campaign_id, amount, test=None):
|
||||
# refund will only work if charge has settled
|
||||
bid = Bid.one(transaction=trans_id, campaign=campaign_id)
|
||||
if trans_id < 0:
|
||||
bid.refund(amount)
|
||||
return True
|
||||
else:
|
||||
success, res = _make_transaction(ProfileTransRefund, amount, user,
|
||||
bid.pay_id, trans_id=trans_id,
|
||||
test=test)
|
||||
if success:
|
||||
bid.refund(amount)
|
||||
elif success == False:
|
||||
msg = "Refund failed, response: %r" % res
|
||||
raise AuthorizeNetException(msg)
|
||||
return True
|
||||
|
||||
@@ -209,7 +209,7 @@ class RenderableCampaign():
|
||||
if transaction.is_void():
|
||||
status['paid'] = False
|
||||
status['free'] = False
|
||||
elif transaction.is_charged():
|
||||
elif transaction.is_charged() or transaction.is_refund():
|
||||
status['complete'] = True
|
||||
|
||||
rc = cls(campaign_id36, start_date, end_date, duration, bid, sr,
|
||||
|
||||
@@ -344,8 +344,15 @@ class Bid(Sessionized, Base):
|
||||
"""
|
||||
return (self.status == self.STATUS.CHARGE)
|
||||
|
||||
def refund(self):
|
||||
def refund(self, amount):
|
||||
current_charge = self.charge or self.bid # needed if charged() not
|
||||
# setting charge attr
|
||||
self.charge = current_charge - amount
|
||||
self.set_status(self.STATUS.REFUND)
|
||||
self._commit()
|
||||
|
||||
def is_refund(self):
|
||||
return (self.status == self.STATUS.REFUND)
|
||||
|
||||
|
||||
class PromotionWeights(Sessionized, Base):
|
||||
|
||||
Reference in New Issue
Block a user