Guest User

Untitled

a guest
Apr 23rd, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. def signup_unlimited_create
  2. @user = User.new(params[:user])
  3. @user.account_type = "Unlimited"
  4. @user.login = @user.email
  5. @number = params[:card_number]
  6. @month = params[:card_expiration_month]
  7. @year = params[:card_expiration_year]
  8. @type = params[:card_type]
  9.  
  10. gateway = ActiveMerchant::Billing::BraintreeGateway.new({
  11. :login => 'demo',
  12. :password => 'demo'
  13. })
  14.  
  15. if @user.errors.empty?
  16. if @number != "" and @month and "" and @year != "" and @type != ""
  17. @card = ActiveMerchant::Billing::CreditCard.new(:first_name => @user.first_name,
  18. :last_name => @user.last_name,
  19. :number => params[:card_number],
  20. :month => params[:card_expiration_month],
  21. :year => params[:card_expiration_year],
  22. :type => params[:card_type])
  23.  
  24. @options = { :store => true, :order_id => "1212451" }
  25. response = gateway.authorize(1099.95, @card, @options)
  26.  
  27. if @card.id != nil
  28. self.current_user = @user
  29. @user.credit_card_id = response.params["customer_vault_id"]
  30. end
  31.  
  32. if @user.credit_card_id == nil
  33. flash[:notice] = "Please verify your credit card information below."
  34. render :action => 'signup_unlimited'
  35. end
  36.  
  37. if @user.credit_card_id != nil
  38. @user.save
  39. @invoice = Invoice.new(params[:invoice])
  40. @invoice.amount = "9.95"
  41. @invoice.due_date = Date.today + 30
  42. @invoice.generated_date = Date.today
  43. @invoice.status = "Due"
  44. @invoice.user_id = @user.id
  45. @invoice.save
  46. self.current_user = @user
  47. flash[:notice] = "Thanks for signing up"
  48. redirect_to :action => 'index'
  49. end
  50. else
  51. flash[:notice] = "please fill out all credit card fields"
  52. render :action => 'signup_unlimited'
  53. end
  54. else
  55. flash[:notice] = "problem creating your account"
  56. render :action => 'signup_unlimited'
  57. end
  58. end
Add Comment
Please, Sign In to add comment