#MMunir-metadata

1 messages · Page 1 of 1 (latest)

potent seal
#

Can you rephrase your question or provide more details? Radio check boxes have nothing to do with metadata, so I'm not exactly sure what you're asking

lone mauve
#

Its like i have some value that is displayed in radio checkbox. On payment form my customer has to mention what he is paying so if he has selected a checkbox i want it to be displayed at metadata

#

Let me send you some codes

#

(function() {
var stripe = Stripe('pk_test_51JWkHLK7X12cK8Ptf5y5DQn6Ugf6miu3AqSuhH9wdLsyTB9ouf0TY31vDQxq19xIt6YH76uMTEX1kU9HMyrcEb6w00MTxHnGxc');

var cause = document.getElementById('cause');
var amount = document.getElementById('amount');
var currency = document.getElementById('currency');
var datepicker = document.getElementById('datepicker');
var adults = document.getElementById('adults');
var children = document.getElementById('children');
var btn = document.getElementById('btn');

btn.addEventListener('click', async (e) => {
  e.preventDefault();
  fetch('/checkout_sessions', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      cause: cause.value,
      datepicker: datepicker.value,
      adults: adults.value,
      children: children.value,
      currency: currency.value,
      amount: parseInt(amount.value * 100, 10),
    }),
  })
  .then((response) => response.json())
  .then((session) => {
    stripe.redirectToCheckout({ sessionId: session.id });
  })
  .catch((error) => {
    console.error('Error:', error);
  });
});

})();

#

this is javascript

server side php

#

$session = \Stripe\Checkout\Session::create([
'success_url' => 'http://localhost:4242/?success=true',
'cancel_url' => 'http://localhost:4242/?cancel=true',
'mode' => 'payment',
'payment_method_types' => $payment_method_types[$params->currency],
'metadata' => [
'datepicker' => $params->datepicker,
'adults' => $params->adults,
'children' => $params->children,
'cause' => $params->cause,
'currency' => $params->currency,
],
'submit_type' => 'donate',
'line_items' => [[
'price_data' => [
'currency' => $params->currency,
'product' => $products[$params->cause],
'unit_amount' => $params->amount,
],
'quantity' => 1,
]]
]);

return $response->withJson([
'id' => $session->id
]);
});

#

how can i send radiobox value to metadata what ever is checked so i get to know what my customer has selected and paid for

potent seal
#

You would just pull the radiobox value, pass it along to your server side call to create the checkout session, and then include that as metadata in the Checkout Session

lone mauve
#

i tried var occupancy =document.getElementByName ('occupancy');

#

but couldnt pass it

potent seal
#

Did you get an error? You need to be more specific

lone mauve
#

i got error in console it says js has error when i try to find which line it takes me to .catch((error) => {
console.error('Error:', error);

potent seal
#

But what did the console error say?

lone mauve
#

donate.js:35 Error: SyntaxError: Unexpected token < in JSON at position 75
(anonymous) @ donate.js:35
Promise.catch (async)
(anonymous)

#

this is the error

potent seal
#

Have you checked the request to create the CHeckout Session to confirm that it succeeded?

lone mauve
#

how do i do that

#

like before i insert this var get elemnt for occupancy checkout woks fine as i insert to gat params for checked radio box i get this error

potent seal
#

For checking whether the issue is with the request to create you'd check your server logs or dashboard requests

#

You need to take the time to look at your own integration and add logs so you can self-serve and understand where the bug is

gilded needle