You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.4 KiB

  1. class Admin::PaypalPaymentsController < Admin::BaseController
  2. before_filter :load_data
  3. before_filter :load_amount, :except => :country_changed
  4. resource_controller
  5. belongs_to :order
  6. ssl_required
  7. update do
  8. wants.html { redirect_to edit_object_url }
  9. end
  10. def country_changed
  11. end
  12. include Spree::PaypalExpress::Gateway
  13. def capture
  14. if !@order.paypal_payments.empty? && (payment = @order.paypal_payments.last).can_capture?
  15. do_capture(payment.find_authorization)
  16. flash[:notice] = t("paypal_capture_complete")
  17. else
  18. flash[:error] = t("unable_to_capture_paypal")
  19. end
  20. redirect_to edit_object_url
  21. end
  22. private
  23. def load_data
  24. load_object
  25. @selected_country_id = params[:payment_presenter][:address_country_id].to_i if params.has_key?('payment_presenter')
  26. @selected_country_id ||= @order.bill_address.country_id if @order and @order.bill_address
  27. @selected_country_id ||= Spree::Config[:default_country_id]
  28. @states = State.find_all_by_country_id(@selected_country_id, :order => 'name')
  29. @countries = Country.find(:all)
  30. end
  31. # what for?
  32. def load_amount
  33. @amount = params[:amount] || @order.total
  34. end
  35. def build_object
  36. @object ||= end_of_association_chain.send parent? ? :build : :new, object_params
  37. # not relevant?
  38. # @object.creditcard = Creditcard.new(:address => @object.order.bill_address.clone) unless @object.creditcard
  39. @object
  40. end
  41. end