Skip to content

Instantly share code, notes, and snippets.

@miharekar
Last active January 28, 2019 14:49
Show Gist options
  • Save miharekar/d3ee71bbc84e31a7c239bce28357f246 to your computer and use it in GitHub Desktop.
Save miharekar/d3ee71bbc84e31a7c239bce28357f246 to your computer and use it in GitHub Desktop.
UPN QR to N26 and Toshl
# frozen_string_literal: true
source 'https://rubygems.org'
gem 'sinatra'
gem 'twentysix'
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment