Class: Spree::MercadopagoController
- Inherits:
-
StoreController
- Object
- StoreController
- Spree::MercadopagoController
- Defined in:
- app/controllers/spree/mercadopago_controller.rb
Instance Method Summary collapse
-
#checkout ⇒ Object
skip_before_action :set_current_order, only: :ipn.
- #failure ⇒ Object
- #ipn ⇒ Object
-
#success ⇒ Object
Success/pending callbacks are currently aliases, this may change if required.
Instance Method Details
#checkout ⇒ Object
skip_before_action :set_current_order, only: :ipn
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/spree/mercadopago_controller.rb', line 8 def checkout current_order.state_name == :payment || raise(ActiveRecord::RecordNotFound) payment_method = PaymentMethod::Mercadopago.find(params[:payment_method_id]) payment = current_order.payments .create!(amount: current_order.total, payment_method: payment_method) payment.started_processing! preferences = ::Mercadopago::OrderPreferencesBuilder .new(current_order, payment, callback_urls) .preferences_hash provider = payment_method.provider provider.create_preferences(preferences) redirect_to provider.redirect_url end |
#failure ⇒ Object
34 35 36 37 38 39 |
# File 'app/controllers/spree/mercadopago_controller.rb', line 34 def failure payment.failure! flash.notice = Spree.t(:payment_processing_failed) flash['order_completed'] = true redirect_to spree.checkout_state_path(state: :payment) end |
#ipn ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/spree/mercadopago_controller.rb', line 41 def ipn notification = Mercadopago::Notification .new(operation_id: params[:id], topic: params[:topic]) if notification.save Mercadopago::HandleReceivedNotification.new(notification).process! status = :ok else status = :bad_request end render json: :empty, status: status end |
#success ⇒ Object
Success/pending callbacks are currently aliases, this may change if required.
27 28 29 30 31 32 |
# File 'app/controllers/spree/mercadopago_controller.rb', line 27 def success payment.order.next flash.notice = Spree.t(:order_processed_successfully) flash['order_completed'] = true redirect_to spree.order_path(payment.order) end |