#djk3600
1 messages ยท Page 1 of 1 (latest)
Hi there!
Can you share the ID (req_xxx) of the failing API request?
https://support.stripe.com/questions/finding-the-id-for-an-api-request
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
most likely item.name is null in your code, you should log/inspect that item variable to check that.
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,
}));
I mean here :
name: item.name,
most likely youritemvariable'snamefield is null or undefined, so nothing is passed to the API, so the API complains that that the required value is not passed.
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
seems logical
Ill try it now, one second please ๐
It doesn't seem to be fixed for some reason
I changed it to,
title: item.title,
Can you send the request ID from that attempt as well?
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]
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.
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
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
I may be coming across silly, but I am unsure how to do that??
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?
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
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
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?
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',
I recognize that error, there is a doc on the new format to use. Let me see if I can find it
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??
Unfortunately we don't offer calls on this server but I think we can solve it otherwise. Here is the doc that shows the old format vs the new format https://stripe.com/docs/payments/checkout/migrating-prices#server-side-code-for-inline-items
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!
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?
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
So it looks like that shipping_options hash that you are passing in is not in the format that we are expecting https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-shipping_options-shipping_rate
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
We got something like:
shipping_options: ["shr_1LhDIRK7ED5S47qKPckAuvZu"]
But we are expecting:
shipping_options: ["shipping_rate": "shr_1LhDIRK7ED5S47qKPckAuvZu"]