|
# frozen_string_literal: true |
|
|
|
require 'sinatra' |
|
require 'twentysix' |
|
|
|
set :bind, '0.0.0.0' |
|
|
|
TOSHL_TAGS = { |
|
'SI56610000007233637' => [32338697, 32338696], # Terca stroski |
|
'SI56610000005275886' => [32338697, 31463354], # Terca sklad |
|
'SI56051008013558749' => [31553594, 31463358], # T-2 |
|
'SI56290000055197804' => [31558007, 31463357], # Telemach |
|
'SI56029220012973357' => [31558007, 31463357], # Telemach |
|
'SI56011008493106536' => [31496147], # RTV |
|
'SI56290000155731029' => [31735355, 31463356] # GEN-i |
|
}.freeze |
|
|
|
post '/pay' do |
|
qr = params['qr'].split("\r\n") |
|
|
|
@amount = qr[8].to_i / 100.0 |
|
@iban = qr[14] |
|
@reference = qr[15] |
|
@name = qr[16] |
|
|
|
client = TwentySix::Core.authenticate(params['username'], params['password']) |
|
client.create_transfer(params['pin'], @name, @iban, '', @amount, @reference) |
|
|
|
HTTParty.post( |
|
'https://api.toshl.com/entries', |
|
body: toshl_params.to_json, |
|
headers: { |
|
'Content-Type' => 'application/json', |
|
'Authorization' => 'Bearer xxxx' # Get your personal Toshl token here: https://developer.toshl.com/apps/ |
|
} |
|
) |
|
|
|
'Done' |
|
end |
|
|
|
def toshl_params |
|
{ |
|
amount: - @amount, |
|
currency: { code: 'EUR' }, |
|
date: Time.now.strftime('%F'), |
|
account: '2924479', |
|
category: '56232306', |
|
tags: TOSHL_TAGS.fetch(@iban, []) |
|
} |
|
end |