· 5 years ago · Aug 24, 2020, 01:16 PM
1<?php
2require_once('sys/import3p/PayPal/vendor/autoload.php');
3use PayPal\Api\Payer;
4use PayPal\Api\Item;
5use PayPal\Api\ItemList;
6use PayPal\Api\Details;
7use PayPal\Api\Amount;
8use PayPal\Api\Transaction;
9use PayPal\Api\RedirectUrls;
10use PayPal\Api\Payment;
11use PayPal\Api\PaymentExecution;
12
13$paypal = new \PayPal\Rest\ApiContext(
14 new \PayPal\Auth\OAuthTokenCredential(
15 $config['paypal_id'],
16 $config['paypal_secret']
17 )
18);
19$paypal->setConfig(
20 array(
21 'mode' => $config['paypal_mode']
22 )
23);
24
25if ($action == 'get_paypal_link' && IS_LOGGED && !empty($config['paypal_id']) && !empty($config['paypal_secret'])) {
26 $type = 'pro';
27 $sum = $config['pro_price'];
28 $dec = "Upgrade to pro";
29 if (!empty($_POST['type']) && $_POST['type'] == 'wallet' && !empty($_POST['amount']) && is_numeric($_POST['amount']) && $_POST['amount'] > 0) {
30 $sum = Generic::secure($_POST['amount']);
31 $type = 'wallet';
32 $dec = "Wallet top up";
33 }
34
35 $payer = new Payer();
36 $payer->setPaymentMethod('paypal');
37 $item = new Item();
38 $item->setName($dec)->setQuantity(1)->setPrice($sum)->setCurrency($config['currency']);
39 $itemList = new ItemList();
40 $itemList->setItems(array(
41 $item
42 ));
43 $details = new Details();
44 $details->setSubtotal($sum);
45 $amount = new Amount();
46 $amount->setCurrency($config['currency'])->setTotal($sum)->setDetails($details);
47 $transaction = new Transaction();
48 $transaction->setAmount($amount)->setItemList($itemList)->setDescription($dec)->setInvoiceNumber(time());
49 $redirectUrls = new RedirectUrls();
50 if ($type == 'pro') {
51 $redirectUrls->setReturnUrl($config['site_url'] . "/aj/go_pro/get_paid&success=1")->setCancelUrl($config['site_url']);
52 }
53 elseif ($type == 'wallet') {
54 $redirectUrls->setReturnUrl($config['site_url'] . "/aj/go_pro/wallet_top_up&success=1&amount=".$sum)->setCancelUrl($config['site_url']);
55 }
56 $payment = new Payment();
57 $payment->setIntent('sale')->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array(
58 $transaction
59 ));
60 try {
61 $payment->create($paypal);
62 }
63 catch (Exception $e) {
64 $data = array(
65 'status' => 400,
66 'message' => json_decode($e->getData())
67 );
68 if (empty($data['message'])) {
69 $data['message'] = json_decode($e->getCode());
70 }
71 }
72 if (empty($data['message'])) {
73 $data = array(
74 'status' => 200,
75 'url' => $payment->getApprovalLink()
76 );
77 }
78
79}
80
81 use YandexCheckout\Client;
82 require_once('sys/import3p/YandexCheckout/vendor/autoload.php');
83
84
85if ($action == 'yandex_kassa' && IS_LOGGED && !empty($config['yandex_shop_id']) && !empty($config['yandex_api_key'])) {
86 $client = new Client();
87 $client->setAuth('yandex_shop_id', 'yandex_api_key');
88 $type = 'pro';
89 $sum = $config['pro_price'];
90 $dec = "Upgrade to pro";
91 if (!empty($_POST['type']) && $_POST['type'] == 'wallet' && !empty($_POST['amount']) && is_numeric($_POST['amount']) && $_POST['amount'] > 0) {
92 $sum = Generic::secure($_POST['amount']);
93 $type = 'wallet';
94 $dec = "Wallet top up";
95 }
96
97 $payer = new Payer();
98 $payer->setPaymentMethod('YandexCheckout');
99 $item = new Item();
100 $item->setName($dec)->setQuantity(1)->setPrice($sum)->setCurrency($config['currency']);
101 $itemList = new ItemList();
102 $itemList->setItems(array(
103 $item
104 ));
105 $details = new Details();
106 $details->setSubtotal($sum);
107 $amount = new Amount();
108 $amount->setCurrency($config['currency'])->setTotal($sum)->setDetails($details);
109 $transaction = new Transaction();
110 $transaction->setAmount($amount)->setItemList($itemList)->setDescription($dec)->setInvoiceNumber(time());
111 $redirectUrls = new RedirectUrls();
112 if ($type == 'pro') {
113 $redirectUrls->setReturnUrl($config['site_url'] . "/aj/go_pro/get_paid&success=1")->setCancelUrl($config['site_url']);
114 }
115 elseif ($type == 'wallet') {
116 $redirectUrls->setReturnUrl($config['site_url'] . "/aj/go_pro/wallet_top_up&success=1&amount=".$sum)->setCancelUrl($config['site_url']);
117 }
118 $payment = new Payment();
119 $payment->setIntent('sale')->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array(
120 $transaction
121 ));
122 try {
123 $payment->create($YandexCheckout);
124 }
125 catch (Exception $e) {
126 $data = array(
127 'status' => 400,
128 'message' => json_decode($e->getData())
129 );
130 if (empty($data['message'])) {
131 $data['message'] = json_decode($e->getCode());
132 }
133 }
134 if (empty($data['message'])) {
135 $data = array(
136 'status' => 200,
137 'url' => $payment->getApprovalLink()
138 );
139 }
140
141}
142
143
144if($action == 'paysera_success' || $action == 'paysera_callback'){
145 $response = WebToPay::checkResponse($_GET, array(
146 'projectid' => $config['paysera_project_id'],
147 'sign_password' => $config['paysera_password'],
148 ));
149
150 if ($response['type'] !== 'macro') {
151 die('Only macro payment callbacks are accepted');
152 }
153
154 $update = $user->updateStatic($me['user_id'],array('is_pro' => 1,'verified' => 1));
155 $amount = $config['pro_price'];
156 $date = time();
157
158 $db->insert(T_PAYMENTS,array('user_id' => $me['user_id'],
159 'amount' => $amount,
160 'type' => 'pro_member',
161 'date' => $date));
162
163 $db->insert(T_TRANSACTIONS,array('user_id' => $me['user_id'],
164 'amount' => $amount,
165 'type' => 'pro_member',
166 'time' => $date));
167
168
169 header('Location: ' . $config['site_url'] . "/upgraded");
170 exit();
171}
172if($action == 'paysera_cancel'){
173 header('Location: ' . $config['site_url']);
174 exit();
175}
176if($action == 'get_sms_link'){
177 $amount = intval( $config['pro_price'] );
178 $url = '';
179 try {
180 $self_url = $config['site_url'];
181 $payment_url = WebToPay::getPaymentUrl();
182
183 $request = WebToPay::buildRequest(array(
184 'projectid' => $config['paysera_project_id'],
185 'sign_password' => $config['paysera_password'],
186 'orderid' => rand(1111,4444),
187 'amount' => $amount,
188 'currency' => $config['currency'],
189 'country' => 'TR',
190 'accepturl' => $self_url.'/aj/go_pro/paysera_success',
191 'cancelurl' => $self_url.'/aj/go_pro/paysera_cancel',
192 'callbackurl' => $self_url.'/aj/go_pro/paysera_callback',
193 'test' => ($config['paysera_test_mode'] == 'test') ? 1 : 0,
194 ));
195
196 $url = $payment_url . '?data='. $request['data'] . '&sign=' . $request['sign'];
197 $data = array(
198 'status' => 200,
199 'url' => $url
200 );
201 }
202 catch (WebToPayException $e) {
203 echo $e->getMessage();
204 }
205}
206
207if ($action == 'get_paid' && IS_LOGGED && !empty($config['paypal_id']) && !empty($config['paypal_secret']) && $_GET['success'] == 1 && !empty($_GET['paymentId']) && !empty($_GET['PayerID'])) {
208 $paymentId = $_GET['paymentId'];
209 $PayerID = $_GET['PayerID'];
210 $payment = Payment::get($paymentId, $paypal);
211 $execute = new PaymentExecution();
212 $execute->setPayerId($PayerID);
213 $error = '';
214 try {
215 $result = $payment->execute($execute, $paypal);
216 }
217 catch (Exception $e) {
218 $error = json_decode($e->getData(), true);
219 }
220
221 if (empty($error)) {
222 $update = $user->updateStatic($me['user_id'],array('is_pro' => 1,'verified' => 1));
223 $amount = $config['pro_price'];
224 $date = time();
225
226 $db->insert(T_PAYMENTS,array('user_id' => $me['user_id'],
227 'amount' => $amount,
228 'type' => 'pro_member',
229 'date' => $date));
230
231 $db->insert(T_TRANSACTIONS,array('user_id' => $me['user_id'],
232 'amount' => $amount,
233 'type' => 'pro_member',
234 'time' => $date));
235
236 header("Location: " . $config['site_url'] . "/upgraded");
237 exit();
238 }
239 else{
240 header("Location: " . $config['site_url'] . "/oops");
241 exit();
242 }
243}
244
245if ($action == 'wallet_top_up' && IS_LOGGED && !empty($config['paypal_id']) && !empty($config['paypal_secret']) && $_GET['success'] == 1 && !empty($_GET['paymentId']) && !empty($_GET['PayerID']) && !empty($_GET['amount'])) {
246 $paymentId = $_GET['paymentId'];
247 $PayerID = $_GET['PayerID'];
248 $payment = Payment::get($paymentId, $paypal);
249 $execute = new PaymentExecution();
250 $execute->setPayerId($PayerID);
251 $error = '';
252 try {
253 $result = $payment->execute($execute, $paypal);
254 }
255 catch (Exception $e) {
256 $error = json_decode($e->getData(), true);
257 }
258
259 if (empty($error)) {
260 $wallet = $me['wallet'] + $_GET['amount'];
261 $update = $user->updateStatic($me['user_id'],array('wallet' => $wallet));
262
263 $db->insert(T_TRANSACTIONS,array('user_id' => $me['user_id'],
264 'amount' => Generic::secure($_GET['amount']),
265 'type' => 'Advertise',
266 'time' => time()));
267
268 header("Location: " . $config['site_url'] . "/ads/wallet");
269 exit();
270 }
271 else{
272 header("Location: " . $config['site_url'] . "/oops");
273 exit();
274 }
275}
276
277if ($action == 'stripe_payment' && IS_LOGGED && $config['credit_card'] == 'on' && !empty($config['stripe_id']) && !empty($config['stripe_id'])) {
278 require_once('sys/import3p/stripe-php-3.20.0/vendor/autoload.php');
279 $stripe = array(
280 "secret_key" => $config['stripe_secret'],
281 "publishable_key" => $config['stripe_id']
282 );
283
284 \Stripe\Stripe::setApiKey($stripe['secret_key']);
285 $token = $_POST['stripeToken'];
286
287 if (!empty($_POST['type']) && $_POST['type'] == 'pro' && !empty($_POST['amount'])) {
288 if ($config['pro_price'].'00' == $_POST['amount']) {
289 try {
290 $customer = \Stripe\Customer::create(array(
291 'source' => $token
292 ));
293 $charge = \Stripe\Charge::create(array(
294 'customer' => $customer->id,
295 'amount' => $config['pro_price'].'00',
296 'currency' => 'usd'
297 ));
298 if ($charge) {
299 $update = $user->updateStatic($me['user_id'],array('is_pro' => 1,'verified' => 1));
300 $amount = $config['pro_price'];
301 $date = time();
302
303 $db->insert(T_PAYMENTS,array('user_id' => $me['user_id'],
304 'amount' => $amount,
305 'type' => 'pro_member',
306 'date' => $date));
307
308 $db->insert(T_TRANSACTIONS,array('user_id' => $me['user_id'],
309 'amount' => $amount,
310 'type' => 'pro_member',
311 'time' => $date));
312 $data = array(
313 'status' => 200,
314 'url' => $config['site_url'] . "/upgraded"
315 );
316 }
317 }
318 catch (Exception $e) {
319 $data = array(
320 'status' => 400,
321 'error' => $e->getMessage()
322 );
323 }
324 }
325 }
326 elseif (!empty($_POST['type']) && $_POST['type'] == 'wallet' && !empty($_POST['amount'])) {
327 $amount = Generic::secure($_POST['amount']);
328 try {
329 $customer = \Stripe\Customer::create(array(
330 'source' => $token
331 ));
332 $charge = \Stripe\Charge::create(array(
333 'customer' => $customer->id,
334 'amount' => $_POST['amount'].'00',
335 'currency' => 'usd'
336 ));
337 if ($charge) {
338 $wallet = $me['wallet'] + $amount;
339 $update = $user->updateStatic($me['user_id'],array('wallet' => $wallet));
340
341 $db->insert(T_TRANSACTIONS,array('user_id' => $me['user_id'],
342 'amount' => $amount,
343 'type' => 'Advertise',
344 'time' => time()));
345 $data = array(
346 'status' => 200,
347 'url' => $config['site_url'] . "/ads/wallet"
348 );
349 }
350 }
351 catch (Exception $e) {
352 $data = array(
353 'status' => 400,
354 'error' => $e->getMessage()
355 );
356 }
357 }
358
359
360
361}
362
363if ($action == 'bank_transfer' && IS_LOGGED) {
364 if (!empty($_FILES['image'])) {
365 if (!empty($_FILES['image']) && file_exists($_FILES['image']['tmp_name'])) {
366 $media = new Media();
367 $media->setFile(array(
368 'file' => $_FILES['image']['tmp_name'],
369 'name' => $_FILES['image']['name'],
370 'size' => $_FILES['image']['size'],
371 'type' => $_FILES['image']['type'],
372 'allowed' => 'jpeg,jpg,png'
373 ));
374
375 $upload = $media->uploadFile();
376
377 $description = 'Upgrade to pro';
378 $price = $config['pro_price'];
379 $mode = 'pro_member';
380 $funding_id = 0;
381
382 if (!empty($_POST['type']) && $_POST['type'] == 'wallet' && !empty($_POST['price']) && is_numeric($_POST['price']) && $_POST['price'] > 0) {
383 $description = 'Wallet top up';
384 $mode = 'wallet';
385 $price = Generic::secure($_POST['price']);
386 }
387 if (!empty($_POST['type']) && $_POST['type'] == 'donate' && !empty($_POST['price']) && is_numeric($_POST['price']) && $_POST['price'] > 0 && !empty($_POST['fund_id'])) {
388 $description = 'Donate to funding ';
389 $mode = 'donate';
390 $price = Generic::secure($_POST['price']);
391 $funding_id = Generic::secure($_POST['fund_id']);
392 }
393 if (!empty($upload)) {
394 $image = $upload['filename'];
395 $db->insert(T_BANK_TRANSFER,array('user_id' => $me['user_id'],
396 'receipt_file' => $image,
397 'description' => $description,
398 'price' => $price,
399 'mode' => $mode,
400 'funding_id' => $funding_id));
401 $data['status'] = 200;
402 $data['message'] = lang('bank_transfer_request');
403 }
404 }
405 }
406 else{
407 $data = array(
408 'status' => 400,
409 'message' => lang('please_fill_fields')
410 );
411 }
412}
413
414
415
416
417if ($action == 'paypal_donate' && IS_LOGGED && !empty($config['paypal_id']) && !empty($config['paypal_secret'])) {
418
419 if (!empty($_POST['amount']) && is_numeric($_POST['amount']) && $_POST['amount'] > 0 && !empty($_POST['fund_id']) && is_numeric($_POST['fund_id']) && $_POST['fund_id'] > 0) {
420
421 $user = new User();
422 $fund_id = Generic::secure($_POST['fund_id']);
423
424 $fund = $user->GetFundingById($fund_id);
425 if (!empty($fund)) {
426 $sum = Generic::secure($_POST['amount']);
427 $type = 'wallet';
428 $dec = "donate";
429
430
431 $payer = new Payer();
432 $payer->setPaymentMethod('paypal');
433 $item = new Item();
434 $item->setName($dec)->setQuantity(1)->setPrice($sum)->setCurrency($config['currency']);
435 $itemList = new ItemList();
436 $itemList->setItems(array(
437 $item
438 ));
439 $details = new Details();
440 $details->setSubtotal($sum);
441 $amount = new Amount();
442 $amount->setCurrency($config['currency'])->setTotal($sum)->setDetails($details);
443 $transaction = new Transaction();
444 $transaction->setAmount($amount)->setItemList($itemList)->setDescription($dec)->setInvoiceNumber(time());
445 $redirectUrls = new RedirectUrls();
446 $redirectUrls->setReturnUrl($config['site_url'] . "/aj/go_pro/donate_to_user&amount=".$sum."&fund_id=".$fund_id)->setCancelUrl($config['site_url']);
447 $payment = new Payment();
448 $payment->setIntent('sale')->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array(
449 $transaction
450 ));
451 try {
452 $payment->create($paypal);
453 }
454 catch (Exception $e) {
455 $data = array(
456 'status' => 400,
457 'message' => json_decode($e->getData())
458 );
459 if (empty($data['message'])) {
460 $data['message'] = json_decode($e->getCode());
461 }
462 }
463
464 if (empty($data['message'])) {
465 $data = array(
466 'status' => 200,
467 'url' => $payment->getApprovalLink()
468 );
469 }
470 }
471 else{
472 $data = array(
473 'status' => 400,
474 'message' => lang('fund_not_found')
475 );
476 }
477 }
478 else{
479 $data = array(
480 'status' => 400,
481 'message' => lang('please_fill_fields')
482 );
483 }
484}
485
486if ($action == 'donate_to_user' && IS_LOGGED && !empty($config['paypal_id']) && !empty($config['paypal_secret']) && !empty($_GET['paymentId']) && !empty($_GET['PayerID']) && !empty($_GET['amount']) && !empty($_GET['fund_id'])) {
487
488 $paymentId = $_GET['paymentId'];
489 $PayerID = $_GET['PayerID'];
490 $payment = Payment::get($paymentId, $paypal);
491 $execute = new PaymentExecution();
492 $execute->setPayerId($PayerID);
493 $error = '';
494 try {
495 $result = $payment->execute($execute, $paypal);
496 }
497 catch (Exception $e) {
498 $error = json_decode($e->getData(), true);
499 }
500
501 if (empty($error)) {
502
503 $amount = Generic::secure($_GET['amount']);
504 $fund_id = Generic::secure($_GET['fund_id']);
505 $user = new User();
506
507 $fund = $user->GetFundingById($fund_id);
508 if (!empty($fund)) {
509 $admin_com = 0;
510 if (!empty($config['donate_percentage']) && is_numeric($config['donate_percentage']) && $config['donate_percentage'] > 0) {
511 $admin_com = ($config['donate_percentage'] * $amount) / 100;
512 $amount = $amount - $admin_com;
513 }
514 $db->where('user_id',$fund->user_id)->update(T_USERS,array('balance'=>$db->inc($amount)));
515 $db->insert(T_FUNDING_RAISE,array('user_id' => $me['user_id'],
516 'funding_id' => $fund_id,
517 'amount' => $amount,
518 'time' => time()));
519
520 $db->insert(T_TRANSACTIONS,array('user_id' => $me['user_id'],
521 'amount' => $amount,
522 'type' => 'donate',
523 'time' => time(),
524 'admin_com' => $admin_com));
525 $notif = new Notifications();
526 $hashed_id = $fund_id;
527 if (!empty($fund->hashed_id)) {
528 $hashed_id = $fund->hashed_id;
529 }
530 if ($fund->user_id != $me['user_id']) {
531
532 $re_data = array(
533 'notifier_id' => $me['user_id'],
534 'recipient_id' => $fund->user_id,
535 'type' => 'donated',
536 'url' => $config['site_url'] . "/funding/".$hashed_id,
537 'time' => time()
538 );
539 try {
540 $notif->notify($re_data);
541 } catch (Exception $e) {
542 }
543
544
545 }
546
547 header("Location: " . $config['site_url'] . "/funding/".$hashed_id);
548 exit();
549 }
550 else{
551 header("Location: " . $config['site_url'] . "/oops");
552 exit();
553 }
554 }
555 else{
556 header("Location: " . $config['site_url'] . "/oops");
557 exit();
558 }
559}
560
561
562if ($action == 'stripe_donate' && IS_LOGGED && $config['credit_card'] == 'on' && !empty($config['stripe_id']) && !empty($config['stripe_id'])) {
563 if (!empty($_POST['amount']) && is_numeric($_POST['amount']) && $_POST['amount'] > 0 && !empty($_POST['fund_id']) && is_numeric($_POST['fund_id']) && $_POST['fund_id'] > 0) {
564 require_once('sys/import3p/stripe-php-3.20.0/vendor/autoload.php');
565 $stripe = array(
566 "secret_key" => $config['stripe_secret'],
567 "publishable_key" => $config['stripe_id']
568 );
569
570 \Stripe\Stripe::setApiKey($stripe['secret_key']);
571 $token = $_POST['stripeToken'];
572
573 $amount = Generic::secure($_POST['amount']);
574 $fund_id = Generic::secure($_POST['fund_id']);
575 $user = new User();
576
577 $fund = $user->GetFundingById($fund_id);
578 if (!empty($fund)) {
579 try {
580 $customer = \Stripe\Customer::create(array(
581 'source' => $token
582 ));
583 $charge = \Stripe\Charge::create(array(
584 'customer' => $customer->id,
585 'amount' => $_POST['amount'].'00',
586 'currency' => 'usd'
587 ));
588 if ($charge) {
589 $admin_com = 0;
590 if (!empty($config['donate_percentage']) && is_numeric($config['donate_percentage']) && $config['donate_percentage'] > 0) {
591 $admin_com = ($config['donate_percentage'] * $amount) / 100;
592 $amount = $amount - $admin_com;
593 }
594
595 $db->where('user_id',$fund->user_id)->update(T_USERS,array('balance'=>$db->inc($amount)));
596 $db->insert(T_FUNDING_RAISE,array('user_id' => $me['user_id'],
597 'funding_id' => $fund_id,
598 'amount' => $amount,
599 'time' => time()));
600
601 $db->insert(T_TRANSACTIONS,array('user_id' => $me['user_id'],
602 'amount' => $amount,
603 'type' => 'donate',
604 'time' => time(),
605 'admin_com' => $admin_com));
606
607 $notif = new Notifications();
608 $re_data = array(
609 'notifier_id' => $me['user_id'],
610 'recipient_id' => $fund->user_id,
611 'type' => 'donated',
612 'url' => $config['site_url'] . "/funding/".$fund_id,
613 'time' => time()
614 );
615
616 try {
617 $notif->notify($re_data);
618 } catch (Exception $e) {
619 }
620 $data = array(
621 'status' => 200
622 );
623 }
624 }
625 catch (Exception $e) {
626 $data = array(
627 'status' => 400,
628 'error' => $e->getMessage()
629 );
630 }
631 }
632 }
633
634
635
636}