2015-09-14 17:29:00 +02:00
|
|
|
TabApiJob = Struct.new(:order_id) do
|
|
|
|
def perform(*args)
|
|
|
|
order = Order.find_by(id: order_id)
|
|
|
|
if order && !order.transaction_id
|
2015-09-14 20:26:16 +02:00
|
|
|
body = {
|
|
|
|
transaction: {
|
2015-09-18 13:20:57 +02:00
|
|
|
debtor: order.user.name,
|
2015-09-14 20:26:16 +02:00
|
|
|
cents: order.price_cents,
|
|
|
|
message: order.to_sentence,
|
|
|
|
id_at_client: order.id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
headers = {
|
2017-01-18 21:56:45 +01:00
|
|
|
"Authorization" => "Token token=#{Rails.application.secrets.tab_api_key}",
|
|
|
|
'Accept' => 'application/json'
|
2015-09-14 20:26:16 +02:00
|
|
|
}
|
|
|
|
|
2015-09-18 13:20:57 +02:00
|
|
|
result = HTTParty.post(File.join(Rails.application.config.api_url, "transactions"), body: body, headers: headers )
|
2015-09-14 17:29:00 +02:00
|
|
|
order.update_attribute(:transaction_id, JSON.parse(result.body)["id"].to_i)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-02 14:42:02 +01:00
|
|
|
def headers
|
|
|
|
{
|
|
|
|
"Authorization" => "Token token=#{Rails.application.secrets.tab_api_key}"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2015-09-14 17:29:00 +02:00
|
|
|
def error(job, exception)
|
|
|
|
Airbrake.notify(exception)
|
|
|
|
end
|
|
|
|
end
|