#Bruki

1 messages · Page 1 of 1 (latest)

stiff lintelBOT
rare elm
#

👋 happy to help

#

first things first,

"charge.succeeded"
it's better to listen to payment_intent.succeeded instead

thorn tundra
#

alright, I did that now. When I try to make a Transfer to move money to the seller, it says:

Transfers using this transaction as a source must not exceed the source amount of $21.00. (There is already a transfer using this source, amounting to $15.96.)

although I didn't make that transfer myself.

#

or it's trying to make it twice for some reason. I do it in a loop, but I'm testing it with one product only so there's only one iteration within that loop.

rare elm
#

would you mind sharing your code and the request ID?

thorn tundra
#
        if event["type"] == "payment_intent.succeeded":
            event_data = event["data"]["object"]
            payment_intent = stripe.client.PaymentIntent.retrieve(event_data["id"])

            if payment_intent["status"] != "succeeded":
                raise exceptions.SuspiciousOperation("no payment_intent_id")

            receipt_url = payment_intent["charges"]["data"][0]["receipt_url"]

            product_ids = literal_eval(
                payment_intent["charges"]["data"][0]["metadata"]["product_ids"]
            )

            user_id = payment_intent["charges"]["data"][0]["metadata"]["user_id"]

            charge_id = payment_intent["charges"]["data"][0]["id"]
            transfer_group = payment_intent["transfer_group"]

            split_payments = {}
            products = models.Product.objects.filter(pk__in=product_ids)
            for product in products:
                if product.store not in split_payments.keys():
                    split_payments[product.store] = product.price
                else:
                    split_payments[product.store] = split_payments[product.store] + product.price
 
            for store, amount in split_payments.items():
                transfer = stripe.client.Transfer.create(
                    amount=int(amount*(1-store.percentage_fee)),
                    currency="usd",
                    destination=store.stripe_account_id,
                    transfer_group=transfer_group,
                    source_transaction=charge_id
                )
#

here's the event block

#

what's interesting is that when the error pops up there's no event that caused it in logs, it looks like this

#
2023-02-22 10:58:41   --> payment_intent.created [evt_3MeF5xAcL2olRWU11lNEJMX2]
2023-02-22 10:58:41  <--  [200] POST http://localhost:8000/api/v3/marketplace/stripe/webhook [evt_3MeF5xAcL2olRWU11lNEJMX2]
2023-02-22 10:59:02   --> payment_intent.succeeded [evt_3MeF5xAcL2olRWU11ymD0M9k]
2023-02-22 10:59:02   --> charge.succeeded [evt_3MeF5xAcL2olRWU11f7FtjGM]
2023-02-22 10:59:02  <--  [200] POST http://localhost:8000/api/v3/marketplace/stripe/webhook [evt_3MeF5xAcL2olRWU11f7FtjGM]
2023-02-22 10:59:04   --> transfer.created [evt_3MeF5xAcL2olRWU11HJBAoW1]
2023-02-22 10:59:04  <--  [200] POST http://localhost:8000/api/v3/marketplace/stripe/webhook [evt_3MeF5xAcL2olRWU11HJBAoW1]
2023-02-22 10:59:04   --> connect payment.created [evt_1MeF6KPPB7QtLixnuC1UdRtN]
2023-02-22 10:59:04  <--  [200] POST http://localhost:8000/api/v3/marketplace/stripe/webhook [evt_1MeF6KPPB7QtLixnuC1UdRtN]
2023-02-22 10:59:04  <--  [500] POST http://localhost:8000/api/v3/marketplace/stripe/webhook [evt_3MeF5xAcL2olRWU11ymD0M9k]
rare elm
#

taking a look

thorn tundra
#

ah, there is when I open it in dashboard - payment_intent.succeeded.

Do events not get printed if it's not 200?

rare elm
#

would you mind sharing the request ID that generated the error you shared earlier?

thorn tundra
#

req_4zhW3s6Hsc7iZe

#

and this one is the one I made, I believe, resulting with 200 - req_UbHmz4HuiOMQ2b

#

they're invoked at the same timestamp

rare elm
#

I think you should debug this

for product in products:
                if product.store not in split_payments.keys():
                    split_payments[product.store] = product.price
                else:
                    split_payments[product.store] = split_payments[product.store] + product.price
 
            for store, amount in split_payments.items():
                transfer = stripe.client.Transfer.create(
                    amount=int(amount*(1-store.percentage_fee)),
                    currency="usd",
                    destination=store.stripe_account_id,
                    transfer_group=transfer_group,
                    source_transaction=charge_id
                )
#

split_payments might be wrongly generated

thorn tundra
#

I'll give it a try, thanks!

#

is there a chance that payment_intent.succeeded event is called twice? Cause I just added a breakpoint where I calculate split_payments, but then I tried to fetch Transfers for its transfer group and there already was one, with correctly calculated amount that should be moved to Connect partner

#

oh no... it seems like my staging webhook is picking it up as well, I'll shut it down for a bit

#

that actually makes sense

#

nonetheless, I think that payment_intent.succeeded works a lot better so thanks for sharing that

#

solved!

split quail
#

Glad to hear that!