diff --git a/resources/views/checkout/buy.blade.php b/resources/views/checkout/buy.blade.php index cb36c03..525fc4c 100755 --- a/resources/views/checkout/buy.blade.php +++ b/resources/views/checkout/buy.blade.php @@ -1,91 +1,301 @@ @extends('layouts.app') + @section('content') -
- SonarDesk -

Choose your licence

-

Every subscription starts with a 7-day free trial. Cancel before the trial ends and you won't be charged.

- @if($paddleEnvironment === 'sandbox')
Sandbox checkout — no real payment is taken
@endif -
+
+ SonarDesk +

Choose your licence

+

+ Every subscription starts with a 7-day free trial. + Cancel before the trial ends and you won't be charged. +

-
-@foreach($plans as $code => $plan) -
-
-
-
-

{{ $plan['name'] }}

-
{{ $plan['billing'] }} billing
-
- @if($plan['billing'] === 'Annual')Best value@endif + @if($paddleEnvironment === 'sandbox') +
+ Sandbox checkout — no real payment is taken
-
{{ $plan['display_price'] }}
-
    -
  • 7-day free trial
  • -
  • {{ $plan['activation_limit'] }} active Mac{{ $plan['activation_limit'] === 1 ? '' : 's' }}
  • -
  • Secure online activation
  • -
  • Licence management portal
  • -
-
- -
-@endforeach -
+ @endif +
- +
+ @foreach($plans as $code => $plan) +
+
+
+
+

{{ $plan['name'] }}

+
{{ $plan['billing'] }} billing
+
- - + + + + try { + if (environment === 'sandbox') { + Paddle.Environment.set('sandbox'); + } + + Paddle.Initialize({ + token: token, + eventCallback: logPaddleEvent + }); + + console.log('Paddle initialized successfully.'); + } catch (error) { + console.error('PADDLE INITIALIZATION ERROR:', error); + + showCheckoutError( + error?.message || 'Paddle could not be initialized.' + ); + + return; + } + + const priceElements = new Map( + Array.from( + document.querySelectorAll('[data-price-display]') + ).map(element => [ + element.dataset.priceDisplay, + element + ]) + ); + + const previewItems = Array.from(priceElements.keys()).map(priceId => ({ + priceId: priceId, + quantity: 1 + })); + + console.log('PADDLE PRICE PREVIEW ITEMS:', previewItems); + + Paddle.PricePreview({ + items: previewItems + }) + .then(result => { + console.log('PADDLE PRICE PREVIEW RESULT:', result); + + for (const item of (result?.data?.details?.lineItems ?? [])) { + const element = priceElements.get(item?.price?.id); + + const formatted = + item?.formattedTotals?.total ?? + item?.formattedUnitTotals?.total; + + if (!element || !formatted) { + continue; + } + + const suffix = + element.dataset.billing === 'annual' + ? ' / year' + : ' / month'; + + element.textContent = formatted + suffix; + } + }) + .catch(error => { + console.error('PADDLE PRICE PREVIEW ERROR:', error); + + // Server-rendered GBP price remains visible. + }); + + document + .querySelectorAll('.checkout-button') + .forEach(button => { + button.addEventListener('click', () => { + const priceId = button.dataset.priceId; + const plan = button.dataset.plan; + + console.log('OPENING PADDLE CHECKOUT:', { + environment: environment, + priceId: priceId, + plan: plan + }); + + errorPanel.hidden = true; + + try { + Paddle.Checkout.open({ + items: [ + { + priceId: priceId, + quantity: 1 + } + ], + + settings: { + displayMode: 'overlay', + theme: window.matchMedia( + '(prefers-color-scheme: dark)' + ).matches + ? 'dark' + : 'light', + allowLogout: false + }, + + customData: { + source: 'sonardesk-buy-page', + plan: plan + } + }); + } catch (error) { + console.error( + 'PADDLE CHECKOUT OPEN ERROR:', + error + ); + + showCheckoutError( + error?.message || + 'Paddle could not open the checkout.' + ); + } + }); + }); + })(); + @endsection