LoadError in OmniauthCallbacksController#passthru(with devise / stripe connect) [英] LoadError in OmniauthCallbacksController#passthru (with devise/stripe connect)

查看:287
本文介绍了LoadError in OmniauthCallbacksController#passthru(with devise / stripe connect)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试实现Stripe Connect,当我点击连接到条带按钮时,出现以下错误。

Trying to implement Stripe Connect, and am getting the following error when I click the "connect to stripe" button.

无法找到动作passthru对于OmniauthCallbacksController

The action 'passthru' could not be found for OmniauthCallbacksController

users / omniauth_callbacks_controller.rb

users/omniauth_callbacks_controller.rb

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
    def stripe_connect
        @user = current_user
        if @user.update_attributes({
          provider: request.env["omniauth.auth"].provider,
          uid: request.env["omniauth.auth"].uid,
          access_code: request.env["omniauth.auth"].credentials.token,
          publishable_key: request.env["omniauth.auth"].info.stripe_publishable_key
        })
          # anything else you need to do in response..
          sign_in_and_redirect @user, :event => :authentication
          set_flash_message(:notice, :success, :kind => "Stripe") if is_navigational_format?
        else
          session["devise.stripe_connect_data"] = request.env["omniauth.auth"]
          redirect_to new_user_registration_url
        end
      end
end

models / user.rb

models/user.rb

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:stripe_connect]

routes.rb

routes.rb

devise_for :users, controllers: { registrations: 'users/registrations', :omniauth_callbacks => "users/omniauth_callbacks" }

gemfile.rb

gemfile.rb

gem 'omniauth-stripe-connect'

/stripe.rb

initializers/stripe.rb

Rails.configuration.stripe = {
  :publishable_key => ENV['PUBLISHABLE_KEY'],
  :secret_key      => ENV['SECRET_KEY']
}
Stripe.api_key = Rails.configuration.stripe[:secret_key]

initializers / devise.rb

initializers/devise.rb

config.omniauth :stripe_connect,
  ENV['STRIPE_CONNECT_CLIENT_ID'],
  ENV['STRIPE_SECRET_KEY'],
  :scope => 'read_write',
  :stripe_landing => 'register'

按钮链接:

<%= link_to image_tag('blue-on-light.png'), user_stripe_connect_omniauth_authorize_path(:stripe_connect) %>

正如我所理解的那样,我的noob Ruby心灵,我需要定义passthru?怎么定义呢?当我输入:

As I understand it with my noob Ruby mind, I need to define 'passthru'? how do I define it though? when I enter:

def passthru
end

链接不起作用/页面重新加载本身。在这里找不到解决方案。我失踪了什么

the link doesn't work / the page reloads itself. Haven't been able to find a solution on here. What am I missing?

编辑:

将我的连接更改为条带链接:

Changed my connect to stripe link to:

 <%= link_to image_tag('blue-on-light.png'), "/users/auth/stripe_connect" %>

链接带我到连接到条带页面,但是当我点击连接到条带按钮,页面无法找到,不加载或重定向。

The link takes me to the connect to stripe page, but when I click the "connect to stripe" button, the page cant be found, and doesn't load or redirect.

推荐答案

您可以尝试更改

# app/controllers/omniauth_callbacks_controller.rb
class OmniauthCallbacksController < ApplicationController
    def stripe_connect
    ....

to

class OmniauthCallbacksController < Devise::OmniauthCallbacksController 
    def stripe_connect
      @user = User.find_for_stripe_connect(request.env['omniauth.auth'], current_user)
      set_notice_and_redirect
    end

    private

    def set_notice_and_redirect          
      if @user.persisted?
          flash[:notice] = 'Successfully signed in'
          set_flash_message(:notice, :success, :kind => "Stripe") if is_navigational_format?
        else
          session["devise.stripe_connect_data"] = request.env["omniauth.auth"]
          redirect_to new_user_registration_url
      end
    end
end

在您的用户模型中

# Checks if user exists, otherwise create it
def self.find_for_stripe_connect(access_token, _ = nil)
  data = access_token.info
  user = User.where(email: data['email']).first_or_create(
    email: data['email'],
    password: Devise.friendly_token[0, 20],
    provider: request.env["omniauth.auth"].provider,
    uid: request.env["omniauth.auth"].uid,
    access_code: request.env["omniauth.auth"].credentials.token,
    publishable_key: request.env["omniauth.auth"].info.stripe_publishable_key
  )
  user
end

,并在路径中唱歌

<%= link_to image_tag('blue-on-light.png'), user_stripe_connect_omniauth_authorize %>

我想你不需要定义一个passthru动作。如果您在路线中看到以下两个可以工作。授权路径是将用户重定向到条带,回调是将用户从条带重定向到您的站点

I think you don't need to define a passthru action. If you see the below two in the routes it can work. Authorize path is for redirecting user to stripe and callback is for redirecting user from stripe back to your site

$ rake routes

user_stripe_connect_omniauth_authorize /auth/stripe_connect(.:format)  ....
user_stripe_connect_omniauth_callback /auth/stripe_connect/callback(.:format) ....

这篇关于LoadError in OmniauthCallbacksController#passthru(with devise / stripe connect)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆