Search code examples
ruby-on-railsstripe-paymentsstripe-connect

Stripe landing page setting not working


I'm currently taking an online course to make an airbnb like web application with ruby on rails. It utilizes Stripe for the payment and I want to make the landing page from my app to the Stripe a register page instead of a login page.

I'm completely following the tutorial that successfully makes the register page as the landing page with the below code.

stripe_landing: 'register'

But my landing page is still the login page. I googled the above code but all I could find was pages from 2-4 years ago. I wonder if Stripe changed it recently. (but hpar replied saying nothing has changed)

I put the whole code here... When I click the link to Stripe, it goes to stripe#oauth.

    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

then,

    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

The terminal says;

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

so I think I get the right url here (same as the tutorial video gets). However, in Chrome, it actually goes to;

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

Sorry for the poor explanation but it would be great if anyone can solve this mystery. Thanks a lot!


Solution

  • I tried on safari and it worked properly so I deleted related cookies on chrome and it worked.