Guest User

Untitled

a guest
Nov 20th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. class HomeController < ApplicationController
  2. def index
  3. @photo = Photo.new
  4. if current_user
  5. @album_hash = get_album_hash(current_user)
  6. end
  7. end
  8.  
  9. # '/share'
  10. def share
  11. if params[:id]
  12. @photo = Photo.find(params[:id])
  13. if current_user
  14. @fb_user = FbGraph::User.me(current_user.fb_token)
  15. @friends = @fb_user.fetch.friends.collection.to_json
  16. end
  17. end
  18.  
  19. render :layout => true
  20. end
  21.  
  22. # '/share/postcard'
  23. def postcard
  24. @postcard = Postcard.new
  25. @postcard.build_address
  26. end
  27.  
  28. # POST '/share/postcard'
  29. def postcard_create
  30. @photo = Photo.find(params[:postcard][:photo_id])
  31. params[:postcard].delete(:photo_id)
  32. @postcard = Postcard.new(params[:postcard])
  33. if @postcard.save
  34. @photo.postcard_id = @postcard.id
  35. @photo.save
  36. render :text => "OK!"
  37. end
  38. end
  39.  
  40. def stripe
  41. # remember to change secret key to live key
  42. Stripe.api_key = "M3t0pd80EUGG0ocyWtpoFqKBZsVyNsmE"
  43. puts "HELLO@!!"
  44. puts params
  45. puts current_user
  46. puts session
  47. puts "HELLO!!!"
  48. if params[:stripeToken]
  49. # get the credit card details submitted by the form
  50. token = params[:stripeToken]
  51.  
  52. # create a customer
  53. customer = Stripe::Customer.create(
  54. :card => token,
  55. :description => current_user.id
  56. )
  57.  
  58. # save the stripe_id to the user model
  59. current_user.stripe_id = customer.id
  60. current_user.save
  61. end
  62.  
  63. # create the charge on Stripe's servers - this will charge the user's card
  64. charge = Stripe::Charge.create(
  65. :amount => 100, #amount in cents, again
  66. :currency => "usd",
  67. :customer => current_user.stripe_id
  68. )
  69.  
  70. render :text => "OK!"
  71. end
  72.  
  73. private
  74.  
  75. def get_album_hash(current_user)
  76. fb_user = FbGraph::User.me(current_user.fb_token)
  77.  
  78. @albums = fb_user.albums
  79. @album_hash = Hash.new
  80. @albums.each do |album|
  81. @album_hash.merge!(album.raw_attributes["id"] => album.raw_attributes["name"])
  82. end
  83. return @album_hash
  84. end
  85.  
  86. def get_photos_from_album(album_id)
  87. @album = FbGraph::Album.new(album_id, :access_token => current_user.fb_token)
  88. @photos = @album.photos
  89. @photos.each do |photo|
  90. photo.picture
  91. end
  92. end
  93. end
Add Comment
Please, Sign In to add comment