<?php
//
// Run this script to check if any proxied invocies from the LN_SERVICE are paid or expired
// It will apply store_credit if the invoice was paid and associated with a deposit
// It will make adjustments to quotes or orders if the invoice was paid and associated with a quote or order payment
// It will mark invoices as expired if they are expired
//
// Run this every 10 seconds with cron like this...
// * * * * * bash -c 'start=$(date +%s); for i in {1..6}; do php /path/to/scripts/check_all_invoices.php; sleep $((10 - ($(date +%s) - start) % 10)); done'
//
// Cron only lets you run every minute, using this we can run every 10 seconds.
// It accounts for the execution time of this script
// so there will be minimal 'drift' over time.
//
require_once __DIR__ . '/../../vendor/autoload.php';

// Load environment variables from the .env file at project root
Dotenv\Dotenv::createImmutable(__DIR__ . '/../../')->load();

use app\app;
use app\models\invoices;

app::init_db();
invoices::checkAll();
