Skip to content

Commit

Permalink
Merge pull request #2305 from liberapay/various
Browse files Browse the repository at this point in the history
  • Loading branch information
Changaco authored Jan 5, 2024
2 parents 2486e6b + b720bb3 commit 23c92d6
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 26 deletions.
1 change: 1 addition & 0 deletions liberapay/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ def generate_value(self, currency):
RATE_LIMITS = {
'add_email.source': (5, 60*60*24), # 5 per day
'add_email.target': (2, 60*60*24), # 2 per day
'add_payment_instrument': (20, 60*60*24*7), # 20 per week
'admin.http-unsafe': (10, 60*60*24), # 10 per day
'change_currency': (4, 60*60*24*7), # 4 per week
'change_password': (7, 60*60*24*7), # 7 per week
Expand Down
4 changes: 2 additions & 2 deletions liberapay/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ def default_body_parser(body_bytes, headers):
cron(intervals.get('dequeue_emails', 60), Participant.dequeue_emails, True)
cron(intervals.get('send_newsletters', 60), Participant.send_newsletters, True)
cron(intervals.get('send_account_disabled_notifications', 600), send_account_disabled_notifications, True)
cron(intervals.get('refetch_elsewhere_data', 120), refetch_elsewhere_data, True)
cron(intervals.get('refetch_repos', 60), refetch_repos, True)
cron(intervals.get('refetch_elsewhere_data', 30), refetch_elsewhere_data, True)
cron(intervals.get('refetch_repos', 20), refetch_repos, True)
cron(Weekly(weekday=3, hour=2), create_payday_issue, True)
cron(intervals.get('clean_up_counters', 3600), website.db.clean_up_counters, True)
cron(Daily(hour=1), clean_up_emails, True)
Expand Down
2 changes: 1 addition & 1 deletion liberapay/models/account_elsewhere.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def refetch_elsewhere_data():
SELECT e, p
FROM elsewhere e
JOIN participants p ON p.id = e.participant
WHERE e.info_fetched_at < now() - interval '90 days'
WHERE e.info_fetched_at < now() - interval '30 days'
AND (e.missing_since IS NULL OR e.missing_since > (current_timestamp - interval '30 days'))
AND (e.last_fetch_attempt IS NULL OR e.last_fetch_attempt < (current_timestamp - interval '3 days'))
AND (p.status = 'active' OR p.receiving > 0)
Expand Down
3 changes: 2 additions & 1 deletion liberapay/models/exchange_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import stripe

from ..constants import CARD_BRANDS
from ..exceptions import InvalidId
from ..exceptions import InvalidId, TooManyAttempts


class ExchangeRoute(Model):
Expand Down Expand Up @@ -70,6 +70,7 @@ def from_address(cls, participant, network, address):
def insert(cls, participant, network, address, status,
one_off=False, remote_user_id=None, country=None, currency=None):
p_id = participant.id
cls.db.hit_rate_limit('add_payment_instrument', str(p_id), TooManyAttempts)
r = cls.db.one("""
INSERT INTO exchange_routes AS r
(participant, network, address, status,
Expand Down
34 changes: 18 additions & 16 deletions liberapay/payin/stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,22 +460,24 @@ def settle_charge_and_transfers(
payer = db.Participant.from_id(payin.payer)
undeliverable_amount = amount_settled.zero()
for i, pt in enumerate(payin_transfers):
if payer.is_suspended and pt.status not in ('failed', 'succeeded'):
pt = update_payin_transfer(
db, pt.id, None, 'suspended', None,
update_donor=(update_donor and i == last),
)
elif pt.destination_id == 'acct_1ChyayFk4eGpfLOC':
pt = update_payin_transfer(
db, pt.id, None, charge.status, error,
update_donor=(update_donor and i == last),
)
elif pt.remote_id is None and pt.status in ('pre', 'pending'):
pt = execute_transfer(
db, pt, pt.destination_id, charge.id,
update_donor=(update_donor and i == last),
)
elif payin.refunded_amount and pt.remote_id:
if payer.is_suspended:
if pt.status not in ('failed', 'succeeded'):
pt = update_payin_transfer(
db, pt.id, None, 'suspended', None,
update_donor=(update_donor and i == last),
)
elif pt.remote_id is None:
if pt.destination_id == 'acct_1ChyayFk4eGpfLOC':
pt = update_payin_transfer(
db, pt.id, None, charge.status, error,
update_donor=(update_donor and i == last),
)
elif pt.status in ('pre', 'pending'):
pt = execute_transfer(
db, pt, pt.destination_id, charge.id,
update_donor=(update_donor and i == last),
)
else:
pt = sync_transfer(
db, pt,
update_donor=(update_donor and i == last),
Expand Down
2 changes: 1 addition & 1 deletion liberapay/utils/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def iter_payin_events(db, participant, period_start, period_end, minimize=False)
params = locals()
payins = db.all("""
SELECT pi.id, pi.ctime, pi.amount, pi.status, pi.error, pi.amount_settled, pi.fee
, pi.refunded_amount, pi.off_session, r.network AS payin_method
, pi.refunded_amount, pi.off_session, pi.remote_id, r.network AS payin_method
FROM payins pi
JOIN exchange_routes r ON r.id = pi.route
WHERE pi.payer = %(id)s
Expand Down
4 changes: 2 additions & 2 deletions www/%username/ledger/index.spt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ if participant.join_time:
years = list(range(current_year, max(participant.join_time.year, 2018) - 1, -1))

[---] text/html
% from "templates/macros/icons.html" import glyphicon
% from "templates/macros/icons.html" import fontawesome, glyphicon
% from "templates/macros/payment-methods.html" import payment_method_icon with context

% extends "templates/layouts/settings.html"
Expand Down Expand Up @@ -184,7 +184,7 @@ if participant.join_time:
<td class="fees">{{ locale.format_money(event['fee']) if event['fee'] else '' }}</td>
<td class="method">{{ payment_method_icon(event['payin_method']) }}</td>
% if show_id
<td class="id">{{ event['id'] }}</td>
<td class="id">{{ event['id'] }}{% if event['remote_id'] %} <a href="https://dashboard.stripe.com/payments/{{ event['remote_id'] }}">{{ fontawesome('external-link-square') }}</a>{% endif %}</td>
% endif
</tr>
% elif event['kind'] == 'payin_transfer'
Expand Down
10 changes: 7 additions & 3 deletions www/%username/routes/index.spt
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ routes = website.db.all("""
FROM exchange_routes r
WHERE r.participant = %s
AND r.network IN ('stripe-card', 'stripe-sdd')
AND r.status IN ('chargeable', 'pending')
AND ( r.status IN ('chargeable', 'pending') OR %s )
ORDER BY r.ctime DESC
""", (participant.id,))
""", (participant.id, user.is_acting_as('admin')))

today = utcnow().date()

Expand Down Expand Up @@ -96,7 +96,7 @@ title = _("Payment Instruments")
<form action="" method="POST">
<input type="hidden" name="csrf_token" value="{{ csrf_token }}" />
% for route, last_payin in routes
<div class="payment-instrument">
<div class="payment-instrument{% if route.status not in ('chargeable', 'pending') %} text-muted{% endif %}">
<span>{{
fontawesome('credit-card', _("Credit/Debit Card")) if route.network == 'stripe-card' else
fontawesome('bank', _("Bank Account")) if route.network == 'stripe-sdd' else
Expand Down Expand Up @@ -124,6 +124,8 @@ title = _("Payment Instruments")
% endif
% if route.status == 'pending'
&nbsp; <span class="label label-warning">{{ _("pending") }}</span>
% elif route.status != 'chargeable'
&nbsp; <span class="label label-default">{{ route.status }}</span>
% endif
<br>{{ _("Added on {date}", date=route.ctime.date()) }}
% set mandate_url = route.get_mandate_url()
Expand Down Expand Up @@ -175,6 +177,7 @@ title = _("Payment Instruments")
<br><span class="text-muted">{{ _("This payment instrument hasn't been used yet.") }}</span>
% endif
</span>
% if route.status in ('chargeable', 'pending')
<span>
<button class="btn btn-danger btn-xs" name="remove" value="{{ route.id }}">{{ _("Remove") }}</button>
% if not route.is_default
Expand All @@ -191,6 +194,7 @@ title = _("Payment Instruments")
% endif
% endif
</span>
% endif
</div>
% endfor
</form>
Expand Down

0 comments on commit 23c92d6

Please sign in to comment.