0

I'm using stripe connect on my website, and when a user in production tries to connect his stripe account to my web site, I have the following error in the stripe callback :

{
  "error": "invalid_redirect_uri",
  "error_description": "Invalid redirect URI 'http://www.mywebsite.com/stripe_connections/callback'. Ensure this uri exactly matches one of the uris specified in your application settings",
  "state": "4 »
}  

whereas my redirecti URIS in my stripe application setting is https://www.mywebsite.com/stripe_connections/callback

here is my controller :

  require 'oauth2'

  class StripeConnectionsController < ApplicationController
    skip_after_action :verify_authorized

    def new
      stripe_auth_url = "https://connect.stripe.com/oauth"
      client = OAuth2::Client.new(ENV['STRIPE_CONNECT_CLIENT_ID'], ENV['STRIPE_SECRET_KEY'], :site => stripe_auth_url)
      @stripe_url = client.auth_code.authorize_url(:redirect_uri => "#{request.protocol}#{request.host_with_port}/stripe_connections/callback", :scope => 'read_write', state: params[:brief_id])
    end

    def callback
      @brief = Brief.find(params[:state])
      stripe_auth_url = "https://connect.stripe.com/oauth"
      @user = current_user
      client = OAuth2::Client.new(ENV['STRIPE_CONNECT_CLIENT_ID'], ENV['STRIPE_SECRET_KEY'], :site => stripe_auth_url)
      access_token = client.auth_code.get_token(params[:code], :redirect_uri => '#{request.protocol}#{request.host_with_port}/oauth2/callback')
      stripe_connection = StripeConnection.find_or_create_by(user_id: @user.id)
      stripe_connection.update_attributes(access_token: access_token.token,
                                          refresh_token: access_token.refresh_token,
                                          livemode: access_token.params['livemode'],
                                          stripe_user_id: access_token.params['stripe_user_id'],
                                          publishable_key: access_token.params['stripe_publishable_key']
                                          )
      @user.profile.projects.where(state: 'pending').update_all(state: "on_sale")
    end
  end

I'm using heroku and paying the SSL add-ons already. I don't know why stripe is returning http instead of https. Does anyone have an idea? thx.

ps: this has already worked before in production and works in the beta version of the website

Richard Osseweyer
  • 1,693
  • 20
  • 25
Arthur H
  • 39
  • 5
  • I suspect the callback URL (HTTP) is provided by you somewhere, and Stripe is just checking if it matches the one you set up (HTTPS). – awendt Sep 02 '15 at 11:03
  • I've added the controller to the question. It's being called by `request.protocol` – Arthur H Sep 02 '15 at 11:13
  • Can it be set somewhere within a stripe account? – j-dexx Sep 02 '15 at 11:17
  • no, not in my knowledge – Arthur H Sep 02 '15 at 12:40
  • I'm having the same exact issue..all of a sudden it's attempting to hit http. The url is set in stripe though. Did you have any updates? – Matt Kim Sep 04 '15 at 15:39
  • No i didn't. I told my users to add an -s- in the url that stripe returns. I'll try to fixe the problem next week, I'm in vacations :/ Did you succeed in fixing the problem? – Arthur H Sep 06 '15 at 21:51

2 Answers2

0

Do you have a button that the user clicks to connect to stripe? I just removed the redirect_uri parameter.

Matt Kim
  • 759
  • 7
  • 19
  • I did that too, because it's optional so my application settings would return the right uri, but still not working. – Arthur H Sep 06 '15 at 21:53
0

You have to remove the redirect_uri of client.auth_code.authorize_url() in the new method and also the redirect_uri in the callback method and put the right protocol in the dashboard stripe.

Arthur H
  • 39
  • 5