forked from mboyd1/bitcoin-sv-payments-for-woocommerce
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbwwc-render-settings.php
335 lines (302 loc) · 17.8 KB
/
bwwc-render-settings.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<?php
/*
Bitcoin Cash Payments for WooCommerce
https://github.com/sanchaz/bitcoin-cash-payments-for-woocommerce
*/
// Include everything
include(dirname(__FILE__) . '/bwwc-include-all.php');
//===========================================================================
function BWWC__render_general_settings_page()
{
BWWC__render_settings_page('general');
}
function BWWC__render_advanced_settings_page()
{
BWWC__render_settings_page('advanced');
}
//===========================================================================
//===========================================================================
function BWWC__render_settings_page($menu_page_name)
{
$bwwc_settings = BWWC__get_settings();
if (isset($_POST['button_update_bwwc_settings'])) {
BWWC__update_settings("", false);
echo <<<HHHH
<div align="center" style="background-color:#FFFFE0;padding:5px;font-size:120%;border: 1px solid #E6DB55;margin:5px;border-radius:3px;">
Settings updated!
</div>
HHHH;
} elseif (isset($_POST['button_reset_bwwc_settings'])) {
BWWC__reset_all_settings(false);
echo <<<HHHH
<div align="center" style="background-color:#FFFFE0;padding:5px;font-size:120%;border: 1px solid #E6DB55;margin:5px;border-radius:3px;">
All settings reverted to all defaults
</div>
HHHH;
} elseif (isset($_POST['button_reset_partial_bwwc_settings'])) {
BWWC__reset_partial_settings(false);
echo <<<HHHH
<div align="center" style="background-color:#FFFFE0;padding:5px;font-size:120%;border: 1px solid #E6DB55;margin:5px;border-radius:3px;">
Settings on this page reverted to defaults
</div>
HHHH;
} elseif (isset($_POST['validate_bwwc-license'])) {
BWWC__update_settings("", false);
}
// Output full admin settings HTML
$gateway_status_message = "";
$gateway_valid_for_use = BWWC__is_gateway_valid_for_use($gateway_status_message);
if (!$gateway_valid_for_use) {
$gateway_status_message =
'<p style="border:1px solid #DDD;padding:5px 10px;font-weight:bold;color:#EE0000;background-color:#FFFFAA;">' .
"Bitcoin Cash Payment Gateway is NOT operational (try to re-enter and save settings): " . $gateway_status_message .
'</p>';
} else {
$gateway_status_message =
'<p style="border:1px solid #DDD;padding:5px 10px;font-weight:bold;color:#004400;background-color:#CCFFCC;">' .
"Bitcoin Cash Payment Gateway is operational" .
'</p>';
}
$currency_code = false;
if (function_exists('get_woocommerce_currency')) {
$currency_code = @get_woocommerce_currency();
}
if (!$currency_code || $currency_code=='BTC') {
$currency_code = 'USD';
}
$exchange_rate_message =
'<p style="border:1px solid #DDD;padding:5px 10px;background-color:#cceeff;">' .
BWWC__get_exchange_rate_per_bitcoin($currency_code, 'getfirst', true) .
'</p>';
echo '<div class="wrap">';
switch ($menu_page_name) {
case 'general':
echo BWWC__GetPluginNameVersionEdition(true);
echo $gateway_status_message . $exchange_rate_message;
BWWC__render_general_settings_page_html();
break;
case 'advanced':
echo BWWC__GetPluginNameVersionEdition(false);
echo $gateway_status_message . $exchange_rate_message;
BWWC__render_advanced_settings_page_html();
break;
default:
break;
}
echo '</div>'; // wrap
}
//===========================================================================
//===========================================================================
function BWWC__render_general_settings_page_html()
{
$bwwc_settings = BWWC__get_settings();
global $g_BWWC__cron_script_url; ?>
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<p class="submit">
<input type="submit" class="button-primary" name="button_update_bwwc_settings" value="<?php _e('Save Changes') ?>" />
<input type="submit" class="button-secondary" style="color:red;" name="button_reset_partial_bwwc_settings" value="<?php _e('Reset settings') ?>" onClick="return confirm('Are you sure you want to reset settings on this page?');" />
</p>
<table class="form-table">
<tr valign="top">
<th scope="row">Delete all plugin-specific settings, database tables and data on uninstall:</th>
<td>
<input type="hidden" name="delete_db_tables_on_uninstall" value="0" /><input type="checkbox" name="delete_db_tables_on_uninstall" value="1" <?php if ($bwwc_settings['delete_db_tables_on_uninstall']) {
echo 'checked="checked"';
} ?> />
<p class="description">If checked - all plugin-specific settings, database tables and data will be removed from Wordpress database upon plugin uninstall (but not upon deactivation or upgrade).</p>
</td>
</tr>
<tr valign="top">
<th scope="row">Bitcoin Cash Service Provider:</th>
<td>
<select name="service_provider" class="select ">
<option <?php if ($bwwc_settings['service_provider'] == 'electrum_wallet') {
echo 'selected="selected"';
} ?> value="electrum_wallet">Your own Electron Cash wallet</option>
<option disabled <?php if ($bwwc_settings['service_provider'] == 'blockchain_info') {
echo 'selected="selected"';
} ?> value="blockchain_info">Blockchain.info API (DOES NOT WORK FOR BITCOIN CASH! use Electron Cash instead)</option>
</select>
<p class="description">
Please select your Bitcoin Cash service provider and press [Save changes]. Then fill-in necessary details and press [Save changes] again.
<br />Recommended setting: <b>Your own Electron Cash wallet</b>.
</p>
</td>
</tr>
<tr valign="top">
<th scope="row">Electron Cash Master Public Key (MPK):</th>
<td>
<textarea style="width:75%;" name="electrum_mpk_saved"><?php echo $bwwc_settings['electrum_mpk_saved']; ?></textarea>
<p class="description">
<ol class="description">
<li>
Launch Electron Cash wallet and get Master Public Key value from:
Wallet -> Master Public Key, or:
<br />older version of Electron Cash: Preferences -> Import/Export -> Master Public Key -> Show.
</li>
<li>
Copy long number string and paste it in this field.
</li>
<li>
Change "gap limit" value to bigger value (to make sure youll see the total balance on your wallet):
<br />Click on "Console" tab and run this command: <tt>wallet.storage.put('gap_limit',100)</tt>
</li>
<li>
Restart Electron Cash wallet to activate new gap limit. You may do it later at any time - gap limit does not affect functionlity of your online store.
<br />If your online store receives lots of orders in bitcoin cash - you might need to set gap limit to even bigger value.
</li>
</ol>
</p>
</td>
</tr>
<tr valign="top">
<th scope="row">Number of confirmations required before accepting payment:</th>
<td>
<input type="text" name="confs_num" value="<?php echo $bwwc_settings['confs_num']; ?>" size="4" />
<p class="description">
After a transaction is broadcast to the Bitcoin Cash network, it may be included in a block that is published
to the network. When that happens it is said that one <a href="https://en.bitcoin.it/wiki/Confirmation"><b>confirmation</b></a> has occurred for the transaction.
With each subsequent block that is found, the number of confirmations is increased by one. To protect against double spending, a transaction should not be considered as confirmed until a certain number of blocks confirm, or verify that transaction.
6 is considered very safe number of confirmations, although it takes longer to confirm.
</p>
</td>
</tr>
<tr valign="top">
<th scope="row">Bitcoin Cash Exchange rate calculation type:</th>
<td>
<select name="exchange_rate_type" class="select ">
<option <?php if ($bwwc_settings['exchange_rate_type'] == 'vwap') {
echo 'selected="selected"';
} ?> value="vwap">Weighted Average</option>
<option <?php if ($bwwc_settings['exchange_rate_type'] == 'realtime') {
echo 'selected="selected"';
} ?> value="realtime">Real Time</option>
<option <?php if ($bwwc_settings['exchange_rate_type'] == 'bestrate') {
echo 'selected="selected"';
} ?> value="bestrate">Most profitable</option>
</select>
<p class="description">
Weighted Average (recommended): <a href="http://en.wikipedia.org/wiki/Volume-weighted_average_price">weighted average</a> rates polled from a number of exchange services
<br />Real time: the most recent transaction rates polled from a number of exchange services.
<br />Most profitable: pick better exchange rate of all indicators (most favorable for merchant). Calculated as: MIN (Weighted Average, Real time)
</p>
</td>
</tr>
<tr valign="top">
<th scope="row">Exchange rate multiplier:</th>
<td>
<input type="text" name="exchange_multiplier" value="<?php echo $bwwc_settings['exchange_multiplier']; ?>" size="4" />
<p class="description">
Extra multiplier to apply to convert store default currency to bitcoin cash price.
<br />Example: 1.05 - will add extra 5% to the total price in bitcoin cash.
May be useful to compensate for market volatility or for merchant's loss to fees when converting bitcoin cash to local currency,
or to encourage customer to use bitcoin cash for purchases (by setting multiplier to < 1.00 values).
</p>
</td>
</tr>
<tr valign="top">
<th scope="row">Extreme privacy mode enabled?</th>
<td>
<select name="reuse_expired_addresses" class="select">
<option <?php if ($bwwc_settings['reuse_expired_addresses']) { echo 'selected="selected"'; } ?>value="1">No (default)</option>
<option <?php if (!$bwwc_settings['reuse_expired_addresses']) { echo 'selected="selected"'; } ?>value="0">Yes</option>
</select>
<p class="description">
<b>No</b> (default, recommended) - will allow to recycle bitcoin cash addresses that been generated for each placed order but never received any payments. The drawback of this approach is that potential snoop can generate many fake (never paid for) orders to discover sequence of bitcoin cash addresses that belongs to the wallet of this store and then track down sales through blockchain analysis. The advantage of this option is that it very efficiently reuses empty (zero-balance) bitcoin cash addresses within the wallet, allowing only 1 sale per address without growing the wallet size (Electron Cash "gap" value).
<br />
<b>Yes</b> - This will guarantee to generate unique bitcoin cash address for every order (real, accidental or fake). This option will provide the most anonymity and privacy to the store owner's wallet. The drawback is that it will likely leave a number of addresses within the wallet never used (and hence will require setting very high 'gap limit' within the Electron Cash wallet much sooner).
<br />It is recommended to regenerate new wallet after number of used bitcoin cash addresses reaches 1000. Wallets with very high gap limits (>1000) are very slow to sync with blockchain and they put an extra load on the network. <br />
Extreme privacy mode offers the best anonymity and privacy to the store albeit with the drawbacks of potentially flooding your Electron Cash wallet with expired and zero-balance addresses. Hence, for vast majority of cases (where you just need a secure way to operate bitcoin cash based store) it is suggested to set this option to 'No').<br />
</p>
</td>
</tr>
<tr valign="top">
<th scope="row">Auto-complete paid orders:</th>
<td>
<input type="hidden" name="autocomplete_paid_orders" value="0" /><input type="checkbox" name="autocomplete_paid_orders" value="1" <?php if ($bwwc_settings['autocomplete_paid_orders']) {
echo 'checked="checked"';
} ?> />
<p class="description">If checked - fully paid order will be marked as 'completed' and '<i>Your order is complete</i>' email will be immediately delivered to customer.
<br />If unchecked: store admin will need to mark order as completed manually - assuming extra time needed to ship physical product after payment is received.
<br />Note: virtual/downloadable products will automatically complete upon receiving full payment (so this setting does not have effect in this case).
</p>
</td>
</tr>
<tr valign="top">
<th scope="row">Cron job type:</th>
<td>
<select name="enable_soft_cron_job" class="select ">
<option <?php if ($bwwc_settings['enable_soft_cron_job'] == '1') {
echo 'selected="selected"';
} ?> value="1">Soft Cron (Wordpress-driven)</option>
<option <?php if ($bwwc_settings['enable_soft_cron_job'] != '1') {
echo 'selected="selected"';
} ?> value="0">Hard Cron (Cpanel-driven)</option>
</select>
<p class="description">
<?php if ($bwwc_settings['enable_soft_cron_job'] != '1') {
echo '<p style="background-color:#FFC;color:#2A2;"><b>NOTE</b>: Hard Cron job is enabled: make sure to follow instructions below to enable hard cron job at your hosting panel.</p>';
} ?>
Cron job will take care of all regular bitcoin cash payment processing tasks, like checking if payments are made and automatically completing the orders.<br />
<b>Soft Cron</b>: - Wordpress-driven (runs on behalf of a random site visitor).
<br />If DISABLE_WP_CRON is true then this behaves like Hard Cron. However there is no need to run the script manually.
<br />DISABLE_WP_CRON is: <?php echo (defined('DISABLE_WP_CRON') && constant('DISABLE_WP_CRON') ? 'true' : 'false'); ?>
<br />
<b>Hard Cron</b>: - Cron job driven by the website hosting system/server (usually via CPanel). <br />
When enabling Hard Cron job - make this script to run every 5 minutes at your hosting panel cron job scheduler:<br />
<?php echo '<tt style="background-color:#FFA;color:#B00;padding:0px 6px;">wget -O /dev/null ' . $g_BWWC__cron_script_url . '?hardcron=1</tt>'; ?>
<br /><b style="color:red;">NOTE:</b> Cron jobs <b>might not work</b> if your site is password protected with HTTP Basic auth or other methods. This will result in WooCommerce store not seeing received payments (even though funds will arrive correctly to your bitcoin cash addresses).
<br /><u>Note:</u> You will need to deactivate/reactivate plugin after changing this setting for it to have effect.<br />
"Hard" cron jobs may not be properly supported by all hosting plans (many shared hosting plans has restrictions in place).
</p>
</td>
</tr>
<tr valign="top">
<th scope="row">Checkout Icon:</th>
<td>
<fieldset>
<p>
<?php
$plugin_root = dirname(__FILE__);
$icon_dir = '/images/checkout-icons/';
$icons = scandir($plugin_root . $icon_dir);
foreach($icons as $icon) {
if (!is_file($plugin_root . $icon_dir . $icon)) {
continue;
}
$icon_rel_path = $icon_dir . $icon;
$icon_url = plugins_url($icon_rel_path, __FILE__);
$checked = "";
if ($bwwc_settings['selected_checkout_icon'] == $icon_rel_path) {
$checked = 'checked';
}
echo '<input type="radio" name="selected_checkout_icon" id="' . $icon. '" value="' . $icon_rel_path . '" ' . $checked . '/>';
echo '<label for="' . $icon. '"><img src="' . $icon_url . '" height="32"></img></label><br />';
}
?>
</p>
</fieldset>
<p class="description">
Icon displayed to users when choosing the payment method.<br />
You can upload new icons to: <?php echo str_replace(ABSPATH, "", $plugin_root . $icon_dir); ?><br />
Make sure to scale the image to a height of 32px.
</p>
</td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" name="button_update_bwwc_settings" value="<?php _e('Save Changes') ?>" />
<input type="submit" class="button-secondary" style="color:red;" name="button_reset_partial_bwwc_settings" value="<?php _e('Reset settings') ?>" onClick="return confirm('Are you sure you want to reset settings on this page?');" />
</p>
</form>
<?php
}
//===========================================================================
//===========================================================================
function BWWC__render_advanced_settings_page_html()
{
?>
<p style="text-align:center;"><h3>Bitcoin Cash is for everyone!!!</h3></p>
<?php
}
//===========================================================================