28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'app/controllers/spree/admin/billets_controller.rb', line 28
def return_info
data = case params[:file_type].to_sym
when :cnab240 then Brcobranca::Retorno::RetornoCnab240.load_lines params[:file].path
when :cnab400 then Brcobranca::Retorno::RetornoCnab400.load_lines params[:file].path
when :cbr643 then Brcobranca::Retorno::RetornoCbr643.load_lines params[:file].path
end
@lines = []
data.each do |line|
next if line == data.last
payment = Spree::Payment.find_by id: line.nosso_numero
if payment and line.valor_recebido.to_i > 0 and !(payment.completed? or payment.void?)
amount_paid = line.valor_recebido.to_f + line.valor_tarifa.to_f
payment.capture! amount_paid
year = line.data_credito.size == 6 ? line.data_credito : "20#{line.data_credito}"
paid_at = "#{year}#{line.data_credito[2..3]}#{line.data_credito[0..1]}".to_date
value = (line.valor_titulo.to_f / 100) + (line.valor_tarifa.to_f / 100)
@lines.push({document_number: line.nosso_numero,
value: Spree::Money.new(value, { currency: payment.currency }),
paid_at: paid_at,
order_id: payment.order_id,
order_number: payment.order.number})
end
end
rescue
flash[:error] = Spree.t('errors.error_in_billets_return')
end
|