Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stripe fixes #2494

Merged
merged 3 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions liberapay/payin/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,9 @@

Returns a copy of `base_amounts` with updated values.
"""
if available_amount < (minimum_amount or 0):
raise ValueError("available_amount can't be less than minimum_amount or 0")

Check warning on line 562 in liberapay/payin/common.py

View check run for this annotation

Codecov / codecov/patch

liberapay/payin/common.py#L562

Added line #L562 was not covered by tests

currency = available_amount.currency
zero = Money.ZEROS[currency]
inf = Money('inf', currency)
Expand Down
25 changes: 16 additions & 9 deletions liberapay/payin/stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@
ORDER BY pt.id
""", (payin.id,))
last = len(payin_transfers) - 1
if amount_settled is not None:
if charge.status == 'succeeded':
payer = db.Participant.from_id(payin.payer)
undeliverable_amount = amount_settled.zero()
for i, pt in enumerate(payin_transfers):
Expand All @@ -501,7 +501,7 @@
)
elif pt.status in ('pre', 'pending'):
pt = execute_transfer(
db, pt, pt.destination_id, charge.id,
db, pt, charge.id,
update_donor=(update_donor and i == last),
)
else:
Expand Down Expand Up @@ -542,7 +542,8 @@
update_donor=(update_donor and i == last),
)

elif charge.status in ('failed', 'pending'):
else:
assert charge.status in ('failed', 'pending')
for i, pt in enumerate(payin_transfers):
update_payin_transfer(
db, pt.id, None, charge.status, error,
Expand All @@ -552,12 +553,11 @@
return payin


def execute_transfer(db, pt, destination, source_transaction, update_donor=True):
def execute_transfer(db, pt, source_transaction, update_donor=True):
"""Create a Transfer.

Args:
pt (Record): a row from the `payin_transfers` table
destination (str): the Stripe ID of the destination account
source_transaction (str): the ID of the Charge this transfer is linked to

Returns:
Expand All @@ -570,7 +570,7 @@
amount=Money_to_int(pt.amount),
currency=pt.amount.currency,
description=generate_transfer_description(pt),
destination=destination,
destination=pt.destination_id,
metadata={'payin_transfer_id': pt.id},
source_transaction=source_transaction,
idempotency_key='payin_transfer_%i' % pt.id,
Expand All @@ -583,9 +583,9 @@
SET is_current = null
WHERE provider = 'stripe'
AND id = %s
""", (destination,))
""", (pt.destination_id,))
alternate_destination = db.one("""
SELECT id
SELECT id, pk
FROM payment_accounts
WHERE participant = %(p_id)s
AND provider = 'stripe'
Expand All @@ -597,7 +597,14 @@
LIMIT 1
""", dict(p_id=pt.recipient, SEPA=SEPA, currency=pt.amount.currency))
if alternate_destination:
return execute_transfer(db, pt, alternate_destination, source_transaction)
pt = db.one("""

Check warning on line 600 in liberapay/payin/stripe.py

View check run for this annotation

Codecov / codecov/patch

liberapay/payin/stripe.py#L600

Added line #L600 was not covered by tests
UPDATE payin_transfers
SET destination = %s
WHERE id = %s
RETURNING *
""", (alternate_destination.pk, pt.id))
pt.destination_id = alternate_destination.id
return execute_transfer(db, pt, source_transaction)

Check warning on line 607 in liberapay/payin/stripe.py

View check run for this annotation

Codecov / codecov/patch

liberapay/payin/stripe.py#L606-L607

Added lines #L606 - L607 were not covered by tests
error = "The recipient's account no longer exists."
return update_payin_transfer(
db, pt.id, None, 'failed', error, update_donor=update_donor,
Expand Down
2 changes: 1 addition & 1 deletion www/%username/giving/pay/stripe/%payin_id.spt
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ if tippees:
if len(tips) == 1:
proto_transfers = resolve_tip(
website.db, tips[0], tips[0].tippee_p, 'stripe', payer, payer.guessed_country,
tips[0].periodic_amount
tips[0].amount * 52
)
if len(proto_transfers) == 1:
if proto_transfers[0].destination.country not in constants.SEPA:
Expand Down
Loading