Skip to content

Commit

Permalink
Merge pull request #2468 from liberapay/stripe-sdd-pm-4
Browse files Browse the repository at this point in the history
  • Loading branch information
Changaco authored Oct 8, 2024
2 parents b466f76 + 736f818 commit 86e3c37
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
8 changes: 7 additions & 1 deletion emails/missing_route.spt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[---] text/html
% if len(payins) == 1
% set sp = payins[0]
% set n_transfers = len(sp.transfers)
<p>{{ _(
"You have a payment of {amount} scheduled for {payment_date} to renew your donation to {recipient}, but we can't process it because a valid payment instrument is missing.",
amount=sp.amount, payment_date=sp.execution_date, recipient=website.tippee_links(sp.transfers)[0]
Expand All @@ -12,6 +13,7 @@
amount=sp.amount, payment_date=sp.execution_date, recipients=website.tippee_links(sp.transfers)
) }}</p>
% else
% set n_transfers = [0]
<p>{{ ngettext(
"",
"You have {n} payments scheduled to renew your donations, but we can't process them because a valid payment instrument is missing.",
Expand All @@ -20,6 +22,7 @@
<p>{{ _("The payment dates, amounts and recipients are:") }}</p>
<ul>
% for sp in payins
% do n_transfers.__setitem__(0, n_transfers[0] + len(sp.transfers))
<li>{{ _(
"{date}: {money_amount} to {recipient}",
date=sp.execution_date, money_amount=sp.amount, recipient=website.tippee_links(sp.transfers)[0]
Expand All @@ -29,8 +32,11 @@
) }}</li>
% endfor
</ul>
% set n_transfers = n_transfers[0]
% endif

<p><a href="{{ participant.url('routes/') }}" style="{{ button_style('primary') }}">{{ _("Add a payment instrument") }}</a></p>
<p><a href="{{ participant.url('giving/pay/') }}" style="{{ button_style('primary') }}">{{ ngettext(
"Renew this donation", "Renew these donations", n_transfers
) }}</a></p>

<p><a href="{{ participant.url('giving/') }}" style="{{ button_style('default') }}">{{ _("Manage your donations") }}</a></p>
29 changes: 26 additions & 3 deletions liberapay/payin/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pando import json

from ..billing.payday import compute_next_payday_date
from ..constants import SEPA
from ..cron import logger
from ..exceptions import (
AccountSuspended, BadDonationCurrency, MissingPaymentAccount, NoSelfTipping,
Expand Down Expand Up @@ -282,7 +283,29 @@ def execute_scheduled_payins():
WHERE r.participant = sp.payer
AND r.status = 'chargeable'
AND r.network::text LIKE 'stripe-%%'
AND ( sp.amount::currency = 'EUR' OR r.network <> 'stripe-sdd' )
AND ( r.network <> 'stripe-sdd' OR
sp.amount::currency = 'EUR' AND
( SELECT count(*) > 0
FROM json_array_elements(sp.transfers) tr
JOIN LATERAL (
SELECT 1
FROM payment_accounts a
WHERE ( a.participant = (tr->>'tippee')::bigint OR
a.participant IN (
SELECT t.member
FROM current_takes t
WHERE t.team = (tr->>'tippee')::bigint
AND t.amount <> 0
)
)
AND a.is_current IS TRUE
AND a.verified IS TRUE
AND a.charges_enabled IS TRUE
AND a.country IN %(SEPA)s
LIMIT 1
) ON true
)
)
ORDER BY r.is_default_for = sp.amount::currency DESC NULLS LAST
, r.is_default DESC NULLS LAST
, r.ctime DESC
Expand All @@ -296,7 +319,7 @@ def execute_scheduled_payins():
AND p.is_suspended IS NOT TRUE
GROUP BY p.id
ORDER BY p.id
""")
""", dict(SEPA=SEPA,))
for payer, scheduled_payins in rows:
scheduled_payins[:] = [Object(**sp) for sp in scheduled_payins]
for sp in scheduled_payins:
Expand All @@ -319,7 +342,7 @@ def unpack():
if transfers:
payin_amount = sum(tr['amount'] for tr in transfers)
proto_transfers = []
sepa_only = len(transfers) > 1
sepa_only = len(transfers) > 1 or route.network == 'stripe-sdd'
for tr in list(transfers):
try:
proto_transfers.extend(resolve_tip(
Expand Down

0 comments on commit 86e3c37

Please sign in to comment.