1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Models\User; |
6
|
|
|
use Blacklight\libraries\Geary; |
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
use Spatie\Permission\Models\Role; |
9
|
|
|
|
10
|
|
|
class BtcPaymentController extends BasePageController |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @param \Illuminate\Http\Request $request |
14
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
15
|
|
|
* @throws \Exception |
16
|
|
|
*/ |
17
|
|
|
public function show(Request $request) |
18
|
|
|
{ |
19
|
|
|
$this->setPrefs(); |
20
|
|
|
$gateway_id = env('MYCELIUM_GATEWAY_ID'); |
21
|
|
|
$gateway_secret = env('MYCELIUM_GATEWAY_SECRET'); |
22
|
|
|
|
23
|
|
|
$action = $request->input('action') ?? 'view'; |
24
|
|
|
$donation = Role::query()->where('donation', '>', 0)->get(['id', 'name', 'donation', 'addyears']); |
25
|
|
|
$this->smarty->assign('donation', $donation); |
|
|
|
|
26
|
|
|
|
27
|
|
|
switch ($action) { |
28
|
|
|
case 'submit': |
29
|
|
|
$price = $request->input('price'); |
30
|
|
|
$role = $request->input('role'); |
31
|
|
|
$roleName = $request->input('rolename'); |
32
|
|
|
$addYears = $request->input('addyears'); |
33
|
|
|
$data = ['user_id' => $this->userdata->id, 'username' => $this->userdata->username, 'price' => $price, 'role' => $role, 'rolename' => $roleName, 'addyears' => $addYears]; |
34
|
|
|
$keychain_id = random_int(0, 19); |
35
|
|
|
$callback_data = json_encode($data); |
36
|
|
|
|
37
|
|
|
$geary = new Geary($gateway_id, $gateway_secret); |
38
|
|
|
$order = $geary->create_order($price, $keychain_id, $callback_data); |
39
|
|
|
|
40
|
|
|
if ($order->payment_id) { |
41
|
|
|
// Redirect to a payment gateway |
42
|
|
|
$url = 'https://gateway.gear.mycelium.com/pay/'.$order->payment_id; |
43
|
|
|
|
44
|
|
|
return redirect($url); |
45
|
|
|
} |
46
|
|
|
break; |
47
|
|
|
case 'view': |
48
|
|
|
default: |
49
|
|
|
$userId = $this->userdata->id; |
|
|
|
|
50
|
|
|
break; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$title = 'Become a supporter'; |
54
|
|
|
$meta_title = 'Become a supporter'; |
55
|
|
|
$meta_description = 'Become a supporter'; |
56
|
|
|
|
57
|
|
|
$content = $this->smarty->fetch('btc_payment.tpl'); |
|
|
|
|
58
|
|
|
|
59
|
|
|
$this->smarty->assign(compact('content', 'meta_title', 'title', 'meta_description')); |
60
|
|
|
$this->pagerender(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Callback data from Mycelium Gear. |
65
|
|
|
*/ |
66
|
|
|
public function callback() |
67
|
|
|
{ |
68
|
|
|
$gateway_id = env('MYCELIUM_GATEWAY_ID'); |
69
|
|
|
$gateway_secret = env('MYCELIUM_GATEWAY_SECRET'); |
70
|
|
|
|
71
|
|
|
$geary = new Geary($gateway_id, $gateway_secret); |
72
|
|
|
$order = $geary->check_order_callback(); |
73
|
|
|
|
74
|
|
|
// Order status was received |
75
|
|
|
if ($order !== false) { |
76
|
|
|
$callback_data = json_decode($order['callback_data'], true); |
77
|
|
|
$newRole = $callback_data['role']; |
78
|
|
|
$amount = $callback_data['price']; |
|
|
|
|
79
|
|
|
$addYear = $callback_data['addyears']; |
80
|
|
|
// If order was paid in full (2) or overpaid (4) |
81
|
|
|
if ((int) $order['status'] === 2 || (int) $order['status'] === 4) { |
82
|
|
|
User::updateUserRole($callback_data['user_id'], $newRole); |
83
|
|
|
User::updateUserRoleChangeDate($callback_data['user_id'], null, $addYear); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.