#Add items from Cart to Paypal Checkout

1 messages · Page 1 of 1 (latest)

bold cairnBOT
#

Hi @warm crypt. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the information provided in the extracts, it seems you are trying to create a PayPal checkout session with your cart items. However, the extracts do not provide specific information on how to add items from a cart to a PayPal checkout session in a Next.js application.

The extracts do provide information on how to create a Stripe checkout session, handle API routes, read request bodies, and set up payment integrations in your .env.local file. However, these may not directly apply to your specific question about PayPal checkout.

I recommend checking the official PayPal API documentation or Next.js examples for more specific guidance on this topic. If you have any questions related to Next.js, feel free to ask!

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@warm crypt kapa.ai is still learning and improving, please let us know how it did by reacting below

warm crypt
#

this is my Cart.tsx file

{/* components/Cart.tsx */}
const Cart = ({ setShowCart }: any) => {
    
    const products = useAppSelector((state) => state.cartReducer);

    const getTotal = () => {
        let total = 0;
        products.forEach((item) => (total = total + item.price * item.quantity));
        return total;
    };

    return (
        <div className="bg-[#0000007d] w-[1380px] min-h-screen fixed left-0 top-0 overflow-y-scroll cart-container">
            <div className="max-w-[400px] w-full min-h-full bg-white absolute right-0 top-0 p-6">

                <div className="mt-6 space-y-2">
                    {products?.map((item: any) => (
                        <CartProduct 
                        key={item.id}
                        id={item.id}
                        img={item.img}
                        name={item.name}
                        price={item.price}
                        quantity={item.quantity}/>
                    ))}
                </div>
                <PayPalScriptProvider options={{clientId: "ASXqACbzEw_e1-Ks3JFtNstwgpRWegot9yHeYTmG9tvvVJzjeaw2YWTjOB0twiNsuiQ3Sr0fVnCahrhp"}}>
                    <PayPalButtons
                    style={{
                        color: "blue", 
                        layout: "horizontal",
                    }} 
                    createOrder={async () => { 
                        const res = await fetch('/api/checkout', {
                            method: "POST",
                            headers: {
                              "Content-Type": "application/json",
                          },
                        })
                        const order = await res.json()
                        console.log("ORDER:", order)
                        return order.id
                    }}/>
                </PayPalScriptProvider>
            </div>
        </div>
    )

}```

@bold cairn
bold cairnBOT
#

Let me check the knowledge base for you. One moment! :books:

#

From the provided Cart.tsx file, it seems you are using the Redux state to manage your cart items and PayPal's JavaScript SDK for the checkout process.

However, in the provided extracts, there is no specific information on how to integrate the PayPal checkout process with a cart in a Next.js application.

The extracts do provide information on how to handle API routes and read request bodies in Next.js, which could be useful for your /api/checkout route. Here is an example of how to handle a POST request in Next.js:

import type { NextApiRequest, NextApiResponse } from 'next'
 
export default async function handler(
 req: NextApiRequest,
 res: NextApiResponse
) {
 const data = req.body
 const id = await createItem(data)
 res.status(200).json({ id })
}

Source (https://nextjs.org/docs/pages/building-your-application/data-fetching/forms-and-mutations#server-only-form)

In your case, you would need to replace createItem(data) with your PayPal checkout logic.

For more specific guidance on integrating PayPal with your cart, I recommend checking the official PayPal API documentation or Next.js examples.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: