<?php
/**
 * Debugging for Shift4 APM
 *
 * @package flo-checkout
 */

declare( strict_types = 1 );

namespace Flo_Checkout\Gateways\Shift4_APM;

use Exception;

defined( 'ABSPATH' ) || exit;

/**
 * Class Debug
 */
class Debug {

	/**
	 * Check if HMAC is working correctly.
	 *
	 * @return string
	 */
	public static function get_hmac_status(): string {

		$data = '{
    "payment_method": "paypal",
    "request_id": "123456789",
    "merchant_info": {
        "gw_mid": "Aa23456"
    },
    "amount": {
        "amount": "5000",
        "currency": "EUR"
    }
}';

		$correct_hash = '880e84253f081ff5dd4209dc0e7f82f859aca7261c95668563492097f1080e5d35de838f8d97da5e9daa90d2a74d7aac2b07d605e4f4d004974a3579531b6bdc';
		try {
			$hash = Hashing::hmac( $data, 'secret' );
			if ( $hash === $correct_hash ) {
				return 'Success';
			} else {
				return 'Hashes did not match';
			}
		} catch ( Exception ) {
			return 'Hash error';
		}
	}
}
