I'm looking for feedback on the best way to inject "tax_percent" into my app's Stripe subscription at checkout.
Since I live in NJ, I need to determine if the subscription purchaser (current_user) also lives in NJ. Right now, I'm asking the user at checkout what state they live in and if they select NJ, I add in 7% sales tax through javascript call to update the displayed tax and order total.
When the form is submitted and the subscription created, it's not passing in the tax_percent value as a subscription object since it's only a client-side function. So my challenge is getting that tax_percent injected into the subscription form so it gets submitted to Stripe's API and recorded with Stripe.
I think I have a couple options and I was wondering what the best approach to this issue is.
- The first option I thought of is to ask the user what state they live in when they first sign-up to the site through devise. I can add a home_state column to the user's table. I'll also need to add in a tax_percent column to my subscription table. Then I'll have a current_user.home_state value I can query at checkout.
At checkout I can essentially ask:
<% if current_user.home_state == "NJ" %>
<%= hidden_field :subscription, :tax_percent, :value => '7' %>
<% end %>
But since this value can be changed by a savvy user, this might not be the best approach.
How else can I set the :tax_percent more securely? Again, it only applies to NJ residents. If you don't live in NJ, tax_percent can be null.
For some background, I was initially trying to figure out how to pass it in from the javascript math (Stripe and tax_percent in my Rails app)
Thanks!