From ae6bbc0aec792049bbde67866a7980ffaf802230 Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Fri, 8 Apr 2022 15:27:40 -0400 Subject: [PATCH] Showing refunds and finding both paypal and stripe refunds in premium history. --- apps/profile/models.py | 14 +++++++++----- media/css/reader/reader.css | 3 ++- media/js/newsblur/reader/reader_account.js | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/apps/profile/models.py b/apps/profile/models.py index 3e47344f1..9841d6169 100644 --- a/apps/profile/models.py +++ b/apps/profile/models.py @@ -519,9 +519,8 @@ class Profile(models.Model): logging.user(self.user, f"~FRCouldn't find paypal transactions: ~SB{paypal_id}") continue for transaction in transactions['transactions']: - import pdb; pdb.set_trace() created = dateutil.parser.parse(transaction['time']) - if transaction['status'] not in ['COMPLETED', 'PARTIALLY_REFUNDED']: continue + if transaction['status'] not in ['COMPLETED', 'PARTIALLY_REFUNDED', 'REFUNDED']: continue if created in seen_payments: continue seen_payments.add(created) total_paypal_payments += 1 @@ -561,10 +560,14 @@ class Profile(models.Model): if created in seen_payments: continue seen_payments.add(created) total_stripe_payments += 1 + refunded = None + if payment.refunded: + refunded = True PaymentHistory.objects.get_or_create(user=self.user, payment_date=created, payment_amount=payment.amount / 100.0, - payment_provider='stripe') + payment_provider='stripe', + refunded=refunded) else: logging.user(self.user, "~FBNo Stripe payments") @@ -746,7 +749,7 @@ class Profile(models.Model): if days_since < 365: days_left = (365 - days_since) pct_left = days_left/365 - refund_amount = pct_left * refund_amount * 0.5 + refund_amount = pct_left * refund_amount else: logging.user(self.user, f"~FRCouldn't prorate paypal payment, too old: ~SB{transaction}") try: @@ -765,7 +768,7 @@ class Profile(models.Model): logging.user(self.user, f"Paypal refund response: {response}") if 'status' in response and response['status'] == "COMPLETED": refunded = int(float(transaction['amount_with_breakdown']['gross_amount']['value'])) - logging.user(self.user, "~FRRefunding paypal payment: $%s" % refunded) + logging.user(self.user, "~FRRefunding paypal payment: $%s/%s" % (refund_amount, refunded)) else: logging.user(self.user, "~FRCouldn't refund paypal payment: %s" % response) refunded = response @@ -1841,6 +1844,7 @@ class PaymentHistory(models.Model): 'payment_date': self.payment_date.strftime('%Y-%m-%d'), 'payment_amount': self.payment_amount, 'payment_provider': self.payment_provider, + 'refunded': self.refunded, } @classmethod diff --git a/media/css/reader/reader.css b/media/css/reader/reader.css index a1cb6dcab..5f4d0e5ea 100644 --- a/media/css/reader/reader.css +++ b/media/css/reader/reader.css @@ -11220,7 +11220,8 @@ form.opml_import_form input { .NB-account-payments .NB-scheduled .NB-account-payment-provider { color: darkgrey; } -.NB-account-payments .NB-scheduled.NB-canceled .NB-account-payment-provider { +.NB-account-payments .NB-scheduled.NB-canceled .NB-account-payment-provider, +.NB-account-payments .NB-refunded .NB-account-payment-amount { text-decoration: line-through; color: darkred; } diff --git a/media/js/newsblur/reader/reader_account.js b/media/js/newsblur/reader/reader_account.js index 095791d06..2d63b0202 100644 --- a/media/js/newsblur/reader/reader_account.js +++ b/media/js/newsblur/reader/reader_account.js @@ -503,7 +503,7 @@ _.extend(NEWSBLUR.ReaderAccount.prototype, { } _.each(data.payments, function (payment) { var date = new Date(payment.payment_date); - $history.append($.make('li', { className: 'NB-account-payment ' + (payment.scheduled ? 'NB-scheduled' : '') }, [ + $history.append($.make('li', { className: 'NB-account-payment ' + (payment.scheduled ? ' NB-scheduled' : '') + (payment.refunded ? ' NB-refunded' : '') }, [ $.make('div', { className: 'NB-account-payment-date' }, date.format("F d, Y")), $.make('div', { className: 'NB-account-payment-amount' }, "$" + payment.payment_amount), $.make('div', { className: 'NB-account-payment-provider' }, payment.payment_provider)