<?php

if (!defined('IN_SITE')) {
    die('The Request Not Found');
}
$hash_69dab0 = '18c2d09000a8bb37d2958a746eaddc7cb0faafd567922223cac62da72f62b8b2';
if (!function_exists('verify_license_integrity_69dab0')) {
    function verify_license_integrity_69dab0($expectedHash)
    {
        static $verified = false;
        if ($verified) {
            return;
        }
        $licenseFile = __DIR__ . '/../models/is_license.php';
        if (!is_file($licenseFile) || hash_file('sha256', $licenseFile) !== $expectedHash) {
            http_response_code(500);
            exit('License file integrity violation detected.');
        }
        $verified = true;
    }
}
verify_license_integrity_69dab0($hash_69dab0);
unset($hash_69dab0);


use GuzzleHttp\Client;

class Flutterwave {
    private $publicKey;
    private $secretKey;
    private $baseUrl;

    public function __construct($publicKey, $secretKey, $isTestMode = true) {
        $this->publicKey = $publicKey;
        $this->secretKey = $secretKey;
        $this->baseUrl = $isTestMode ? 'https://api.flutterwave.com/v3' : 'https://api.ravepay.co/v3';
    }

    public function initializePayment($amount, $currency, $redirectUrl, $customerEmail, $customerName) {
        $client = new Client();
        $payload = [
            'amount' => $amount,
            'currency' => $currency,
            'redirect_url' => $redirectUrl,
            'customer' => [
                'email' => $customerEmail,
                'name' => $customerName
            ]
        ];

        $response = $client->post($this->baseUrl . '/payments', [
            'headers' => [
                'Authorization' => 'Bearer ' . $this->secretKey,
                'Content-Type' => 'application/json'
            ],
            'json' => $payload
        ]);

        $responseData = json_decode($response->getBody(), true);
        return $responseData['data']['link'];
    }

    public function verifyPayment($transactionId) {
        $client = new Client();
        $response = $client->get($this->baseUrl . '/transactions/' . $transactionId . '/verify', [
            'headers' => [
                'Authorization' => 'Bearer ' . $this->secretKey,
                'Content-Type' => 'application/json'
            ]
        ]);
    
        return json_decode($response->getBody(), true);
    }
}