<?php
    error_reporting(E_ALL);
    header('Access-Control-Allow-Origin: *');
    include_once 'inc/functions.php';
    include 'inc/database.php';



    $data = decodeSignedRequest($_GET['signed_payload']);
    
    $stripe = new \Stripe\StripeClient(
        $stripe['secret_key']
    );

    $hash	= $data['store_hash'];
    
    $db->query("UPDATE `stores` SET `uninstall` = '1', `script_enabled` = 0  WHERE `store_id` = '".$hash."'");
    $db->query("UPDATE `subscription` SET `status` = 'deactive' WHERE `store_id` = '".$hash."'");
    
    $getSubscription = $db->select("subscription", "*" ,array( "store_id" => $hash ));
    if($getSubscription["id"]){
        $getSubscription = array($getSubscription);
    }
    foreach ($getSubscription as $key => $subscription) {
        $cancelObj = $stripe->subscriptions->cancel(
            $subscription["stripe_subscription_id"]
        );
    }
    
?>