project_e_commerce icon indicating copy to clipboard operation
project_e_commerce copied to clipboard

The given data was invalid

Open andrewnashed opened this issue 3 years ago • 9 comments

Hi guys i'm creating an e-commerce with CommerceJs and NextJS when handling payment i get this error

message: "The given data was invalid." type: "unprocessable_entity" line_items.item_7RyWOwmK5nEa2V.quantity: ["Requested quantity is not available."]

i tried to change my code like the docs but no luck

andrewnashed avatar Aug 15 '21 05:08 andrewnashed

I'm having the same issue

ashrithyvs avatar Aug 15 '21 07:08 ashrithyvs

Getting the same issue

rajmahil avatar Sep 03 '21 05:09 rajmahil

@andrewnashed have u got any solution for it

ARNAV-GHATE avatar Nov 05 '21 06:11 ARNAV-GHATE

Please feel free to post if u get any solution

ARNAV-GHATE avatar Nov 05 '21 06:11 ARNAV-GHATE

@ARNAV-GHATE this solution worked for me

function sanitizedLineItems(lineItems) { return lineItems.reduce((data, lineItem) => { const item = data; let variantData = null; if (lineItem.selected_options.length) { variantData = { [lineItem.selected_options[0].group_id]: lineItem.selected_options[0].option_id, }; } item[lineItem.id] = { quantity: lineItem.quantity, variants: variantData, ...data };

  return item;
  
  }, {});
};

and then you would use the function in the orderData like so

    `line_items: sanitizedLineItems(checkoutToken.live.line_items)`

andrewnashed avatar Nov 07 '21 01:11 andrewnashed

@ARNAV-GHATE this solution worked for me

function sanitizedLineItems(lineItems) { return lineItems.reduce((data, lineItem) => { const item = data; let variantData = null; if (lineItem.selected_options.length) { variantData = { [lineItem.selected_options[0].group_id]: lineItem.selected_options[0].option_id, }; } item[lineItem.id] = { quantity: lineItem.quantity, variants: variantData, ...data };

  return item;
  
  }, {});
};

and then you would use the function in the orderData like so

    `line_items: sanitizedLineItems(checkoutToken.live.line_items)`

where we have to use this code in which component??? not able to get u?

ARNAV-GHATE avatar Nov 08 '21 04:11 ARNAV-GHATE

@ARNAV-GHATE this solution worked for me function sanitizedLineItems(lineItems) { return lineItems.reduce((data, lineItem) => { const item = data; let variantData = null; if (lineItem.selected_options.length) { variantData = { [lineItem.selected_options[0].group_id]: lineItem.selected_options[0].option_id, }; } item[lineItem.id] = { quantity: lineItem.quantity, variants: variantData, ...data };

  return item;
  
  }, {});
};

and then you would use the function in the orderData like so

    `line_items: sanitizedLineItems(checkoutToken.live.line_items)`

where we have to use this code in which component??? not able to get u?

inside the payment form

andrewnashed avatar Nov 08 '21 09:11 andrewnashed

Im getting a memory leak when it says error invalid data, anyone know why? Its in the address form

eramadani3 avatar Dec 18 '21 03:12 eramadani3

That fix above did not work for me as the customer data was not sent.

portercol avatar Apr 03 '22 03:04 portercol