अवलोकन
Astro minimal boilerplate एक starter app है, जिसमें Dodo Payments पहले से connected है। अपनी API keys और product IDs जोड़ें और आपको एक pricing page मिलेगा जो checkout खोलता है, payment events के लिए एक webhook endpoint मिलेगा, और Customer Portal का एक link मिलेगा।यह boilerplate TypeScript, Tailwind CSS 4 और
@dodopayments/astro adaptor के साथ Astro 5 का उपयोग करता है। किसी मौजूदा app में वही API routes जोड़ने के लिए Astro Adaptor देखें।विशेषताएँ
Boilerplate में शामिल हैं:- त्वरित Setup: clone से चलने वाले pricing page तक लगभग पाँच मिनट में पहुँचें।
- Checkout:
@dodopayments/astroपर बना pre-configured checkout flow। - Pricing Page: Tailwind CSS से styled dark-themed pricing page।
- Webhook Handler: ऐसा endpoint जो हर webhook signature को verify करता है और event के लिए आपका code चलाता है।
- Customer Portal: header में एक link जो Customer Portal खोलता है, जहाँ customers अपनी subscriptions manage करते हैं।
- TypeScript: typed product definitions और handlers।
- Pre-filled Checkout: customer का name और email checkout में भेजता है, ताकि customer को उन्हें दोबारा न भरना पड़े।
आवश्यकताएँ
शुरू करने से पहले आपके पास ये चीज़ें होनी चाहिए:- Node.js का एक LTS version, जिसकी Astro 5 को आवश्यकता है।
- Dodo Payments account, dashboard में API key और webhook signing secret बनाने के लिए।
त्वरित शुरुआत
1
Clone the Repository
2
Install Dependencies
3
Get API Credentials
Dodo Payments पर sign up करें, फिर dashboard से अपनी credentials प्राप्त करें:
- API Key: Dashboard → Developer → API Keys के अंतर्गत एक key बनाएँ।
- Webhook Key: Dashboard → Developer → Webhooks के अंतर्गत एक endpoint जोड़ें, फिर उसका signing secret copy करें। Endpoint URL public होना चाहिए और HTTPS का उपयोग करना चाहिए। अपनी machine पर events प्राप्त करने के लिए Webhook Events देखें।
4
Configure Environment Variables
Root directory में एक Values को अपनी Dodo Payments credentials पर set करें:
.env file बनाने के लिए example file को copy करें:.env.example, DODO_PAYMENTS_RETURN_URL को port 3000 पर set करता है। इसे 4321 में बदलें, जो Astro dev server द्वारा उपयोग किया जाने वाला port है, ताकि checkout के बाद customer आपके app पर वापस आ सके।API routes इन variables को पढ़ते हैं:DODO_PAYMENTS_API_KEYcheckout और Customer Portal routes को authenticate करता है।DODO_PAYMENTS_WEBHOOK_KEYwebhook signatures को verify करता है।DODO_PAYMENTS_RETURN_URLवह स्थान है जहाँ checkout payment के बाद customer को भेजता है।DODO_PAYMENTS_ENVIRONMENT,test_modeयाlive_modeहै।
5
Add Your Products
src/lib/products.ts में sample products को अपने products से replace करें। हर product_id को dashboard के Products के अंतर्गत मौजूद product की ID पर set करें:name, description, price और features display करता है। Checkout Dodo Payments में product पर set price charge करता है, इसलिए price को उसके साथ sync रखें।6
Run the Development Server
Project Structure
Checkout, Customer Portal और webhook API routessrc/pages/api/ के अंतर्गत मौजूद हैं:
Customization
Product Information अपडेट करें
बदलाव करने के लिएsrc/lib/products.ts edit करें:
- Dodo Payments dashboard के Products से Product IDs
- Prices
- Features
- Descriptions
Customer Data पहले से भरें
src/components/ProductCard.astro में checkout script हर checkout request के साथ hardcoded name और email भेजती है। इन्हें signed-in user की details से replace करें:
Customer Portal अपडेट करें
src/components/Header.astro में मौजूद Customer Portal link hardcoded customer ID के साथ /api/customer-portal खोलता है। इसे अपने authentication system या database से customer ID के साथ replace करें:
Webhook Events
src/pages/api/webhook.ts में मौजूद handler हर request को DODO_PAYMENTS_WEBHOOK_KEY से verify करता है, फिर दो events handle करता है:
onSubscriptionActiveतब चलता है जब subscription active हो जाती है (subscription.active)।onSubscriptionCancelledतब चलता है जब subscription cancel हो जाती है (subscription.cancelled)।
onPaymentSucceeded। Astro Adaptor सभी supported handlers की सूची देता है।
Dodo Payments localhost तक नहीं पहुँच सकता। Local development के लिए अपने local server को expose करने हेतु ngrok जैसे tunnel का उपयोग करें और tunnel URL को अपने webhook endpoint के रूप में इस्तेमाल करें।
Deployment
Astro pages को static output के रूप में build करता है और हर API routeexport const prerender = false set करता है, ताकि वह on demand render हो। On-demand routes के लिए आपके deployment platform का Astro adapter आवश्यक है:
अन्य platforms के लिए Astro’s deployment guides देखें। अपने hosting platform में चारों environment variables जोड़ें और
DODO_PAYMENTS_RETURN_URL को अपने production URL पर set करें।
Webhook URL अपडेट करें
Deploy करने के बाद Dodo Payments Dashboard में अपना production webhook URL जोड़ें:DODO_PAYMENTS_WEBHOOK_KEY को इस endpoint के signing secret पर set करें।
Troubleshooting
Module not found or build errors
Module not found or build errors
node_modules और package-lock.json को delete करें, फिर dependencies reinstall करें:Checkout redirect fails
Checkout redirect fails
इन सामान्य कारणों की जाँच करें:
- Product ID आपके Dodo Payments dashboard में मौजूद नहीं है।
.envमें API key याDODO_PAYMENTS_ENVIRONMENTगलत है। Test mode key केवलtest_modeके साथ काम करती है।
npm run dev चलाने वाले terminal में error देखें।Webhooks not receiving events
Webhooks not receiving events
Local testing के लिए अपने server को expose करने हेतु ngrok का उपयोग करें:अपने Dodo dashboard में ngrok HTTPS URL के बाद
/api/webhook वाला endpoint जोड़ें। उस endpoint का signing secret अपनी .env file में DODO_PAYMENTS_WEBHOOK_KEY में copy करें।Customer portal link doesn't work
Customer portal link doesn't work
src/components/Header.astro में hardcoded CUSTOMER_ID को अपने Dodo Payments dashboard में मौजूद किसी customer की ID से replace करें।Production में इसके बजाय अपने authentication system और database से customer ID प्राप्त करें।Build fails with adapter error
Build fails with adapter error
API routes on demand render होते हैं और repository में deployment adapter शामिल नहीं है। Production के लिए build करने से पहले अपने platform का Astro adapter install करें।विवरण के लिए Astro’s deployment guides देखें।
अधिक जानें
- Dodo Payments Documentation
- Checkout Sessions Documentation
- Webhooks Documentation
- Astro Adaptor:
Checkout,CustomerPortalऔरWebhookshandlers के options - Astro Documentation
सहायता
Boilerplate के लिए सहायता पाने हेतु:- Discord community में प्रश्न पूछें।
- GitHub repository में issues report करें और updates follow करें।
- support team को email करें।