ju57in

Company profile controller

May 11th, 2014
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 5.91 KB | None | 0 0
  1. class Company::ProfileController < Company::BaseController
  2.   def show
  3.   end
  4.  
  5.   def update
  6.     if !params[:company][:password].present? and !params[:company][:password_confirmation].present?
  7.       params[:company].delete(:password)
  8.       params[:company].delete(:password_confirmation)
  9.     end
  10.  
  11.     # THIS IS A TERRIBLE SPOT FOR THIS LOGIC
  12.     # BUT
  13.     #REMOVED CODE TO ALLOW COUPONS and CARDS
  14.     # if params[:stripeToken] || params[:stripe_coupon]
  15.     #       token = params[:stripeToken]
  16.     #       #must all be updated for company..
  17.     #       begin
  18.     #       #THIS NEEDS TO BE UPDATED TO HAVE THE USER CASE OF A PERSON WHO HAS USED A COUPON
  19.     #        # Company signs up for pro
  20.     #        customer = Stripe::Customer.create(
  21.     #          :card => token,
  22.     #          :plan => "sortboxpro",
  23.     #          :email => @company.email
  24.     #        )
  25.  
  26.     #start new coupon code
  27.     if params[:stripeToken] || params[:stripe_coupon]
  28.  
  29.       stripe_params = {
  30.        :plan => "sortboxpro",
  31.        :email => @company.email        
  32.       }
  33.  
  34.       stripe_params[:card] = params[:stripeToken] if params[:stripeToken]
  35.       stripe_params[:coupon] = params[:stripe_coupon] if params[:stripe_coupon].present?
  36.  
  37.       #must all be updated for company..
  38.       begin
  39.         # Company signs up for pro
  40.         customer = Stripe::Customer.create(stripe_params)
  41.         #end coupon code..
  42.  
  43.  
  44.         @company.companypro = true
  45.         @company.customerid = customer.id.to_s
  46.  
  47.       # abort if coupon doesn't exist
  48.       rescue Stripe::InvalidRequestError => e
  49.         @error = e
  50.         flash[:alert] = "Your Coupon has Expired or is not Valid."
  51.  
  52.       rescue Stripe::CardError => e
  53.        @error = e
  54.       end
  55.  
  56.     end
  57.    
  58.     if @company.update_attributes(params[:company])
  59.       flash[:notice] = "Updated successfuly"
  60.       redirect_to company_profile_path
  61.     else
  62.       render :action => "show"
  63.     end
  64.  
  65.   end
  66.   #CORY this is where I have added the stripe info for subscription. I don't know if this is correct.
  67.  
  68.   def remove_subscription
  69.     if @company.customerid
  70.       cu = Stripe::Customer.retrieve(@company.customerid)
  71.       if cu
  72.         cu.cancel_subscription
  73.         @company.customerid = nil
  74.         @company.companypro = false
  75.         @company.save
  76.       end
  77.     end
  78.     redirect_to company_profile_path
  79.   end
  80.  
  81. #this is most likely dead code. SMELLY!!
  82.  
  83.   def submit
  84.      if params[:stripeToken]
  85.        token = params[:stripeToken]
  86.        #must all be updated for company..
  87.        begin
  88.      
  89.          # Company signs up for pro
  90.          customer = Stripe::Customer.create(
  91.            :card => token,
  92.            :plan => "sortboxpro",
  93.            :email => @company.email
  94.          )
  95.  
  96.        @company.companypro = true
  97.        @company.customerid = customer.id.to_s
  98.        @company.save!
  99.        
  100.        rescue Stripe::CardError => e
  101.        @error = e
  102.        end
  103.   end
  104. end
  105. end
  106.  
  107. # class Company::ProfileController < Company::BaseController
  108. #   def show
  109. #   end
  110. #
  111. #   def update
  112. #     if !params[:company][:password].present? and !params[:company][:password_confirmation].present?
  113. #       params[:company].delete(:password)
  114. #       params[:company].delete(:password_confirmation)
  115. #     end
  116. #
  117. #     # THIS IS A TERRIBLE SPOT FOR THIS LOGIC
  118. #     # BUT
  119. #     #REMOVED CODE TO ALLOW COUPONS and CARDS
  120. #    # if params[:stripeToken] || params[:stripe_coupon]
  121. #    #       token = params[:stripeToken]
  122. #    #       #must all be updated for company..
  123. #    #       begin
  124. #    #       #THIS NEEDS TO BE UPDATED TO HAVE THE USER CASE OF A PERSON WHO HAS USED A COUPON
  125. #    #        # Company signs up for pro
  126. #    #        customer = Stripe::Customer.create(
  127. #    #          :card => token,
  128. #    #          :plan => "sortboxpro",
  129. #    #          :email => @company.email
  130. #    #        )
  131. #      
  132. #       #start new coupon code
  133. #       if params[:stripeToken] || params[:stripe_coupon]
  134. #
  135. #          stripe_params = {
  136. #           :plan => "sortboxpro",
  137. #           :email => @company.email        
  138. #             }
  139. #
  140. #          stripe_params[:card] = params[:stripeToken] if params[:stripeToken]
  141. #          stripe_params[:coupon] = params[:stripe_coupon] if params[:stripe_coupon].present?
  142. #
  143. #             #must all be updated for company..
  144. #         begin
  145. #           # Company signs up for pro
  146. #           customer = Stripe::Customer.create(stripe_params)
  147. #       #end coupon code..
  148. #        
  149. #
  150. #
  151. #
  152. #
  153. #
  154. #       @company.companypro = true
  155. #       @company.customerid = customer.id.to_s
  156. #
  157. #       rescue Stripe::CardError => e
  158. #        @error = e
  159. #       end
  160. #     end
  161. #    
  162. #     if @company.update_attributes(params[:company])
  163. #       #flash[:notice] = "Updated successfuly"
  164. #       redirect_to company_profile_path
  165. #     else
  166. #       render :action => "show"
  167. #     end
  168. #   end
  169. #   #CORY this is where I have added the stripe info for subscription. I don't know if this is correct.
  170. #
  171. #   def remove_subscription
  172. #     if @company.customerid
  173. #       cu = Stripe::Customer.retrieve(@company.customerid)
  174. #       if cu
  175. #         cu.cancel_subscription
  176. #         @company.customerid = nil
  177. #         @company.companypro = false
  178. #         @company.save
  179. #       end
  180. #     end
  181. #     redirect_to company_profile_path
  182. #   end
  183. #
  184. # #this is most likely dead code. SMELLY!!
  185. #
  186. #   def submit
  187. #      if params[:stripeToken]
  188. #        token = params[:stripeToken]
  189. #        #must all be updated for company..
  190. #        begin
  191. #      
  192. #          # Company signs up for pro
  193. #          customer = Stripe::Customer.create(
  194. #            :card => token,
  195. #            :plan => "sortboxpro",
  196. #            :email => @company.email
  197. #          )
  198. #
  199. #        @company.companypro = true
  200. #        @company.customerid = customer.id.to_s
  201. #        @company.save!
  202. #        
  203. #        rescue Stripe::CardError => e
  204. #        @error = e
  205. #      end
  206. #   end
  207. # end
  208. # end
Advertisement
Add Comment
Please, Sign In to add comment