#DeadlyData - Invalid Integer

1 messages · Page 1 of 1 (latest)

warm mauve
#

Also, can you share the code that leads to that error? Specifically the code that's calculating that value?

twilit isle
#

req_CEZ77YORRMTEVd

#

This is the information being sent over from Android to my server

#

usd
request body {
currency: 'usd',
items: [ { amount: '2566.70', id: 'photo_subscription' } ]
}
currency usd
2566.70

cloud terrace
#

I think amount should be an integer given in cents in case of usd

warm mauve
twilit isle
#

ah i see okay

warm mauve
#

Correct. You should add logic on your server to validate a positive integer is being provided.

#

If you're getting an amount in dollars you should multiply it by 100 to get the amount in cents.

twilit isle
#

so for return it should be something like items[0].amount*100?

warm mauve
#

Yes, plus the validation logic.

twilit isle
#

So i did that wrote logic test if a positive integer is provided and i* the dollars by 100

#

but i am still gettting an error

#

req_3U9nOjmnQokZlL

#

Says invalid integer still

random leaf
#

Hi, I'm stepping in here to further assist. Let me get caught up here.

twilit isle
#

Hello, oaky

#

okay*

#

this is how my server code looks

#

This is the data being sent over

#

StripeInvalidRequestError: Invalid integer: 256669.99999999997

#

req_3U9nOjmnQokZlL

random leaf
#

{
amount: "256669.99999999997",
currency: "usd"
}

shows to have been passed to us

#

So we are receiving amount: 256669.99999999997 on our end for that request. From looking at one of your other requests, we are seeing it working as expected: req_IpLcuJn69p6F4J.

twilit isle
#

So why's it coming as an error here?

random leaf
warm mauve
#

Hello again! To clarify, any number with a decimal will not work, as such a number is not an integer. You need to add code to convert decimals into integers (the exact method depends on your business needs) and then send those integers to the Stripe API.

twilit isle
#

okay i see, so it would be best to convert the double to a decimal then send it to stripe? i tried without a decimal and it was sucessful.

warm mauve
#

For example, if the amount you start with is $23.456 you would first multiply it by 100 to get the amount in cents: 2345.6, then you need to figure out how you want to handle the fraction of a cent. You can round up or round down, but at the end you should end up with an integer that is either 2345 or 2346 with no decimal.

twilit isle
#

I got it working thank you!!

#

🥳