0

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.

  1. 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!

Community
  • 1
  • 1
JohnOHFS
  • 174
  • 14
  • Well first are you saving inside any model the user state? ofcourse I don't like the `hidden_field` option either. So, if you are saving it, then you can easily check the current user state backend inside the controller ot whatever class you are processing the logic, and accordingly apply the tax. No need any input from the client side – Arup Rakshit Jul 28 '16 at 15:04
  • Ok, I just see that you have saved it inside the app, by looking at this line `current_user.home_state == "NJ"`.. :) I missed it in my first reading. So you can put the logic in backend as I said above in the first comment. – Arup Rakshit Jul 28 '16 at 15:08
  • I think it's helpful to show the user what their total purchase is using javascript on the client side. The goal here is to inject the tax_percent on the server side when the subscription is created. How do I do that when the subscription is created during the purchase? @ArupRakshit – JohnOHFS Jul 28 '16 at 15:10
  • @ArupRakshit How do I put this logic in the backend? That's essentially what I need to understand. – JohnOHFS Jul 28 '16 at 15:10
  • for UI/UX show whatever you want to user. But in backend use your own logic. See you have `current_user` method which gives `user` object, and from that object you can easily get the state of the current user who is making the subscription, no? :) – Arup Rakshit Jul 28 '16 at 15:13
  • Yes, but how do I securely post tax_percent without specifying the value => "7", I'd like it to be set in the backend – JohnOHFS Jul 28 '16 at 15:14

0 Answers0