0

I have a controller method that is called as a return url like this

....../paypal/success 

That looks like this ,

 def success   
            transaction = Transaction.find_by_token(params[:token])
            transaction.payer_id = params[:payer_id] 
            transaction.save
            @current_user = user = User.find(transaction.user_id)   
            username = "xxxxxxxxxxxxxxxxxxxx"
            password = "7xxxxxxxxxxxxxxx"
            signature = "xxxxxxxxxxxxxxx"       
            version = 98
            @amount = Currency.convert(user.currency, "USD", transaction.amount.to_f).to_f.round(2)
            url = "https://api-3t.paypal.com/nvp?USER=#{username}&PWD=#{password}&SIGNATURE=#{signature}&VERSION=#{version}&METHOD=DoExpressCheckoutPayment&TOKEN=#{transaction.token}&PAYERID=#{transaction.payer_id}&PAYMENTREQUEST_0_PAYMENTACTION=SALE&PAYMENTREQUEST_0_AMT=#{@amount}&PAYMENTREQUEST_0_CURRENCYCODE=USD"       
            uri = URI.parse(url)
            http = Net::HTTP.new(uri.host, uri.port)
            http.use_ssl = true
            http.verify_mode = OpenSSL::SSL::VERIFY_NONE 
            request = Net::HTTP::Get.new(uri.request_uri)
            res = http.request(request)
            response = res.body
            transaction.save
            user.balance = (user.balance+transaction.amount)
            user.save()         
            transaction.status ="Completed"
            transaction.save()  
            flash[:notice] = 'Payment Transaction Completed. Thank you for using skyline SMS'
            redirect_to user_home_path(@current_user)     

However, the lines

redirect_to user_home_path(@current_user)

instead takes the user to sign in page.

How can i sign in the user from the method so that they are redirected to the their home page.

Authentication system is devise Thank you in advance.

acacia
  • 1,375
  • 1
  • 14
  • 40

1 Answers1

0

You can use the sign_in() method from Devise::Controllers::Helpers which are already mixed into the ApplicationController and hence available to all your controllers. So, in your success action, you'll do the following:

user = User.find(transaction.user_id) 
sign_in(user)

The Devise::Controllers::Helpers in turn include Devise::Controllers::SignInOut which is where you'll see the real code.

Chandranshu
  • 3,669
  • 3
  • 20
  • 37