-
-
Save sfelde/4149095 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BankAccount < ActiveRecord::Base | |
# Umsätze von start_date bis end_date abrufen | |
# * passport_type, passphrase, pin und file kommen in dieser Implementation aus der zugrunde liegenden Tabelle. | |
# * Wenn passport_type = "PinTan" ist, wird die pin verwendet. | |
# * Wenn passport_type = "RDHNew" ist, wird die Schlüsseldatei aus filename verwendet und mit der passphrase entschlüsselt. | |
def get_transactions(start_date, end_date) | |
HBCIUtils.setParam("client.passport.#{passport_type}.filename", filename) | |
HBCIUtils.setParam("client.passport.#{passport_type}.init", '1') | |
passport = AbstractHBCIPassport.getInstance(passport_type, [passphrase, pin]) | |
handle = HBCIHandler.new(passport.getHBCIVersion, passport) | |
job = handle.newJob('KUmsAll') | |
my_account = passport.getAccount(self.number) | |
job.setParam('my', my_account) | |
ruby_startdate = start_date || (Date.today - 1) | |
job.setParam('startdate', JavaUtil::Date.new(ruby_startdate.year-1900, ruby_startdate.month-1, ruby_startdate.day)) | |
ruby_enddate = end_date || (Date.today - 1) | |
job.setParam('enddate', JavaUtil::Date.new(ruby_enddate.year-1900, ruby_enddate.month-1, ruby_enddate.day)) | |
job.addToQueue | |
status = handle.execute | |
handle.close | |
if status.isOK | |
result = job.getJobResult | |
result.getFlatData | |
else | |
puts "Fehler: " + status.getErrorString | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'java' | |
require File.join(RAILS_ROOT,'vendor/hbci4java.jar') | |
import 'org.kapott.hbci.manager.HBCIUtils' | |
import 'org.kapott.hbci.manager.HBCIUtilsInternal' | |
import 'org.kapott.hbci.passport.AbstractHBCIPassport' | |
import 'org.kapott.hbci.callback.HBCICallbackConsole' | |
import 'org.kapott.hbci.manager.HBCIHandler' | |
class HBCIRunnable | |
include java.lang.Runnable | |
def initialize(&block) | |
@block = block | |
end | |
def run | |
RAILS_DEFAULT_LOGGER.info "Starte HBCI-Job" | |
@block.call | |
RAILS_DEFAULT_LOGGER.info "HBCI-Job beendet!" | |
end | |
end | |
# Wrapper für HBCI-Aufrufe | |
def hbci(&block) | |
target = HBCIRunnable.new(&block) | |
thread = java.lang.Thread.new($hbci_thread_group, target) | |
thread.start | |
thread.join | |
end | |
# ThreadGroup mit eindeutigem Namen für jeden Rails-Thread erzeugen! | |
$hbci_thread_group = java.lang.ThreadGroup.new("HBCI_#{java.lang.Thread.currentThread.getId}") | |
hbci do | |
HBCIUtils.init(nil, nil, MyHBCICallback.new) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Callback für HBCI-Aufrufe | |
class MyHBCICallback < HBCICallbackConsole | |
@@status_names = {} | |
constants.each { |c| @@status_names[const_get(c)] = c } | |
def callback(passport, reason, msg, dataType, retData) | |
passphrase, pin, tan = passport.getClientData('init') | |
case reason | |
when NEED_PASSPHRASE_LOAD then retData.replace(0, retData.length, passphrase) | |
# when NEED_PASSPHRASE_SAVE then retData.replace(0, retData.length, passphrase) | |
when NEED_PT_PIN then retData.replace(0, retData.length, pin) | |
when NEED_PT_TAN then retData.replace(0, retData.length, tan) | |
when NEED_CONNECTION, CLOSE_CONNECTION then nil | |
else super | |
end | |
end | |
def log(msg, level, date, trace) | |
# Alle HBCI-Statusmeldungen einfach an der Konsole ausgeben | |
puts msg | |
end | |
def status(passport, statusTag, o) | |
puts @@status_names[statusTag] | |
end | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TransactionsController < ActionController::Base | |
def index | |
account = BankAccount.first | |
hbci do | |
@umsaetze = account.get_transactions(Date.today - 1, Date.today - 1) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment