<?php

/* 
 * File     : getContixoPaymentsList.php
 * Created  : Dec 18, 2024 11:00:33 AM
 * Author   : Thomas Kirby <tkirby at dynengsys.com> (Thomas)
 * Company  : Dynamic Engineering Systems
 * Rights   : Under license to assignee. Not for resale or redistribution.
 * Encoding : UTF-8
 */

/* 
 * This is a test file to list payment method details
 * https://pos.emberservices.net/api/getContixoPaymentsList.php
 */

require("inc.php");
require($sysfiles."/debug.php");

// set error handling
error_reporting(0);		// default, errors off
//debug_set_mode(2);	// uncomment to debug
//debug_max_errors(2);	// uncomment to debug

require_once($sysfiles."/payment-storage.php");

$groupNumber = 2;
$payments_table = "njia_za_malipo_".$groupNumber;

require($sysfiles."/connect_to_subscribers.php");

print "payments_table=$payments_table<br>";

$result = mysqli_query($dbc,"SELECT * FROM `$payments_table` WHERE 1 ORDER BY epm_created DESC, epm_userid ASC, epm_type ASC;");

if (!$result) die("query error");

print <<<END
<table border=1>
<tr>
	<th>epm_id</th>
	<th>epm_token</th>
	<th>epm_userid</th>
	<th>epm_type</th>
	<th>epm_data</th>
	<th>epm_created</th>
	<th>epm_modified</th>
	<th>stored data</th>
</tr>
END;

while( $row = mysqli_fetch_assoc($result) ) {
	//var_dump($row);
	extract($row);
	
	//---------------------------------------
	// load and decrypt stored data
	$stored_data = GetPaymentInfo($groupNumber, $epm_userid, $epm_token);
	
	if (!$stored_data) {
		//Stored Payment Method not found for this user and token
print <<<END
<tr>
	<td colspan="8" align=left> not found </td>
</tr>
END;
	} 
	else {
		extract($stored_data);
print <<<END
<tr>
	<td>$epm_id</td>
	<td>$epm_token</td>
	<td>$epm_userid</td>
	<td>$epm_type</td>
	<td>epm_data</td>
	<td>$epm_created</td>
	<td>$epm_modified</td>
	<td>
END;
	//var_dump($stored_data);
	print "</td></tr>";		
	}
}

print <<<END
</table>
END;

die("ok");