/*
Theme Name: Avada Child
Description: Child theme for Avada theme
Author: ThemeFusion
Author URI: https://theme-fusion.com
Template: Avada
Version: 1.0.0
Text Domain:  Avada
*/

<?php

// --- Gumroad Webhook Handler ---

/**
 * Register a custom API endpoint for Gumroad webhooks.
 * This creates the URL: /wp-json/gumroad/v1/webhook
 */
add_action( 'rest_api_init', function () {
    register_rest_route( 'gumroad/v1', '/webhook', array(
        'methods' => 'POST',
        'callback' => 'handle_gumroad_webhook',
        'permission_callback' => '__return_true', // Anyone can access this URL
    ) );
} );

/**
 * The main function that handles the incoming webhook data from Gumroad.
 * For now, this is a placeholder.
 *
 * @param WP_REST_Request $request The incoming request data.
 */
function handle_gumroad_webhook( WP_REST_Request $request ) {
    // For now, we just acknowledge that we received the request successfully.
    // In the next steps, we will add logic here to process the sale
    // and send an email to the customer.
    return new WP_REST_Response( 'Webhook received.', 200 );
}

// --- End Gumroad Webhook Handler ---