###前提・実現したいこと
Stripeで支払い機能を追加したいと思っています。アプリケーションからStripeのページに遷移する際に、loginではなくregister画面にしたいのですが、うまくいきません。
stripe_landing: 'register'
とあるチュートリアルには上記でregister画面に飛ぶとありましたが、loginに飛びます。上記コードで検索すると、どれも2-4年前の記述がヒットします。現在のStripeは仕様が変わっているのかとも考えましたが、別サイトで仕様に変更はないとの回答をいただきました。
###問題のコード
class StripeController < ApplicationController # Connect yourself to a Stripe account. # Only works on the currently logged in user. # See app/services/stripe_oauth.rb for #oauth_url details. 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
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 ) ) [ url, nil ] end # A simple OAuth2 client we can use to generate a URL # to redirect the user to as well as get an access token. # Used in #oauth_url and #verify! # see this docs https://github.com/intridea/oauth2 def client @client ||= OAuth2::Client.new( ENV['STRIPE_CONNECT_CLIENT_ID'], Stripe.api_key, { site: 'https://connect.stripe.com', authorize_url: '/oauth/authorize', token_url: '/oauth/token' } ).auth_code end end
###発生している問題
ターミナルでは以下が表示されます。
Started GET "/connect/oauth" for ::1 at 2017-07-09 00:37:55 +0800 Processing by StripeController#oauth as HTML User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]] Redirected to https://connect.stripe.com/oauth/authorize?client_id=ca_AuidWGx68TXWlWO3d3UbWcRcuPqfSeNH&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fconnect%2Fconfirm&response_type=code&scope=read_write&stripe_landing=register&stripe_user%5Bemail%5D=aaa%40gmail.com
このurlはチュートリアル動画内にあるものと一致するので、コード自体はうまく走っているのではと思います。ただ、実際にクロームでたどり着くページのurlは以下です。
遷移先に設定すべきurlが最新のStripeではすでに変わっているのでしょうか。いずれにせよ、解決策ご存知の方いらっしゃいましたらよろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。