-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgettxs.php
110 lines (98 loc) · 3.7 KB
/
gettxs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!---<html xmlns="http://www.w3.org/1999/xhtml">--->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="Epic Payments">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"/>
<title>Epic Payments</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<center>
<p class="bigtext"><strong>Epic Payments</strong></p>
<br><br><br>
<form method="POST">
<br><br><br>
<button class="button" name="txs">Get txs</button>
</form>
<br><br>
<?php
// database: epictxs table: txsdata
// id (auto-increment), tranid (integer,unique), slate (varchar(40)), txmsg (varchar(40))
// parse invoice from message0 and match to POS invoice to settle as paid (POS coding needed)
// click 'Get txs' after checkout to see transaction on screen to match invoice and amount
// creates new records in local mariadb/mysql db for easy recall later via php, mysql client, MS/LO Base
if (array_key_exists('txs',$_POST)) {
$url = 'http://localhost:3420/v2/owner';
$usrpwd = 'epic:.owner_api_secret'; // from .epic/main/.owner_api_secret
$con = new mysqli('dbhost', 'dbuser', 'dbpwd', 'epictxs'); // set host, user, pwd
$sql = 'select id, tranid from txsdata order by id desc limit 1'; //get last transaction id
$rtn = $con->query($sql);
if ($rtn) { // check for empty local db if true start at wallet txID 0
$nr = mysqli_num_rows($rtn);
if ($nr > 0) {
$result = $rtn->fetch_assoc();
$txid = $result['tranid'];
} else {
$txid = -1;
}
} else {
$txid = -1;
}
$newrec = true;
while ($newrec) {
$txid++; // look for wallet txs newer than last local db txs or id=0 if local db empty
$data = [
'id' => '1',
'jsonrpc' => '2.0',
'method' => 'retrieve_txs',
'params' => [
'tx_slate_id' => null,
'refresh_from_node' => true,
'tx_id' => $txid
],
];
$qs = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $usrpwd);
curl_setopt($ch, CURLOPT_POSTFIELDS, $qs);
$rtn = curl_exec($ch);
curl_close($ch);
$output = json_decode($rtn,true);
//print "<PRE>";
//print_r($output);
if (isset($output['result']['Ok']['1']['0']['id'])) {
if (isset($output['result']['Ok']['1']['0']['tx_slate_id'])) { //check for slate
$slate = $output['result']['Ok']['1']['0']['tx_slate_id'];
if ($slate == null) { $slate = ''; }
} else {
$slate = '';
}
if (isset($output['result']['Ok']['1']['0']['messages']['messages']['0']['message'])) { // check for message0
$txdata = $output['result']['Ok']['1']['0']['messages']['messages']['0']['message'];
if ($txdata == null) { $txdata = ''; }
} else {
$txdata = '';
}
echo '<p>txID: ' . $txid . ' tx POS Data: ' . $txdata;
echo ' Slate ID: ' . $slate . '<br><br>';
//$txdata = substr($txdata,0,strpos($txdata,"#")); //return just the invoice number (use for POS settlement)
$sql = "INSERT INTO txsdata (tranid, txmsg, slate) VALUES (" . $txid . ", '" . $txdata . "', '" . $slate . "')";
$rtn = $con->query($sql);
} else {
$newrec = false; //no more new wallet txs, end update loop
}
}
$con -> close();
}
?>
</body>
</html>