Usage Charge with prices like 1.345 (>1 and <2) are being created as 1345 (>1000).

electricsms
New Member
1 0 1

Hey everyone, hope someone can help me with this issue.

I'm developing a Shopify App that has monthly recurrent plans with usage fees based on the number of SMS messages the shop sends to their customers. Here's a image on how our pricing is defined:

Screen Shot 2020-06-16 at 8.46.07 AM.png

Giving an example, if a customer is using the Spark plan and sends in a day a number of 149 SMS messages, we will add an usage fee of:

149 * 0,016 = 2,384.  (>2 and <3)

Our app is currently using RoR integrated with the official shopify_app gem provided by Shopify. We are also integrating with Shopify Billing, using their RoR API to integrate with all resources: ApplicationCharge, UsageCharge, RecurringApplicationCharge.

Every day we bill users for all the SMS sent by our app, so here it's how the cron job looks like:

usage_price = SMS.pending_charge.sum(:price) # E.g: 2.345
usage_charge = ShopifyAPI::UsageCharge.new(
  description: "Usage SMS #{usage_price}",
  price: usage_price
)
usage_charge.save


This is code is creating usage charges of $2345 instead of $2.34 or $2.35.

The confusion here is because the param price accordingly to the documentation is a number, not a string. But if you look at the custom scalars documentation here, you can see that Decimal values are actually expected as serialized strings, not numbers. So what the shopify_api does is to get the number 2.345 and convert it directly to string, which will return "2.345" resulting in the Shopify API parsing this value as 2345 instead of 2.34.

I believe that the ruby gem API should be safe enough to avoid this kind of mistake, by making sure that any extra decimal are removed before actually being sent to Shopify API, specially when something like this can happen.

I've fixed the problem on my side, by simple doing:

usage_price = SMS.pending_charge.sum(:price).round(2)

And now it seems like it's working fine.

The problem that I'm facing right now is that one of my clients has a charge of $9750 instead of $9,75 and it seems like there's no API endpoint available to cancel these wrong value usage charges. I've tried contacting support and they told me to ask for help here on how to change these usage charges values to their correct ones.

I've done some research and it seems like creating application credit is an option, but I don't want my client to get credit in other apps, I just want to refund all these wrong charges.

Thanks, please let me know if I've done any wrong conclusion about how these values are serialized.

SBD_
Shopify Staff
Shopify Staff
1044 141 183

Hey @electricsms 

Thanks for reporting this. I'm able to replicate and I've created an issue internally.

Regarding the refund, please reach out to Shopify support with the merchant info and the charge, and our support teams will be able to issue the refund to the merchant.