質問編集履歴

1

より詳細な説明を追加

2017/07/08 17:06

投稿

ymatt
ymatt

スコア20

test CHANGED
File without changes
test CHANGED
@@ -8,4 +8,136 @@
8
8
 
9
9
  ```
10
10
 
11
- とあるチュートリアルには上記でregister画面に飛ぶとありましたが、loginに飛びます。上記コードで検索すると、どれも2-4年前の記述がヒットします。現在のStripeは仕様が異なるのでしょう。ご存知の方いらっしゃいましたらご教示お願いいたします
11
+ とあるチュートリアルには上記でregister画面に飛ぶとありましたが、loginに飛びます。上記コードで検索すると、どれも2-4年前の記述がヒットします。現在のStripeは仕様が変わっているのかとも考えましたが、別サイトで仕様に変更はなとの回答をいただきま
12
+
13
+
14
+
15
+ ###問題のコード
16
+
17
+ ```
18
+
19
+ class StripeController < ApplicationController
20
+
21
+ # Connect yourself to a Stripe account.
22
+
23
+ # Only works on the currently logged in user.
24
+
25
+ # See app/services/stripe_oauth.rb for #oauth_url details.
26
+
27
+
28
+
29
+ def oauth
30
+
31
+ connector = StripeOauth.new( current_user )
32
+
33
+ url, error = connector.oauth_url( redirect_uri: stripe_confirm_url )
34
+
35
+
36
+
37
+ if url.nil?
38
+
39
+ flash[:error] = error
40
+
41
+ redirect_to manage_listing_payment_path( session[:listing_id] )
42
+
43
+ else
44
+
45
+ redirect_to url
46
+
47
+ end
48
+
49
+ end
50
+
51
+
52
+
53
+ end
54
+
55
+ ```
56
+
57
+ ```
58
+
59
+ class StripeOauth < Struct.new( :user )
60
+
61
+
62
+
63
+ def oauth_url( params )
64
+
65
+ url = client.authorize_url( {
66
+
67
+ scope: 'read_write',
68
+
69
+ stripe_landing: 'register',
70
+
71
+ stripe_user: {
72
+
73
+ email: user.email
74
+
75
+ }
76
+
77
+ }.merge( params ) )
78
+
79
+
80
+
81
+ [ url, nil ]
82
+
83
+ end
84
+
85
+
86
+
87
+ # A simple OAuth2 client we can use to generate a URL
88
+
89
+ # to redirect the user to as well as get an access token.
90
+
91
+ # Used in #oauth_url and #verify!
92
+
93
+ # see this docs https://github.com/intridea/oauth2
94
+
95
+ def client
96
+
97
+ @client ||= OAuth2::Client.new(
98
+
99
+ ENV['STRIPE_CONNECT_CLIENT_ID'],
100
+
101
+ Stripe.api_key,
102
+
103
+ {
104
+
105
+ site: 'https://connect.stripe.com',
106
+
107
+ authorize_url: '/oauth/authorize',
108
+
109
+ token_url: '/oauth/token'
110
+
111
+ }
112
+
113
+ ).auth_code
114
+
115
+ end
116
+
117
+
118
+
119
+ end
120
+
121
+ ```
122
+
123
+
124
+
125
+ ###発生している問題
126
+
127
+ ターミナルでは以下が表示されます。
128
+
129
+
130
+
131
+ 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
132
+
133
+
134
+
135
+ このurlはチュートリアル動画内にあるものと一致するので、コード自体はうまく走っているのではと思います。ただ、実際にクロームでたどり着くページのurlは以下です。
136
+
137
+
138
+
139
+ https://connect.stripe.com/login?redirect=%2Foauth%2Fauthorize%3Fclient_id%3Dca_AuidWGx68TXWlWO3d3UbWcRcuPqfSeNH%26redirect_uri%3Dhttp%253A%252F%252Flocalhost%253A3000%252Fconnect%252Fconfirm%26response_type%3Dcode%26scope%3Dread_write%26stripe_landing%3Dregister%26stripe_user%255Bemail%255D%3Daaa%2540gmail.com&force_login=true
140
+
141
+
142
+
143
+ 遷移先に設定すべきurlが最新のStripeではすでに変わっているのでしょうか。いずれにせよ、解決策ご存知の方いらっしゃいましたらよろしくお願いいたします。