Skip to content

Commit a13aa41

Browse files
Switch to polar astro package (#3361)
* Switch to polar astro package * Update pricing.astro * Update pricing.astro
1 parent e932ccb commit a13aa41

5 files changed

Lines changed: 77 additions & 69 deletions

File tree

landing/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"dependencies": {
1414
"@astrojs/mdx": "^4.3.13",
1515
"@astrojs/vercel": "^9.0.2",
16-
"@polar-sh/sdk": "^0.20.2",
16+
"@polar-sh/astro": "^0.7.3",
1717
"astro": "^5.17.1",
1818
"shepherd.js": "workspace:*"
1919
},

landing/src/actions/index.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

landing/src/pages/api/checkout.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Checkout } from '@polar-sh/astro';
2+
3+
export const prerender = false;
4+
5+
export const GET = Checkout({
6+
accessToken: import.meta.env.POLAR_ACCESS_TOKEN ?? '',
7+
successUrl: 'https://docs.shepherdjs.dev'
8+
});

landing/src/pages/pricing.astro

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import { SITE_TITLE, SITE_DESCRIPTION } from '../consts';
5353
<button
5454
class="button bg-white border-2 border-navy p-6 text-navy whitespace-nowrap w-full"
5555
aria-describedby="purchase business license"
56-
data-pricing-id="4d72f490-47e5-4b83-b6e7-5fde0d0ee009"
56+
data-pricing-id="5dea1175-6e19-4613-bf7a-a0ae4354ccf9"
5757
type="button"
5858
>
5959
Purchase
@@ -140,7 +140,7 @@ import { SITE_TITLE, SITE_DESCRIPTION } from '../consts';
140140
<button
141141
class="button bg-white border-2 border-navy p-6 text-navy whitespace-nowrap w-full"
142142
aria-describedby="purchase enterprise license"
143-
data-pricing-id="c27eb1ec-bc59-446e-8aab-6adf920f9962"
143+
data-pricing-id="713b19cd-7fbf-41fb-9bf7-b5c25c318406"
144144
type="button"
145145
>
146146
Purchase
@@ -339,18 +339,50 @@ import { SITE_TITLE, SITE_DESCRIPTION } from '../consts';
339339
</html>
340340

341341
<script>
342-
import { actions } from 'astro:actions';
343-
import { navigate } from 'astro:transitions/client';
344342
document.addEventListener('astro:page-load', () => {
345343
const buttons = document.querySelectorAll('[data-pricing-id]');
346344

345+
// Store original button texts
346+
const buttonStates = new Map();
347+
buttons.forEach((button) => {
348+
if (button instanceof HTMLButtonElement) {
349+
buttonStates.set(button, button.innerHTML);
350+
}
351+
});
352+
353+
// Reset button states when user navigates back
354+
const resetButtons = () => {
355+
buttons.forEach((button) => {
356+
if (button instanceof HTMLButtonElement) {
357+
const originalText = buttonStates.get(button);
358+
if (originalText) {
359+
button.disabled = false;
360+
button.innerHTML = originalText;
361+
}
362+
}
363+
});
364+
};
365+
366+
// Listen for page visibility changes (when user comes back from checkout)
367+
document.addEventListener('visibilitychange', () => {
368+
if (document.visibilityState === 'visible') {
369+
resetButtons();
370+
}
371+
});
372+
373+
// Also reset on page show event (handles browser back button)
374+
window.addEventListener('pageshow', (event) => {
375+
// Reset buttons if coming back via browser navigation
376+
resetButtons();
377+
});
378+
347379
buttons.forEach((button) => {
348380
button.addEventListener('click', async (event) => {
349381
if (!(event.target instanceof HTMLButtonElement)) {
350382
return;
351383
}
352384
const btn = event.target;
353-
const originalText = btn.innerHTML;
385+
const originalText = buttonStates.get(btn);
354386
btn.disabled = true;
355387
btn.innerHTML = `
356388
<span class="inline-flex items-center">
@@ -363,31 +395,17 @@ import { SITE_TITLE, SITE_DESCRIPTION } from '../consts';
363395
</span>
364396
`;
365397

366-
const productPriceId = event.target?.dataset.pricingId;
398+
const productId = event.target?.dataset.pricingId;
367399

368-
if (!productPriceId) {
369-
console.warn('No pricing ID found for this button');
400+
if (!productId) {
401+
console.warn('No product ID found for this button');
402+
btn.disabled = false;
403+
btn.innerHTML = originalText || '';
370404
return;
371405
}
372406

373-
try {
374-
const { data, error } = await actions.checkout({
375-
productPriceId
376-
});
377-
378-
console.log('Checkout result:', data, error, productPriceId);
379-
380-
if (!error) {
381-
navigate(data);
382-
} else {
383-
console.error('Checkout error:', error);
384-
}
385-
} catch (error) {
386-
console.error('An error occurred during checkout:', error);
387-
} finally {
388-
btn.disabled = false;
389-
btn.innerHTML = originalText;
390-
}
407+
// Use full-page navigation to follow server-side redirect to external Polar checkout
408+
window.location.href = `/api/checkout?products=${productId}`;
391409
});
392410
});
393411
});

pnpm-lock.yaml

Lines changed: 24 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)