forked from cryptoapi/Payment-Gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cryptobox.class.php
1282 lines (1026 loc) · 81.6 KB
/
cryptobox.class.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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* ##########################################
* ### PLEASE DO NOT MODIFY THIS FILE ! ###
* ##########################################
*
*
* PHP Cryptocurrency Payment Class
*
* @package GoUrl PHP Bitcoin/Altcoin Payments and Crypto Captcha
* @copyright 2014-2016 Delta Consultants
* @category Libraries
* @website https://gourl.io
* @api https://gourl.io/api-php.html
* @example https://gourl.io/bitcoin-payment-gateway-api.html
* @gitHub https://github.com/cryptoapi/Payment-Gateway
* @license Free GPLv2
* @version 1.7.7
*
*
* CLASS CRYPTOBOX - LIST OF METHODS:
* --------------------------------------
* 1. function display_cryptobox(..) // Show Cryptocoin Payment Box and automatically displays successful payment message. If $submit_btn = true, display user submit button 'Click Here if you have already sent coins' or not
* 2. function is_paid(..) // If payment received - return true, otherwise return false
* 3. function is_confirmed() // Returns true if transaction/payment have 6+ confirmations. Average transaction/payment confirmation time - 10-20min for 6 confirmations (altcoins)
* 4. function amount_paid() // Returns the amount of coins received from the user
* 5. function amount_paid_usd() // Returns the approximate amount in USD received from the user using live cryptocurrency exchange rates on the datetime of payment
* 6. function set_status_processed() // Optional - if payment received, set payment status to 'processed' and save this status in database
* 7. function is_processed() // Optional - if payment status in database is 'processed' - return true, otherwise return false
* 8. function cryptobox_type() // Returns cryptobox type - paymentbox or captchabox
* 9. function payment_id() // Returns current record id in the table crypto_payments. Crypto_payments table stores all payments from your users
* 10.function payment_date() // Returns payment/transaction datetime in GMT format
* 11.function payment_info() // Returns object with current user payment details - amount, txID, datetime, usercointry, etc
* 12.function cryptobox_reset() // Optional, Delete cookies/sessions and new cryptobox with new payment amount will be displayed. Use this function only if you have not set userID manually.
* 13.function coin_name() // Returns coin name (bitcoin, dogecoin, etc)
* 14.function coin_label() // Returns coin label (DOGE, BTC, etc)
* 15.function iframe_id() // Returns payment box frame id
*
*
* LIST OF GENERAL FUNCTIONS:
* -------------------------------------
* A. function payment_history(..) // Returns array with history payment details of any of your users / orders / etc.
* B. function payment_unrecognised(..) // Returns array with unrecognised payments for custom period - $time (users paid wrong amount on your internal wallet address)
* C. function display_language_box(..) // Language selection dropdown list for cryptocoin payment box
* D. function display_currency_box(..) // Multiple crypto currency selection list. You can accept payments in multiple crypto currencies (for example: bitcoin, litecoin, dogecoin)
* E. function cryptobox_selcoin(..) // Current selected coin by user (bitcoin, dogecoin, etc. - for multiple coin payment boxes)
* F. function get_country_name(..) // Get country name by country code or reverse
* G. function convert_currency_live(..) // Fiat currency converter using Google Finance live exchange rates
* H. function validate_gourlkey(..) // Validate gourl private/public/affiliate keys
* I. function run_sql(..) // Run SQL queries and return result in array/object formats
*
*
* Note: Complete Description of the Functions, see on the page below or here - https://gourl.io/api-php.html
*
*
*/
if(!defined("CRYPTOBOX_WORDPRESS")) define("CRYPTOBOX_WORDPRESS", false);
if (!CRYPTOBOX_WORDPRESS) { // Pure PHP
require_once( "cryptobox.config.php" );
require_once( "cryptobox.newpayment.php" );
}
elseif (!defined('ABSPATH')) exit; // Wordpress
define("CRYPTOBOX_VERSION", "1.7.7");
// GoUrl supported crypto currencies
define("CRYPTOBOX_COINS", json_encode(array('bitcoin', 'litecoin', 'paycoin', 'dogecoin', 'dash', 'speedcoin', 'reddcoin', 'potcoin', 'feathercoin', 'vertcoin', 'vericoin', 'peercoin', 'monetaryunit')));
class Cryptobox {
// Custom Variables
private $public_key = ""; // value from your gourl.io member page - https://gourl.io/info/memberarea
private $private_key = ""; // value from your gourl.io member page. Also you setup cryptocoin name on gourl.io member page
private $webdev_key = ""; // optional, web developer affiliate key
private $amount = 0; // amount of cryptocoins which will be used in the payment box/captcha, precision is 4 (number of digits after the decimal), example: 0.0001, 2.444, 100, 2455, etc.
/* we will use this $amount value of cryptocoins in the payment box with a small fraction after the decimal point to uniquely identify each of your users individually
* (for example, if you enter 0.5 BTC, one of your user will see 0.500011 BTC, and another will see 0.500046 BTC, etc) */
private $amountUSD = 0; /* you can specify your price in USD and cryptobox will automatically convert that USD amount to cryptocoin amount using today live cryptocurrency exchange rates.
* Using that functionality (price in USD), you don't need to worry if cryptocurrency prices go down or up.
* User will pay you all times the actual price which is linked on current exchange price in USD on the datetime of purchase.
* You can use in cryptobox options one variable only: amount or amountUSD. You cannot place values of those two variables together. */
private $period = ""; // period after which the payment becomes obsolete and new cryptobox will be shown; allow values: NOEXPIRY, 1 MINUTE..90 MINUTE, 1 HOUR..90 HOURS, 1 DAY..90 DAYS, 1 WEEK..90 WEEKS, 1 MONTH..90 MONTHS
private $language = "en"; // cryptobox localisation; en - English, es - Spanish, fr - French, de - German, ru - Russian, nl - Dutch, pt - Portuguese, fa - Persian, ko - Korean, ar - Arabic, cn - Simplified Chinese, zh - Traditional Chinese, hi - Hindi
private $iframeID = ""; // optional, html iframe element id; allow symbols: a..Z0..9_-
private $orderID = ""; // your page name / product name or order name (not unique); allow symbols: a..Z0..9_-@.; max size: 50 symbols
private $userID = ""; // optional, manual setup unique identifier for each of your users; allow symbols: a..Z0..9_-@.; max size: 50 symbols
/* IMPORTANT - If you use Payment Box/Captcha for registered users on your website, you need to set userID manually with
* an unique value for each of your registered user. It is better than to use cookies by default. Examples: 'user1', 'user2', '3vIh9MjEis' */
private $userFormat = "COOKIE"; // this variable use only if $userID above is empty - it will save random userID in cookies, sessions or use user IP address as userID. Available values: COOKIE, SESSION, IPADDRESS
/* PLEASE NOTE -
* If you use multiple stores/sites online, please create separate GoUrl Payment Box (with unique payment box public/private keys) for each of your stores/websites.
* Do not use the same GoUrl Payment Box with the same public/private keys on your different websites/stores.
* if you use the same $public_key, $orderID and $userID in your multiple cryptocoin payment boxes on different website pages and a user has made payment; a successful result for that user will be returned on all those pages (if $period time valid).
* if you change - $public_key or $orderID or $userID - new cryptocoin payment box will be shown for exisiting paid user. (function $this->is_paid() starts to return 'false').
* */
// Internal Variables
private $boxID = 0; // cryptobox id, the same as on gourl.io member page. For each your cryptocoin payment boxes you will have unique public / private keys
private $coinLabel = ""; // current cryptocoin label (BTC, DOGE, etc.)
private $coinName = ""; // current cryptocoin name (Bitcoin, Dogecoin, etc.)
private $paid = false; // paid or not
private $confirmed = false; // transaction/payment have 6+ confirmations or not
private $paymentID = false; // current record id in the table crypto_payments (table stores all payments from your users)
private $paymentDate = ""; // transaction/payment datetime in GMT format
private $amountPaid = 0; // exact paid amount; for example, $amount = 0.5 BTC and user paid - $amountPaid = 0.50002 BTC
private $amountPaidUSD = 0; // approximate paid amount in USD; using cryptocurrency exchange rate on datetime of payment
private $boxType = ""; // cryptobox type - 'paymentbox' or 'captchabox'
private $processed = false; // optional - set flag to paid & processed
private $cookieName = ""; // user cookie/session name (if cookies/sessions use)
private $localisation = ""; // localisation; en - English, es - Spanish, fr - French, de - German, ru - Russian, nl - Dutch, pt - Portuguese, fa - Persian, ko - Korean, ar - Arabic, cn - Simplified Chinese, zh - Traditional Chinese, hi - Hindi
public function __construct($options = array())
{
// Min requirements
if (!function_exists( 'mb_stripos' ) || !function_exists( 'mb_strripos' )) die(sprintf("Error. Please enable <a target='_blank' href='%s'>MBSTRING extension</a> in PHP. <a target='_blank' href='%s'>Read here »</a>", "http://php.net/manual/en/book.mbstring.php", "http://www.knowledgebase-script.com/kb/article/how-to-enable-mbstring-in-php-46.html"));
if (!function_exists( 'curl_init' )) die(sprintf("Error. Please enable <a target='_blank' href='%s'>CURL extension</a> in PHP. <a target='_blank' href='%s'>Read here »</a>", "http://php.net/manual/en/book.curl.php", "http://stackoverflow.com/questions/1347146/how-to-enable-curl-in-php-xampp"));
if (!function_exists( 'mysqli_connect' )) die(sprintf("Error. Please enable <a target='_blank' href='%s'>MySQLi extension</a> in PHP. <a target='_blank' href='%s'>Read here »</a>", "http://php.net/manual/en/book.mysqli.php", "http://crybit.com/how-to-enable-mysqli-extension-on-web-server/"));
if (version_compare(phpversion(), '5.4.0', '<')) die(sprintf("Error. You need PHP 5.4.0 (or greater). Current php version: %s", phpversion()));
foreach($options as $key => $value)
if (in_array($key, array("public_key", "private_key", "webdev_key", "amount", "amountUSD", "period", "language", "iframeID", "orderID", "userID", "userFormat"))) $this->$key = (is_string($value)) ? trim($value) : $value;
$this->boxID = $this->left($this->public_key, "AA");
if (preg_replace('/[^A-Za-z0-9]/', '', $this->public_key) != $this->public_key || strlen($this->public_key) != 50 || !strpos($this->public_key, "AA") || !$this->boxID || !is_numeric($this->boxID) || strpos($this->public_key, "77") === false || !strpos($this->public_key, "PUB")) die("Invalid Cryptocoin Payment Box PUBLIC KEY - " . ($this->public_key?$this->public_key:"cannot be empty"));
if (preg_replace('/[^A-Za-z0-9]/', '', $this->private_key) != $this->private_key || strlen($this->private_key) != 50 || !strpos($this->private_key, "AA") || $this->boxID != $this->left($this->private_key, "AA") || !strpos($this->private_key, "PRV") || $this->left($this->private_key, "PRV") != $this->left($this->public_key, "PUB")) die("Invalid Cryptocoin Payment Box PRIVATE KEY".($this->private_key?"":" - cannot be empty"));
if (!defined("CRYPTOBOX_PRIVATE_KEYS") || !in_array($this->private_key, explode("^", CRYPTOBOX_PRIVATE_KEYS))) die("Error. Please add your Cryptobox Private Key ".(CRYPTOBOX_WORDPRESS ? "on your plugin settings page" : "to \$cryptobox_private_keys in file cryptobox.config.php"));
if ($this->webdev_key && (preg_replace('/[^A-Za-z0-9]/', '', $this->webdev_key) != $this->webdev_key || strpos($this->webdev_key, "DEV") !== 0 || $this->webdev_key != strtoupper($this->webdev_key) || $this->icrc32($this->left($this->webdev_key, "G", false)) != $this->right($this->webdev_key, "G", false))) $this->webdev_key = "";
$c = substr($this->right($this->left($this->public_key, "PUB"), "AA"), 5);
$this->coinLabel = $this->right($c, "77");
$this->coinName = $this->left($c, "77");
if ($this->amount && strpos($this->amount, ".")) $this->amount = rtrim(rtrim($this->amount, "0"), ".");
if ($this->amountUSD && strpos($this->amountUSD, ".")) $this->amountUSD = rtrim(rtrim($this->amountUSD, "0"), ".");
if (!$this->amount || $this->amount <= 0) $this->amount = 0;
if (!$this->amountUSD || $this->amountUSD <= 0) $this->amountUSD = 0;
if (($this->amount <= 0 && $this->amountUSD <= 0) || ($this->amount > 0 && $this->amountUSD > 0)) die("You can use in cryptobox options one of variable only: amount or amountUSD. You cannot place values in that two variables together");
if ($this->amount && (!is_numeric($this->amount) || $this->amount < 0.0001 || $this->amount > 50000000)) die("Invalid Amount - $this->amount $this->coinLabel. Allowed range: 0.0001 .. 50,000,000");
if ($this->amountUSD && (!is_numeric($this->amountUSD) || $this->amountUSD < 0.01 || $this->amountUSD > 1000000)) die("Invalid amountUSD - $this->amountUSD USD. Allowed range: 0.01 .. 1,000,000");
$this->period = trim(strtoupper(str_replace(" ", "", $this->period)));
if (substr($this->period, -1) == "S") $this->period = substr($this->period, 0, -1);
for ($i=1; $i<=90; $i++) { $arr[] = $i."MINUTE"; $arr[] = $i."HOUR"; $arr[] = $i."DAY"; $arr[] = $i."WEEK"; $arr[] = $i."MONTH"; }
if ($this->period != "NOEXPIRY" && !in_array($this->period, $arr)) die("Invalid Cryptobox Period - $this->period");
$this->period = str_replace(array("MINUTE", "HOUR", "DAY", "WEEK", "MONTH"), array(" MINUTE", " HOUR", " DAY", " WEEK", " MONTH"), $this->period);
$id = "gourlcryptolang";
$this->language = strtolower($this->language);
$this->localisation = json_decode(CRYPTOBOX_LOCALISATION, true);
if (isset($_GET[$id]) && in_array($_GET[$id], array_keys($this->localisation))) $this->language = $_GET[$id];
elseif (isset($_COOKIE[$id]) && in_array($_COOKIE[$id], array_keys($this->localisation))) $this->language = $_COOKIE[$id];
elseif (!in_array($this->language, array_keys($this->localisation))) $this->language = "en";
$this->localisation = $this->localisation[$this->language];
unset($id);
if ($this->iframeID && preg_replace('/[^A-Za-z0-9\_\-]/', '', $this->iframeID) != $this->iframeID || $this->iframeID == "cryptobox_live_") die("Invalid iframe ID - $this->iframeID. Allowed symbols: a..Z0..9_-");
$this->userID = trim($this->userID);
if ($this->userID && preg_replace('/[^A-Za-z0-9\.\_\-\@]/', '', $this->userID) != $this->userID) die("Invalid User ID - $this->userID. Allowed symbols: a..Z0..9_-@.");
if (strlen($this->userID) > 50) die("Invalid User ID - $this->userID. Max: 50 symbols");
$this->orderID = trim($this->orderID);
if ($this->orderID && preg_replace('/[^A-Za-z0-9\.\_\-\@]/', '', $this->orderID) != $this->orderID) die("Invalid Order ID - $this->orderID. Allowed symbols: a..Z0..9_-@.");
if (!$this->orderID || strlen($this->orderID) > 50) die("Invalid Order ID - $this->orderID. Max: 50 symbols");
if ($this->userID)
$this->userFormat = "MANUAL";
else
{
switch ($this->userFormat)
{
case "COOKIE":
$this->cookieName = 'cryptoUsr'.$this->icrc32($this->boxID."*&*".$this->coinLabel."*&*".$this->orderID."*&*".$this->private_key);
if (isset($_COOKIE[$this->cookieName]) && trim($_COOKIE[$this->cookieName]) && strpos($_COOKIE[$this->cookieName], "__")) $this->userID = trim($_COOKIE[$this->cookieName]);
else
{
$s = trim(strtolower($_SERVER['SERVER_NAME']), " /");
if (stripos($s, "www.") === 0) $s = substr($s, 4);
$d = time(); if ($d > 1410000000) $d -= 1410000000;
$v = trim($d."__".substr(md5(uniqid(mt_rand().mt_rand().mt_rand())), 0, 10));
setcookie($this->cookieName, $v, time()+(10*365*24*60*60), '/', $s);
$this->userID = $v;
}
break;
case "SESSION":
if (session_status() == PHP_SESSION_NONE) session_start();
$this->cookieName = 'cryptoUser'.$this->icrc32($this->private_key."*&*".$this->boxID."*&*".$this->coinLabel."*&*".$this->orderID);
if (isset($_SESSION[$this->cookieName]) && trim($_SESSION[$this->cookieName]) && strpos($_SESSION[$this->cookieName], "--")) $this->userID = trim($_SESSION[$this->cookieName]);
else
{
$d = time(); if ($d > 1410000000) $d -= 1410000000;
$v = trim($d."--".substr(md5(uniqid(mt_rand().mt_rand().mt_rand())), 0, 10));
$this->userID = $_SESSION[$this->cookieName] = $v;
}
break;
case "IPADDRESS":
if (session_status() == PHP_SESSION_NONE) session_start();
if (isset($_SESSION['cryptoUserIP']) && filter_var($_SESSION['cryptoUserIP'], FILTER_VALIDATE_IP))
$ip = $_SESSION['cryptoUserIP'];
else $ip = $_SESSION['cryptoUserIP'] = $this->ip_address();
$this->userID = trim(md5($ip."*&*".$this->boxID."*&*".$this->coinLabel."*&*".$this->orderID));
break;
default:
die("Invalid userFormat value - $this->userFormat");
break;
}
}
if (!$this->iframeID) $this->iframeID = $this->iframe_id();
$this->check_payment();
return true;
}
/* 1. Function display_cryptobox() -
*
* Display Cryptocoin Payment Box; the cryptobox will automatically displays successful message if payment has been received
*
* Usually user will see on bottom of payment box button 'Click Here if you have already sent coins' (when $submit_btn = true)
* and when they click on that button, script will connect to our remote cryptocoin payment box server
* and check user payment.
*
* As backup, our server will also inform your server automatically through IPN every time a payment is received
* (file cryptobox.callback.php). I.e. if the user does not click on the button or you have not displayed the button,
* your website will receive a notification about a given user anyway and save it to your database.
* Next time your user goes to your website/reloads page they will automatically see the message
* that their payment has been received successfully.
*/
public function display_cryptobox($submit_btn = true, $width = "530", $height = "230", $box_style = "", $message_style = "", $anchor = "")
{
if (!$box_style) $box_style = "border-radius:15px;box-shadow:0 0 12px #aaa;-moz-box-shadow:0 0 12px #aaa;-webkit-box-shadow:0 0 12px #aaa;padding:3px 6px;margin:10px";
if (!$message_style) $message_style = "display:inline-block;max-width:580px;padding:15px 20px;box-shadow:0 0 10px #aaa;-moz-box-shadow: 0 0 10px #aaa;margin:7px;font-size:13px;font-weight:normal;line-height:21px;font-family: Verdana, Arial, Helvetica, sans-serif;";
$width = intval($width);
$height = intval($height);
$cryptobox_html = "";
$val = md5($this->iframeID.$this->private_key.$this->userID);
if ($submit_btn && isset($_POST["cryptobox_live_"]) && $_POST["cryptobox_live_"] == $val)
{
$id = "id".md5(mt_rand());
if (!$this->paid) $cryptobox_html .= "<a id='c".$this->iframeID."' name='c".$this->iframeID."'></a>";
$cryptobox_html .= "<br><div id='$id' align='center'>";
$cryptobox_html .= '<div'.(in_array($this->language, array("ar", "fa"))?' dir="rtl"':'').' style="'.htmlspecialchars($message_style, ENT_COMPAT).'">';
if ($this->paid) $cryptobox_html .= "<span style='color:#339e2e;white-space:nowrap;'>".str_replace(array("%coinName%", "%coinLabel%", "%amountPaid%"), array($this->coinName, $this->coinLabel, $this->amountPaid), $this->localisation[($this->boxType=="paymentbox"?"msg_received":"msg_received2")])."</span>";
else $cryptobox_html .= "<span style='color:#eb4847'>".str_replace(array("%coinName%", "%coinNames%", "%coinLabel%"), array($this->coinName, ($this->coinLabel=='DASH'?$this->coinName:$this->coinName.'s'), $this->coinLabel), $this->localisation["msg_not_received"])."</span><script type='text/javascript'>cryptobox_msghide('$id')</script>";
$cryptobox_html .= "</div></div><br>";
}
$hash_str = $this->boxID.$this->coinName.$this->public_key.$this->private_key.$this->webdev_key.$this->amount.$this->period.$this->amountUSD.$this->language.$this->amount.$this->iframeID.$this->amountUSD.$this->userID.$this->userFormat.$this->orderID.$width.$height;
$hash = md5($hash_str);
$cryptobox_html .= "<div align='center' style='min-width:".$width."px'><iframe id='$this->iframeID' ".($box_style?'style="'.htmlspecialchars($box_style, ENT_COMPAT).'"':'')." scrolling='no' marginheight='0' marginwidth='0' frameborder='0' width='$width' height='$height'></iframe></div>";
$cryptobox_html .= "<div><script type='text/javascript'>";
$cryptobox_html .= "cryptobox_show($this->boxID, '$this->coinName', '$this->public_key', $this->amount, $this->amountUSD, '$this->period', '$this->language', '$this->iframeID', '$this->userID', '$this->userFormat', '$this->orderID', '$this->cookieName', '$this->webdev_key', '$hash', $width, $height);";
$cryptobox_html .= "</script></div>";
if ($submit_btn && !$this->paid)
{
$cryptobox_html .= "<form action='".$_SERVER["REQUEST_URI"]."#".($anchor?$anchor:"c".$this->iframeID)."' method='post'>";
$cryptobox_html .= "<input type='hidden' id='cryptobox_live_' name='cryptobox_live_' value='$val'>";
$cryptobox_html .= "<div align='center'>";
$cryptobox_html .= "<button".(in_array($this->language, array("ar", "fa"))?' dir="rtl"':'')." style='color:#555;border-color:#ccc;background:#f7f7f7;-webkit-box-shadow:inset 0 1px 0 #fff,0 1px 0 rgba(0,0,0,.08);box-shadow:inset 0 1px 0 #fff,0 1px 0 rgba(0,0,0,.08);vertical-align:top;display:inline-block;text-decoration:none;font-size:13px;line-height:26px;min-height:28px;margin:20px 0 25px 0;padding:0 10px 1px;cursor:pointer;border-width:1px;border-style:solid;-webkit-appearance:none;-webkit-border-radius:3px;border-radius:3px;white-space:nowrap;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;font-family:\"Open Sans\",sans-serif;font-size: 13px;font-weight: normal;text-transform: none;'>  ".str_replace(array("%coinName%", "%coinNames%", "%coinLabel%"), array($this->coinName, ($this->coinLabel=='DASH'?$this->coinName:$this->coinName.'s'), $this->coinLabel), $this->localisation["button"]).($this->language!="ar"?" »":"")."  </button>";
$cryptobox_html .= "</div>";
$cryptobox_html .= "</form>";
}
$cryptobox_html .= "<br>";
return $cryptobox_html;
}
/* 2. Function is_paid($remotedb = false) -
*
* This Checks your local database whether payment has been received and is stored on your local database.
*
* If use $remotedb = true, it will check also on the remote cryptocoin payment server (gourl.io),
* and if payment is received, it saves it in your local database. Usually user will see on bottom
* of payment box button 'Click Here if you have already sent coins' and when they click on that button,
* script it will connect to our remote cryptocoin payment box server. Therefore you don't need to use
* $remotedb = true, it will make your webpage load slowly if payment on gourl.io is checked during
* each of your page loadings.
*
* Please note that our server will also inform your server automatically every time when payment is
* received through callback url: cryptobox.callback.php. I.e. if the user does not click on button,
* your website anyway will receive notification about a given user and save it in your database.
* And when your user next time comes on your website/reload page he will automatically will see
* message that his payment has been received successfully.
*/
public function is_paid($remotedb = false)
{
if (!$this->paymentID && $remotedb) $this->check_payment($remotedb);
if ($this->paid) return true;
else return false;
}
/* 3. Function is_confirmed() -
*
* Function return is true if transaction/payment has 6+ confirmations.
* It connects with our payment server and gets the current transaction status (confirmed/unconfirmed).
* Some merchants wait until this transaction has been confirmed.
* Average transaction confirmation time - 10-20min for 6+ confirmations (altcoins)
*/
public function is_confirmed()
{
if ($this->confirmed) return true;
else return false;
}
/* 4. Function amount_paid()
*
* Returns the amount of coins received from the user
*/
public function amount_paid()
{
if ($this->paid) return $this->amountPaid;
else return 0;
}
/* 5. Function amount_paid_usd()
*
* Returns the approximate amount in USD received from the user
* using live cryptocurrency exchange rates on the datetime of payment.
* Live Exchange Rates obtained from sites poloniex.com and bitstamp.net
* and are updated every 30 minutes!
*
* Or you can directly specify your price in USD and submit it in cryptobox using
* variable 'amountUSD'. Cryptobox will automatically convert that USD amount
* to cryptocoin amount using today current live cryptocurrency exchange rates.
*
* Using that functionality, you don't need to worry if cryptocurrency prices go down or up.
* User will pay you all times the actual price which is linked on current exchange
* price in USD on the datetime of purchase.
*
* You can accepting cryptocoins on your website with cryptobox variable 'amountUSD'.
* It increase your online sales and also use Poloniex.com AutoSell feature
* (to trade your cryptocoins to USD/BTC during next 30 minutes after payment received).
*/
public function amount_paid_usd()
{
if ($this->paid) return $this->amountPaidUSD;
else return 0;
}
/* 6. Functions set_status_processed() and is_processed()
*
* You can use this function when user payment has been received
* (function is_paid() returns true) and want to make one time action,
* for example display 'thank you' message to user, etc.
* These functions helps you to exclude duplicate processing.
*
* Please note that the user will continue to see a successful payment result in
* their crypto Payment box during the period/timeframe you specify in cryptobox option $period
*/
public function set_status_processed()
{
if ($this->paymentID && $this->paid)
{
if (!$this->processed)
{
$sql = "UPDATE crypto_payments SET processed = 1, processedDate = '".gmdate("Y-m-d H:i:s")."' WHERE paymentID = $this->paymentID LIMIT 1";
run_sql($sql);
$this->processed = true;
}
return true;
}
else return false;
}
/* 7. Function is_processed()
*
* If payment status in database is 'processed' - return true,
* otherwise return false. You need to use it with
* function set_status_processed() together
*/
public function is_processed()
{
if ($this->paid && $this->processed) return true;
else return false;
}
/* 8. Function cryptobox_type()
*
* Returns 'paymentbox' or 'captchabox'
*
* The Cryptocoin Payment Box and Crypto Captcha are
* absolutely identical technically except for their visual effect.
*
* It uses the same code to get your user payment, to process that
* payment and to forward received coins to you. They have only two
* visual differences - users will see different logos and different
* text on successful result page.
* For example, for dogecoin it will be - 'Dogecoin Payment' or
* 'Dogecoin Captcha' logos and when payment is received we will publish
* 'Payment received successfully' or 'Captcha Passed successfully'.
*
* We have made it easier for you to adapt our payment system to your website.
* On signup page you can use 'Bitcoin Captcha' and on sell products page - 'Bitcoin Payment'.
*/
public function cryptobox_type()
{
return $this->boxType;
}
/* 9. Function payment_id()
*
* Returns current record id in the table crypto_payments.
* Crypto_payments table stores all payments from your users
*/
public function payment_id()
{
return $this->paymentID;
}
/* 10. Function payment_date()
*
* Returns payment/transaction datetime in GMT format
* Example - 2014-09-26 17:31:58 (is 26 September 2014, 5:31pm GMT)
*/
public function payment_date()
{
return $this->paymentDate;
}
/* 11. Function payment_info()
*
* Returns object with current user payment details -
* coinLabel - cryptocurrency label
* countryID - user location country, 3 letter ISO country code
* countryName - user location country
* amount - paid cryptocurrency amount
* amountUSD - approximate paid amount in USD with exchange rate on datetime of payment made
* addr - your internal wallet address on gourl.io which received this payment
* txID - transaction id
* txDate - transaction date (GMT time)
* txConfirmed - 0 - unconfirmed transaction/payment or 1 - confirmed transaction/payment
* processed - true/false. True if you called function set_status_processed() for that payment before
* processedDate - GMT time when you called function set_status_processed()
* recordCreated - GMT time a payment record was created in your database
* etc.
*/
public function payment_info()
{
$obj = ($this->paymentID) ? run_sql("SELECT * FROM crypto_payments WHERE paymentID = $this->paymentID LIMIT 1") : false;
if ($obj) $obj->countryName = get_country_name($obj->countryID);
return $obj;
}
/* 12. Function cryptobox_reset()
*
* Optional, It will delete cookies/sessions with userID and new cryptobox with new payment amount
* will be displayed after page reload. Cryptobox will recognize user as a new one with new generated userID.
* For example, after you have successfully received the cryptocoin payment and had processed it, you can call
* one-time cryptobox_reset() in end of your script. Use this function only if you have not set userID manually.
*/
public function cryptobox_reset()
{
if (in_array($this->userFormat, array("COOKIE", "SESSION")))
{
$iframeID = $this->iframe_id();
switch ($this->userFormat)
{
case "COOKIE":
$s = trim(strtolower($_SERVER['SERVER_NAME']), " /");
if (stripos($s, "www.") === 0) $s = substr($s, 4);
$d = time(); if ($d > 1410000000) $d -= 1410000000;
$v = trim($d."__".substr(md5(uniqid(mt_rand().mt_rand().mt_rand())), 0, 10));
setcookie($this->cookieName, $v, time()+(10*365*24*60*60), '/', $s);
$this->userID = $v;
break;
case "SESSION":
$d = time(); if ($d > 1410000000) $d -= 1410000000;
$v = trim($d."--".substr(md5(uniqid(mt_rand().mt_rand().mt_rand())), 0, 10));
$this->userID = $_SESSION[$this->cookieName] = $v;
break;
}
if ($this->iframeID == $iframeID) $this->iframeID = $this->iframe_id();
return true;
}
else return false;
}
/* 13. Function coin_name()
*
* Returns coin name (bitcoin, dogecoin, litecoin, etc)
*/
public function coin_name()
{
return $this->coinName;
}
/* 14. Function coin_label()
*
* Returns coin label (DOGE, BTC, LTC, etc)
*/
public function coin_label()
{
return $this->coinLabel;
}
/* 15. Function iframe_id()
*
* Returns payment box frame id
*/
public function iframe_id()
{
return "box".$this->icrc32($this->boxID."__".$this->orderID."__".$this->userID."__".$this->private_key);
}
/*
* Other Internal functions
*/
private function check_payment($remotedb = false)
{
$this->paymentID = $diff = 0;
$obj = run_sql("SELECT paymentID, amount, amountUSD, txConfirmed, txCheckDate, txDate, processed, boxType FROM crypto_payments WHERE boxID = $this->boxID && orderID = '$this->orderID' && userID = '$this->userID' ".($this->period=="NOEXPIRY"?"":"&& txDate >= DATE_SUB('".gmdate("Y-m-d H:i:s")."', INTERVAL ".$this->period.")")." ORDER BY txDate DESC LIMIT 1");
if ($obj)
{
$this->paymentID = $obj->paymentID;
$this->paymentDate = $obj->txDate;
$this->amountPaid = $obj->amount;
$this->amountPaidUSD = $obj->amountUSD;
$this->paid = true;
$this->confirmed = $obj->txConfirmed;
$this->boxType = $obj->boxType;
$this->processed = ($obj->processed) ? true : false;
$diff = strtotime(gmdate('Y-m-d H:i:s')) - strtotime($obj->txCheckDate);
}
if (!$obj && isset($_POST["cryptobox_live_"]) && $_POST["cryptobox_live_"] == md5($this->iframeID.$this->private_key.$this->userID)) $remotedb = true;
if ((!$obj && $remotedb) || ($obj && !$this->confirmed && ($diff > (($this->coinLabel=='BTC'?35:12)*60) || $diff < 0))) // if $diff < 0 - user have incorrect time on local computer
{
$this->check_payment_live();
}
return true;
}
private function check_payment_live()
{
$ip = $this->ip_address();
$hash = md5($this->boxID.$this->private_key.$this->userID.$this->orderID.$this->language.$this->period.$ip);
$box_status = "";
$data = array(
"r" => $this->private_key,
"b" => $this->boxID,
"o" => $this->orderID,
"u" => $this->userID,
"l" => $this->language,
"e" => $this->period,
"i" => $ip,
"h" => $hash
);
$ch = curl_init( "https://coins.gourl.io/result.php" );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt( $ch, CURLOPT_TIMEOUT, 20);
$res = curl_exec( $ch );
if ($res) $res = json_decode($res, true);
if ($res) foreach ($res as $k => $v) if (is_string($v)) $res[$k] = trim($v);
if (isset($res["status"]) && in_array($res["status"], array("payment_received")) &&
$res["box"] && is_numeric($res["box"]) && $res["box"] > 0 && $res["amount"] && is_numeric($res["amount"]) && $res["amount"] > 0 &&
$res["private_key"] && preg_replace('/[^A-Za-z0-9]/', '', $res["private_key"]) == $res["private_key"] && $res["private_key"] == $this->private_key)
{
foreach ($res as $k => $v)
{
if ($k == "datetime") $mask = '/[^0-9\ \-\:]/';
elseif (in_array($k, array("err", "date"))) $mask = '/[^A-Za-z0-9\.\_\-\@\ ]/';
else $mask = '/[^A-Za-z0-9\.\_\-\@]/';
if ($v && preg_replace($mask, '', $v) != $v) $res[$k] = "";
}
if (!$res["amountusd"] || !is_numeric($res["amountusd"])) $res["amountusd"] = 0;
if (!$res["confirmed"] || !is_numeric($res["confirmed"])) $res["confirmed"] = 0;
$dt = gmdate('Y-m-d H:i:s');
$obj = run_sql("select paymentID, processed, txConfirmed from crypto_payments where boxID = ".$res["box"]." && orderID = '".$res["order"]."' && userID = '".$res["user"]."' && txID = '".$res["tx"]."' limit 1");
if ($obj)
{
$this->paymentID = $obj->paymentID;
$this->processed = ($obj->processed) ? true : false;
$this->confirmed = $obj->txConfirmed;
// refresh
$sql = "UPDATE crypto_payments
SET boxType = '".$res["boxtype"]."',
amount = ".$res["amount"].",
amountUSD = ".$res["amountusd"].",
coinLabel = '".$res["coinlabel"]."',
unrecognised = 0,
addr = '".$res["addr"]."',
txDate = '".$res["datetime"]."',
txConfirmed = ".$res["confirmed"].",
txCheckDate = '".$dt."'
WHERE paymentID = $this->paymentID
LIMIT 1";
run_sql($sql);
if ($res["confirmed"] && !$this->confirmed) $box_status = "cryptobox_updated";
}
else
{
// Save new payment details in local database
$sql = "INSERT INTO crypto_payments (boxID, boxType, orderID, userID, countryID, coinLabel, amount, amountUSD, unrecognised, addr, txID, txDate, txConfirmed, txCheckDate, recordCreated)
VALUES (".$res["box"].", '".$res["boxtype"]."', '".$res["order"]."', '".$res["user"]."', '".$res["usercountry"]."', '".$res["coinlabel"]."', ".$res["amount"].", ".$res["amountusd"].", 0, '".$res["addr"]."', '".$res["tx"]."', '".$res["datetime"]."', ".$res["confirmed"].", '$dt', '$dt')";
$this->paymentID = run_sql($sql);
$box_status = "cryptobox_newrecord";
}
$this->paymentDate = $res["datetime"];
$this->amountPaid = $res["amount"];
$this->amountPaidUSD = $res["amountusd"];
$this->paid = true;
$this->boxType = $res["boxtype"];
$this->confirmed = $res["confirmed"];
/**
* User-defined function for new payment - cryptobox_new_payment(...)
* For example, send confirmation email, update database, update user membership, etc.
* You need to modify file - cryptobox.newpayment.php
* Read more - https://gourl.io/api-php.html#ipn
*/
if (in_array($box_status, array("cryptobox_newrecord", "cryptobox_updated")) && function_exists('cryptobox_new_payment')) cryptobox_new_payment($this->paymentID, $res, $box_status);
return true;
}
return false;
}
public function left($str, $findme, $firstpos = true)
{
$pos = ($firstpos)? stripos($str, $findme) : strripos($str, $findme);
if ($pos === false) return $str;
else return substr($str, 0, $pos);
}
public function right($str, $findme, $firstpos = true)
{
$pos = ($firstpos)? stripos($str, $findme) : strripos($str, $findme);
if ($pos === false) return $str;
else return substr($str, $pos + strlen($findme));
}
public function icrc32($str)
{
$in = crc32($str);
$int_max = pow(2, 31)-1;
if ($in > $int_max) $out = $in - $int_max * 2 - 2;
else $out = $in;
$out = abs($out);
return $out;
}
public function ip_address()
{
static $ip_address;
if ($ip_address) return $ip_address;
$ip_address = "";
$proxy_ips = (defined("PROXY_IPS")) ? unserialize(PROXY_IPS) : array(); // your server internal proxy ip
$internal_ips = array('127.0.0.0', '127.0.0.1', '127.0.0.2', '192.0.0.0', '192.0.0.1', '192.168.0.0', '192.168.0.1', '192.168.0.253', '192.168.0.254', '192.168.0.255', '192.168.1.0', '192.168.1.1', '192.168.1.253', '192.168.1.254', '192.168.1.255', '192.168.2.0', '192.168.2.1', '192.168.2.253', '192.168.2.254', '192.168.2.255', '10.0.0.0', '10.0.0.1', '11.0.0.0', '11.0.0.1', '1.0.0.0', '1.0.1.0', '1.1.1.1', '255.0.0.0', '255.0.0.1', '255.255.255.0', '255.255.255.254', '255.255.255.255', '0.0.0.0', '::', '0::', '0:0:0:0:0:0:0:0');
for ($i = 1; $i <= 2; $i++)
if (!$ip_address)
{
foreach (array('HTTP_CLIENT_IP', 'HTTP_X_CLIENT_IP', 'HTTP_X_CLUSTER_CLIENT_IP', 'X-Forwarded-For', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'HTTP_X_REAL_IP', 'REMOTE_ADDR') as $header)
if (!$ip_address && isset($_SERVER[$header]) && $_SERVER[$header])
{
$ip = trim($_SERVER[$header]);
$ip2 = "";
if (strpos($ip, ',') !== FALSE)
{
list($ip, $ip2) = explode(',', $ip, 2);
$ip = trim($ip);
$ip2 = trim($ip2);
}
if ($ip && filter_var($ip, FILTER_VALIDATE_IP) && !in_array($ip, $proxy_ips) && ($i==2 || !in_array($ip, $internal_ips))) $ip_address = $ip;
elseif ($ip2 && filter_var($ip2, FILTER_VALIDATE_IP) && !in_array($ip2, $proxy_ips) && ($i==2 || !in_array($ip2, $internal_ips))) $ip_address = $ip2;
}
}
if (!$ip_address || !filter_var($ip_address, FILTER_VALIDATE_IP)) $ip_address = '0.0.0.0';
return $ip_address;
}
}
// end class
/* A. Function payment_history()
*
* Returns array with history payment details of any of your users / orders / etc. (except unrecognised payments) for custom period - $period
* It includes -
* paymentID - current record id in the table crypto_payments.
* boxID - your cryptobox id, the same as on gourl.io member page
* boxType - 'paymentbox' or 'captchabox'
* orderID - your order id / page name / etc.
* userID - your user identifier
* countryID - your user's location (country) , 3 letter ISO country code
* coinLabel - cryptocurrency label
* amount - paid cryptocurrency amount
* amountUSD - approximate paid amount in USD with exchange rate on datetime of payment made
* addr - your internal wallet address on gourl.io which received this payment
* txID - transaction id
* txDate - transaction date (GMT time)
* txConfirmed - 0 - unconfirmed transaction/payment or 1 - confirmed transaction/payment with 6+ confirmations
* you can use function is_confirmed() above, it will connect with payment server and get transaction status (confirmed/unconfirmed)
* processed - true/false. True if you called function set_status_processed() before
* processedDate - GMT time when you called function set_status_processed()
* recordCreated - GMT time a payment record was created in your database
*/
function payment_history($boxID = "", $orderID = "", $userID = "", $countryID = "", $boxType = "", $period = "7 DAY")
{
if ($boxID && (!is_numeric($boxID) || $boxID < 1 || round($boxID) != $boxID)) return false;
if ($orderID && preg_replace('/[^A-Za-z0-9\.\_\-\@]/', '', $orderID) != $orderID) return false;
if ($userID && preg_replace('/[^A-Za-z0-9\.\_\-\@]/', '', $userID) != $userID) return false;
if ($countryID && (preg_replace('/[^A-Za-z]/', '', $countryID) != $countryID || strlen($countryID) != 3)) return false;
if ($boxType && !in_array($boxType, array('paymentbox','captchabox'))) return false;
if ($period && preg_replace('/[^A-Za-z0-9\ ]/', '', $period) != $period) return false;
$res = run_sql("SELECT paymentID, boxID, boxType, orderID, userID, countryID, coinLabel, amount, amountUSD, addr, txID, txDate, txConfirmed, processed, processedDate, recordCreated
FROM crypto_payments WHERE unrecognised = 0 ".($boxID?" && boxID = $boxID":"").($orderID?" && orderID = '$orderID'":"").($userID?" && userID='$userID'":"").($countryID?" && countryID='".strtoupper($countryID)."'":"").($period?" && recordCreated > DATE_SUB('".gmdate("Y-m-d H:i:s")."', INTERVAL $period)":"")." ORDER BY txDate DESC LIMIT 10000");
if ($res && !is_array($res)) $res = array($res);
return $res;
}
/* B. Function payment_unrecognised()
*
* Returns array with unrecognised payments for custom period - $period.
* (users paid wrong amount to your internal wallet address).
* You will need to process unrecognised payments manually.
*
* We forward you ALL coins received to your internal wallet address
* including all possible incorrect amount/unrecognised payments
* automatically every 30 minutes.
*
* Therefore if your user contacts us, regarding the incorrect sent payment,
* we will forward your user to you (because our system forwards all received payments
* to your wallet automatically every 30 minutes). We provide a payment gateway only.
* You need to deal with your user directly to resolve the situation or return the incorrect
* payment back to your user. In unrecognised payments statistics table you will see the
* original payment sum and transaction ID - when you click on that transaction's ID
* it will open external blockchain explorer website with wallet address/es showing
* that payment coming in. You can tell your user about your return of that incorrect
* payment to one of their sending address (which will protect you from bad claims).
*
* You will have a copy of the statistics on your gourl.io member page
* with details of incorrect received payments.
*
* It includes -
* paymentID - current record id in the table crypto_payments.
* boxID - your cryptobox id, the same as on gourl.io member page
* boxType - 'paymentbox' or 'captchabox'
* coinLabel - cryptocurrency label
* amount - paid cryptocurrency amount
* amountUSD - approximate paid amount in USD with exchange rate on datetime of payment made
* addr - your internal wallet address on gourl.io which received this payment
* txID - transaction id
* txDate - transaction date (GMT time)
* recordCreated - GMT time a payment record was created in your database
*/
function payment_unrecognised($boxID = "", $period = "7 DAY")
{
if ($boxID && (!is_numeric($boxID) || $boxID < 1 || round($boxID) != $boxID)) return false;
if ($period && preg_replace('/[^A-Za-z0-9\ ]/', '', $period) != $period) return false;
$res = run_sql("SELECT paymentID, boxID, boxType, coinLabel, amount, amountUSD, addr, txID, txDate, recordCreated
FROM crypto_payments WHERE unrecognised = 1 ".($boxID?" && boxID = $boxID":"").($period?" && recordCreated > DATE_SUB('".gmdate("Y-m-d H:i:s")."', INTERVAL $period)":"")." ORDER BY txDate DESC LIMIT 10000");
if ($res && !is_array($res)) $res = array($res);
return $res;
}
/* D. Function display_language_box()
*
* Language selection dropdown list for cryptocoin payment box
*/
function display_language_box($default = "en", $anchor = "gourlcryptolang")
{
$default = strtolower($default);
$localisation = json_decode(CRYPTOBOX_LOCALISATION, true);
$id = "gourlcryptolang";
$arr = $_GET;
if (isset($_GET[$id]) && in_array($_GET[$id], array_keys($localisation))) { $lan = $_GET[$id]; unset($arr[$id]); setcookie($id, $lan, time()+7*24*3600, "/"); }
elseif (isset($_COOKIE[$id]) && in_array($_COOKIE[$id], array_keys($localisation))) $lan = $_COOKIE[$id];
elseif (in_array($default, array_keys($localisation))) $lan = $default;
else $lan = "en";
$url = $_SERVER["REQUEST_URI"];
if (mb_strpos($url, "?")) $url = mb_substr($url, 0, mb_strpos($url, "?"));
$tmp = "<select name='$id' id='$id' onchange='window.open(\"//".$_SERVER["HTTP_HOST"].$url."?".http_build_query($arr).($arr?"&":"").$id."=\"+this.options[this.selectedIndex].value+\"#".$anchor."\",\"_self\")' style='width:130px;font-family:Arial,Helvetica,sans-serif;font-size:12px;color:#666;border-radius:5px;-moz-border-radius:5px;border: #ccc 1px solid;margin:0;padding:3px 0 3px 6px;white-space:nowrap;overflow:hidden;'>";
foreach ($localisation as $k => $v) $tmp .= "<option ".($k==$lan?"selected":"")." value='$k'>".$v["name"]."</option>";
$tmp .= "</select>";
return $tmp;
}
/* D. Function display_currency_box()
*
* Multiple crypto currency selection list. You can accept payments in multiple crypto currencies
* For example you can accept payments in bitcoin, litecoin, dogecoin and use the same price in USD
*/
function display_currency_box($coins = array(), $defCoin = "", $defLang = "en", $iconWidth = 50, $style = "width:350px; margin: 10px 0 10px 320px", $directory = "images", $anchor = "gourlcryptocoins")
{
if (!$coins) return "";
$defCoin = strtolower($defCoin);
$defLang = strtolower($defLang);
$available_payments = json_decode(CRYPTOBOX_COINS, true);
$arr = $_GET;
if (!in_array($defCoin, $available_payments)) die("Invalid your default value '$defCoin' in display_currency_box()");
if (!in_array($defCoin, $coins)) $coins[] = $defCoin;
// Current Coin
$coinName = cryptobox_selcoin($coins, $defCoin);
// Url for Change Coin
$coin_url = $_SERVER["REQUEST_URI"];
if (mb_strpos($coin_url, "?")) $coin_url = mb_substr($coin_url, 0, mb_strpos($coin_url, "?"));
if (isset($arr["gourlcryptocoin"])) unset($arr["gourlcryptocoin"]);
$coin_url = "//".$_SERVER["HTTP_HOST"].$coin_url."?".http_build_query($arr).($arr?"&":"")."gourlcryptocoin=";
// Current Language
$localisation = json_decode(CRYPTOBOX_LOCALISATION, true);
$id = "gourlcryptolang";
$keys = array_keys($localisation);
if (isset($_GET[$id]) && in_array($_GET[$id], $keys)) $lan = $_GET[$id];
elseif (isset($_COOKIE[$id]) && in_array($_COOKIE[$id], $keys)) $lan = $_COOKIE[$id];
elseif (in_array($defLang, $keys)) $lan = $defLang;
else $lan = "en";
$localisation = $localisation[$lan];
$id = "gourlcryptocoins";
$tmp = '<div id="'.$id.'" align="center" style="'.htmlspecialchars($style, ENT_COMPAT).'"><div style="margin-bottom:15px"><b>'.$localisation["payment"].' -</b></div>';
foreach ($coins as $v)
{
$v = trim(strtolower($v));
if (!in_array($v, $available_payments)) die("Invalid your submitted value '$v' in display_currency_box()");
if (strpos(CRYPTOBOX_PRIVATE_KEYS, ucfirst($v)."77") === false) die("Please add your Private Key for '$v' in variable \$cryptobox_private_keys, file cryptobox.config.php");
$tmp .= "<a href='".$coin_url.$v."#".$anchor."'><img style='box-shadow:none;margin:".round($iconWidth/10)."px ".round($iconWidth/7)."px;border:0;' width='$iconWidth' title='".str_replace("%coinName%", ucfirst($v), $localisation["pay_in"])."' alt='".str_replace("%coinName%", $v, $localisation["pay_in"])."' src='".$directory."/".$v.($iconWidth>70?"2":"").".png'></a>";
}
$tmp .= "</div>";
return $tmp;
}
/* E. Function cryptobox_selcoin()
*
* Current selected coin by user
*/
function cryptobox_selcoin($coins = array(), $defCoin = "")
{
if (!$coins) return "";
$defCoin = strtolower($defCoin);
$available_payments = json_decode(CRYPTOBOX_COINS, true); // GoUrl supported crypto currencies
$id = "gourlcryptocoin";
if (!in_array($defCoin, $coins)) $coins[] = $defCoin;
// Current Selected Coin
if (isset($_GET[$id]) && in_array($_GET[$id], $available_payments) && in_array($_GET[$id], $coins)) { $coinName = $_GET[$id]; setcookie($id, $coinName, time()+7*24*3600, "/"); }
elseif (isset($_COOKIE[$id]) && in_array($_COOKIE[$id], $available_payments) && in_array($_COOKIE[$id], $coins)) $coinName = $_COOKIE[$id];
else $coinName = $defCoin;