-
Notifications
You must be signed in to change notification settings - Fork 0
/
new-orders.php
123 lines (107 loc) · 4.05 KB
/
new-orders.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
/*
Plugin Name: Paylike orders
Description: See latest orders
Author: Vass Ardei
Version: 0.1
*/
add_action('admin_menu', 'add_new_orders_menu');
function add_new_orders_menu(){
add_menu_page( 'PL New Order', 'PL New Order', 'manage_options', 'new-orders', 'show_new_orders' );
}
/* A java way to extract the damn key!
import java.util.Base64;
public class Base64{
public static void main(String []args){
String result = "Basic " + new String(Base64.getEncoder().encode((":" + "key").getBytes()));
System.out.println(result);
}
}
*/
function show_new_orders(){
echo "<h1>New Orders</h1>";
global $wpdb;
$table_name = $wpdb->prefix . 'orders';
$results = $wpdb->get_results('SELECT id FROM ' . $table_name);
$filterOut = array();
if(!empty($results)) {
foreach($results as $row){
$filterOut[$row->id] = true;
}
}
$key = "Basic {addKeyHere}";
$merchantId = "{addMerchantIdHere}";
$url = "https://api.paylike.io/merchants/" . $merchantId . "/transactions?limit=1000";
$request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
$args = array(
'headers' => array(
'Authorization' => $key,
'Content-Type' => 'application/json'
),
);
$response = wp_remote_get( $url, $args );
$response_code = wp_remote_retrieve_response_code( $response );
$response_body = wp_remote_retrieve_body( $response );
$data = json_decode( $response_body );
if($response_code == 200){
$contentRows = '';
$alternate = true;
for ($i = 0; $i < count($data); $i++) {
$item = $data[$i];
if($filterOut[$item->id]){
continue;
}
$alternateText = '';
if($alternate){
$alternateText = 'alternate';
$alternate = !$alternate;
}
$contentRows .= ' <tr class="'. $alternateText .'">
<th class="column-columnname">' . $item->id . ' </th>
<td class="column-columnname">' . $item->amount / 100 . $item->currency . ' </td>
<td class="column-columnname">' . $item->custom->name . ' </td>
<td class="column-columnname">' . $item->custom->email . ' </td>
<td class="column-columnname">' . $item->custom->phone . ' </td>
<td class="column-columnname">' . $item->custom->adress . ' - ' . $item->custom->postalCode . '</td>
<td class="column-columnname">' . $item->created . '</td>
<td class="column-column">
<form action="" method="post">
<input class="hidden" type="text" name="finishId" value="' . $item->id . '"/>
<textarea class="hidden" name="finishData">' . $response_body . '</textarea>
<input type="submit" value="Seen"/>
</td>
</tr>';
}
echo ('
<table class="widefat fixed" cellspacing="0">
<thead>
<tr>
<th class="manage-column" scope="col">ID</th>
<th class="manage-column" scope="col">Suma</th>
<th class="manage-column" scope="col">Nume</th>
<th class="manage-column" scope="col">Email</th>
<th class="manage-column" scope="col">Phone</th>
<th class="manage-column" scope="col">Adresa</th>
<th class="manage-column" scope="col">Date</th>
<th class="manage-column" scope="col">Done</th>
</tr>
</thead>
<tbody>'
. $contentRows .
'</tbody>
</table>
');
} else {
echo "<h1>No data to see</h1>";
}
}
if (isset($_POST['finishId'])) {
setDone($_POST['finishId'], $_POST['finishData']);
}
// you need to create this table. probably encrypt this (depending on data)
function setDone($orderId, $data) {
global $wpdb;
$table_name = $wpdb->prefix . 'orders';
$wpdb->insert($table_name, array('id' => $orderId, 'data' => $data));
}
?>