andrewculver / koudoku

Robust subscription support for Rails with Stripe.
MIT License
1.16k stars 187 forks source link

Unauthorized - after choosing plan + stripe payment #189

Open Michi441 opened 6 years ago

Michi441 commented 6 years ago

So when i choose a plan as a user in my project, stripe registers it and the new subscription is visible in the stripe dashboard. This seem to be working just fine.

However, when i try to edit the plan as the user inside my project (via <%= link_to "Check profile", koudoku.owner_subscriptions_path(@user) %>), i always get the unauthorized page.

Association between subscription & user is working, in rails c:

Subscription.last:

=> #<Subscription id: 5, stripe_id: "cus_not_important, plan_id: 1, last_four: "4242", coupon_id: nil, card_type: "undefined", current_price: 20.0, user_id: 6, created_at: "2018-03-10 10:20:20", updated_at: "2018-03-10 10:20:20">

User.last:

=> #<User id: 6, email: "test6@test.com", created_at: "2018-03-10 10:19:32", updated_at: "2018-03-10 10:19:33", name: "Test8", provider: nil, uid: nil, image: nil, description: nil, plan_id: nil>

So this seems to be working just fine.

Im using devise and when i installed koudoku i used:

rails g koudoku:install user

Inside Koudoku.rb:


Koudoku.setup do |config|

  config.subscriptions_owned_by = :user
  config.stripe_publishable_key = ENV[#]
  config.stripe_secret_key = ENV[#]

  Stripe.api_version = '2017-08-15' # Making sure the API version used is compatible.
  # config.prorate = false # Default is true, set to false to disable prorating subscriptions
  # config.free_trial_length = 30

  # Specify layout you want to use for the subscription pages, default is application
  config.layout = 'application'

  # you can subscribe to additional webhooks here
  # we use stripe_event under the hood and you can subscribe using the
  # stripe_event syntax on the config object:
  # config.subscribe 'charge.failed', Koudoku::ChargeFailed

end

Any ideas whats going on?

//EDIT:

When i add


<h1><%= t('koudoku.failure.unauthorized') %></h1>

<%= @owner.name %>

to the unauthorized.html.erb file, the owner names is displayed correctly. If this may help.

MiselAdemi commented 6 years ago

@Prometheus88 I have the same problem in production. I development env everything works good. Did you find solution for this problem?

Michi441 commented 6 years ago

@MiselAdemi Hey! No, couldn't fix it. I've contacted one of the makers of koudoku and asked if they could check this issue out, but they haven't replied on here since then. I removed koudoku completely and added stripe payment manually. Theres a good tutorial on gorails about it if you don't know how exactly.

I think the problem has something to do with devise and the current_user definition, but i have no idea what exactly. There are also some other gems out there that can do the job (one of them is Payola but honestly, integrating it manually wasn't that hard.

Hope this helps!

Greetings!

ACPK commented 5 years ago

@Prometheus88 - Did they reply?

gwalshington commented 5 years ago

I never had this issue until now, seemingly out of no where, and there's hundreds of users now getting 'Unauthorized' once they create a subscription, or want to edit. Would love if this ticket was looked at!

andrewculver commented 5 years ago

@Prometheus88 @ACPK I'm sorry we weren't more responsive to this issue report last year.

@gwalshington I'm in regular contact with lots of developers who are using Koudoku in production applications at scale and haven't heard any rumblings about this issue beyond what has been reported above (and maybe on other issues if there are any submitted). There haven't been any recent updates either, so it leads me to believe that something else might have changed in your applications configuration, permissions (maybe CanCanCan abilities), or some other bug that's causing the request type to change or something else that has caused this to present itself in your application. However, it's difficult to be completely sure without being able to dig into an application's code.

I believe the best help we can offer is to hop on a pair programming call via https://tuple.app (I can provide a guest account) and work through the issue together on your machine. If you're interested, please email me at my first name at the domain of https://bullettrain.co and we can discuss rates and availability.

gwalshington commented 5 years ago

I don't use cancancan. There are other people above reporting the same issue.

I'd rather rebuild with stripe than pay you to debug your own gem.

andrewculver commented 5 years ago

@gwalshington OK! No problem at all! I was just trying to be helpful.

Alternatively (and I only suggest this because Koudoku seems to have been working well for you until this point) you could also just bust open the gem source yourself and try to debug the error being thrown that way.

If you do figure this out, please let us know what the issue was so we can close this issue!