Skip to content

Commit 80de8a9

Browse files
committed
PUSH
-> Fix bug with stripe doing with cents instead of normal money -> In settings you can now change only related settings that will apply to both paypal and stripe like currency and price per coin -> Finished the settings page
1 parent 9452354 commit 80de8a9

File tree

6 files changed

+202
-28
lines changed

6 files changed

+202
-28
lines changed

routes/admin/settings.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@
4949
require("../view/admin/settings/stripe.php");
5050
});
5151

52+
$router->add("/admin/settings/payments", function () {
53+
require("../include/main.php");
54+
require("../view/admin/settings/payments.php");
55+
});
56+
57+
$router->add("/admin/settings/paypal", function () {
58+
require("../include/main.php");
59+
require("../view/admin/settings/paypal.php");
60+
});
61+
5262
$router->add("/admin/settings/security", function () {
5363
require("../include/main.php");
5464
require("../view/admin/settings/security.php");

view/admin/settings/main.php

Lines changed: 134 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,6 @@ class="btn btn-primary me-2 waves-effect waves-light" value="true">Save
267267
<h5 class="card-header text-center">Stripe</h5>
268268
<div class="card-text text-center">
269269
<label>Customize your stripe settings here. &NewLine;</label><br>
270-
<label>Currency: This shall be your currency ISO (<a
271-
href="https://stripe.com/docs/currencies#presentment-currencies">Here you can
272-
find a list</a>).</label><br>
273-
<label>Price: This shall be the price per 1 coin (This shall be cents EX 1000 = 1
274-
<?= strtoupper(SettingsManager::getSetting('payments_currency')) ?>).
275-
</label><br>
276270
<label>Public Key: This shall be the publishable key that you can get from <a
277271
href="https://dashboard.stripe.com/apikeys">here</a>.</label><br>
278272
<label>Secret Key: This shall be the secret key that you can get from <a
@@ -306,38 +300,157 @@ class="btn btn-primary me-2 waves-effect waves-light" value="true">Save
306300

307301
</div>
308302
</div>
309-
<div class="form-group col-md-1">
310-
<label class="control-label">Currency</label>
303+
<div class="form-group col-md-4">
304+
<label class="control-label">Public Key</label>
311305
<div>
312306
<input type="text" required="" class="form-control"
313-
name="stripe:stripe_currency"
314-
value="<?= strtoupper(SettingsManager::getSetting('payments_currency')) ?>">
307+
name="stripe:public_key"
308+
value="<?= SettingsManager::getSetting('stripe_publishable_key') ?>">
315309
</div>
316310
</div>
317-
<div class="form-group col-md-1">
318-
<label class="control-label">Price</label>
311+
<div class="form-group col-md-4">
312+
<label class="control-label">Secret Key</label>
319313
<div>
320-
<input type="text" required="" class="form-control"
321-
name="stripe:coin_per_balance"
322-
value="<?= SettingsManager::getSetting('coin_per_balance') ?>">
314+
<input type="password" required="" class="form-control"
315+
name="stripe:private_key"
316+
value="<?= SettingsManager::getSetting('stripe_secret_key') ?>">
317+
</div>
318+
</div>
319+
<br>
320+
321+
</div>
322+
<br>
323+
<div class="mt-2 text-center">
324+
<button type="submit" name="update_settings"
325+
class="btn btn-primary me-2 waves-effect waves-light" value="true">Save
326+
changes</button>
327+
<a href="/admin" class="btn btn-label-secondary waves-effect">Cancel</a>
328+
</div>
329+
</form>
330+
</div>
331+
</div>
332+
<div class="card mb-4">
333+
<h5 class="card-header text-center">PayPal</h5>
334+
<div class="card-text text-center">
335+
<label>Customize your paypal settings here. &NewLine;</label><br>
336+
<label>Client ID: This shall be the publishable key that you can get from <a
337+
href="https://developer.paypal.com/dashboard/applications/sandbox">here</a>.</label><br>
338+
<label>Secret Key: This shall be the secret key that you can get from <a
339+
href="https://developer.paypal.com/dashboard/applications/sandbox">here</a>.</label>
340+
<p></p>
341+
</div>
342+
<hr class="my-0">
343+
<div class="card-body">
344+
<form action="/admin/settings/paypal" method="GET">
345+
<div class="row">
346+
<div class="form-group col-md-2">
347+
<label class="control-label">Status</label>
348+
<div>
349+
<?php
350+
if (SettingsManager::getSetting('enable_paypal') == 'true') {
351+
?>
352+
<select class="form-control" name="paypal:enabled">
353+
<option value="true">Enabled</option>
354+
<option value="false">Disabled</option>
355+
</select>
356+
<?php
357+
} else {
358+
?>
359+
<select class="form-control" name="paypal:enabled">
360+
<option value="false">Disabled</option>
361+
<option value="true">Enabled</option>
362+
</select>
363+
<?php
364+
}
365+
?>
366+
323367
</div>
324368
</div>
325369
<div class="form-group col-md-4">
326-
<label class="control-label">Public Key</label>
370+
<label class="control-label">Client ID</label>
327371
<div>
328372
<input type="text" required="" class="form-control"
329-
name="stripe:public_key"
330-
value="<?= SettingsManager::getSetting('stripe_publishable_key') ?>">
373+
name="paypal:client_id"
374+
value="<?= SettingsManager::getSetting('paypal_client_id') ?>">
331375
</div>
332376
</div>
333377
<div class="form-group col-md-4">
334-
<label class="control-label">Secret Key</label>
378+
<label class="control-label">Secret key</label>
335379
<div>
336380
<input type="password" required="" class="form-control"
337-
name="stripe:private_key"
338-
value="<?= SettingsManager::getSetting('stripe_secret_key') ?>">
381+
name="paypal:secret_key"
382+
value="<?= SettingsManager::getSetting('paypal_client_secret') ?>">
383+
</div>
384+
</div>
385+
<br>
386+
387+
</div>
388+
<br>
389+
<div class="mt-2 text-center">
390+
<button type="submit" name="update_settings"
391+
class="btn btn-primary me-2 waves-effect waves-light" value="true">Save
392+
changes</button>
393+
<a href="/admin" class="btn btn-label-secondary waves-effect">Cancel</a>
394+
</div>
395+
</form>
396+
</div>
397+
</div>
398+
<div class="card mb-4">
399+
<h5 class="card-header text-center">Payments</h5>
400+
<div class="card-text text-center">
401+
<label>Customize your payments settings here. &NewLine;</label><br>
402+
<label>Currency: This shall be your currency ISO (<a
403+
href="https://stripe.com/docs/currencies#presentment-currencies">Here you can
404+
find a list</a>).</label><br>
405+
<label>Price: This shall be the price per 1 coin (This shall be cents EX 1000 = 1
406+
<?= strtoupper(SettingsManager::getSetting('payments_currency')) ?>).
407+
</label><br>
408+
<p></p>
409+
</div>
410+
<hr class="my-0">
411+
<div class="card-body">
412+
<form action="/admin/settings/payments" method="GET">
413+
<div class="row">
414+
<div class="form-group col-md-4">
415+
<label class="control-label">Status</label>
416+
<div>
417+
<?php
418+
if (SettingsManager::getSetting('allow_payments') == 'true') {
419+
?>
420+
<select class="form-control" name="payments:enabled">
421+
<option value="true">Enabled</option>
422+
<option value="false">Disabled</option>
423+
</select>
424+
<?php
425+
} else {
426+
?>
427+
<select class="form-control" name="payments:enabled">
428+
<option value="false">Disabled</option>
429+
<option value="true">Enabled</option>
430+
</select>
431+
<?php
432+
}
433+
?>
434+
435+
</div>
436+
</div>
437+
<div class="form-group col-md-4">
438+
<label class="control-label">Currency</label>
439+
<div>
440+
<input type="text" required="" class="form-control"
441+
name="payments:payments_currency"
442+
value="<?= strtoupper(SettingsManager::getSetting('payments_currency')) ?>">
443+
</div>
444+
</div>
445+
<div class="form-group col-md-4">
446+
<label class="control-label">Price</label>
447+
<div>
448+
<input type="text" required="" class="form-control"
449+
name="payments:coin_per_balance"
450+
value="<?= SettingsManager::getSetting('coin_per_balance') ?>">
339451
</div>
340452
</div>
453+
341454
<br>
342455

343456
</div>

view/admin/settings/payments.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
use MythicalDash\ErrorHandler;
3+
include (__DIR__ . '/../../requirements/page.php');
4+
include (__DIR__ . '/../../requirements/admin.php');
5+
6+
try {
7+
if (isset($_GET['update_settings'])) {
8+
$allow_payments = mysqli_real_escape_string($conn, $_GET['payments:enabled']);
9+
$payments_currency = mysqli_real_escape_string($conn, $_GET['payments:payments_currency']);
10+
$coin_per_balance = mysqli_real_escape_string($conn, $_GET['payments:coin_per_balance']);
11+
mysqli_query($conn, "UPDATE `mythicaldash_settings` SET `allow_payments` = '" . $allow_payments . "' WHERE `mythicaldash_settings`.`id` = 1;");
12+
mysqli_query($conn, "UPDATE `mythicaldash_settings` SET `payments_currency` = '" . $payments_currency . "' WHERE `mythicaldash_settings`.`id` = 1;");
13+
mysqli_query($conn, "UPDATE `mythicaldash_settings` SET `coin_per_balance` = '" . $coin_per_balance . "' WHERE `mythicaldash_settings`.`id` = 1;");
14+
header('location: /admin/settings?s=We updated the settings inside the database');
15+
$conn->close();
16+
die ();
17+
} else {
18+
header('location: /admin/settings?e=Failed to update the settings inside the database');
19+
die();
20+
}
21+
} catch (Exception $ex) {
22+
ErrorHandler::Critical("Failed to update settings ",$ex);
23+
header('location: /admin/settings?e=Failed to update the settings inside the database');
24+
die ();
25+
}
26+
?>

view/admin/settings/paypal.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
use MythicalDash\ErrorHandler;
3+
include (__DIR__ . '/../../requirements/page.php');
4+
include (__DIR__ . '/../../requirements/admin.php');
5+
6+
try {
7+
if (isset($_GET['update_settings'])) {
8+
$enable_paypal = mysqli_real_escape_string($conn, $_GET['paypal:enabled']);
9+
$client_id = mysqli_real_escape_string($conn, $_GET['paypal:client_id']);
10+
$secret_key = mysqli_real_escape_string($conn, $_GET['paypal:secret_key']);
11+
12+
mysqli_query($conn, "UPDATE `mythicaldash_settings` SET `enable_paypal` = '" . $enable_paypal . "' WHERE `mythicaldash_settings`.`id` = 1;");
13+
mysqli_query($conn, "UPDATE `mythicaldash_settings` SET `paypal_client_id` = '" . $client_id . "' WHERE `mythicaldash_settings`.`id` = 1;");
14+
mysqli_query($conn, "UPDATE `mythicaldash_settings` SET `paypal_client_secret` = '" . $secret_key . "' WHERE `mythicaldash_settings`.`id` = 1;");
15+
header('location: /admin/settings?s=We updated the settings inside the database');
16+
$conn->close();
17+
die ();
18+
} else {
19+
header('location: /admin/settings?e=Failed to update the settings inside the database');
20+
die();
21+
}
22+
} catch (Exception $ex) {
23+
ErrorHandler::Critical("Failed to update settings ",$ex);
24+
header('location: /admin/settings?e=Failed to update the settings inside the database');
25+
die ();
26+
}
27+
?>

view/admin/settings/stripe.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@
88
$enable_stripe = mysqli_real_escape_string($conn, $_GET['stripe:enabled']);
99
$stripe_publishable_key = mysqli_real_escape_string($conn, $_GET['stripe:public_key']);
1010
$stripe_secret_key = mysqli_real_escape_string($conn, $_GET['stripe:private_key']);
11-
$coin_per_balance = mysqli_real_escape_string($conn, $_GET['stripe:coin_per_balance']);
12-
$stripe_currency = strtolower(mysqli_real_escape_string($conn, $_GET['stripe:stripe_currency']));
1311
mysqli_query($conn, "UPDATE `mythicaldash_settings` SET `enable_stripe` = '" . $enable_stripe . "' WHERE `mythicaldash_settings`.`id` = 1;");
1412
mysqli_query($conn, "UPDATE `mythicaldash_settings` SET `stripe_publishable_key` = '" . $stripe_publishable_key . "' WHERE `mythicaldash_settings`.`id` = 1;");
1513
mysqli_query($conn, "UPDATE `mythicaldash_settings` SET `stripe_secret_key` = '" . $stripe_secret_key . "' WHERE `mythicaldash_settings`.`id` = 1;");
16-
mysqli_query($conn, "UPDATE `mythicaldash_settings` SET `coin_per_balance` = '" . $coin_per_balance . "' WHERE `mythicaldash_settings`.`id` = 1;");
17-
mysqli_query($conn, "UPDATE `mythicaldash_settings` SET `payments_currency` = '" . $stripe_currency . "' WHERE `mythicaldash_settings`.`id` = 1;");
1814
header('location: /admin/settings?s=We updated the settings inside the database');
1915
$conn->close();
2016
die ();

view/stripe/buy_coins.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
header('location: /');
1212
die();
1313
}
14-
14+
function convertToCents($amount) {
15+
return round($amount * 100);
16+
}
1517
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
1618
if (isset($_GET['paystripe'])) {
1719
$mypaymentkey = Encryption::generate_keynoinfo();
@@ -29,7 +31,7 @@
2931
"quantity" => 1,
3032
"price_data" => [
3133
"currency" => strtolower(SettingsManager::getSetting('payments_currency')),
32-
"unit_amount" => intval(SettingsManager::getSetting('coin_per_balance')) * intval($_GET['coins']),
34+
"unit_amount" => intval(convertToCents(SettingsManager::getSetting('coin_per_balance'))) * intval($_GET['coins']),
3335
"product_data" => [
3436
"images" => [
3537
$appURL . "/assets/img/illustrations/page-pricing-standard.png"
@@ -175,7 +177,7 @@
175177

176178
<script src="<?= $appURL ?>/assets/js/user/paymentss-ecommerce.js"></script>
177179
<script
178-
src="https://www.paypal.com/sdk/js?client-id=<?= SettingsManager::getSetting('paypal_client_id') ?>&currency=EUR"></script>
180+
src="https://www.paypal.com/sdk/js?client-id=<?= SettingsManager::getSetting('paypal_client_id') ?>&currency=<?= strtoupper(SettingsManager::getSetting('payments_currency')) ?>"></script>
179181
<script>
180182
var key = "";
181183
paypal.Buttons({

0 commit comments

Comments
 (0)