#nikky_webhooks

1 messages · Page 1 of 1 (latest)

solemn knollBOT
#

đź‘‹ Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

đź”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1361441569562955926

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

floral dagger
#

Hello

minor sapphire
#

Hello!

floral dagger
#

You are saying you want to transfer funds to a Connected Account after a successful charge?

cold scaffold
#

Hello

#

I need help

minor sapphire
#

try {
$event = \Stripe\Webhook::constructEvent($payload, $sig_header, $endpoint_secret);

    if ($event->type === 'payment_intent.succeeded') {
        $paymentIntent = $event['data']['object'];
        $charge = $paymentIntent['charges']['data'][0];
        $charge_id = $charge['id'];
        $metadata_raw = $charge['metadata']['vendor_earnings'] ?? null;

        if (!$metadata_raw) {
            error_log("No vendor_earnings metadata found on charge.");
            return;
        }

        $metadata = json_decode($metadata_raw, true);

        foreach ($metadata as $index => $item) {
            error_log("Processing vendor item #{$index}: " . json_encode($item));

            if (
                !isset($item['other']) ||
                !isset($item['stripe_id']) ||
                !isset($item['fee_amount'])
            ) {
                error_log("Missing fields in vendor metadata at index {$index}.");
                continue;
            }

            $other= $item['other'];
            $stripeId = $item['stripe_id'];
            $feeAmount = round($item['fee_amount'] * 100); // convert to cents

            try {
                // Create the transfer to the vendor’s connected account
                $transfer = \Stripe\Transfer::create([
                    'amount' => $feeAmount,
                    'currency' => 'usd',
                    'destination' => $stripeId,
                    'source_transaction' => $charge_id,
                    'transfer_group' => "ORDER_{$charge_id}_{$stripeId}",
                ]);

                error_log("Transfer successful to {$stripeId} for amount {$feeAmount}");
solemn knollBOT
minor sapphire
floral dagger
#

@cold scaffold please start your own thread via #help

#

Okay @minor sapphire and are you seeing an error?

cold scaffold
#

ok

minor sapphire
#

Yes, it is balance_insufficient, which means it is still trying to use the platform account instead of transferring to vendors from the charge.

#

Error creating transfers: balance_insufficient is what I keep getting.

minor sapphire
quaint dust
#

đź‘‹ Stepping in for my teammate, give me a minute to catch up

minor sapphire
#

That is here try {
// Create the transfer to the vendor’s connected account
$transfer = \Stripe\Transfer::create([
'amount' => $feeAmount,
'currency' => 'usd',
'destination' => $stripeId,
'source_transaction' => $charge_id,
'transfergroup' => "ORDER{$chargeid}{$stripeId}",
]);

quaint dust
#

Can you trigger this code again? I'm looking at your test mode requests but don't see any failed requests that include source_transaction

#

Can you try logging the value of $charge_id on your end and also making sure edits to your code are saved?

minor sapphire
#

Yes.

#

It is present in the most recent log.

quaint dust
minor sapphire
quaint dust
#

This request failed because source_transaction is expecting a Charge ID (ch_)

minor sapphire
#

I am having difficulty extracting the charge ID.

quaint dust
#

Okay, let's see. So you're starting with the Checkout Session

#

I recommend retrieving the Session and expanding the PaymentIntent, then inspecting the PaymentIntent's latest_charge

quaint dust
#

@minor sapphire let me know if you have any other questions

minor sapphire
#

I am still working on extracting it.

solemn knollBOT