$name, 'description' => $description, ]); // Step 2: Create a Price in Stripe $price_obj = \Stripe\Price::create([ 'product' => $product->id, 'unit_amount' => $price * 100, // Price in cents 'currency' => 'usd', ]); // Step 3: Save the package to the database $stmt = db()->prepare( 'INSERT INTO service_packages (coach_id, name, description, price, stripe_product_id, stripe_price_id, package_type, max_clients, start_date, end_date, payment_plan, num_sessions) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0)' ); $stmt->execute([$coach_id, $name, $description, $price, $product->id, $price_obj->id, $package_type, $max_clients, $start_date, $end_date, $payment_plan]); $package_id = db()->lastInsertId(); // Step 4: Save service items $total_sessions = 0; foreach ($service_items as $item) { $item_type = $item['type']; $item_quantity = $item['quantity']; if (!empty($item_type) && !empty($item_quantity)) { $stmt = db()->prepare('INSERT INTO package_service_items (package_id, service_type, quantity) VALUES (?, ?, ?)'); $stmt->execute([$package_id, $item_type, $item_quantity]); $total_sessions += $item_quantity; } } // Step 5: Update num_sessions in service_packages $stmt = db()->prepare('UPDATE service_packages SET num_sessions = ? WHERE id = ?'); $stmt->execute([$total_sessions, $package_id]); $success_message = 'Service package created successfully!'; } catch (\Stripe\Exception\ApiErrorException $e) { $error_message = 'Stripe Error: ' . $e->getMessage(); } catch (PDOException $e) { $error_message = 'Database Error: ' . $e->getMessage(); } } // Fetch existing packages for the coach $stmt = db()->prepare('SELECT * FROM service_packages WHERE coach_id = ?'); $stmt->execute([$coach_id]); $packages = $stmt->fetchAll(); ?> Manage Service Packages

Manage Service Packages

Create New Package

Service Items

Your Packages

You have not created any packages yet.

  • Price: $ | Type: | Total Sessions:

    Max Clients:

    Date: -

    Payment Plan:

Back to Dashboard