Skip to content

Commit

Permalink
Merge pull request #2054 from liberapay/various
Browse files Browse the repository at this point in the history
  • Loading branch information
Changaco committed Aug 1, 2021
2 parents f4fa37b + 4929a29 commit 8958977
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
19 changes: 9 additions & 10 deletions liberapay/models/participant.py
Expand Up @@ -2844,30 +2844,29 @@ def find_partial_match(new_sp, current_schedule_map):
new_sp.transfers.sort(key=tippee_id_getter)
# Check the charge amount
if renewal_mode == 2:
adjust = False
unadjusted_amount = new_sp.amount
pp = PayinProspect(self, payin_tips, 'stripe')
if new_sp.amount < pp.min_acceptable_amount:
adjust = True
new_sp.amount = pp.min_acceptable_amount
elif new_sp.amount > pp.max_acceptable_amount:
adjust = True
new_sp.amount = pp.max_acceptable_amount
if past_payin_amount_maximum:
maximum = past_payin_amount_maximum.convert(payin_currency)
adjust = (
new_sp.amount > maximum and
maximum >= pp.moderate_proposed_amount
)
if adjust:
new_sp.amount = maximum
if adjust:
if new_sp.amount > maximum:
new_sp.amount = max(
maximum,
pp.moderate_fee_amount,
pp.one_weeks_worth,
)
if new_sp.amount != unadjusted_amount:
tr_amounts = resolve_amounts(
new_sp.amount,
{tip.tippee: tip.amount for tip in payin_tips}
)
for tr in new_sp.transfers:
tr['amount'] = tr_amounts[tr['tippee_id']]
del tr_amounts
del unadjusted_amount
# Try to find this new payment in the current schedule
tippees = get_tippees_tuple(new_sp)
cur_sp = current_schedule_map.pop(tippees, None)
Expand Down
14 changes: 7 additions & 7 deletions tests/py/test_schedule.py
Expand Up @@ -676,18 +676,18 @@ def test_no_new_renewal_is_scheduled_when_there_is_a_pending_transfer(self):
assert len(scheduled_payins) == 0

def test_newly_scheduled_automatic_payments_are_at_least_a_week_away(self):
# Set up an automatic donation funded 4 weeks ago
# Set up an automatic donation partially funded 4 weeks ago
alice = self.make_participant('alice', email='alice@liberapay.com')
bob = self.make_participant('bob')
alice.set_tip_to(bob, EUR('0.23'), renewal_mode=2)
alice.set_tip_to(bob, EUR('3.00'), renewal_mode=2)
alice_sdd = self.upsert_route(alice, 'stripe-sdd')
payin, pt = self.make_payin_and_transfer(alice_sdd, bob, EUR('0.22'), status='pending')
payin, pt = self.make_payin_and_transfer(alice_sdd, bob, EUR('2.00'), status='pending')
self.db.run("UPDATE payin_transfers SET ctime = ctime - interval '4 weeks'")
update_payin_transfer(self.db, pt.id, pt.remote_id, 'succeeded', None)
# At this point we should have an automatic renewal scheduled one week from now
scheduled_payins = self.db.all("SELECT * FROM scheduled_payins")
assert len(scheduled_payins) == 1
assert scheduled_payins[0].amount == EUR('10.12')
assert scheduled_payins[0].amount == EUR('10.00')
assert scheduled_payins[0].automatic is True
payment_timedelta = scheduled_payins[0].execution_date - utcnow().date()
assert payment_timedelta.days in (6, 7)
Expand All @@ -702,9 +702,9 @@ def test_late_manual_payment_switched_to_automatic_is_scheduled_a_week_away(self
# Set up a manual donation
alice = self.make_participant('alice', email='alice@liberapay.com')
bob = self.make_participant('bob')
alice.set_tip_to(bob, EUR('0.23'), renewal_mode=1)
alice.set_tip_to(bob, EUR('3.00'), renewal_mode=1)
alice_sdd = self.upsert_route(alice, 'stripe-sdd')
payin, pt = self.make_payin_and_transfer(alice_sdd, bob, EUR('0.22'), status='pending')
payin, pt = self.make_payin_and_transfer(alice_sdd, bob, EUR('2.00'), status='pending')
self.db.run("UPDATE payin_transfers SET ctime = ctime - interval '3 weeks'")
update_payin_transfer(self.db, pt.id, pt.remote_id, 'succeeded', None)
# At this point we should have a manual renewal scheduled in the past
Expand All @@ -726,7 +726,7 @@ def test_late_manual_payment_switched_to_automatic_is_scheduled_a_week_away(self
assert tip.renewal_mode == 2
scheduled_payins = self.db.all("SELECT * FROM scheduled_payins WHERE payin IS NULL")
assert len(scheduled_payins) == 1
assert scheduled_payins[0].amount == EUR('10.12')
assert scheduled_payins[0].amount == EUR('10.00')
assert scheduled_payins[0].automatic is True
payment_timedelta = scheduled_payins[0].execution_date - utcnow().date()
assert payment_timedelta.days in (6, 7)
Expand Down
15 changes: 9 additions & 6 deletions www/admin/users.spt
Expand Up @@ -337,19 +337,22 @@ title = "Users Admin"
</p>
% endif

% if row.sign_up_request|default(None)
% set headers = row.sign_up_request.get('headers', {})
% else
% set headers = {}
% endif
% if row.sign_up_request is defined
% set headers = (row.sign_up_request or {}).get('headers', {})
% set ip_address = headers.get('Cf-Connecting-Ip')
% set country_code = headers.get('Cf-Ipcountry')
% if country_code
% set country_name = locale.countries.get(country_code, country_code)
% else
% set country_name = 'country unknown'
% endif
% if ip_address
<p><strong>IP address:</strong> {{ ip_address }} ({{ country_code or 'country unknown' }})</p>
<p><strong>IP address:</strong> {{ ip_address }} ({{ country_name }})</p>
% else
<p><strong>IP address:</strong> unknown.</p>
% endif
% endif
% endif

<div><strong>Profile descriptions:</strong>
% if p.public_name
Expand Down

0 comments on commit 8958977

Please sign in to comment.