```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();


    $query = "
        SELECT validity_days
        FROM plans
        WHERE id = :plan_id
        LIMIT 1
    ";

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

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

    $plan = $stmt->fetch();

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


    $query = "
        SELECT expiry_date
        FROM provider_subscriptions
        WHERE provider_id = :provider_id
        AND status = 'active'
        LIMIT 1
    ";

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

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

    $sub = $stmt->fetch();


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


    $conn->prepare("
        UPDATE provider_subscriptions
        SET expiry_date = :expiry
        WHERE provider_id = :provider_id
        AND status = 'active'
    ")->execute([

        ':expiry'=>$new_expiry,
        ':provider_id'=>$data['provider_id']

    ]);


    Response::success([
        "new_expiry"=>$new_expiry
    ],"Subscription renewed");

}
catch(Exception $e){

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

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

}