<?php
/**
 * Plugin Name: Knit Pay - UPI
 * Plugin URI: https://www.knitpay.org
 * Description: Add support of UPI Business apps in Knit Pay
 *
 * Version: 1.9.3.0
 * Requires at least: 6.5
 * Requires PHP: 8.1
 * Requires Plugins: knit-pay
 *
 * Author: KnitPay
 * Author URI: https://profiles.wordpress.org/knitpay/#content-plugins
 *
 * Text Domain: knit-pay-upi
 * Domain Path: /languages/
 *
 * License: GPL-3.0-or-later
 *
 * @author    KnitPay
 * @license   GPL-3.0-or-later
 * @package   KnitPay
 * @copyright 2020-2026 Knit Pay
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

if ( ! defined( 'KNIT_PAY_UPI' ) ) {
	define( 'KNIT_PAY_UPI', true );
	define( 'KNITPAY_UPI_VERSION', get_file_data( __FILE__, [ 'Version' ] )[0] );
}
define( 'KNIT_PAY_UPI_RAPIDAPI_BASE_URL', 'https://knit-pay-upi.p.rapidapi.com/' );
define( 'KNIT_PAY_UPI_RAPIDAPI_HOST', 'knit-pay-upi.p.rapidapi.com' );
define( 'KNIT_PAY_UPI_URL', plugins_url( '', __FILE__ ) );
define( 'KNIT_PAY_UPI_DIR', plugin_dir_path( __FILE__ ) );

/**
 * Autoload.
 */
require_once __DIR__ . '/vendor/autoload_packages.php';

add_action( 'plugins_loaded', 'knit_pay_upi_dependency_check', -10 );
function knit_pay_upi_dependency_check() {
	if ( ! defined( 'KNITPAY_VERSION' ) || version_compare( KNITPAY_VERSION, '8.85.15.1', '<' ) ) {
		return;
	}

	new KnitPayUPI_Setup();
}

class KnitPayUPI_Setup {
	public function __construct() {
		add_filter( 'pronamic_pay_gateways', [ $this, 'update_gateways' ] );
	}
	
	public function update_gateways( $gateways ) {
		// BharatPe QR.
		$gateways[] = new \KnitPayUPI\Gateways\UpiQR\BharatPe\Integration();

		// GPay Business QR.
		$gateways[] = new \KnitPayUPI\Gateways\UpiQR\GpayBiz\Integration();

		// Paytm for Business QR.
		$gateways[] = new \KnitPayUPI\Gateways\UpiQR\Paytm\Integration();

		// PhonePe Business QR.
		$gateways[] = new \KnitPayUPI\Gateways\UpiQR\PhonePe\Integration();

		// HDFC SmartHub Vyapar.
		$gateways[] = new \KnitPayUPI\Gateways\UpiQR\HdfcSmartHubVyapar\Integration();

		// MobiKwik.
		// $gateways[] = new \KnitPayUPI\Gateways\UpiQR\Mobikwik\Integration();

		// Freecharge.
		$gateways[] = new \KnitPayUPI\Gateways\UpiQR\Freecharge\Integration();

		// Tata Neu.
		$gateways[] = new \KnitPayUPI\Gateways\UpiQR\TataNeu\Integration();

		// Return gateways.
		return $gateways;
	}
}
