#nikky_webhooks
1 messages · Page 1 of 1 (latest)
đź‘‹ 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.
Hello
Hello!
You are saying you want to transfer funds to a Connected Account after a successful charge?
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}");
Yes, and it will be to more than one connected account in some cases.
@cold scaffold please start your own thread via #help
Okay @minor sapphire and are you seeing an error?
ok
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.
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.
đź‘‹ Stepping in for my teammate, give me a minute to catch up
Ah, source_transaction isn't being included in your request; see this for example: https://dashboard.stripe.com/test/logs/req_d2bu2cxa53V0UP
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}",
]);
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
I see you just triggered this: https://dashboard.stripe.com/test/logs/req_dHkkMX49lIjw6D
source_transaction is missing here still
Can you try logging the value of $charge_id on your end and also making sure edits to your code are saved?
Taking a step back, the reason this is failing is because the available balance in test mode for your platform is less than what you're attempting to transfer: https://dashboard.stripe.com/test/balance/overview
The Transfer should succeed if source_transaction is included: https://docs.stripe.com/connect/separate-charges-and-transfers#:~:text=When you specify the associated charge as the transfer’s source_transaction%2C the transfer request automatically succeeds.
Yep, I see it: https://dashboard.stripe.com/test/logs/req_MV1qnpkdqt5ckp
Right, I am structuring for transfers from the charge and not from the platform.
I am having difficulty extracting the charge ID.
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
@minor sapphire let me know if you have any other questions
I am still working on extracting it.