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

4

2 回答 2

0

您是否有用户单击以连接到条带的按钮?我刚刚删除了 redirect_uri 参数。

于 2015-09-04T16:34:45.660 回答
0

您必须删除方法中的of 以及方法redirect_uriclient.auth_code.authorize_url()的,并将正确的协议放在仪表板条带中。newredirect_uricallback

于 2015-09-17T14:12:01.307 回答