Class: Supercharged::ChargesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Supercharged::ChargesController
- Defined in:
- app/controllers/supercharged/charges_controller.rb
Instance Method Summary collapse
- #complete ⇒ Object
- #create ⇒ Object
- #new ⇒ Object
-
#setup_purchase ⇒ Object
For example for PayPal Express, which requires getting token before purchase action.
Instance Method Details
#complete ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/supercharged/charges_controller.rb', line 30 def complete params.require(:token) @charge = Charge.with_token(params[:token]) if @charge @charge.complete(params) redirect_to root_url else head :not_found end end |
#create ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'app/controllers/supercharged/charges_controller.rb', line 6 def create charge = Charge.new(charge_params) charge.user = current_user if charge.save render json: charge.as_json(only: [:id]) else render json: { errors: charge.errors }, status: :unprocessable_entity end end |
#new ⇒ Object
3 4 |
# File 'app/controllers/supercharged/charges_controller.rb', line 3 def new end |
#setup_purchase ⇒ Object
For example for PayPal Express, which requires getting token before purchase action.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/supercharged/charges_controller.rb', line 18 def setup_purchase charge = Charge.find(params[:charge_id]) token = charge.setup_purchase( ip: request.remote_ip, return_url: complete_charges_url, cancel_return_url: new_charge_url ) redirect_to charge.gateway.redirect_url_for(token) end |