From 510f6f16e97b01b6b2887fbcfa21b01d340b81d9 Mon Sep 17 00:00:00 2001
From: Matronator <5470780+matronator@users.noreply.github.com>
Date: Sat, 6 Jan 2024 20:03:34 +0100
Subject: [PATCH] gear
---
app/config/config.local.example.neon | 1 +
app/config/config.neon | 2 --
app/model/UserRepository.php | 5 ++-
.../components/Assault/AttackerCard.latte | 11 +++++++
.../Front/components/Assault/PlayerCard.latte | 14 +++++++-
.../Front/components/Assault/VictimCard.latte | 11 +++++++
.../components/UI/ProgressBar/ProgressBar.css | 3 ++
.../Front/presenters/PremiumPresenter.php | 13 ++++++--
.../Front/presenters/WebhookPresenter.php | 1 +
.../Front/templates/Premium/cancel.latte | 3 +-
.../Front/templates/Premium/default.latte | 32 +++++++++----------
.../Front/templates/Premium/success.latte | 3 +-
app/services/StripeService.php | 7 ++--
13 files changed, 80 insertions(+), 26 deletions(-)
diff --git a/app/config/config.local.example.neon b/app/config/config.local.example.neon
index 9e0d899..4ff40c6 100644
--- a/app/config/config.local.example.neon
+++ b/app/config/config.local.example.neon
@@ -15,6 +15,7 @@ parameters:
secret: 'secret_key'
appUrl: 'https://global-collapse.com'
webhookSecret: 'webhook_secret'
+ devMode: true
darknetUpdate:
hash: '2Rc9XqqWXa3ur4iiL5IKox782'
confirm: 'aRXPKmm1Fgzyy6m4z2LZgii1q'
diff --git a/app/config/config.neon b/app/config/config.neon
index 5f8b21a..7e17bca 100755
--- a/app/config/config.neon
+++ b/app/config/config.neon
@@ -51,8 +51,6 @@ services:
payment: App\Services\PaymentService(%psp%)
nette.latteFactory:
setup:
- # - addFilter(NULL, 'App\Filter\StaticFilters::common')
- # - addFilter('imageGenerator', '@App\Filter\ImageFilter')
- addFilter('fromSnake', 'App\Filter\StaticFilters::fromSnake')
- addFilter('firstLower', 'App\Filter\StaticFilters::firstLower')
- addFilter('time', 'App\Filter\StaticFilters::time')
diff --git a/app/model/UserRepository.php b/app/model/UserRepository.php
index 6e98719..fecfd09 100755
--- a/app/model/UserRepository.php
+++ b/app/model/UserRepository.php
@@ -123,7 +123,7 @@ public static function getModifiedDuration($time, int $modifier = 100): int
public static function getPremiumDuration($time, int $tier): int
{
- return self::getModifiedDuration($time, $tier === 3 ? 50 : ($tier === 2 ? 25 : 100));
+ return self::getModifiedDuration($time, $tier === 3 ? 50 : 0);
}
public function findAllActions()
@@ -357,6 +357,9 @@ public function addXp(int $id, $xp) {
}
$player = $this->getUser($id);
+ if ($player->tier > 1) {
+ $xp = (int) floor($xp * ($player->tier === 2 ? 1.25 : 1.5));
+ }
$xpNow = $player->player_stats->xp;
$xpMax = $player->player_stats->xp_max;
$level = $player->player_stats->level;
diff --git a/app/modules/Front/components/Assault/AttackerCard.latte b/app/modules/Front/components/Assault/AttackerCard.latte
index 027709d..32817d9 100644
--- a/app/modules/Front/components/Assault/AttackerCard.latte
+++ b/app/modules/Front/components/Assault/AttackerCard.latte
@@ -28,6 +28,17 @@
small => true,
name => 'attackerHp'
}
+
+ {include '../../components/UI/ProgressBar/ProgressBar.latte',
+ min => 0,
+ max => $attackerGearStats->armor,
+ value => $attackerGearStats->armor,
+ type => 'gray',
+ small => true,
+ tooltip => 'Armor',
+ name => 'playerArmor'
+ }
+
diff --git a/app/modules/Front/components/Assault/PlayerCard.latte b/app/modules/Front/components/Assault/PlayerCard.latte
index 84bd94a..81074e0 100644
--- a/app/modules/Front/components/Assault/PlayerCard.latte
+++ b/app/modules/Front/components/Assault/PlayerCard.latte
@@ -22,7 +22,19 @@
value => ($player->player_stats->stamina + $playerGearStats->stamina) * 2,
type => 'red',
small => true,
- name => 'playerHP'
+ name => 'playerHP',
+ class => $playerGearStats->armor > 0 ? 'uk-margin-remove-bottom' : ''
+ }
+
+
+ {include '../../components/UI/ProgressBar/ProgressBar.latte',
+ min => 0,
+ max => $playerGearStats->armor,
+ value => $playerGearStats->armor,
+ type => 'gray',
+ small => true,
+ tooltip => 'Armor',
+ name => 'playerArmor'
}
diff --git a/app/modules/Front/components/Assault/VictimCard.latte b/app/modules/Front/components/Assault/VictimCard.latte
index b7c551e..61be0c1 100644
--- a/app/modules/Front/components/Assault/VictimCard.latte
+++ b/app/modules/Front/components/Assault/VictimCard.latte
@@ -28,6 +28,17 @@
small => true,
name => 'victimHp'
}
+
+ {include '../../components/UI/ProgressBar/ProgressBar.latte',
+ min => 0,
+ max => $victimGearStats->armor,
+ value => $victimGearStats->armor,
+ type => 'gray',
+ small => true,
+ tooltip => 'Armor',
+ name => 'playerArmor'
+ }
+
diff --git a/app/modules/Front/components/UI/ProgressBar/ProgressBar.css b/app/modules/Front/components/UI/ProgressBar/ProgressBar.css
index 6382330..c5fc39c 100644
--- a/app/modules/Front/components/UI/ProgressBar/ProgressBar.css
+++ b/app/modules/Front/components/UI/ProgressBar/ProgressBar.css
@@ -47,6 +47,9 @@
.progress-bar.red .progress-bar-fill {
background: var(--c-red);
}
+.progress-bar.gray .progress-bar-fill {
+ background: var(--c-light-5);
+}
.progress-bar.yellow .progress-bar-value {
color: var(--black);
}
diff --git a/app/modules/Front/presenters/PremiumPresenter.php b/app/modules/Front/presenters/PremiumPresenter.php
index c857a2c..d164b32 100644
--- a/app/modules/Front/presenters/PremiumPresenter.php
+++ b/app/modules/Front/presenters/PremiumPresenter.php
@@ -5,6 +5,7 @@
namespace App\FrontModule\Presenters;
use App\Services\StripeService;
+use Tracy\Debugger;
use VoteCallback;
final class PremiumPresenter extends GamePresenter
@@ -23,12 +24,13 @@ public function __construct(
protected function startup()
{
parent::startup();
- $this->redirect('Default:default');
+ // $this->redirect('Default:default');
}
public function renderDefault()
{
$this->template->stripePublicKey = $this->stripeService->publicKey;
+ $this->template->dev = $this->stripeService->devMode;
}
public function renderManage()
@@ -39,11 +41,18 @@ public function renderManage()
$this->template->stripePublicKey = $this->stripeService->publicKey;
}
- public function renderSuccess(string $sessionId = null)
+ public function renderSuccess(string $sessionId = null, ?string $mode = null)
{
if (!$sessionId) {
$this->redirect('default');
}
+
+ $this->template->mode = $mode;
+ }
+
+ public function renderCancel(?string $mode = null)
+ {
+ $this->template->mode = $mode;
}
public function handleUpgradeAccount(string $item)
diff --git a/app/modules/Front/presenters/WebhookPresenter.php b/app/modules/Front/presenters/WebhookPresenter.php
index 85ae7c6..3116728 100644
--- a/app/modules/Front/presenters/WebhookPresenter.php
+++ b/app/modules/Front/presenters/WebhookPresenter.php
@@ -145,6 +145,7 @@ private function checkoutSessionCompleted($event)
http_response_code(200);
die;
}
+ $this->stripeOrdersRepository->saveOrder($session, $event->type);
if ($session->payment_status === 'paid') {
if ($session->mode === 'subscription') {
$price = Price::retrieve($session->line_items->data[0]->price->id);
diff --git a/app/modules/Front/templates/Premium/cancel.latte b/app/modules/Front/templates/Premium/cancel.latte
index a457cd7..188a6c6 100644
--- a/app/modules/Front/templates/Premium/cancel.latte
+++ b/app/modules/Front/templates/Premium/cancel.latte
@@ -6,7 +6,8 @@
Payment Cancelled
-
Account not upgraded, because the payment was cancelled. Go back.
+
Account not upgraded, because the payment was cancelled. Go back.
+
The payment was cancelled. Go back.
{/block}
diff --git a/app/modules/Front/templates/Premium/default.latte b/app/modules/Front/templates/Premium/default.latte
index ed6947b..a3203a2 100644
--- a/app/modules/Front/templates/Premium/default.latte
+++ b/app/modules/Front/templates/Premium/default.latte
@@ -58,7 +58,7 @@
playerTier: $user->tier,
img: $basePath . '/dist/front/images/premium/survivor.jpg',
imgAlt: 'Survivor Premium Account',
- priceId: 'price_1NpXM1JJBQOBYTuQNyUN0T86',
+ priceId: $dev ? 'price_1NpXM1JJBQOBYTuQNyUN0T86' : 'price_1NpXalJJBQOBYTuQitS7mpvM',
}
@@ -70,7 +70,7 @@
playerTier: $user->tier,
img: $basePath . '/dist/front/images/premium/immune.jpg',
imgAlt: 'Immune Premium Account',
- priceId: 'price_1NpXMPJJBQOBYTuQ4geLaLqp',
+ priceId: $dev ? 'price_1NpXMPJJBQOBYTuQ4geLaLqp' : 'price_1NpglSJJBQOBYTuQYA000C56',
}
{else}
@@ -122,59 +122,59 @@
client-reference-id="{$user->username}"
> *}
-
+
{include '../../components/UI/Premium/BitcoinCard.latte',
amount: 10,
price: 5,
- priceId: 'price_1Nx8jXJJBQOBYTuQD2Dd9kFk',
+ priceId: $dev ? 'price_1Nx8jXJJBQOBYTuQD2Dd9kFk' : 'price_1NqL7bJJBQOBYTuQvVhwLcOj',
img: $basePath . '/dist/front/images/premium/10btc.jpg',
}
-
+
{include '../../components/UI/Premium/BitcoinCard.latte',
amount: 25,
price: 10,
- priceId: '',
+ priceId: $dev ? '' : 'price_1NqL8JJJBQOBYTuQh0ZFjANY',
img: $basePath . '/dist/front/images/premium/25btc.jpg',
}
-
+ {*
{include '../../components/UI/Premium/BitcoinCard.latte',
amount: 50,
price: 20,
priceId: '',
img: $basePath . '/dist/front/images/premium/50btc.jpg',
}
-
-
+
*}
+
{include '../../components/UI/Premium/BitcoinCard.latte',
amount: 100,
price: 40,
- priceId: '',
+ priceId: $dev ? '' : 'price_1NqL9KJJBQOBYTuQ5E7hRMRR',
img: $basePath . '/dist/front/images/premium/100btc.jpg',
}
-
+
{include '../../components/UI/Premium/BitcoinCard.latte',
amount: 250,
price: 90,
- priceId: '',
+ priceId: $dev ? '' : 'price_1NqLAVJJBQOBYTuQ2XOmPbiq',
img: $basePath . '/dist/front/images/premium/250btc.jpg',
}
-
+
{include '../../components/UI/Premium/BitcoinCard.latte',
amount: 500,
price: 175,
- priceId: '',
+ priceId: $dev ? '' : 'price_1NqLBDJJBQOBYTuQ2k1qW6jX',
img: $basePath . '/dist/front/images/premium/500btc.jpg',
}
-
+
{include '../../components/UI/Premium/BitcoinCard.latte',
amount: 1000,
price: 330,
- priceId: '',
+ priceId: $dev ? '' : 'price_1NqLDFJJBQOBYTuQD2KtlE3T',
img: $basePath . '/dist/front/images/premium/1000btc.jpg',
}
diff --git a/app/modules/Front/templates/Premium/success.latte b/app/modules/Front/templates/Premium/success.latte
index 7bfbc90..7325482 100644
--- a/app/modules/Front/templates/Premium/success.latte
+++ b/app/modules/Front/templates/Premium/success.latte
@@ -6,7 +6,8 @@
{/block}
diff --git a/app/services/StripeService.php b/app/services/StripeService.php
index 9215b1a..a8ebf8e 100644
--- a/app/services/StripeService.php
+++ b/app/services/StripeService.php
@@ -17,6 +17,7 @@ class StripeService
public string $publicKey;
public string $webhookSecret;
private string $secretKey;
+ public bool $devMode;
public string $appUrl;
@@ -28,6 +29,7 @@ public function __construct(array $config)
$this->secretKey = $config['secret'];
$this->appUrl = $config['appUrl'];
$this->webhookSecret = $config['webhookSecret'];
+ $this->devMode = $config['devMode'];
Stripe::setApiKey($this->secretKey);
$this->stripeClient = new StripeClient($this->secretKey);
@@ -83,9 +85,10 @@ public function createCheckoutSession(string $priceId, ActiveRow $user, string $
'mode' => $mode,
'metadata' => [
'user_id' => $user->id,
+ 'mode' => $mode,
],
- 'success_url' => $this->appUrl . '/premium/success?sessionId={CHECKOUT_SESSION_ID}',
- 'cancel_url' => $this->appUrl . '/premium/cancel',
+ 'success_url' => $this->appUrl . '/premium/success?mode=' . $mode . '&sessionId={CHECKOUT_SESSION_ID}',
+ 'cancel_url' => $this->appUrl . '/premium/cancel?mode=' . $mode,
]);
if ($mode === 'subscription') {