<?php declare(strict_types=1);

use io\billdesk\client\hmacsha256\BillDeskJWEHS256Client;
use io\billdesk\client\Logging;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use PHPUnit\Framework\TestCase;

class RefundTxnTest extends TestCase {
    private $client;

    protected function setUp(): void
    {
        $this->client = new BillDeskJWEHS256Client("https://pguat.billdesk.io", "bduathmac2", "EkCa5bjGfpk37TKYeXc7NkMXZBeR6zAB");
        $logger = new Logger("default");
        $logger->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG));
        $this->client->setLogger($logger);
    }
    
    public function testRefundTxn() {
        $request = array(
            'transactionid' => 'UAB00000000001',
            'mercid' => "V2BDMON3",
            'orderid' => uniqid(),
            'txn_amount' => "1.0",
            'refund_amount' => "1.0",
            'transaction_date' => date_format(new \DateTime(), DATE_W3C),
            'currency' => "356",
            'merc_refund_ref_no' => uniqid()
        );

        $response = $this->client->refundTransaction($request);
        $this->assertEquals(404, $response->getResponseStatus());
        $this->assertEquals('RFNFE0002', $response->getResponse()->error_code);
    }
}
