Question about pass money amount from frontend to backend using web payment sdk

Hi everyone,

We are integrating Square payment into our site, can I ask a few straight questions ? in Square website I saw a code like blow : and MY QUESTION is how do we pass amount we got from other payment page of our site and pass it to backend,

I tried to get amount from cookie and put it in JSON.stringify({ }) function and convert to Long in backend but that doesn’t seem to work so that’s why I feel urgent to ask , are we allowed to put amount in JSON.stringify({ }) and pass it to backend, if no, could anyone shed some lights on how do we pass amount we got from frontend and pass to backend ? thanks

async function createPayment(token) {

  const body = JSON.stringify({
        
    locationId,
    sourceId: token,

 

  });

const paymentResponse = await fetch( payments, {
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json’,
},
body,

   });

    if (paymentResponse.ok) {
       return paymentResponse.json();
   }

    const errorBody = await paymentResponse.text();
    throw new Error(errorBody);
    
}

:wave: Currently, we don’t have an example of passing the amount to the backend. All integrations are different and may choose to calculate and pass the amount to the backend differently. However passing the amount_money using JSON.stringify({ }) should work. Are you taking into account that the amount is nested in amount_money? :slightly_smiling_face:

1 Like