Class: CatarseStripe::Payment::StripeController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- CatarseStripe::Payment::StripeController
- Defined in:
- app/controllers/catarse_stripe/payment/stripe_controller.rb
Constant Summary collapse
- SCOPE =
"users.projects"
Instance Method Summary collapse
- #cancel ⇒ Object
- #charge ⇒ Object
-
#connect ⇒ Object
TODO add auth code - replace omniauth.
- #ipn ⇒ Object
- #notifications ⇒ Object
- #pay ⇒ Object
-
#review ⇒ Object
end.
- #success ⇒ Object
Instance Method Details
#cancel ⇒ Object
153 154 155 156 157 |
# File 'app/controllers/catarse_stripe/payment/stripe_controller.rb', line 153 def cancel backer = current_user.backs.find params[:id] flash[:failure] = t('stripe_cancel', scope: SCOPE) redirect_to main_app.new_project_backer_path(backer.project) end |
#charge ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'app/controllers/catarse_stripe/payment/stripe_controller.rb', line 70 def charge @backer = current_user.backs.find params[:id] access_token = @backer.project.stripe_access_token #Project Owner SECRET KEY respond_to do |format| format.html format.js end end |
#connect ⇒ Object
TODO add auth code - replace omniauth
19 20 21 22 23 24 25 26 |
# File 'app/controllers/catarse_stripe/payment/stripe_controller.rb', line 19 def connect @user = current_user respond_to do |format| format.html format.js end end |
#ipn ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/catarse_stripe/payment/stripe_controller.rb', line 39 def ipn backer = Backer.where(:payment_id => details.id).first if backer notification = backer.payment_notifications.new({ extra_data: JSON.parse(params.to_json.force_encoding(params['charset']).encode('utf-8')) }) notification.save! backer.update_attribute :payment_service_fee => details.fee end return render status: 200, nothing: true rescue Stripe::CardError => e ::Airbrake.notify({ :error_class => "Stripe Notification Error", :error_message => "Stripe Notification Error: #{e.inspect}", :parameters => params}) rescue nil return render status: 200, nothing: true end |
#notifications ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/catarse_stripe/payment/stripe_controller.rb', line 54 def notifications backer = Backer.find params[:id] details = Stripe::Charge.retrieve( id: backer.payment_id ) if details.paid = true build_notification(backer, details) render status: 200, nothing: true else render status: 404, nothing: true end rescue Stripe::CardError => e ::Airbrake.notify({ :error_class => "Stripe Notification Error", :error_message => "Stripe Notification Error: #{e.inspect}", :parameters => params}) rescue nil render status: 404, nothing: true end |
#pay ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'app/controllers/catarse_stripe/payment/stripe_controller.rb', line 80 def pay @backer = current_user.backs.find params[:id] access_token = @backer.project.stripe_access_token #Project Owner SECRET KEY begin customer = Stripe::Customer.create( { email: @backer.payer_email, card: params[:stripeToken] }, access_token ) @backer.update_attributes(:payment_token => customer.id) @backer.save flash[:notice] = "Stripe Customer ID Saved!" response = Stripe::Charge.create( { #card: token, customer: @backer.payment_token, amount: @backer.price_in_cents, currency: 'usd', description: t('stripe_description', scope: SCOPE, :project_name => @backer.project.name, :value => @backer.display_value), application_fee: @backer.platform_fee.to_i }, access_token #ACCESS_TOKEN (Stripe Secret Key of Connected Project Owner NOT platform) ) @backer.update_attributes({ :payment_method => 'Stripe', :payment_token => response.customer, #Stripe Backer Customer_id :payment_id => response.id, #Stripe Backer Payment Id :confirmed => response.paid #Paid = True, Confirmed = true }) @backer.save build_notification(@backer, response) redirect_to payment_success_stripe_url(id: @backer.id) rescue Stripe::CardError => e ::Airbrake.notify({ :error_class => "Stripe #Pay Error", :error_message => "Stripe #Pay Error: #{e.inspect}", :parameters => params}) rescue nil Rails.logger.info "-----> #{e.inspect}" flash[:error] = e. return redirect_to main_app.new_project_backer_path(@backer.project) end end |
#review ⇒ Object
end
35 36 37 |
# File 'app/controllers/catarse_stripe/payment/stripe_controller.rb', line 35 def review end |
#success ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'app/controllers/catarse_stripe/payment/stripe_controller.rb', line 127 def success backer = current_user.backs.find params[:id] access_token = backer.project.stripe_access_token #Project Owner SECRET KEY begin details = Stripe::Charge.retrieve( { id: backer.payment_id }, access_token ) build_notification(backer, details) if details.id backer.update_attribute :payment_id, details.id end stripe_flash_success redirect_to main_app.thank_you_project_backer_path(project_id: backer.project.id, id: backer.id) rescue Stripe::CardError => e ::Airbrake.notify({ :error_class => "Stripe Error", :error_message => "Stripe Error: #{e.}", :parameters => params}) rescue nil Rails.logger.info "-----> #{e.inspect}" flash[:error] = e. return redirect_to main_app.new_project_backer_path(backer.project) end end |