```php
<?php

require_once '../../core/api_bootstrap.php';

$data = Request::post();

try {

    Validator::required($data,[
        'provider_id',
        'plan_id'
    ]);

    $db = new Database();
    $conn = $db->connect();


    /*
    GET PLAN DETAILS
    */

    $query = "
        SELECT
        name,
        price,
        categories_allowed,
        daily_lead_limit,
        validity_days
        FROM plans
        WHERE id = :plan_id
        AND status = 1
        LIMIT 1
    ";

    $stmt = $conn->prepare($query);

    $stmt->execute([
        ':plan_id'=>$data['plan_id']
    ]);

    $plan = $stmt->fetch();

    if(!$plan){
        Response::error("Invalid plan",404);
    }


    /*
    CALCULATE DATES
    */

    $start_date = date("Y-m-d");
    $expiry_date = date("Y-m-d",strtotime("+".$plan['validity_days']." days"));


    /*
    INSERT SUBSCRIPTION
    */

    $query = "

        INSERT INTO provider_subscriptions
        (
            provider_id,
            plan_id,
            plan_name,
            plan_price,
            categories_allowed,
            daily_lead_limit,
            validity_days,
            start_date,
            expiry_date,
            status
        )

        VALUES
        (
            :provider_id,
            :plan_id,
            :plan_name,
            :plan_price,
            :categories_allowed,
            :daily_lead_limit,
            :validity_days,
            :start_date,
            :expiry_date,
            'active'
        )

    ";

    $stmt = $conn->prepare($query);

    $stmt->execute([

        ':provider_id'=>$data['provider_id'],
        ':plan_id'=>$data['plan_id'],
        ':plan_name'=>$plan['name'],
        ':plan_price'=>$plan['price'],
        ':categories_allowed'=>$plan['categories_allowed'],
        ':daily_lead_limit'=>$plan['daily_lead_limit'],
        ':validity_days'=>$plan['validity_days'],
        ':start_date'=>$start_date,
        ':expiry_date'=>$expiry_date

    ]);


    Response::success([
        "subscription_id"=>$conn->lastInsertId(),
        "expiry_date"=>$expiry_date
    ],"Subscription activated");

}
catch(Exception $e){

    Logger::log("system.log",$e->getMessage());

    Response::error("Server error",500);

}