#djk3600

1 messages ยท Page 1 of 1 (latest)

placid boughBOT
empty laurel
candid wadi
#

That was fasst!!!!

#

You guys are efficient :)))

#

So there is this

#

parameter_missing - line_items[0][price_data][product_data][name]
Looks like you are missing the name field tied to a given line item's product_data.

This field is required in that it contains the name that will show up on associated invoice line item descriptions.

#

Im trying to find the id via the logs... one second please ๐Ÿ™‚

#

found it!

#

req_LSaMMSejhQKU7f

willow star
#

most likely item.name is null in your code, you should log/inspect that item variable to check that.

candid wadi
#

Hi Karl,

do you mean here?

 const transformedItems = items.map((item) => ({
    price_data: {
      currency: "usd",
      product_data: {
        images: [item.image],
        name: item.name,
      },
      unit_amount: item.price * 100,
    },
    description: item.description,
    quantity: item.quantity,
  }));
willow star
#

I mean here :

name: item.name,
most likely your item variable's name field is null or undefined, so nothing is passed to the API, so the API complains that that the required value is not passed.

candid wadi
#

Ahhhh! That might be it ๐Ÿ™‚

#

Look at the JSON object that I am recieving here,

{
      "id":1,
      "title":"Fjallraven - Foldsack No. 1 Backpack, Fits 15 Laptops",
      "price":109.95,
      "description":"Your perfect pack for everyday use and walks in the forest. Stash your laptop (up to 15 inches) in the padded sleeve, your everyday",
      "category":"men's clothing",
      "image":"https://fakestoreapi.com/img/81fPKd-2AYL._AC_SL1500_.jpg",
      "rating":{
         "rate":3.9,
         "count":120
      }

There is no name but instead it is called title, so I am assuming switching name to title will work correctly

willow star
#

seems logical

candid wadi
#

Ill try it now, one second please ๐Ÿ™‚

#

It doesn't seem to be fixed for some reason

#

I changed it to,

        title: item.title,
solemn elk
#

Can you send the request ID from that attempt as well?

candid wadi
#

Will do - one second

#

also thanks so much for helping me, means the world ๐Ÿ™‚

#

This is the ID:
req_cqwdLt41EJ5XDS

This is the logged message:
parameter_unknown - line_items[0][price_data][product_data][title]
Received unknown parameter: line_items[0][price_data][product_data][title]

willow star
#

you should change it to name:item.title

#

the name of the field in the Stripe API is still name, that doesn't change. You're just changing the name of the variable in your code.

candid wadi
#

I tried this, but it didnt help. I'll try again to be 1000% sure

#

Okay got a different error

#

This is the error,

Invalid val: ["https://fakestoreapi.com/img/71-3HjGNDUL._AC_SY879._SX._UX._SY.UY.jpg","https://fakestoreapi.com/img/71-3HjGNDUL._AC_SY879._SX._UX._SY.UY.jpg","https://fakestoreapi.com/img/71-3HjGNDUL._AC_SY879._SX._UX._SY.UY.jpg","https://fakestoreapi.com/img/71-3HjGNDUL._AC_SY879._SX._UX._SY.UY.jpg","https://fakestoreapi.com/img/71-3HjGNDUL._AC_SY879._SX._UX._SY.UY.jpg","https://fakestoreapi.com/img/71-3HjGNDUL._AC_SY879._SX._UX._SY.UY.jpg","https://fakestoreapi.com/img/71-3HjGNDUL._AC_SY879._SX._UX._SY.UY.jpg"] must be a string under 500 characters
#

An API issue sigh, seems to be in regards to the image?? I am going to pull out the image data and see

solemn elk
#

I see it in your logs, it looks like that is about passing too long of a string in to your metadata param

#

You will want to split that string up here

candid wadi
#

I may be coming across silly, but I am unsure how to do that??

solemn elk
#

Looking at that again it looks like it is the same link 8 times. Is there a reason you are linking it 8 times instead of once?

candid wadi
#

Its because lets say I order the same product 8 times, it is being linked 8 times, (I haven't grouped the products together yet) I just want to integrate stripe first

solemn elk
#

Gotcha

#

So for splitting the string, that is kind of up to you how to do it. You could do something simple like write out your URL array to a string, split that up in to 500 char chunks, and then reassemble the full string on your webhook endpoint

#

Or you can split it up by full URLs

candid wadi
#

I have no idea how to do those oh dear

#

is there an article which can explain??

solemn elk
#

Not really, I'm just kind of suggesting ideas to get around the 500 character limit.

#

This is just string manipulation rather than a Stripe specific thing

#

The first one would be pretty similar to what you are doing already. You are printing out your URL array to a string to pass it in as metadata correct?

candid wadi
#

I see I see

#

okay so these are merely the two things I am doing

#

Using Next.JS to get the API data like so:

export async function getServerSideProps(context) {
  const products = await fetch("https://fakestoreapi.com/products").then(
    (res) => res.json()
  );

  return {
    props: {
      products,
    },
  };
}
#

then creating a checkout session function like so:

  const createCheckoutSession = async () => {
    const stripe = await stripePromise;

    // Call the backend to create a session
    const checkoutSession = await axios.post("/api/create-checkout-session", {
      items,
      email: session.user.email,
    });

    // Redirect

    const result = await stripe.redirectToCheckout({
      sessionId: checkoutSession.data.id,
    });

    if (result.error) alert(result.error.message);
  };
#

and I have created this create-checkout-session.js file:

const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);

export default async (req, res) => {
  const { items, email } = req.body;

  const transformedItems = items.map((item) => ({
    price_data: {
      currency: "usd",
      product_data: {
        images: [item.image],
        name: item.title,
      },
      unit_amount: item.price * 100,
    },
    description: item.description,
    quantity: item.quantity,
  }));

  const session = await stripe.checkout.sessions.create({
    payment_method_types: ["card"],
    shipping_rates: ["shr_1Lg3iTK7ED5S47qK8weRstua"],
    shipping_address_collection: {
      allowed_countries: ["GB", "US", "CA"],
    },
    line_items: transformedItems,
    mode: "payment",
    success_url: `${process.env.HOST}/success`,
    cancel_url: `${process.env.HOST}/checkout`,
    metadata: {
      email,
      images: JSON.stringify(items.map((item) => item.image)),
    },
  });

  res.status(200).json({ id: session.id });
};
#

Even if I pull the image data out, I still get this error

#
You cannot use `line_items.amount`, `line_items.currency`, `line_items.name`, `line_items.description`, or `line_items.images` in this API version. Please use `line_items.price` or `line_items.price_data`. Please see https://stripe.com/docs/payments/checkout/migrating-prices for more information.',
    type: 'invalid_request_error',
solemn elk
#

I recognize that error, there is a doc on the new format to use. Let me see if I can find it

candid wadi
#

Thanks ! I tried to follow the docs but have had no luck to be honest

#

I am unsure if this is allowed for you, but would we be able to jump on a call please??

#

A video one, so I can share my screen??

solemn elk
candid wadi
#

No problem my man

#

okay I think I have configure it correctly now

#

New error,

 message: 'Quantity is required. Add `quantity` to `line_items[0]`'
#

but I did hahaha

#
  const transformedItems = items.map((item) => ({
    price_data: {
      currency: "usd",
      unit_amount: item.price * 100,
      product_data: {
        name: item.title,
        description: item.description,
      },
    },
    quantity: item.quantity,
  }));
#

as per the docs!

solemn elk
#

Interestingly I don't see the quantity param in the request that we received on our side but I do see the rest of that data. Can you double check if item.quantity is somehow null?

candid wadi
#

will do ๐Ÿ™‚

#

Okay I just changed the quantity to one

#

1

#

just for now

#

and now I am getting a different error

#

message: 'Invalid object',
param: 'shipping_options[0]',
type: 'invalid_request_error',

#

let em get you the id

#

I am so confused

#

But I am getting this error

#
StripeInvalidRequestError: Invalid object
solemn elk
#

We got something like:
shipping_options: ["shr_1LhDIRK7ED5S47qKPckAuvZu"]

#

But we are expecting:
shipping_options: ["shipping_rate": "shr_1LhDIRK7ED5S47qKPckAuvZu"]