forked from cryptoapi/Bitcoin-Gateway-Paid-Memberships-Pro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gourl_paidmembershipspro.php
889 lines (669 loc) · 34.3 KB
/
gourl_paidmembershipspro.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
<?php
/*
Plugin Name: GoUrl Paid Memberships Pro - Bitcoin Payment Gateway Addon
Plugin URI: https://gourl.io/bitcoin-payments-paid-memberships-pro.html
Description: Provides a <a href="https://gourl.io">GoUrl.io</a> Bitcoin/Altcoin Payment Gateway for <a href="https://wordpress.org/plugins/paid-memberships-pro/">Paid Memberships Pro 1.8+</a>. Direct Integration on your website, no external payment pages opens (as other payment gateways offer). Accept Bitcoin, Litecoin, Paycoin, Dogecoin, Dash, Speedcoin, Reddcoin, Potcoin, Feathercoin, Vertcoin, Vericoin, Peercoin, MonetaryUnit payments online. You will see the bitcoin/altcoin payment statistics in one common table on your website. No Chargebacks, Global, Secure. All in automatic mode.
Version: 1.1.3
Author: GoUrl.io
Author URI: https://gourl.io
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html
GitHub Plugin URI: https://github.com/cryptoapi/Bitcoin-Gateway-Paid-Memberships-Pro
*/
if (!defined( 'ABSPATH' )) exit; // Exit if accessed directly
if (!function_exists('gourl_pmp_gateway_load'))
{
// localisation
add_action( 'plugins_loaded', 'gourl_pmp_load_textdomain' );
// gateway load
add_action( 'plugins_loaded', 'gourl_pmp_gateway_load', 20);
DEFINE('GOURLPMP', "gourl-paidmembershipspro");
function gourl_pmp_load_textdomain()
{
load_plugin_textdomain( GOURLPMP, false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
function gourl_pmp_gateway_load()
{
// paid memberships pro required
if (!class_exists('PMProGateway')) return;
// load classes init method
add_action('init', array('PMProGateway_gourl', 'init'));
// add cryptocurrencies
add_filter('pmpro_currencies', array('PMProGateway_gourl', 'pmpro_currencies'), 10, 1);
// order log
add_action('pmpro_after_order_settings', array('PMProGateway_gourl', 'pmpro_after_order_settings'));
// custom confirmation page
add_filter('pmpro_pages_shortcode_confirmation', array('PMProGateway_gourl', 'pmpro_pages_shortcode_confirmation'), 20, 1);
// custom invoice
add_filter('pmpro_invoice_bullets_bottom', array('PMProGateway_gourl', 'pmpro_invoice_bullets_bottom'), 20, 1);
// plugin links
add_filter('plugin_action_links', array('PMProGateway_gourl', 'plugin_action_links'), 10, 2 );
/*
* 1.
*/
class PMProGateway_gourl extends PMProGateway
{
/**
* 1.1
*/
public function PMProGateway_gourl($gateway = NULL)
{
$this->gateway = $gateway;
return $this->gateway;
}
/**
* 1.2 Run on WP init
*/
public static function init()
{
//make sure Pay by Bitcoin/Altcoin is a gateway option
add_filter('pmpro_gateways', array('PMProGateway_gourl', 'pmpro_gateways'));
//add fields to payment settings
add_filter('pmpro_payment_options', array('PMProGateway_gourl', 'pmpro_payment_options'));
add_filter('pmpro_payment_option_fields', array('PMProGateway_gourl', 'pmpro_payment_option_fields'), 10, 2);
//code to add at checkout
$gateway = pmpro_getGateway();
if($gateway == "gourl")
{
add_filter('pmpro_include_billing_address_fields', '__return_false');
add_filter('pmpro_include_payment_information_fields', '__return_false');
add_filter('pmpro_required_billing_fields', array('PMProGateway_gourl', 'pmpro_required_billing_fields'));
add_filter('pmpro_checkout_before_change_membership_level', array('PMProGateway_gourl', 'pmpro_checkout_before_change_membership_level'), 10, 2);
}
}
/**
* 1.3
*/
public static function plugin_action_links($links, $file)
{
static $this_plugin;
if (false === isset($this_plugin) || true === empty($this_plugin)) {
$this_plugin = plugin_basename(__FILE__);
}
if ($file == $this_plugin) {
$settings_link = '<a href="'.admin_url('admin.php?page=pmpro-paymentsettings').'">'.__( 'Settings', GOURLPMP ).'</a>';
array_unshift($links, $settings_link);
}
return $links;
}
/**
* 1.4 Make sure Gourl is in the gateways list
*/
public static function pmpro_gateways($gateways)
{
if(empty($gateways['gourl']))
$gateways = array_slice($gateways, 0, 1) + array("gourl" => __('GoUrl Bitcoin/Altcoins', GOURLPMP)) + array_slice($gateways, 1);
return $gateways;
}
/**
* 1.5 Get a list of payment options that the gourl gateway needs/supports.
*/
public static function getGatewayOptions()
{
$options = array(
'gourl_defcoin',
'gourl_deflang',
'gourl_emultiplier',
'gourl_iconwidth',
'currency'
);
return $options;
}
/**
* 1.6 Set payment options for payment settings page.
*/
public static function pmpro_payment_options($options)
{
//get stripe options
$gourl_options = self::getGatewayOptions();
//merge with others.
$options = array_merge($gourl_options, $options);
return $options;
}
/**
* 1.7 Add cryptocurrencies
*/
public static function pmpro_currencies($currencies)
{
global $gourl;
if (class_exists('gourlclass') && defined('GOURL') && defined('GOURL_ADMIN') && is_object($gourl))
{
$arr = $gourl->coin_names();
foreach ($arr as $k => $v)
$currencies[$k] = __( "Cryptocurrency", GOURLPMP ) . " - " . __( ucfirst($v), GOURLPMP );
}
__( 'Bitcoin', GOURLPMP ); // use in translation
return $currencies;
}
/**
* 1.8 Display fields for Gourl options.
*/
public static function pmpro_payment_option_fields($options, $gateway)
{
global $gourl;
$payments = array();
$coin_names = array();
$languages = array();
$mainplugin_url = admin_url("plugin-install.php?tab=search&type=term&s=GoUrl+Bitcoin+Payment+Gateway+Downloads");
$description = "<a target='_blank' href='https://gourl.io/'><img border='0' style='float:left; margin-right:15px' src='https://gourl.io/images/gourlpayments.png'></a>";
$description .= "<a target='_blank' href='https://gourl.io/bitcoin-payments-paid-memberships-pro.html'>".__( 'Plugin Homepage', GOURLPMP )."</a>  &  <a target='_blank' href='https://gourl.io/bitcoin-payments-paid-memberships-pro.html#screenshot'>".__( 'screenshots', GOURLPMP )." »</a><br>";
$description .= "<a target='_blank' href='https://github.com/cryptoapi/Bitcoin-Gateway-Paid-Memberships-Pro'>".__( 'Plugin on Github - 100% Free Open Source', GOURLPMP )." »</a><br><br>";
if (class_exists('gourlclass') && defined('GOURL') && defined('GOURL_ADMIN') && is_object($gourl))
{
if (true === version_compare(GOURL_VERSION, '1.3.3', '<'))
{
$description .= '<div style="background:#fff;border:1px solid #f77676;padding:7px"><p><b>' .sprintf(__( "Your GoUrl Bitcoin Gateway <a href='%s'>Main Plugin</a> version is too old. Requires 1.3.3 or higher version. Please <a href='%s'>update</a> to latest version.", GOURLPMP ), GOURL_ADMIN.GOURL, $mainplugin_url)."</b>         " .
__( 'Information', GOURLPMP ) . ":   <a href='https://gourl.io/bitcoin-wordpress-plugin.html'>".__( 'Main Plugin Homepage', GOURLPMP )."</a>       " .
"<a href='https://wordpress.org/plugins/gourl-bitcoin-payment-gateway-paid-downloads-membership/'>".__( 'WordPress.org Plugin Page', GOURLPMP )."</a></p></div><br>";
}
elseif (true === version_compare(PMPRO_VERSION, '1.8.4', '<'))
{
$description .= '<div style="background:#fff;border:1px solid #f77676;padding:7px"><p><b>' .sprintf(__( "Your PaidMembershipsPro version is too old. The GoUrl payment plugin requires PaidMembershipsPro 1.8.4 or higher to function. Please update to <a href='%s'>latest version</a>.", GOURLPMP ), admin_url('plugin-install.php?tab=search&type=term&s=paidmembershipspro+affiliates')).'</b></p></div><br>';
}
else
{
$payments = $gourl->payments(); // Activated Payments
$coin_names = $gourl->coin_names(); // All Coins
$languages = $gourl->languages(); // All Languages
}
$coins = implode(", ", $payments);
$url = GOURL_ADMIN.GOURL."settings";
$url2 = GOURL_ADMIN.GOURL."payments&s=pmpro";
$url3 = GOURL_ADMIN.GOURL;
$text = ($coins) ? $coins : __( '- Please setup -', GOURLPMP );
}
else
{
$coins = "";
$url = $mainplugin_url;
$url2 = $url;
$url3 = $url;
$text = '<b>'.__( 'Please install GoUrl Bitcoin Gateway WP Plugin', GOURLPMP ).' »</b>';
$description .= '<div style="background:#fff;border:1px solid #f77676;padding:7px;color:#444"><p><b>' .
sprintf(__( "You need to install GoUrl Bitcoin Gateway Main Plugin also. Go to - <a href='%s'>Automatic installation</a> or <a href='%s'>Manual</a>.", GOURLPMP ), $mainplugin_url, "https://gourl.io/bitcoin-wordpress-plugin.html") . "</b>         " .
__( 'Information', GOURLPMP ) . ":    <a href='https://gourl.io/bitcoin-wordpress-plugin.html'>".__( 'Main Plugin Homepage', GOURLPMP )."</a>       <a href='https://wordpress.org/plugins/gourl-bitcoin-payment-gateway-paid-downloads-membership/'>" .
__( 'WordPress.org Plugin Page', GOURLPMP ) . "</a></p></div><br>";
}
$description .= "<b>" . __( "Secure payments with virtual currency. <a target='_blank' href='https://bitcoin.org/'>What is Bitcoin?</a>", GOURLPMP ) . '</b><br>';
$description .= sprintf(__( 'Accept %s payments online in PaidMembershipsPro.', GOURLPMP ), __( ucwords(implode(", ", $coin_names)), GOURLPMP )).'<br>';
if (class_exists('gourlclass')) $description .= sprintf(__( "If you use multiple websites online, please create separate <a target='_blank' href='%s'>GoUrl Payment Box</a> (with unique payment box public/private keys) for each of your websites. Do not use the same GoUrl Payment Box with the same public/private keys on your different websites.", GOURLPMP ), "https://gourl.io/editrecord/coin_boxes/0") . '<br><br>';
$tr = '<tr class="gateway gateway_gourl"'.($gateway!="gourl"?' style="display: none;"':'').'>';
// a
$tmp = '<tr class="pmpro_settings_divider gateway gateway_gourl"'.($gateway!="gourl"?' style="display: none;"':'').'>';
$tmp .= '<td colspan="2">'.__('Gourl Bitcoin/Altcoin Settings', GOURLPMP).'</td>';
$tmp .= "</tr>";
// b
$tmp .= $tr;
$tmp .= '<td colspan="2"><div style="font-size:13px;line-height:22px">' . $description . '</div></td>';
$tmp .= "</tr>";
// c
$defcoin = $options["gourl_defcoin"];
if (!in_array($defcoin, array_keys($payments))) $defcoin = current(array_keys($payments));
$tmp .= $tr.'<th scope="row" valign="top"><label for="gourl_defcoin">'.__( 'PaymentBox Default Coin', GOURLPMP ).'</label></th>
<td><select name="gourl_defcoin" id="gourl_defcoin">';
foreach ($payments as $k => $v) $tmp .= "<option value='".$k."'".self::sel($k, $defcoin).">".$v."</option>";
$tmp .= "</select>";
$tmp .= '<p class="description">'.sprintf(__( "Default Coin in Crypto Payment Box. Activated Payments : <a href='%s'>%s</a>", GOURLPMP), $url, $text)."</p></td>";
$tmp .= "</tr>";
// d
$deflang = $options["gourl_deflang"];
if (!in_array($deflang, array_keys($languages))) $deflang = current(array_keys($languages));
$tmp .= $tr.'<th scope="row" valign="top"><label for="gourl_deflang">'.__( 'PaymentBox Language', GOURLPMP ).'</label></th>
<td><select name="gourl_deflang" id="gourl_deflang">';
foreach ($languages as $k => $v) $tmp .= "<option value='".$k."'".self::sel($k, $deflang).">".$v."</option>";
$tmp .= "</select>";
$tmp .= '<p class="description">'.__("Default Crypto Payment Box Localisation", GOURLPMP)."</p></td>";
$tmp .= "</tr>";
// e
$emultiplier = str_replace("%", "", $options["gourl_emultiplier"]);
if (!$emultiplier || !is_numeric($emultiplier) || $emultiplier <= 0) $emultiplier = "1.00";
$tmp .= $tr.'<th scope="row" valign="top"><label for="gourl_emultiplier">'.__( 'Exchange Rate Multiplier', GOURLPMP ).'</label></th>
<td><input type="text" value="'.$emultiplier.'" name="gourl_emultiplier" id="gourl_emultiplier">';
$tmp .= '<p class="description">'.__('The system uses the multiplier rate with today LIVE cryptocurrency exchange rates (which are updated every 30 minutes) when the transaction is calculating from a fiat currency (e.g. USD, EUR, etc) to cryptocurrency. <br> Example: <b>1.05</b> - will add an extra 5% to the total price in bitcoin/altcoins, <b>0.85</b> - will be a 15% discount for the price in bitcoin/altcoins. Default: 1.00', GOURLPMP )."</p></td>";
$tmp .= "</tr>";
// f
$iconwidth = str_replace("px", "", $options["gourl_iconwidth"]);
if (!$iconwidth || !is_numeric($iconwidth) || $iconwidth < 30 || $iconwidth > 250) $iconwidth = 60;
$iconwidth = $iconwidth . "px";
$tmp .= $tr.'<th scope="row" valign="top"><label for="gourl_iconwidth">'.__( 'Icons Size', GOURLPMP ).'</label></th>
<td><input type="text" value="'.$iconwidth.'" name="gourl_iconwidth" id="gourl_iconwidth">';
$tmp .= '<p class="description">'.__( "Cryptocoin icons size in 'Select Payment Method' that the customer will see on your checkout. Default 60px. Allowed: 30..250px", GOURLPMP )."</p></td>";
$tmp .= "</tr>";
// g
$tmp .= $tr.'<th scope="row" valign="top"><label for="gourl_boxstyle">'.__( 'PaymentBox Style', GOURLPMP ).'</label></th>
<td>'.sprintf(__( "Payment Box <a href='%s'>sizes</a> and border <a href='%s'>shadow</a> you can change <a href='%s'>here »</a>", GOURLPMP ), "https://gourl.io/images/global/sizes.png", "https://gourl.io/images/global/styles.png", $url."#gourlmonetaryunitprivate_key")."</td>";
$tmp .= "</tr>";
// h
$tmp .= $tr.'<th scope="row" valign="top"><label for="gourl_lang">'.__( 'Languages', GOURLPMP ).'</label></th>
<td>'.sprintf(__( "If you want to use GoUrl PaidMembershipsPro Bitcoin Gateway plugin in a language other than English, see the page <a href='%s'>Languages and Translations</a>", GOURLPMP ), "https://gourl.io/languages.html")."</td>";
$tmp .= "</tr>";
echo $tmp;
return;
}
/**
* 1.9 Remove required billing fields
*/
public static function pmpro_required_billing_fields($fields)
{
unset($fields['bfirstname']);
unset($fields['blastname']);
unset($fields['baddress1']);
unset($fields['bcity']);
unset($fields['bstate']);
unset($fields['bzipcode']);
unset($fields['bphone']);
unset($fields['bemail']);
unset($fields['bcountry']);
unset($fields['CardType']);
unset($fields['AccountNumber']);
unset($fields['ExpirationMonth']);
unset($fields['ExpirationYear']);
unset($fields['CVV']);
return $fields;
}
/**
* 1.10 Process checkout.
*
*/
function process(&$order)
{
return true;
}
/**
* 1.11 Redirect to bitcoin/altcoin payment page
*/
public static function pmpro_checkout_before_change_membership_level($user_id, $order)
{
global $pmpro_currency;
if (!$order || $order->gateway != "gourl") return true;
$order->payment_type = __('GoUrl Bitcoin/Altcoin', GOURLPMP);
// is it initial payment ?
if(!get_option(GOURL."PMPRO_INIT_".$user_id."_".$order->membership_level->id))
{
// Free
if (floatval($order->subtotal) == 0)
{
// Initial Free Payment
update_option(GOURL."PMPRO_INIT_".$user_id."_".$order->membership_level->id, date("m F Y"));
$order->ProfileStartDate = date("Y-m-d") . "T0:0:0";
$order->status = "success";
if (floatval($order->PaymentAmount) > 0)
{
// Free Trial Payment
$order->TrialBillingCycles ++;
$order->payment_transaction_id = "#FREETRIAL";
update_option(GOURL."PMPRO_FREE_".$user_id."_".$order->membership_level->id, date("m F Y"));
}
else
{
$order->TotalBillingCycles++;
$order->payment_transaction_id = "#FREE";
}
if (is_numeric($order->membership_level->expiration_number) && $order->membership_level->expiration_number > 0 && $order->membership_level->expiration_period) $order->subscription_transaction_id = $order->membership_level->expiration_number." ".$order->membership_level->expiration_period;
return true;
}
else
{
$order->total = $order->subtotal;
}
}
// second, third, etc payments ....
else
{
if (floatval($order->subtotal) == 0 && floatval($order->PaymentAmount) == 0)
{
$order->status = "success";
$order->TotalBillingCycles++;
$order->payment_transaction_id = "#FREE";
if (is_numeric($order->membership_level->expiration_number) && $order->membership_level->expiration_number > 0 && $order->membership_level->expiration_period) $order->subscription_transaction_id = $order->membership_level->expiration_number." ".$order->membership_level->expiration_period;
return true;
}
elseif (floatval($order->subtotal) != floatval($order->PaymentAmount))
{
if (floatval($order->PaymentAmount) > 0)
{
$order->subtotal = $order->PaymentAmount;
$order->total = $order->PaymentAmount;
}
else $order->total = $order->subtotal;
}
else $order->total = $order->subtotal;
}
// check for previous pending orders
$morder = new MemberOrder();
$morder->getLastMemberOrder(get_current_user_id(), apply_filters("pmpro_confirmation_order_status", array("pending")));
if ($morder->gateway != "gourl" || $morder->total != $order->total || $morder->membership_id != $order->membership_id || strtotime($order->ProfileStartDate) < (strtotime("now") - 24*60*60) ||
(isset($order->membership_level->expiration_number) && is_numeric($order->membership_level->expiration_number) && $order->membership_level->expiration_number > 0 && $order->membership_level->expiration_period && ($order->membership_level->expiration_number." ".$order->membership_level->expiration_period) != $morder->subscription_transaction_id))
{
$order->payment_type = __('GoUrl Bitcoin/Altcoin', GOURLPMP);
$order->gateway = "gourl";
$order->user_id = get_current_user_id();
$order->status = "pending";
if (is_numeric($order->membership_level->expiration_number) && $order->membership_level->expiration_number > 0 && $order->membership_level->expiration_period) $order->subscription_transaction_id = $order->membership_level->expiration_number." ".$order->membership_level->expiration_period;
$order->saveOrder();
$user = (!get_current_user_id()) ? __('Guest', GOURLPMP) : "<a href='".admin_url("user-edit.php?user_id=".get_current_user_id())."'>user".get_current_user_id()."</a>";
self::add_order_note($order->id, sprintf(__("Order Created by %s <br>Membership - %s <br>Awaiting Cryptocurrency Payment - %s <br>Invoice <a href='%s'>#%s</a>", GOURLPMP ), $user, $order->membership_level->name.", ".$order->membership_level->expiration_number." ".$order->membership_level->expiration_period, $order->total . " " . $pmpro_currency, pmpro_url("invoice", "?invoice=" . $order->code), $order->code));
}
wp_redirect(pmpro_url("confirmation"));
die();
return true;
}
/**
* 1.12 Custom confirmation page
*
*/
public static function pmpro_pages_shortcode_confirmation($content)
{
global $wpdb, $current_user, $pmpro_invoice, $pmpro_currency;
if (empty($pmpro_invoice))
{
$morder = new MemberOrder();
$morder->getLastMemberOrder(get_current_user_id(), apply_filters("pmpro_confirmation_order_status", array("pending", "success")));
if (!empty($morder) && $morder->gateway == "gourl") $pmpro_invoice = $morder;
}
if (!empty($pmpro_invoice) && $pmpro_invoice->gateway == "gourl" && isset($pmpro_invoice->total) && $pmpro_invoice->total > 0)
{
$levelName = $wpdb->get_var("SELECT name FROM $wpdb->pmpro_membership_levels WHERE id = '" . $pmpro_invoice->membership_id . "' LIMIT 1");
$content = "<ul>
<li><strong>".__('Account', GOURLPMP).":</strong> ".$current_user->display_name." (".$current_user->user_email.")</li>
<li><strong>".__('Order', GOURLPMP).":</strong> ".$pmpro_invoice->code."</li>
<li><strong>".__('Membership Level', GOURLPMP).":</strong> ".$levelName."</li>
<li><strong>".__('Amount', GOURLPMP).":</strong> ".$pmpro_invoice->total." ".$pmpro_currency."</li>
</ul>";
$content .= self::pmpro_gourl_cryptocoin_payment($pmpro_invoice);
}
return $content;
}
/**
* 1.13. GoUrl Payment Box
*/
public static function pmpro_gourl_cryptocoin_payment ($order, $invoice = false)
{
global $gourl, $pmpro_currency, $current_user, $wpdb;
$tmp = "";
if (!$order)
{
$tmp .= '<h2>' . __( 'Information', GOURLPMP ) . '</h2>' . PHP_EOL;
$tmp .= "<div class='pmpro_message pmpro_error'>".sprintf(__( 'The GoUrl payment plugin was called to process a payment but could not retrieve the order details for orderID %s. Cannot continue!', GOURLPMP ), $order_id)."</div>";
return $tmp;
}
if ($order->gateway != "gourl") return false;
// Initialize
// ------------------------
if (class_exists('gourlclass') && defined('GOURL') && is_object($gourl))
{
$payments = $gourl->payments(); // Activated Payments
$coin_names = $gourl->coin_names(); // All Coins
$languages = $gourl->languages(); // All Languages
}
else
{
$payments = array();
$coin_names = array();
$languages = array();
}
$defcoin = pmpro_getOption("gourl_defcoin");
if (!in_array($defcoin, array_keys($payments))) $defcoin = current(array_keys($payments));
$deflang = pmpro_getOption("gourl_deflang");
if (!in_array($deflang, array_keys($languages))) $deflang = current(array_keys($languages));
$emultiplier = str_replace("%", "", pmpro_getOption("gourl_emultiplier"));
if (!$emultiplier || !is_numeric($emultiplier) || $emultiplier <= 0) $emultiplier = "1.00";
$iconwidth = str_replace("px", "", pmpro_getOption("gourl_iconwidth"));
if (!$iconwidth || !is_numeric($iconwidth) || $iconwidth < 30 || $iconwidth > 250) $iconwidth = 60;
$iconwidth = $iconwidth . "px";
// Current Order
// -----------------
$order_id = $order->id;
$order_total = $order->total;
$order_currency = $pmpro_currency;
$order_user_id = $order->user_id;
// Security
// -------------
if (!$order_id)
{
$tmp .= '<h2>' . __( 'Information', GOURLPMP ) . '</h2>' . PHP_EOL;
$tmp .= "<div class='pmpro_message pmpro_error'>".sprintf(__( 'The GoUrl payment plugin was called to process a payment but could not retrieve the order details for orderID %s. Cannot continue!', GOURLPMP ), $order_id)."</div>";
}
elseif ($order_user_id && $order_user_id != get_current_user_id() && !current_user_can('manage_options'))
{
return false;
}
elseif (!class_exists('gourlclass') || !defined('GOURL') || !is_object($gourl))
{
$tmp .= '<h2>' . __( 'Information', GOURLPMP ) . '</h2>' . PHP_EOL;
$tmp .= "<div class='pmpro_message pmpro_error'>".sprintf(__( "Please try a different payment method. Admin need to install and activate wordpress plugin <a href='%s'>GoUrl Bitcoin Gateway for Wordpress</a> to accept Bitcoin/Altcoin Payments online.", GOURLPMP ), "https://gourl.io/bitcoin-wordpress-plugin.html")."</div>";
}
elseif (!$payments || !$defcoin || true === version_compare(PMPRO_VERSION, '1.8.4', '<') || true === version_compare(GOURL_VERSION, '1.3.3', '<') ||
(array_key_exists($order_currency, $coin_names) && !array_key_exists($order_currency, $payments)))
{
$tmp .= '<h2>' . __( 'Information', GOURLPMP ) . '</h2>' . PHP_EOL;
$tmp .= "<div class='pmpro_message pmpro_error'>".sprintf(__( 'Sorry, but there was an error processing your order. Please try a different payment method or contact us if you need assistance (GoUrl Bitcoin Plugin not configured / %s not activated)', GOURLPMP ),(!$payments || !$defcoin || !isset($coin_names[$order_currency])?__("Cryptocurrency", GOURLPMP):$coin_names[$order_currency]))."</div>";
}
else
{
$plugin = "gourlpmpro";
$amount = $order_total;
$currency = $order_currency;
$orderID = "order" . $order_id;
$userID = $order_user_id;
$period = "NOEXPIRY";
$language = $deflang;
$coin = $coin_names[$defcoin];
$affiliate_key = "gourl";
$crypto = array_key_exists($currency, $coin_names);
if (!$userID) $userID = "guest"; // allow guests to make payments
if (!$userID)
{
$tmp .= '<h2>' . __( 'Information', GOURLPMP ) . '</h2>' . PHP_EOL;
$tmp .= "<div align='center'><a href='".wp_login_url(get_permalink())."'>
<img style='border:none;box-shadow:none;' title='".__('You need first to login or register on the website to make Bitcoin/Altcoin Payments', GOURLPMP )."' vspace='10'
src='".$gourl->box_image()."' border='0'></a></div>";
}
elseif ($amount <= 0)
{
$tmp .= '<h2>' . __( 'Information', GOURLPMP ) . '</h2>' . PHP_EOL;
$tmp .= "<div class='pmpro_message pmpro_error'>". sprintf(__( "This order's amount is '%s' - it cannot be paid for. Please contact us if you need assistance.", GOURLPMP ), $amount ." " . $currency)."</div>";
}
else
{
// Exchange (optional)
// --------------------
if ($currency != "USD" && !$crypto)
{
$amount = gourl_convert_currency($currency, "USD", $amount);
if ($amount <= 0)
{
$tmp .= '<h2>' . __( 'Information', GOURLPMP ) . '</h2>' . PHP_EOL;
$tmp .= "<div class='pmpro_message pmpro_error'>".sprintf(__( 'Sorry, but there was an error processing your order. Please try later or use a different payment method. Cannot receive exchange rates for %s/USD from Google Finance', GOURLPMP ), $currency)."</div>";
}
else $currency = "USD";
}
if (!$crypto) $amount = $amount * $emultiplier;
// Payment Box
// ------------------
if ($amount > 0)
{
// crypto payment gateway
$result = $gourl->cryptopayments ($plugin, $amount, $currency, $orderID, $period, $language, $coin, $affiliate_key, $userID, $iconwidth);
if (!$result["is_paid"])
{
// trial used before
if ($userID != "guest" && get_option(GOURL."PMPRO_FREE_".$userID."_".$order->membership_id)) $tmp .= ($invoice?"<br>":"")."<i>" . sprintf(__('Free Trial already used on %s', GOURLPMP ), get_option(GOURL."PMPRO_FREE_".$userID."_".$order->membership_id)) . ".</i>";
$tmp .= '<br><h3>' . __( 'Pay Now -', GOURLPMP ) . '</h3>' . PHP_EOL;
}
if ($result["error"]) $tmp .= "<div class='pmpro_message pmpro_error'>".__( "Sorry, but there was an error processing your order. Please try a different payment method.", GOURLPMP )."<br/>".$result["error"]."</div>";
else
{
// display payment box or successful payment result
$tmp .= $result["html_payment_box"];
if ($order_user_id == get_current_user_id())
{
// payment received
if ($result["is_paid"])
{
if ($invoice)
$tmp .= "<div align='center'>" . __('Thank you for your membership.', GOURLPMP) . "</div>";
else
$tmp .= "<div align='center'>" . sprintf(__('Thank you for your membership to %s.<br>Your %s membership is now active.', GOURLPMP), get_bloginfo("name"), $current_user->membership_level->name) . "</div>";
}
if (!$invoice) $tmp .= "<br><br><div align='center'><a href=".pmpro_url("account").">".__('View Your Membership Account', GOURLPMP)." →</a>";
}
}
}
}
}
$tmp .= "<br><br>";
return $tmp;
}
/**
* 1.14 Custom invoice
*
*/
public static function pmpro_invoice_bullets_bottom($order)
{
if (empty($order) || $order->gateway != "gourl" || $order->total == 0) return true;
echo self::pmpro_gourl_cryptocoin_payment($order, true);
return true;
}
/**
* 1.15 Show payment log on order details page
*/
public static function pmpro_after_order_settings($order)
{
if (!empty($order) && $order->gateway == "gourl")
{
$data = self::display_order_notes();
if ($data)
{
$tmp = '<tr><th scope="row" valign="top"></th>';
$tmp .= '<td>';
$tmp .= $data;
$tmp .= '</td>';
$tmp .= '</tr>';
echo $tmp;
}
}
return true;
}
/**
* 1.16 Save payment log
*/
public static function add_order_note($order_id, $notes)
{
$id = GOURLPMP."_".$order_id."_gourl_log";
$dt = current_time("mysql", 0);
$arr = get_option($id);
if (!$arr) $arr = array();
$arr[] = "<tr><th style='padding-top:15px' valign='top'>" . $dt . "</th><td>" . $notes . "</td></tr>";
update_option($id, $arr);
return true;
}
/**
* 1.17 Display payment log
*/
public static function display_order_notes()
{
$tmp = "";
if (is_admin() && isset($_GET["order"]) && is_numeric($_GET["order"]) && isset($_GET["page"]) && $_GET["page"] == "pmpro-orders")
{
$order_id = $_GET["order"];
$data = get_option(GOURLPMP."_".$order_id."_gourl_log");
if ($data)
{
$tmp = "<br><h3>". __("Payment Log", GOURLPMP)." -</h3>";
$tmp .= "<table>" . implode("\n", $data) . "</table>";
}
}
return $tmp;
}
/**
* 1.18
*/
public static function sel($val1, $val2)
{
$tmp = ((is_array($val1) && in_array($val2, $val1)) || strval($val1) == strval($val2)) ? ' selected="selected"' : '';
return $tmp;
}
}
// end class
/*
* 2. Instant Payment Notification Function - pluginname."_gourlcallback"
*
* This function will appear every time by GoUrl Bitcoin Gateway when a new payment from any user is received successfully.
* Function gets user_ID - user who made payment, current order_ID (the same value as you provided to bitcoin payment gateway),
* payment details as array and box status.
*
* The function will automatically appear for each new payment usually two times :
* a) when a new payment is received, with values: $box_status = cryptobox_newrecord, $payment_details[is_confirmed] = 0
* b) and a second time when existing payment is confirmed (6+ confirmations) with values: $box_status = cryptobox_updated, $payment_details[is_confirmed] = 1.
*
* But sometimes if the payment notification is delayed for 20-30min, the payment/transaction will already be confirmed and the function will
* appear once with values: $box_status = cryptobox_newrecord, $payment_details[is_confirmed] = 1
*
* Payment_details example - https://gourl.io/images/plugin2.png
* Read more - https://gourl.io/affiliates.html#wordpress
*/
function gourlpmpro_gourlcallback ($user_id, $order_id, $payment_details, $box_status)
{
global $wpdb;
if (!in_array($box_status, array("cryptobox_newrecord", "cryptobox_updated"))) return false;
if (strpos($order_id, "order") === 0) $order_id = intval(substr($order_id, 5)); else return false;
if (!$user_id || $payment_details["status"] != "payment_received") return false;
// Initialize
$coinName = ucfirst($payment_details["coinname"]);
$amount = $payment_details["amount"] . " " . $payment_details["coinlabel"] . "  ( $" . $payment_details["amountusd"] . " )";
$payID = $payment_details["paymentID"];
$trID = $payment_details["tx"];
$confirmed = ($payment_details["is_confirmed"]) ? __('Yes', GOURLPMP) : __('No', GOURLPMP);
$order = new MemberOrder();
$order->getMemberOrderByID($order_id);
// New Payment Received
if ($box_status == "cryptobox_newrecord")
{
update_option(GOURL."PMPRO_INIT_".$user_id."_".$order->membership_id, date("m F Y"));
PMProGateway_gourl::add_order_note($order_id, sprintf(__("<b>%s</b> payment received <br>%s <br>Payment id <a href='%s'>#%s</a>. Awaiting network confirmation...", GOURLPMP), $coinName, $amount, GOURL_ADMIN.GOURL."payments&s=payment_".$payID, $payID));
}
// Existing Payment confirmed (6+ confirmations)
if ($payment_details["is_confirmed"])
{
PMProGateway_gourl::add_order_note($order_id, sprintf(__("%s Payment id <a href='%s'>#%s</a> Confirmed", GOURLPMP), $coinName, GOURL_ADMIN.GOURL."payments&s=payment_".$payID, $payID));
}
// Update User Membership
if (!empty($order) && $order->gateway == "gourl" && in_array($order->status, array("pending", "review", "token")))
{
$pmpro_level = $wpdb->get_row("SELECT * FROM $wpdb->pmpro_membership_levels WHERE id = '" . (int)$order->membership_id . "' LIMIT 1");
$startdate = apply_filters("pmpro_checkout_start_date", "'" . current_time("mysql") . "'", $user_id, $pmpro_level);
if (strlen($order->subscription_transaction_id) > 3)
{
$enddate = "'" . date("Y-m-d", strtotime("+ " . $order->subscription_transaction_id, current_time("timestamp"))) . "'";
}
elseif (!empty($pmpro_level->expiration_number)) {
$enddate = "'" . date("Y-m-d", strtotime("+ " . $pmpro_level->expiration_number . " " . $pmpro_level->expiration_period, current_time("timestamp"))) . "'";
} else {
$enddate = "NULL";
}
$custom_level = array(
'user_id' => $user_id,
'membership_id' => $pmpro_level->id,
'code_id' => '',
'initial_payment' => $pmpro_level->initial_payment,
'billing_amount' => $pmpro_level->billing_amount,
'cycle_number' => $pmpro_level->cycle_number,
'cycle_period' => $pmpro_level->cycle_period,
'billing_limit' => $pmpro_level->billing_limit,
'trial_amount' => $pmpro_level->trial_amount,
'trial_limit' => $pmpro_level->trial_limit,
'startdate' => $startdate,
'enddate' => $enddate);
if (pmpro_changeMembershipLevel($custom_level, $user_id, 'changed'))
{
$order->status = "success";
$order->membership_id = $pmpro_level->id;
$order->payment_transaction_id = strtoupper($coinName.$payID);
$order->saveOrder();
}
}
return true;
}
}
}