Class: Spree::PayseraController

Inherits:
StoreController
  • Object
show all
Includes:
Spree::Paysera::ErrorHandler
Defined in:
app/controllers/spree/paysera_controller.rb

Instance Method Summary collapse

Instance Method Details

#callbackObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/spree/paysera_controller.rb', line 16

def callback
  Spree::LogEntry.create(
    source: payment_method,
    details: params.to_yaml
  )

  response = Spree::Paysera::ParseResponse.for(payment_method, params)
  raise Spree::Paysera::Error, 'wrong project id' if response[:projectid] != payment_method.preferred_project_id.to_s

  order = Spree::Order.find_by!(number: response[:orderid])

  Spree::Paysera::CompleteOrder.for(order, payment_method, response)
  render plain: 'OK'
end

#cancelObject



46
47
48
49
# File 'app/controllers/spree/paysera_controller.rb', line 46

def cancel
  flash.notice = Spree.t(:order_canceled)
  redirect_to products_path
end

#confirmObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/spree/paysera_controller.rb', line 31

def confirm
  response = Spree::Paysera::ParseResponse.for(payment_method, params)
  order = Spree::Order.find_by(number: response[:orderid])

  if order.paid?
    flash.notice = Spree.t(:order_processed_successfully)
  else
    flash.alert = Spree.t(:payment_processing_failed)
  end
rescue StandardError
  flash.alert = Spree.t(:payment_processing_failed)
ensure
  redirect_to 
end

#indexObject



9
10
11
12
13
14
# File 'app/controllers/spree/paysera_controller.rb', line 9

def index
  form = Spree::Paysera::BuildForm.for(payment_method, current_order)
  url = Spree::Paysera::BuildUrl.for(payment_method, form.attributes)

  redirect_to url
end