Class: Payments::CheckWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
app/workers/payments/check_worker.rb

Instance Method Summary collapse

Instance Method Details

#perform(payment_id) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/workers/payments/check_worker.rb', line 9

def perform(payment_id)
  payment  = Payment.find(payment_id)
  response = RestClient.post "#{Terminal.config.host}/payments",
              :provider => payment.provider.keyword,
              :terminal => Terminal.config.keyword,
              :payment  => {
                :account => payment.,
                :payment_type => payment.payment_type,
                :fields => payment.fields,
                :session_id => payment.id
              }

  answer = JSON.parse(response.to_s, :symbolize_names => true)

  unless answer[:id].nil?
    payment.update_attributes :foreign_id       => answer[:id],
                              :limit            => answer[:limits].sort_by(&:weight).last,
                              :commissions      => (answer[:commissions].empty? ? nil : answer[:commissions]),
                              :receipt_template => answer[:receipt_template],
                              :checked          => true
  end
rescue => e
  Payment.find(payment_id).update_attributes :error => true
end