Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ilestis committed Oct 31, 2024
2 parents b81a619 + 6ef3493 commit 96626ba
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 35 deletions.
4 changes: 1 addition & 3 deletions app/Http/Controllers/Locations/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public function index(Campaign $campaign, Location $location)
return $this->campaign($campaign)->datagridAjax();
}

/*return $this
->campaign($campaign)
->subview('locations.events', $location);*/
return redirect()->to($location->getLink());
}
}
18 changes: 17 additions & 1 deletion app/Http/Controllers/PayPalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

namespace App\Http\Controllers;

use App\Enums\PricingPeriod;
use App\Models\Tier;
use App\Models\TierPrice;
use Illuminate\Http\Request;
use App\Services\PayPalService;
use App\Http\Requests\ValidatePledge;
use Illuminate\Support\Facades\Log;
use Srmklive\PayPal\Services\PayPal as PayPalClient;

class PayPalController extends Controller
Expand Down Expand Up @@ -62,16 +65,29 @@ public function successTransaction(Request $request)

if (isset($response['status']) && $response['status'] == 'COMPLETED') {
$pledge = $response['purchase_units']['0']['reference_id'];
Log::info('Paypal', $response);
$this->service
->user($request->user())
->subscribe($pledge);
$routeOptions = ['success' => 1];
$flash = 'subscribed';

/** @var ?Tier $tier */
$tier = Tier::where('name', $pledge)->first();
/** @var ?TierPrice $tierPrice */
$tierPrice = $tier->prices()
->where('currency', $request->user()->currency())
->where('period', PricingPeriod::Yearly)
->first();


return redirect()
->route('settings.subscription', $routeOptions)
->with('success', __('settings.subscription.success.subscribed'))
->with('sub_tracking', $flash);
->with('sub_tracking', $flash)
->with('sub_id', $tierPrice?->id)
->with('sub_value', $response['purchase_units']['0']['payments']['captures'][0]['amount']['value'])
;
} else {
return redirect()
->route('settings.subscription')
Expand Down
4 changes: 1 addition & 3 deletions app/Http/Controllers/Quests/QuestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public function index(Campaign $campaign, Quest $quest)
return $this->campaign($campaign)->datagridAjax();
}

return $this
->campaign($campaign)
->subview('quests.quests', $quest);
return redirect()->to($quest->getLink());
}
}
25 changes: 22 additions & 3 deletions app/Http/Controllers/Settings/SubscriptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Http\Requests\Settings\UserSubscribeStore;
use App\Jobs\Users\AbandonedCart;
use App\Models\Tier;
use App\Models\TierPrice;
use App\Services\SubscriptionService;
use App\Services\SubscriptionUpgradeService;
use App\Services\Users\CurrencyService;
Expand Down Expand Up @@ -59,10 +60,11 @@ public function index()
$currency = $user->currencySymbol();
$invoices = !empty($user->stripe_id) ? $user->invoices(true, ['limit' => 3]) : [];
$tracking = session()->get('sub_tracking');
$newSubPricingId = session()->get('sub_id');
$tiers = Tier::with('prices')->ordered()->get();
$isPayPal = $user->hasPayPal();
$hasManual = $user->hasManualSubscription();
$gaTrackingEvent = null;
$gaTrackingEvent = $gaPurchase = null;
if (!empty($tracking)) {
$gaTrackingEvent = 'TJhYCMDErpYDEOaOq7oC';
if ($tracking === 'subscribed') {
Expand All @@ -73,6 +75,19 @@ public function index()
}
}

if (!empty($newSubPricingId)) {
/** @var TierPrice $pricing */
$pricing = TierPrice::find($newSubPricingId);
$gaPurchase = [
'value' => $pricing->cost,
'currency' => $pricing->currency,
'coupon' => session()->get('sub_coupon'),
'item_id' => $pricing->tier->id,
'item_name' => $pricing->tier->name . ($pricing->isYearly() ? ' Yearly' : null),
];
}


return view('settings.subscription.index', compact(
'stripeApiToken',
'status',
Expand All @@ -83,6 +98,7 @@ public function index()
'invoices',
'tracking',
'gaTrackingEvent',
'gaPurchase',
'tiers',
'isPayPal',
'hasManual',
Expand All @@ -99,7 +115,7 @@ public function change(Request $request, Tier $tier)
$period = $request->get('period') === 'yearly' ? PricingPeriod::Yearly : PricingPeriod::Monthly;

// If the user has a cancelled sub still ending
if ($user->subscribed('kanka') && $user->subscription('kanka')->onGracePeriod()) {
if ($user->subscribed('kanka') && $user->subscription('kanka')->onGracePeriod() && !$user->hasPayPal()) {
return view('settings.subscription.change_blocked')
->with('user', $user);
}
Expand Down Expand Up @@ -184,7 +200,10 @@ public function subscribe(UserSubscribeStore $request, Tier $tier)
->route('settings.subscription', $routeOptions)
->withSuccess(__('settings.subscription.success.' . $flash))
->with('sub_tracking', $flash)
->with('sub_value', $this->subscription->subscriptionValue());
->with('sub_value', $this->subscription->subscriptionValue())
->with('sub_coupon', $request->get('coupon'))
->with('sub_id', $this->subscription->tierPrice()->id)
;
} catch (IncompletePayment $exception) {
session()->put('subscription_callback', $request->get('payment_id'));
return redirect()->route(
Expand Down
5 changes: 3 additions & 2 deletions app/Models/EntityLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,17 @@ public function attributeKey(string $transKey, string $attribute): string
// Custom mapping
$custom = [
'header_uuid' => 'fields.header-image.title',
'image_uuid' => 'crud.fields.image',
'is_template' => 'entities/actions.templates.toggle',
'is_attributes_private' => 'entities/attributes.fields.is_private',
];
if (!empty($custom[$name])) {
return __($custom[$name]);
}
if (app()->isProduction()) {
return '<i>' . __('crud.users.unknown') . '</i>';
return '<i data-key="' . $transKey . '" data-attr="' . $name . '">' . __('crud.users.unknown') . '</i>';
}
return '<i>' . $name . '</i>';
return '<i data-key="' . $transKey . '" data-attr="' . $name . '">' . $name . '</i>';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/Services/PayPalService.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public function process(): mixed
$oldPrice = $tier->yearly;
}
// @phpstan-ignore-next-line
$price = (floatval($price) - ($oldPrice)) * ($this->user->subscriptions()->first()->ends_at->diffInDays(Carbon::now()) / 365);
$price = number_format($price, 2);
$price = round(($price - ($oldPrice)) * ($this->user->subscriptions()->first()->ends_at->diffInDays(Carbon::now(), true) / 365), 2);
}
$price = max(0, $price);

$provider = new PayPal();
$provider->setApiCredentials(config('paypal'));
Expand Down
2 changes: 1 addition & 1 deletion app/Services/SubscriptionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ protected function isYearly(): bool
return $this->period === PricingPeriod::Yearly;
}

protected function tierPrice(): TierPrice
public function tierPrice(): TierPrice
{
if (isset($this->tierPrice)) {
return $this->tierPrice;
Expand Down
52 changes: 41 additions & 11 deletions app/Services/Tracking/DatalayerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

namespace App\Services\Tracking;

use App\Facades\AdCache;
use App\Models\Campaign;
use Carbon\Carbon;

class DatalayerService
{
/** @var bool|string */
protected $group = false;
/** Group name: a|b */
protected string $group;

/** @var array Extra parameters to pass */
protected array $additional = [];
Expand All @@ -14,10 +18,12 @@ class DatalayerService
protected bool $newAccount = false;

/** @var bool If the user is newly registered */
protected bool $newSubcriber = false;
protected bool $newSubscriber = false;

/** @var bool If the user is newly cancelled */
protected bool $newCancelledSubcriber = false;
protected bool $newCancelledSubscriber = false;

protected ?Campaign $campaign;

/**
*/
Expand All @@ -30,32 +36,56 @@ public function base(): string
'userSubbed' => false,
'route' => $this->route(),
'newAccount' => $this->newAccount ? '1' : '0',
'newSubscriber' => $this->newSubcriber ? '1' : '0',
'newSubscriber' => $this->newSubscriber ? '1' : '0',
'userID' => null,
], $this->additional);


if (auth()->check()) {
$data['userType'] = 'registered';
$data['userTier'] = !empty(auth()->user()->pledge) ? auth()->user()->pledge : null;
$data['userSubbed'] = !empty(auth()->user()->pledge) ? 'true' : 'false';
$data['userID'] = auth()->user()->id;

if ($this->newCancelledSubcriber) {
if ($this->newCancelledSubscriber) {
$data['newCancelled'] = '1';
}
if ($this->newAccount || $this->newSubcriber) {
if ($this->newAccount || $this->newSubscriber) {
$data['userEmail'] = auth()->user()->email;
}
}

// We only track if ads are shown or hidden on page that are set up to actually serve ads
if (AdCache::canHaveAds()) {
$data['showAds'] = $this->showAds();
}
return json_encode($data);
}

public function campaign(?Campaign $campaign)
{
$this->campaign = $campaign;
return $this;
}

protected function showAds(): bool
{
if ($this->campaign && $this->campaign->boosted()) {
return false;
// } elseif (!AdCache::canHaveAds()) {
// return false;
} elseif (auth()->guest()) {
return true;
} elseif (auth()->user()->isSubscriber()) {
return false;
}
return auth()->user()->created_at->diffInHours(Carbon::now()) > 24;
}

/**
*/
public function userGroup(): string
{
if ($this->group !== false) {
if (isset($this->group)) {
return $this->group;
}
// Set in session? Use that
Expand Down Expand Up @@ -107,7 +137,7 @@ protected function route(): string
*/
public function newSubscriber(): self
{
$this->newSubcriber = true;
$this->newSubscriber = true;
return $this;
}

Expand All @@ -117,7 +147,7 @@ public function newSubscriber(): self
*/
public function newCancelledSubscriber(): self
{
$this->newCancelledSubcriber = true;
$this->newCancelledSubscriber = true;
return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion resources/views/emails/welcome/2024/html.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<p style="font-family: 'Inter', sans-serif; color: #515856; font-size: 16px; line-height: 165%; margin-top: 0; margin-bottom: 10px;"></p>
<p style="font-family: 'Inter', sans-serif; color: #515856; font-size: 16px; line-height: 165%; margin-top: 0; margin-bottom: 10px;">{!! __('emails/welcome/2024.lead_1', ['name' => $user->name]) !!}</p>
<p style="font-family: 'Inter', sans-serif; color: #515856; font-size: 16px; line-height: 165%; margin-top: 0; margin-bottom: 10px;"></p>
<p style="font-family: 'Inter', sans-serif; color: #515856; font-size: 16px; line-height: 165%; margin-top: 0; margin-bottom: 10px;">{!! __('emails/welcome/2024.lead_1', ['name' => $user->name]) !!}</p>
<p style="font-family: 'Inter', sans-serif; color: #515856; font-size: 16px; line-height: 165%; margin-top: 0; margin-bottom: 10px;">{!! __('emails/welcome/2024.lead_2', ['name' => $user->name]) !!}</p>
<p style="font-family: 'Inter', sans-serif; color: #515856; font-size: 16px; line-height: 165%; margin-top: 0; margin-bottom: 0;"></p>
</td>
</tr>
Expand Down
11 changes: 9 additions & 2 deletions resources/views/layouts/error.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@
<link rel="apple-touch-icon" sizes="180x180" href="/images/favicon/apple-touch-icon-180x180.png" />

@if (!config('fontawesome.kit'))<link href="/vendor/fontawesome/6.0.0/css/all.min.css" rel="stylesheet">@endif
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppin">

@if (config('app.asset_url'))
<link rel="dns-prefetch" href="{{ config('app.asset_url') }}">
@endif
<link rel="dns-prefetch" href="//cdnjs.cloudflare.com">
<link rel="dns-prefetch" href="//www.googletagmanager.com">

</head>

Expand Down Expand Up @@ -79,7 +84,7 @@

@if ($error === 404)
<section class="max-w-2xl mx-auto flex flex-col gap-10 lg:gap-10 py-10 lg:py-12 px-4 xl:px-0 text-dark">
<img src="/images/errors/lost.jpeg" alt="Lost" class="rounded-2xl" />
<img src="/images/errors/lost.jpeg" alt="Lost construction kobolds in a swamp" class="rounded-2xl" />
</section>
@endif

Expand All @@ -91,5 +96,7 @@
@if (config('fontawesome.kit'))
<script src="https://kit.fontawesome.com/{{ config('fontawesome.kit') }}.js" crossorigin="anonymous"></script>
@endif

@includeWhen(config('tracking.consent'), 'partials.cookieconsent')
</body>
</html>
21 changes: 15 additions & 6 deletions resources/views/layouts/tracking/tracking.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<script async src="https://www.googletagmanager.com/gtag/js?id={{ config('tracking.ga') }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({!! \App\Facades\DataLayer::base() !!});
dataLayer.push({!! \App\Facades\DataLayer::campaign($campaign ?? null)->base() !!});
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ config('tracking.ga') }}');
Expand All @@ -20,10 +20,19 @@ function gtag(){dataLayer.push(arguments);}
@if (isset($gaTrackingEvent) && !empty($gaTrackingEvent))
<script> gtag('event', 'conversion', {'send_to': '{{ config('tracking.ga_convo') }}/{{ $gaTrackingEvent }}'}); </script>
@endif
@if (isset($gaPurchase) && !empty($gaPurchase))
<script> gtag('event', 'purchase', {
'value': {{ $gaPurchase['value'] }},
'currency': '{{ $gaPurchase['currency'] }}',
'coupon': {{ $gaPurchase['coupon'] ?? 'null' }},
'items': [{
'item_id': '{{ $gaPurchase['item_id'] }}',
'item_name': '{{ $gaPurchase['item_name'] }}',
'price': {{ $gaPurchase['value'] }},
'coupon': {{ $gaPurchase['coupon'] ?? 'null' }},
'quantity': 1,
}]
}); </script>
@endif
<!-- End Google Analytics -->
@endif


@if (\App\Facades\AdCache::canHaveAds())

@endif

0 comments on commit 96626ba

Please sign in to comment.