Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ schema.graphql

# macOS
.DS_Store
.env
.env.local
41 changes: 41 additions & 0 deletions examples/nextjs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# env files (can opt-in for committing if needed)
.env*

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
36 changes: 36 additions & 0 deletions examples/nextjs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
44 changes: 44 additions & 0 deletions examples/nextjs/app/checkout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use client';

import type { CheckoutFormSchema, CheckoutSession } from '@godaddy/react';
import { Checkout, GoDaddyProvider } from '@godaddy/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import { useState } from 'react';
import { z } from 'zod';

/* Override the checkout form schema to make shippingPhone required */
const customSchema: CheckoutFormSchema = {
shippingPhone: z.string().min(1, 'Phone number is required'),
};

export function CheckoutPage({ session }: { session: CheckoutSession }) {
const [queryClient] = useState(() => new QueryClient());

return (
<QueryClientProvider client={queryClient}>
<GoDaddyProvider>
<Checkout
session={session}
checkoutFormSchema={customSchema}
squareConfig={{
appId: process.env.NEXT_PUBLIC_SQUARE_APP_ID || '',
locationId: process.env.NEXT_PUBLIC_SQUARE_LOCATION_ID || '',
}}
stripeConfig={{
publishableKey:
process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY || '',
}}
godaddyPaymentsConfig={{
businessId: process.env.NEXT_PUBLIC_GODADDY_BUSINESS_ID || '',
appId: process.env.NEXT_PUBLIC_GODADDY_APP_ID || '',
}}
paypalConfig={{
clientId: process.env.NEXT_PUBLIC_PAYPAL_CLIENT_ID || '',
}}
/>
<ReactQueryDevtools initialIsOpen={false} />
</GoDaddyProvider>
</QueryClientProvider>
);
}
Binary file added examples/nextjs/app/favicon.ico
Binary file not shown.
26 changes: 26 additions & 0 deletions examples/nextjs/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@import "tailwindcss";

:root {
--background: #ffffff;
--foreground: #171717;
}

@theme inline {
--color-background: var(--background);
--color-foreground: var(--foreground);
--font-sans: var(--font-geist-sans);
--font-mono: var(--font-geist-mono);
}

@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
}

body {
background: var(--background);
color: var(--foreground);
font-family: Arial, Helvetica, sans-serif;
}
35 changes: 35 additions & 0 deletions examples/nextjs/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { Metadata } from 'next';
import { Geist, Geist_Mono } from 'next/font/google';
import './globals.css';
import '@godaddy/react/styles.css';

const geistSans = Geist({
variable: '--font-geist-sans',
subsets: ['latin'],
});

const geistMono = Geist_Mono({
variable: '--font-geist-mono',
subsets: ['latin'],
});

export const metadata: Metadata = {
title: 'Unified Checkout NextJS Example',
description: 'An example NextJS application using GoDaddy Unified Checkout',
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang='en'>
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
{children}
</body>
</html>
);
}
104 changes: 104 additions & 0 deletions examples/nextjs/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { createCheckoutSession } from '@godaddy/react/server';
import { unstable_noStore } from 'next/cache';
import { notFound } from 'next/navigation';
import { CheckoutPage } from './checkout';

export const dynamic = 'force-dynamic';

export default async function Home() {
unstable_noStore();
const session = await createCheckoutSession(
{
returnUrl: 'https://godaddy.com',
successUrl: 'https://godaddy.com/success',
draftOrderId: process.env.NEXT_PUBLIC_GODADDY_DRAFT_ORDER_ID || '',
storeId: process.env.NEXT_PUBLIC_GODADDY_STORE_ID || '',
channelId: process.env.NEXT_PUBLIC_GODADDY_CHANNEL_ID || '',
enableLocalPickup: true,
enableShippingAddressCollection: true,
enableBillingAddressCollection: true,
enablePhoneCollection: true,
enableTaxCollection: true,
enableNotesCollection: true,
enablePromotionCodes: true,
shipping: {
fulfillmentLocationId: 'default-location',
originAddress: {
addressLine1: '1600 Pennsylvania Ave NW',
adminArea1: 'DC',
adminArea3: 'Washington',
countryCode: 'US',
postalCode: '20500',
},
},
taxes: {
originAddress: {
addressLine1: '1600 Pennsylvania Ave NW',
adminArea1: 'DC',
adminArea3: 'Washington',
countryCode: 'US',
postalCode: '20500',
},
},
locations: [
{
id: 'default-location',
isDefault: true,
address: {
addressLine1: '1600 Pennsylvania Ave NW',
adminArea1: 'DC',
adminArea3: 'Washington',
countryCode: 'US',
postalCode: '20500',
},
},
],
paymentMethods: {
card: {
processor: 'godaddy',
checkoutTypes: ['standard'],
},
express: {
processor: 'godaddy',
checkoutTypes: ['express'],
},
paypal: {
processor: 'paypal',
checkoutTypes: ['standard'],
},
offline: {
processor: 'offline',
checkoutTypes: ['standard'],
},
},
operatingHours: {
default: {
timeZone: 'America/New_York', // CDT timezone
leadTime: 60, // 60 minutes lead time
pickupWindowInDays: 7,
hours: {
monday: { enabled: true, openTime: '09:00', closeTime: '17:00' },
tuesday: { enabled: true, openTime: '09:00', closeTime: '17:00' },
wednesday: { enabled: false, openTime: null, closeTime: null },
thursday: { enabled: true, openTime: '09:00', closeTime: '17:00' },
friday: { enabled: true, openTime: '09:00', closeTime: '18:00' },
saturday: { enabled: true, openTime: '10:00', closeTime: '16:00' },
sunday: { enabled: true, openTime: '12:00', closeTime: '15:00' },
},
},
},
},
{
auth: {
clientId: process.env.GODADDY_CLIENT_ID || '',
clientSecret: process.env.GODADDY_CLIENT_SECRET || '',
},
}
);

if (!session) {
throw notFound();
}

return <CheckoutPage session={session} />;
}
20 changes: 20 additions & 0 deletions examples/nextjs/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "https://biomejs.dev/schemas/2.3.2/schema.json",
"extends": ["biome-config-godaddy/biome.json"],
"css": {
"parser": {
"cssModules": true,
"tailwindDirectives": true
}
},
"files": {
"includes": ["**/*", "!!**/src/globals.css"]
},
"linter": {
"rules": {
"correctness": {
"useUniqueElementIds": "off"
}
}
}
}
23 changes: 23 additions & 0 deletions examples/nextjs/env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# GoDaddy API Credentials
GODADDY_CLIENT_ID=
GODADDY_CLIENT_SECRET=
NEXT_PUBLIC_GODADDY_ENV=prod
NEXT_PUBLIC_GODADDY_HOST=api.godaddy.com

# Store and Order Identifiers
NEXT_PUBLIC_GODADDY_STORE_ID=
NEXT_PUBLIC_GODADDY_CHANNEL_ID=
NEXT_PUBLIC_GODADDY_DRAFT_ORDER_ID=

# Stripe Payment Credentials
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=
STRIPE_SECRET=

# GoDaddy Payment Credentials
NEXT_PUBLIC_GODADDY_APP_ID=
#NEXT_PUBLIC_GODADDY_BUSINESS_ID=

# Square Credentials
NEXT_PUBLIC_SQUARE_APP_ID=
NEXT_PUBLIC_SQUARE_LOCATION_ID=
NEXT_PUBLIC_PAYPAL_CLIENT_ID=
7 changes: 7 additions & 0 deletions examples/nextjs/next.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { NextConfig } from 'next';

const nextConfig: NextConfig = {
/* config options here */
};

export default nextConfig;
32 changes: 32 additions & 0 deletions examples/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "nextjs",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "biome check .",
"lint:fix": "biome check --write --unsafe ."
},
"dependencies": {
"@godaddy/localizations": "workspace:*",
"@godaddy/react": "workspace:*",
"@tanstack/react-query": "^5.66.0",
"@tanstack/react-query-devtools": "^5.76.1",
"next": "16.0.1",
"react": "19.2.0",
"react-dom": "19.2.0",
"zod": "^3.24.1"
},
"devDependencies": {
"@biomejs/biome": "^2",
"@tailwindcss/postcss": "^4",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"biome-config-godaddy": "workspace:*",
"tailwindcss": "^4",
"typescript": "^5"
}
}
7 changes: 7 additions & 0 deletions examples/nextjs/postcss.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const config = {
plugins: {
'@tailwindcss/postcss': {},
},
};

export default config;
1 change: 1 addition & 0 deletions examples/nextjs/public/file.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/nextjs/public/globe.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading