Skip to content

Commit

Permalink
PUSH
Browse files Browse the repository at this point in the history
-> Some of the paypal integration on the way!
  • Loading branch information
NaysKutzu committed Feb 28, 2024
1 parent 5d3f301 commit 444c812
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 28 deletions.
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,10 @@
"psr-4": {
"MythicalDash\\": "app/"
}
},
"config": {
"allow-plugins": {
"php-http/discovery": true
}
}
}
1 change: 1 addition & 0 deletions include/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
$appURL = $prot . '://' . $svhost;

$lang = Main::getLang();
define("APP_URL", $appURL);

date_default_timezone_set(SettingsManager::getSetting('timezone'));
?>
2 changes: 1 addition & 1 deletion lang/de_DE.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
"already_claimed" => "Der Benutzer hat seine Münzen bereits erhalten!",
"payment_request_cancel" => "Wir haben den Zahlungscode abgebrochen",
"code_not_valid" => "Dieser Code ist ungültig",
"stripe_title" => "Münzen kaufen mit Stripe",
"stripe_title" => "Münzen kaufen",
"stripe_subtitle" => "<p>Willkommen in unserem Abrechnungssystem. Hier können Sie Münzen kaufen, damit Sie sie in unserem Dashboard verwenden können</p> <p>Die Preise betragen '%PLACEHOLDER_1%' in %PLACEHOLDER_2% für 1 Münze</p>",
"server_active" => "Wir haben Ihre Servereinstellungen aktualisiert. Ihr Server überspringt nun die nächste Bereinigung.",
"server_not_own" => "Es tut uns leid, aber Sie besitzen diesen Server nicht!",
Expand Down
2 changes: 1 addition & 1 deletion lang/en_US.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
"already_claimed" => "The user already got his coins!",
"payment_request_cancel" => "We canceled the payment code",
"code_not_valid" => "This code is not valid",
"stripe_title" => "Buy Coins Using Stripe",
"stripe_title" => "Buy Coins",
"stripe_subtitle" => "<p>Welcome to our billing system. Here you can buy coins, so you can use them inside our dashboard</p> <p>The prices are '%PLACEHOLDER_1%' in %PLACEHOLDER_2% for 1 coin</p>",
"server_active" => "We've updated your server settings. Your server will now skip the next purge.",
"server_not_own" => "Sorry but you don't own this server!",
Expand Down
2 changes: 1 addition & 1 deletion lang/fr_FR.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
"already_claimed" => "L'utilisateur a déjà reçu ses pièces!",
"payment_request_cancel" => "Nous avons annulé le code de paiement",
"code_not_valid" => "Ce code n'est pas valide",
"stripe_title" => "Acheter des pièces avec Stripe",
"stripe_title" => "Acheter des pièces",
"stripe_subtitle" => "<p>Bienvenue dans notre système de facturation. Ici vous pouvez acheter des pièces, afin de les utiliser dans notre tableau de bord</p> <p>Les prix sont '%PLACEHOLDER_1%' dans %PLACEHOLDER_2% pour 1 pièce.</p>",
"server_active" => "Nous avons mis à jour les paramètres de votre serveur. Votre serveur ignorera désormais la prochaine purge.",
"server_not_own" => "Désolé, mais ce serveur ne vous appartient pas !",
Expand Down
2 changes: 1 addition & 1 deletion lang/ro_RO.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
"already_claimed" => "Utilizatorul și-a primit deja monedele!",
"payment_request_cancel" => "Am anulat codul de plată",
"code_not_valid" => "Acest cod nu este valid",
"stripe_title" => "Cumpără monede folosind Stripe",
"stripe_title" => "Cumpără monede",
"stripe_subtitle" => "<p>Bine ai venit în sistemul nostru de facturare. Aici poți cumpăra monede, astfel încât să le poți utiliza în panoul nostru de control</p> <p>Prețurile sunt '%PLACEHOLDER_1%' în %PLACEHOLDER_2% pentru 1 monedă</p>",
"server_active" => "Am actualizat setările serverului tău. Serverul tău va sări peste următoarea purgare.",
"server_not_own" => "Regret, dar nu ești proprietarul acestui server!",
Expand Down
1 change: 1 addition & 0 deletions migrate/69.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `mythicaldash_settings` ADD `allow_payments` ENUM('true','false') NOT NULL DEFAULT 'false' AFTER `discord_webhook`;
1 change: 1 addition & 0 deletions migrate/70.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `mythicaldash_settings` ADD `enable_paypal` ENUM('true','false') NOT NULL DEFAULT 'false' AFTER `stripe_currency`, ADD `paypal_client_id` TEXT NULL DEFAULT NULL AFTER `enable_paypal`, ADD `paypal_client_secret` TEXT NULL DEFAULT NULL AFTER `paypal_client_id`;
3 changes: 3 additions & 0 deletions migrate/71.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE `mythicaldash_settings`
DROP `paypal_client_id`,
DROP `paypal_client_secret`;
1 change: 1 addition & 0 deletions migrate/72.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `mythicaldash_settings` ADD `paypal_username` TEXT NULL DEFAULT NULL AFTER `enable_paypal`, ADD `paypal_password` TEXT NULL DEFAULT NULL AFTER `paypal_username`, ADD `paypal_signature` TEXT NULL DEFAULT NULL AFTER `paypal_password`;
1 change: 1 addition & 0 deletions migrate/73.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `mythicaldash_settings` ADD `paypal_sandbox` ENUM('true','false') NOT NULL DEFAULT 'true' AFTER `paypal_signature`;
2 changes: 1 addition & 1 deletion routes/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
require("../view/store.php");
});

$router->add("/store/buy/stripe/coins", function () {
$router->add("/store/buy/coins", function () {
require("../include/main.php");
require("../view/stripe/buy_coins.php");
});
Expand Down
4 changes: 2 additions & 2 deletions view/store.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@
?>
</div>
<?php
if (SettingsManager::getSetting("enable_stripe") == "true") {
if (SettingsManager::getSetting("allow_payments") == "true") {
?>
<div class="alert alert-warning" role="alert">
<?= $lang['store_not_have_enough_coins'] ?> <a href="/store/buy/stripe/coins">
<?= $lang['store_not_have_enough_coins'] ?> <a href="/store/buy/coins">
<?= $lang['store_wana_buy_coins'] ?>
</a>
</div>
Expand Down
124 changes: 105 additions & 19 deletions view/stripe/buy_coins.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use MythicalDash\Encryption;
use MythicalDash\ErrorHandler;
use MythicalDash\SettingsManager;
use MythicalDash\PayPal\Payment;

$csrf = new MythicalDash\CSRF();

Expand All @@ -10,17 +11,17 @@
header('location: /');
}
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (isset($_GET['pay'])) {
if (isset($_GET['paystripe'])) {
$mypaymentkey = Encryption::generate_keynoinfo();
$conn->query("INSERT INTO `mythicaldash_payments` (`code`, `coins`, `ownerkey`, `getaway`, `status`) VALUES ('".mysqli_real_escape_string($conn,$mypaymentkey)."', '".mysqli_real_escape_string($conn, $_GET['coins'])."', '".mysqli_real_escape_string($conn, $_COOKIE['token'])."', 'stripe', 'pending');");
$conn->query("INSERT INTO `mythicaldash_payments` (`code`, `coins`, `ownerkey`, `getaway`, `status`) VALUES ('" . mysqli_real_escape_string($conn, $mypaymentkey) . "', '" . mysqli_real_escape_string($conn, $_GET['coins']) . "', '" . mysqli_real_escape_string($conn, $_COOKIE['token']) . "', 'stripe', 'pending');");
try {
//stripe_secret_key
\Stripe\Stripe::setApiKey(SettingsManager::getSetting('stripe_secret_key'));
$checkout_session = \Stripe\Checkout\Session::create([
"mode" => "payment",
'customer_email' => $session->getUserInfo('email'),
"success_url" => "" . $appURL . "/store/get/stripe/coins?code=".$mypaymentkey,
"cancel_url" => "" . $appURL . "/user/payments?e=".$lang['payment_request_cancel'],
"success_url" => "" . $appURL . "/store/get/stripe/coins?code=" . $mypaymentkey,
"cancel_url" => "" . $appURL . "/user/payments?e=" . $lang['payment_request_cancel'],
"line_items" => [
[
"quantity" => 1,
Expand All @@ -42,7 +43,7 @@
header("location: " . $checkout_session->url);
die();
} catch (Exception $e) {
header("location: /user/payments?e=Stripe Error".$e);
header("location: /user/payments?e=Stripe Error" . $e);
ErrorHandler::Error("Stripe Error ", $e);
die();
}
Expand All @@ -61,26 +62,38 @@
content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
<?php include(__DIR__ . '/../requirements/head.php'); ?>
<title>
<?= SettingsManager::getSetting("name") ?> - <?= $lang['buy_coins']?>
<?= SettingsManager::getSetting("name") ?> -
<?= $lang['buy_coins'] ?>
</title>
<link rel="stylesheet" href="<?= $appURL ?>/assets/vendor/css/pages/page-help-center.css" />
<style>
.custom-paypal-button {
background-color: #161931 !important;
background: #161931 !important;
}

</style>
</head>

<body>
<?php
if (SettingsManager::getSetting("show_snow") == "true") {
include(__DIR__ . '/../components/snow.php');
}
?>
<?php
if (SettingsManager::getSetting("show_snow") == "true") {
include(__DIR__ . '/../components/snow.php');
}
?>

<div class="layout-wrapper layout-content-navbar">
<div class="layout-container">
<?php include(__DIR__ . '/../components/sidebar.php') ?>
<div class="layout-page">
<?php include(__DIR__ . '/../components/navbar.php') ?>
<div class="content-wrapper">
<div class="container-xxl flex-grow-1 container-p-y">
<h4 class="fw-bold py-3 mb-4"><span class="text-muted fw-light"><?= $lang['store']?> / </span> <?= $lang['coins']?></h4>
<h4 class="fw-bold py-3 mb-4"><span class="text-muted fw-light">
<?= $lang['store'] ?> /
</span>
<?= $lang['coins'] ?>
</h4>
<?php include(__DIR__ . '/../components/alert.php') ?>
<div id="ads">
<?php
Expand All @@ -97,19 +110,39 @@
<div class="col-md-12 grid-margin stretch-card">
<div class="card">
<div class="card-header text-center">
<div class="card-title"><?= $lang['stripe_title']?></div>
<div class="card-title">
<?= $lang['stripe_title'] ?>
</div>
</div>
<div class="card-body text-center">
<form method='GET'>
<?=
str_replace(array('%PLACEHOLDER_1%','%PLACEHOLDER_2%'),array(number_format(intval(SettingsManager::getSetting('stripe_coin_per_balance')) / 100, 2), strtoupper(SettingsManager::getSetting('stripe_currency'))), $lang['stripe_subtitle'])
?>
<input type="number" class="form-control mb-2" placeholder="50" value="25"
<?=
str_replace(array('%PLACEHOLDER_1%', '%PLACEHOLDER_2%'), array(number_format(intval(SettingsManager::getSetting('stripe_coin_per_balance')) / 100, 2), strtoupper(SettingsManager::getSetting('stripe_currency'))), $lang['stripe_subtitle'])
?>
<input type="number" id="coins" class="form-control mb-2" placeholder="50" value="25"
name="coins">
<br>
<?= $csrf->input('pay-form'); ?>
<button name="pay" type="subbmit" class="btn btn-primary"><?= $lang['store_buy']?> <?= $lang['coins']?></button>
<?php
if (SettingsManager::getSetting("enable_stripe") == "true") {
?>
<button name="paystripe" type="submit" class="btn btn-primary">
<?= $lang['store_buy'] ?>
<?= $lang['coins'] ?> (Stripe)
</button>
<?php
}
?>
<?php
if (SettingsManager::getSetting('enable_paypal') == 'true') {
?><br><center>
<div id="paypal-button-container" class="mt-3"></div></center>

<?php } ?>

</form>


</div>
</div>
</div>
Expand Down Expand Up @@ -138,5 +171,58 @@
<?php include(__DIR__ . '/../requirements/footer.php') ?>

<script src="<?= $appURL ?>/assets/js/user/paymentss-ecommerce.js"></script>
<script
src="https://www.paypal.com/sdk/js?client-id=<?= SettingsManager::getSetting('paypal_client_id') ?>&currency=EUR"></script>
<script>

paypal.Buttons({
onClick() {
var coins = $('#coins').val();
if (isNaN(coins) || coins === '') {
alert("Please enter a valid number of coins.");
return false;
} else {
var coinPerBalance = parseFloat("<?php echo SettingsManager::getSetting('stripe_coin_per_balance'); ?>");
var price = coins * coinPerBalance;
if (price === 0) {
alert("We failed to fetch the amount of coins inside the textbox please try again later!");
return false;
} else {
alert("Coins: "+coins+"\nPrice: "+price);
}
}
},
createOrder: (data, actions) => {
var coins = $('#coins').val();
var coinPerBalance = parseFloat("<?php echo SettingsManager::getSetting('stripe_coin_per_balance'); ?>");
var price = coins * coinPerBalance;

return actions.order.create({
purchase_units: [{
amount: {
value: price
}
}]
});
},

onApprove: (data,actions) => {
return actions.order.capture().then(function (orderData) {
console.log('Test', orderData, JSON.stringify(orderData, null, 2));
const transaction = orderData.purchase_units[0].payments.captures[0];
alert(`Transaction ${transaction.status}: ${transaction.id}\n\nSee console for all available details!`);
});
},
style: {
color: 'black',
shape: 'pill',
disableMaxWidth: true,
},
onInit: function(data, actions) {
document.querySelector('#paypal-button-container').classList.add('custom-paypal-button');
}
}).render('#paypal-button-container')
</script>


</body>
4 changes: 2 additions & 2 deletions view/user/payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ class="ti-xs ti ti-currency-euro me-1"></i> <?= $lang['payments']?></a>
echo '<td>' . $row['getaway'] . '</td>';
echo '<td>' . $row['status'] . '</td>';
if ($row['status'] == "paid") {
echo '<td><a href="/store/buy/stripe/coins" class="btn btn-primary">'.$lang['buy_again'].'</a></td>';
echo '<td><a href="/store/buy/coins" class="btn btn-primary">'.$lang['buy_again'].'</a></td>';
} else {
echo '<td><a href="/store/buy/stripe/coins" class="btn btn-primary">'.$lang['buy_again'].'</a>&nbsp;<a href="/user/payments/cancel/?id=' . $row['code'] . '" class="btn btn-danger">Cancel</a></td>';
echo '<td><a href="/store/buy/coins" class="btn btn-primary">'.$lang['buy_again'].'</a>&nbsp;<a href="/user/payments/cancel/?id=' . $row['code'] . '" class="btn btn-danger">Cancel</a></td>';
}
echo '</tr>';
}
Expand Down

0 comments on commit 444c812

Please sign in to comment.