Skip to content

Commit

Permalink
gear
Browse files Browse the repository at this point in the history
  • Loading branch information
matronator committed Jan 6, 2024
1 parent 2196881 commit 510f6f1
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 26 deletions.
1 change: 1 addition & 0 deletions app/config/config.local.example.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ parameters:
secret: 'secret_key'
appUrl: 'https://global-collapse.com'
webhookSecret: 'webhook_secret'
devMode: true
darknetUpdate:
hash: '2Rc9XqqWXa3ur4iiL5IKox782'
confirm: 'aRXPKmm1Fgzyy6m4z2LZgii1q'
Expand Down
2 changes: 0 additions & 2 deletions app/config/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
5 changes: 4 additions & 1 deletion app/model/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions app/modules/Front/components/Assault/AttackerCard.latte
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
small => true,
name => 'attackerHp'
}
<div class="uk-width-expand uk-flex" n:if="$attackerGearStats->armor > 0">
{include '../../components/UI/ProgressBar/ProgressBar.latte',
min => 0,
max => $attackerGearStats->armor,
value => $attackerGearStats->armor,
type => 'gray',
small => true,
tooltip => 'Armor',
name => 'playerArmor'
}
</div>
<div class="split">
<div class="uk-width-auto">
<div class="{if $attacker->tier > 1}premium-border tier-{$attacker->tier}{/if}">
Expand Down
14 changes: 13 additions & 1 deletion app/modules/Front/components/Assault/PlayerCard.latte
Original file line number Diff line number Diff line change
Expand Up @@ -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' : ''
}
</div>
<div class="uk-width-expand uk-flex" n:if="$playerGearStats->armor > 0">
{include '../../components/UI/ProgressBar/ProgressBar.latte',
min => 0,
max => $playerGearStats->armor,
value => $playerGearStats->armor,
type => 'gray',
small => true,
tooltip => 'Armor',
name => 'playerArmor'
}
</div>
<div class="split">
Expand Down
11 changes: 11 additions & 0 deletions app/modules/Front/components/Assault/VictimCard.latte
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
small => true,
name => 'victimHp'
}
<div class="uk-width-expand uk-flex" n:if="$victimGearStats->armor > 0">
{include '../../components/UI/ProgressBar/ProgressBar.latte',
min => 0,
max => $victimGearStats->armor,
value => $victimGearStats->armor,
type => 'gray',
small => true,
tooltip => 'Armor',
name => 'playerArmor'
}
</div>
<div class="split">
<div class="uk-width-expand uk-margin-right">
<table class="uk-table uk-table-small uk-table-hover" n:if="!$showStats">
Expand Down
3 changes: 3 additions & 0 deletions app/modules/Front/components/UI/ProgressBar/ProgressBar.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
13 changes: 11 additions & 2 deletions app/modules/Front/presenters/PremiumPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\FrontModule\Presenters;

use App\Services\StripeService;
use Tracy\Debugger;
use VoteCallback;

final class PremiumPresenter extends GamePresenter
Expand All @@ -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()
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions app/modules/Front/presenters/WebhookPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion app/modules/Front/templates/Premium/cancel.latte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<div class="uk-container uk-margin-auto">
<div class="uk-card uk-width-auto uk-card-default uk-card-body">
<h2 class="uk-card-title">Payment Cancelled</h2>
<p>Account not upgraded, because the payment was cancelled. <a n:href="default">Go back.</a></p>
<p n:if="$mode === 'subscription'">Account not upgraded, because the payment was cancelled. <a n:href="default">Go back.</a></p>
<p n:if="$mode === 'payment'">The payment was cancelled. <a n:href="default">Go back.</a></p>
</div>
</div>
{/block}
32 changes: 16 additions & 16 deletions app/modules/Front/templates/Premium/default.latte
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
</div>
<div class="uk-width-1-3@s uk-width-1-1">
Expand All @@ -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',
}
</div>
{else}
Expand Down Expand Up @@ -122,59 +122,59 @@
client-reference-id="{$user->username}"
></stripe-pricing-table> *}
</div>
<div class="uk-width-1-4@s uk-width-1-1">
<div class="uk-width-1-3@s uk-width-1-1">
{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',
}
</div>
<div class="uk-width-1-4@s uk-width-1-1">
<div class="uk-width-1-3@s uk-width-1-1">
{include '../../components/UI/Premium/BitcoinCard.latte',
amount: 25,
price: 10,
priceId: '',
priceId: $dev ? '' : 'price_1NqL8JJJBQOBYTuQh0ZFjANY',
img: $basePath . '/dist/front/images/premium/25btc.jpg',
}
</div>
<div class="uk-width-1-4@s uk-width-1-1">
{* <div class="uk-width-1-3@s uk-width-1-1">
{include '../../components/UI/Premium/BitcoinCard.latte',
amount: 50,
price: 20,
priceId: '',
img: $basePath . '/dist/front/images/premium/50btc.jpg',
}
</div>
<div class="uk-width-1-4@s uk-width-1-1">
</div> *}
<div class="uk-width-1-3@s uk-width-1-1">
{include '../../components/UI/Premium/BitcoinCard.latte',
amount: 100,
price: 40,
priceId: '',
priceId: $dev ? '' : 'price_1NqL9KJJBQOBYTuQ5E7hRMRR',
img: $basePath . '/dist/front/images/premium/100btc.jpg',
}
</div>
<div class="uk-width-1-4@s uk-width-1-1">
<div class="uk-width-1-3@s uk-width-1-1">
{include '../../components/UI/Premium/BitcoinCard.latte',
amount: 250,
price: 90,
priceId: '',
priceId: $dev ? '' : 'price_1NqLAVJJBQOBYTuQ2XOmPbiq',
img: $basePath . '/dist/front/images/premium/250btc.jpg',
}
</div>
<div class="uk-width-1-4@s uk-width-1-1">
<div class="uk-width-1-3@s uk-width-1-1">
{include '../../components/UI/Premium/BitcoinCard.latte',
amount: 500,
price: 175,
priceId: '',
priceId: $dev ? '' : 'price_1NqLBDJJBQOBYTuQ2k1qW6jX',
img: $basePath . '/dist/front/images/premium/500btc.jpg',
}
</div>
<div class="uk-width-1-4@s uk-width-1-1">
<div class="uk-width-1-3@s uk-width-1-1">
{include '../../components/UI/Premium/BitcoinCard.latte',
amount: 1000,
price: 330,
priceId: '',
priceId: $dev ? '' : 'price_1NqLDFJJBQOBYTuQD2KtlE3T',
img: $basePath . '/dist/front/images/premium/1000btc.jpg',
}
</div>
Expand Down
3 changes: 2 additions & 1 deletion app/modules/Front/templates/Premium/success.latte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<div class="uk-container uk-margin-auto">
<div class="uk-card uk-width-auto uk-card-default uk-card-body">
<h2 class="uk-card-title">Payment Successful</h2>
<p>Account was upgraded! <a n:href="default">Go back.</a></p>
<p n:if="$mode === 'subscription'">Account was upgraded! <a n:href="default">Go back.</a></p>
<p n:if="$mode === 'payment'">Bitcoins purchased! <a n:href="default">Go back.</a></p>
</div>
</div>
{/block}
7 changes: 5 additions & 2 deletions app/services/StripeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class StripeService
public string $publicKey;
public string $webhookSecret;
private string $secretKey;
public bool $devMode;

public string $appUrl;

Expand All @@ -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);
Expand Down Expand Up @@ -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') {
Expand Down

0 comments on commit 510f6f1

Please sign in to comment.