$baseUri, 'headers' => [ 'X-Auth-App-Key' => $token, 'Accept' => 'application/json', ], 'verify' => false, ]); // Obtén el contenido del cuerpo de la solicitud $input = @file_get_contents('php://input'); $event_json = json_decode($input); $cadena = json_encode($event_json); file_put_contents(__DIR__ . '/logsiip.log', "[" . date('Y-m-d H:i:s') . "] " . "Valor json: ".$cadena.PHP_EOL); // Maneja el evento del webhook if ($event_json) { switch ($event_json->type) { case 'cash_balance.funds_available': $customer = $event_json->data->object; $customerId = $customer->id; $newBalance = $customer->balance; // El nuevo saldo del cliente try {// Aquí puedes crear un nuevo PaymentIntent o un Cargo (Charge) usando el nuevo saldo $paymentIntent = \Stripe\PaymentIntent::create([ 'amount' => 30000, 'currency' => 'mxn', 'customer' => $customerId, 'payment_method_types' => ['customer_balance'], 'payment_method_data' => ['type' => 'customer_balance'], 'confirm' => true, 'payment_method_options' => [ 'customer_balance' => [ 'funding_type' => 'bank_transfer', 'bank_transfer' => ['type' => 'mx_bank_transfer'] ], ], 'metadata' => [ 'clientId' => $customerId, // ID del cliente en Ubiquiti 'createdBy' => 'UCRM', // ID de la factura en Ubiquiti 'paymentType' => 'card.one_time', 'signedInAdminId' => 1015, ], ]); file_put_contents(__DIR__ . '/logsiip.log', "[" . date('Y-m-d H:i:s') . "] " . "PaymentIntent creado: " . $paymentIntent->id . PHP_EOL, FILE_APPEND); } catch (\Stripe\Exception\ApiErrorException $e) { file_put_contents(__DIR__ . '/logsiip.log', "[" . date('Y-m-d H:i:s') . "] " ."Error creando PaymentIntent: " . $e->getMessage() . PHP_EOL, FILE_APPEND); } break; // Otros eventos relevantes } } http_response_code(200); // Responde con un 200 OK a Stripe