mirror of
https://github.com/viq/NewsBlur.git
synced 2025-08-05 16:49:45 +00:00
A better refund for paypal.
This commit is contained in:
parent
6dfe4a28da
commit
31d9d92b07
1 changed files with 19 additions and 9 deletions
|
@ -312,15 +312,25 @@ class Profile(models.Model):
|
||||||
'API_SIGNATURE': settings.PAYPAL_API_SIGNATURE,
|
'API_SIGNATURE': settings.PAYPAL_API_SIGNATURE,
|
||||||
}
|
}
|
||||||
paypal = PayPalInterface(**paypal_opts)
|
paypal = PayPalInterface(**paypal_opts)
|
||||||
transaction = PayPalIPN.objects.filter(custom=self.user.username,
|
transactions = PayPalIPN.objects.filter(custom=self.user.username,
|
||||||
txn_type='subscr_payment'
|
txn_type='subscr_payment'
|
||||||
).order_by('-payment_date')[0]
|
).order_by('-payment_date')
|
||||||
|
if not transactions:
|
||||||
|
transactions = PayPalIPN.objects.filter(payer_email=self.user.email,
|
||||||
|
txn_type='subscr_payment'
|
||||||
|
).order_by('-payment_date')
|
||||||
|
if transactions:
|
||||||
|
transaction = transactions[0]
|
||||||
refund = paypal.refund_transaction(transaction.txn_id)
|
refund = paypal.refund_transaction(transaction.txn_id)
|
||||||
try:
|
try:
|
||||||
refunded = int(float(refund.raw['TOTALREFUNDEDAMOUNT'][0]))
|
refunded = int(float(refund.raw['TOTALREFUNDEDAMOUNT'][0]))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
refunded = int(transaction.payment_gross)
|
refunded = int(transaction.payment_gross)
|
||||||
logging.user(self.user, "~FRRefunding paypal payment: $%s" % refunded)
|
logging.user(self.user, "~FRRefunding paypal payment: $%s" % refunded)
|
||||||
|
else:
|
||||||
|
logging.user(self.user, "~FRCouldn't refund paypal payment: not found by username or email")
|
||||||
|
refunded = 0
|
||||||
|
|
||||||
|
|
||||||
return refunded
|
return refunded
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue