###前提・実現したいこと
Ruby on Railsで、とあるチュートリアルを見ながらAirBnBのようなサービスを作成中です。Stripeで支払い機能を追加する段階で、物件登録者にStripeの登録ページへ飛んでもらうボタンを作成したのですが、ページ遷移がうまくいきません。解決方法をご存知の方がいらっしゃいましたらご教示よろしくお願いいたします。
###発生している問題・エラーメッセージ
uninitialized constant StripeOauth::RestClient
###該当のソースコード
view fileです。ここからstripe_oauth_pathに飛びます。
<ul class="list-group"> <li class="list-group-item" id="stripe-oauth"> <p>Register your bank account from the below link.</p> <%= link_to stripe_oauth_path do %> <%= image_tag "blue-on-light.png" %> <% end %> </li> </ul>
コントローラです。
class StripeController < ApplicationController def oauth connector = StripeOauth.new( current_user ) url, error = connector.oauth_url( redirect_uri: stripe_confirm_url ) if url.nil? flash[:error] = error redirect_to manage_listing_payment_path( session[:listing_id] ) else redirect_to url end end end
url取得プロセスです。
class StripeOauth < Struct.new( :user ) def oauth_url( params ) url = client.authorize_url( { scope: 'read_write', stripe_landing: 'register', stripe_user: { email: user.email } }.merge( params ) ) # Make a request to this URL by hand before # redirecting the user there. This way we # can handle errors (other than access_denied, which # could come later). # See https://stripe.com/docs/connect/reference#get-authorize-errors begin response = RestClient.get url # If the request was successful, then we're all good to return # this URL. rescue => e # On the other hand, if the request failed, then # we can't send them to connect. json = JSON.parse(e.response.body) rescue nil if json && json['error'] case json['error'] # The application is configured incorrectly and # does not have the right Redirect URI when 'invalid_redirect_uri' return nil, <<-EOF Redirect URI is not setup correctly. Please see the <a href='#{Rails.configuration.github_url}/blob/master/README.markdown' target='_blank'>README</a>. EOF # Something else horrible happened? Network is down, # Stripe API is broken?... else return [ nil, params[:error_description] ] end end # If there was some problem parsing the body # or there's no 'error' parameter, then something # _really_ went wrong. So just blow up here. return [ nil, "Unable to connect to Stripe. #{e.message}" ] end [ url, nil ] end def client @client ||= OAuth2::Client.new( Rails.configuration.stripe[:client_id], Stripe.api_key, { site: 'https://connect.stripe.com', authorize_url: '/oauth/authorize', token_url: '/oauth/token' } ).auth_code end end
###補足情報
Stripe設定方法 https://github.com/rfunduk/rails-stripe-connect-example
RestClientについて https://github.com/rest-client/rest-client
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。