Skip to content
Open
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
6 changes: 6 additions & 0 deletions .changeset/some-berries-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"nextjs": minor
"@godaddy/react": minor
---

Implementation of mercadopago
60 changes: 46 additions & 14 deletions examples/nextjs/app/checkout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,52 @@ export function CheckoutPage({ session }: { session: CheckoutSession }) {
<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 || '',
}}
squareConfig={
process.env.NEXT_PUBLIC_SQUARE_APP_ID &&
process.env.NEXT_PUBLIC_SQUARE_LOCATION_ID
? {
appId: process.env.NEXT_PUBLIC_SQUARE_APP_ID,
locationId: process.env.NEXT_PUBLIC_SQUARE_LOCATION_ID,
}
: undefined
}
stripeConfig={
process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
? {
publishableKey: process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY,
}
: undefined
}
mercadoPagoConfig={
process.env.NEXT_PUBLIC_MERCADOPAGO_PUBLIC_KEY
? {
publicKey: process.env.NEXT_PUBLIC_MERCADOPAGO_PUBLIC_KEY,
country:
(process.env.NEXT_PUBLIC_MERCADOPAGO_COUNTRY as
| 'AR'
| 'BR'
| 'CO'
| 'CL'
| 'PE'
| 'MX') || 'AR',
}
: undefined
}
godaddyPaymentsConfig={
process.env.NEXT_PUBLIC_GODADDY_APP_ID
? {
businessId: process.env.NEXT_PUBLIC_GODADDY_BUSINESS_ID || '',
appId: process.env.NEXT_PUBLIC_GODADDY_APP_ID,
}
: undefined
}
paypalConfig={
process.env.NEXT_PUBLIC_PAYPAL_CLIENT_ID
? {
clientId: process.env.NEXT_PUBLIC_PAYPAL_CLIENT_ID,
}
: undefined
}
/>
);
}
12 changes: 4 additions & 8 deletions examples/nextjs/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,13 @@ export default async function Home() {
processor: 'godaddy',
checkoutTypes: ['standard'],
},
express: {
processor: 'godaddy',
checkoutTypes: ['express'],
mercadopago: {
processor: 'mercadopago',
checkoutTypes: ['standard'],
},
paypal: {
processor: 'paypal',
checkoutTypes: ['standard'],
},
offline: {
processor: 'offline',
checkoutTypes: ['standard'],
checkoutTypes: ['express', 'standard'],
},
},
operatingHours: {
Expand Down
2 changes: 0 additions & 2 deletions examples/nextjs/app/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ export async function checkoutWithOrder(orderId: string) {
throw new Error('Failed to create checkout session');
}

console.log({ session });

if (!session.url) {
throw new Error('No checkout URL returned');
}
Expand Down
5 changes: 1 addition & 4 deletions examples/nextjs/app/store/product/[productId]/product.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ export default function Product({ productId }: { productId: string }) {
<ArrowLeft className='h-4 w-4' />
Back to Store
</Link>
<ProductDetails
productId={productId}
onAddToCartSuccess={openCart}
/>
<ProductDetails productId={productId} onAddToCartSuccess={openCart} />
</div>
);
}
36 changes: 18 additions & 18 deletions examples/nextjs/biome.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"$schema": "https://biomejs.dev/schemas/2.3.3/schema.json",
"extends": ["biome-config-godaddy/biome.json"],
"css": {
"parser": {
"cssModules": true,
"tailwindDirectives": true
}
},
"files": {
"includes": ["**/*", "!!**/src/globals.css"]
},
"linter": {
"rules": {
"correctness": {
"useUniqueElementIds": "off"
}
}
}
"$schema": "https://biomejs.dev/schemas/2.3.3/schema.json",
"extends": ["biome-config-godaddy/biome.json"],
"css": {
"parser": {
"cssModules": true,
"tailwindDirectives": true
}
},
"files": {
"includes": ["**/*", "!!**/src/globals.css"]
},
"linter": {
"rules": {
"correctness": {
"useUniqueElementIds": "off"
}
}
}
}
4 changes: 4 additions & 0 deletions examples/nextjs/env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ NEXT_PUBLIC_GODADDY_APP_ID=
NEXT_PUBLIC_SQUARE_APP_ID=
NEXT_PUBLIC_SQUARE_LOCATION_ID=
NEXT_PUBLIC_PAYPAL_CLIENT_ID=

# MercadoPago Credentials
NEXT_PUBLIC_MERCADOPAGO_PUBLIC_KEY=
NEXT_PUBLIC_MERCADOPAGO_COUNTRY=AR
9 changes: 9 additions & 0 deletions packages/react/src/components/checkout/checkout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ export type PayPalConfig = {
disableFunding?: Array<'credit' | 'card' | 'paylater' | 'venmo'>;
};

export type MercadoPagoConfig = {
publicKey: string;
country: 'AR' | 'BR' | 'CO' | 'CL' | 'PE' | 'MX';
};

interface CheckoutContextValue {
elements?: CheckoutElements;
targets?: Partial<
Expand All @@ -92,6 +97,7 @@ interface CheckoutContextValue {
godaddyPaymentsConfig?: GodaddyPaymentsConfig;
squareConfig?: SquareConfig;
paypalConfig?: PayPalConfig;
mercadoPagoConfig?: MercadoPagoConfig;
isConfirmingCheckout: boolean;
setIsConfirmingCheckout: (isConfirming: boolean) => void;
checkoutErrors?: string[] | undefined;
Expand Down Expand Up @@ -202,6 +208,7 @@ export interface CheckoutProps {
godaddyPaymentsConfig?: GodaddyPaymentsConfig;
squareConfig?: SquareConfig;
paypalConfig?: PayPalConfig;
mercadoPagoConfig?: MercadoPagoConfig;
layout?: LayoutSection[];
direction?: 'ltr' | 'rtl';
showStoreHours?: boolean;
Expand All @@ -221,6 +228,7 @@ export function Checkout(props: CheckoutProps) {
godaddyPaymentsConfig,
squareConfig,
paypalConfig,
mercadoPagoConfig,
isCheckoutDisabled,
} = props;

Expand Down Expand Up @@ -385,6 +393,7 @@ export function Checkout(props: CheckoutProps) {
stripeConfig,
godaddyPaymentsConfig,
squareConfig,
mercadoPagoConfig,
paypalConfig,
requiredFields,
isConfirmingCheckout,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { useFormContext } from 'react-hook-form';
import { useMercadoPago } from '@/components/checkout/payment/utils/mercadopago-provider';
import { Button } from '@/components/ui/button';
import { useGoDaddyContext } from '@/godaddy-provider';

export function MercadoPagoCreditCardCheckoutButton() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the form should be a part of this instead of payment-methods; but if decided that's not the way, this file is not needed.

const { t } = useGoDaddyContext();
const { handleBrickSubmit, isLoading } = useMercadoPago();
const form = useFormContext();

const handleSubmit = async () => {
// Validate form first
const valid = await form.trigger();
if (!valid) {
const firstError = Object.keys(form.formState.errors)[0];
if (firstError) {
form.setFocus(firstError);
}
return;
}

// Trigger MercadoPago brick submission
if (handleBrickSubmit) {
try {
await handleBrickSubmit();
} catch (error) {
console.error('MercadoPago submission error:', error);
}
}
};

return (
<Button
type='button'
onClick={handleSubmit}
disabled={!handleBrickSubmit || isLoading}
className='w-full'
>
{t.payment.payNow}
</Button>
);
}
Loading