<?php
require_once(__DIR__ . '/vendor/autoload.php'); // Require autoload file generated by composer

use baibaratsky\WebMoney\WebMoney;
use baibaratsky\WebMoney\Signer;
use baibaratsky\WebMoney\Request\Requester\CurlRequester;
use baibaratsky\WebMoney\Api\X\X3;

$webMoney = new WebMoney(new CurlRequester);

$request = new X3\Request;
$request->setSignerWmid('413143268781');
$request->setPurse('R267788654712');
$request->setStartDateTime(new DateTime('-1 month'));
$request->setEndDateTime(new DateTime);

$request->sign(new Signer('413143268781', __DIR__ . '/413143268781.kwm', 'YmHW9Q'));

if ($request->validate()) {
    /** @var X3\Response $response */
    $response = $webMoney->request($request);

    if ($response->getReturnCode() === 0) {
        foreach ($response->getOperations() as $operation) {
            // var_dump($operation->getDescription());
            if($operation->getDescription() == $_GET['hash']){
            	exit("OK_".$operation->getAmount()."_".$operation->getTransactionId());
            } else {
            	// echo '<li>' . $operation->getTransactionId() . ': (' . $operation->getAmount() . ' руб.) '
             //        . $operation->getPayerPurse() . ' → ' . $operation->getPayeePurse() . ' ('.$operation->getDescription().')</li>';
            }
            
        }
        exit("False_0");
    } else {
        echo 'Error: ' . $response->getReturnDescription();
    }
} else {
    echo 'Request errors: ' . PHP_EOL;
    foreach ($request->getErrors() as $error) {
        echo ' - ' . $error . PHP_EOL;
    }
}