अपने App में Commerce इंटीग्रेट करें
सीधे अपने app code से checkouts शुरू करें और premium features gate करें।
एक बार जब आप Stripe से कनेक्ट कर लेते हैं और एक product बना लेते हैं, तो आपका app payments ले सकता है। Proyecta से बने app में यह browser से ही public commerce API के ख़िलाफ़ चलता है — आपको कोई backend खड़ा करने की ज़रूरत नहीं, और इसमें कोई secret key शामिल नहीं होती।
Storefront catalogs content होती हैं। अगर आपके products एक content-backed sellable collection हैं (देखें Products & Features), तो आप catalog पढ़ते हैं और Content API के ज़रिए prices render करते हैं — product data वहीं रहता है। Checkout शुरू करने का तरीका वही रहता है, बस Commerce product का
variant_idपास करें।
import * as platform from '@/lib/platformClient.ts';import { useEntitlement } from '@/hooks/useEntitlement.ts';Checkout शुरू करें
Section titled “Checkout शुरू करें”commerceCheckout एक Stripe-hosted checkout session बनाता है और shopper को भेजने के लिए एक URL लौटाता है। आपको पहले customer बनाने की ज़रूरत नहीं — platform checkout से ही एक customer record कर लेता है:
const { url } = await platform.commerceCheckout({ lineItems: [{ variantId: 'var_pro_monthly', quantity: 1 }], successUrl: 'https://myapp.com/welcome', cancelUrl: 'https://myapp.com/pricing', customerEmail: shopperEmail, // optional — prefills Stripe checkout});
window.location.href = url;कई line items support किए जाते हैं। Subscriptions के लिए, quantity seat count होती है। अगर shopper ने कोई coupon code टाइप किया है, तो उसे साथ पास करें — server उसे validate करता है और discount आपके commerce data से निकालता है, कभी भी browser द्वारा भेजी गई राशि से नहीं।
किसी premium feature को gate करें
Section titled “किसी premium feature को gate करें”const { hasAccess, isLoading } = useEntitlement('pro_features');
if (isLoading) return <Spinner />;if (!hasAccess) return <UpgradePrompt />;return <ProOnlyThing />;Key feature का slug होता है (जैसे pro_features), न कि feature object की id। यह check server-side होता है और signed-in session से जुड़ा होता है, इसलिए इसे browser से spoof नहीं किया जा सकता। Entitlement model के लिए Products & Features देखें।
AI से यह wire करवाएँ
Section titled “AI से यह wire करवाएँ”"Build a /pricing page that shows my products and starts a checkout when a button is clicked.""Gate the /pro route so only customers with pro_features access can see it.""Add a cart with a coupon code field and a Checkout button."