Integration Guide · Vue
Build a Vue 3 or Nuxt Storefront
Build reactive product grids and cart drawers in Vue 3 Composition API or Nuxt server routes backed by Shoprivet.
Prerequisites & Setup Checklist
- Vue 3.3+ or Nuxt 3
- A Shoprivet store slug and configured payment provider
- Sign up at shoprivet.io/app/signup, create a store, add products, and configure a payment gateway (or Cash on delivery).
Environment Variables
| Variable | Example Value | Exposure Rule |
|---|---|---|
NUXT_PUBLIC_SHOPRIVET_SLUG |
downtown-shop |
Safe public store slug |
SHOPRIVET_API_KEY |
shoprivet_live_example_key |
Server runtimeConfig only (never public) |
Implementation Steps
1. Prepare store catalog and payment gateway
Publish your products with images and variants in Shoprivet and activate Stripe, Paystack, Flutterwave, Razorpay, PayPal, or Cash on delivery.
2. Create a reactive Vue cart store or composable
Use a composable backed by POST /public/stores/:slug/carts and PATCH /carts/current/items/:itemId so line quantities and totals always match server pricing.
3. Handle payment redirects and order confirmation
Persist orderAccessToken before redirecting to checkout.authorizationUrl and call POST /public/stores/:slug/orders/:orderNumber/confirm upon return.
import { ref } from 'vue';
const API = 'https://api.shoprivet.io';
const SLUG = 'downtown-shop';
export function useShoprivetCart() {
const cart = ref<any>(null);
const credential = ref<string | null>(null);
async function ensureCart() {
if (credential.value) return credential.value;
const res = await fetch(`${API}/public/stores/${SLUG}/carts`, { method: 'POST', credentials: 'omit' });
const data = await res.json();
credential.value = data.credential;
cart.value = data.cart;
return data.credential as string;
}
async function addItem(productId: string, quantity = 1) {
const token = await ensureCart();
const res = await fetch(`${API}/public/stores/${SLUG}/carts/current/items`, {
method: 'POST',
credentials: 'omit',
headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ productId, quantity }),
});
cart.value = await res.json();
}
return { cart, ensureCart, addItem };
}
Payment Verification, Error Handling & Security
In Nuxt, place merchant /v1 API calls inside server/api/ handlers using useRuntimeConfig() (non-public keys) so merchant secrets never reach client hydration state.
- Never expose merchant keys through NUXT_PUBLIC_ or VITE_ variables.
- Validate non-2xx responses (400 validation errors, 409 stock limits, 429 rate limits) and display user-friendly retry messages.
Deployment
Works with Nuxt SSR (Node/Nitro/Cloudflare/Vercel) or static Vue hosting.
