mirror of
https://gitlab.com/t6353/sharee.bike.git
synced 2025-05-10 22:16:26 +02:00
payone_cron refacoring
This commit is contained in:
parent
d5ea6afcd7
commit
43dbaba064
8 changed files with 50 additions and 573 deletions
|
@ -1,244 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
#
|
||||
#
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
|
||||
#
|
||||
#Capture payone payment by cron
|
||||
#
|
||||
#> 1. auto-fixed RadBuchungen (bei service-fixed hat schon jemand die Buchung manuell bearbeitet, oder?)
|
||||
#--> service fixed wird gesetzt wenn das Rad via COPRI terminiert wurde. D.h. das hat keine Aussage ob auch der RadBuchungs Datensatz bearbeitet wurde. Deshalb gilt hier die userid des Datensatz Bearbeiters als key ob Automatik angewandt werden kann.-->ok
|
||||
#> 2. mit defect -->ok
|
||||
#> 3. RadBuchungen länger als 1 Tag oder bei konrad > 9,- € und bei TINK > 15,- € -->ok if int03 <= 5
|
||||
#> 4. Gesamtbetrag > 50,- € -->ok
|
||||
#> 5. OPOS, also bereits fehlgeschlagene Einzüge -->ok
|
||||
# 6. "Internas und Bearbeitungstatus" wenn definiert und nicht Buchungsfreigabe, txid renew
|
||||
#
|
||||
#payone_cron cron Intervall 0=disabled, 1=weekly, 2=monthly
|
||||
#
|
||||
#All with coded conditions
|
||||
#sudo su www-data -c "./src/scripts/payone_cron.pl tinkdms '' 1"
|
||||
|
||||
#One invoice
|
||||
#sudo su www-data -c "./src/scripts/payone_cron.pl tinkdms ctt_id 1"
|
||||
#
|
||||
#
|
||||
use vars qw($syshost);
|
||||
|
||||
BEGIN {
|
||||
$syshost = $ARGV[0] || exit 1;
|
||||
}
|
||||
|
||||
use lib "/var/www/copri-bike/$syshost/src";
|
||||
|
||||
my $ctt_id = $ARGV[1] || "";
|
||||
my $intervall = $ARGV[2] || "1";
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use POSIX;
|
||||
use Lib::Config;
|
||||
use Mod::Libenz;
|
||||
use Mod::DBtank;
|
||||
use Mod::Payment;
|
||||
use Data::Dumper;
|
||||
use Scalar::Util qw(looks_like_number);
|
||||
|
||||
my $cf = new Config;
|
||||
my %varenv = $cf->envonline();
|
||||
my $lb = new Libenz;
|
||||
my $dbt = new DBtank;
|
||||
my $pay = new Payment;
|
||||
my $now_dt = strftime("%Y-%m-%d %H:%M:%S",localtime(time));
|
||||
my $owner = 179;#179=cron
|
||||
|
||||
my $dbh = $dbt->dbconnect();
|
||||
|
||||
#get Firma in contentuser
|
||||
my $fetchuser = {
|
||||
table => "contentuser",
|
||||
fetch => "one",
|
||||
c_id => 100002,
|
||||
};
|
||||
my $ctf = $dbt->fetch_tablerecord($dbh,$fetchuser);
|
||||
|
||||
#collect open invoices
|
||||
my $fetchtrans = {
|
||||
table => "contenttrans",
|
||||
fetch => "all",
|
||||
keyfield => "c_id",
|
||||
main_id => "300008",#Rechnung
|
||||
template_id => "218",#Rechnung
|
||||
state => "is::null",#never tried buchen
|
||||
close_time => "",#invoice isn't closed
|
||||
int14 => "is::null",#OPOS
|
||||
owner => "!=::$owner",#not 179=cron, not still tried by payone_cron
|
||||
};
|
||||
$fetchtrans = { %$fetchtrans , c_id => $ctt_id } if($ctt_id && $ctt_id =~ /^\d+$/);
|
||||
my $ct4rel = $dbt->fetch_record($dbh,$fetchtrans);
|
||||
|
||||
open(FILE,">>$varenv{logdir}/payone_cron.log");
|
||||
print FILE "\n\n*** $now_dt\n";
|
||||
|
||||
my $max_sum = $ctf->{int03} || "10000";
|
||||
my $max_timestamp = "210001012359";
|
||||
my $scol = "mtime";
|
||||
my $i=0;
|
||||
|
||||
#loop invoices
|
||||
#foreach my $id (sort { $ct4rel->{$a}->{$scol} cmp $ct4rel->{$b}->{$scol} }keys (%$ct4rel)){
|
||||
foreach my $id (sort { $ct4rel->{$b}->{$scol} cmp $ct4rel->{$a}->{$scol} }keys (%$ct4rel)){
|
||||
$i++;
|
||||
|
||||
print FILE "\n$i)** loop $now_dt ---> payone_cron select invoice ct.c_id:$ct4rel->{$id}->{c_id}| ca.c_id:$ct4rel->{$id}->{int10}| ct.ct_name:$ct4rel->{$id}->{ct_name}| ct.mtime:$ct4rel->{$id}->{mtime}\n";
|
||||
if($ct4rel->{$id}->{int10} && !$ct4rel->{$id}->{txt22} && $ct4rel->{$id}->{ct_name} =~ /---|^\d+$/){
|
||||
|
||||
#my $umst1619 = $lb->umst_breaking($ct4rel->{$id},$now_dt);
|
||||
|
||||
#get Adresse from contentadr
|
||||
my $fetchadr = {
|
||||
table => "contentadr",
|
||||
fetch => "one",
|
||||
int16 => $intervall,
|
||||
c_id => $ct4rel->{$id}->{int10},
|
||||
};
|
||||
my $ctadr = $dbt->fetch_tablerecord($dbh,$fetchadr);
|
||||
|
||||
#payone_cron cron Intervall 0=disabled, 1=weekly, 2=monthly
|
||||
if($ctadr->{int16}){
|
||||
#collect invoice positions
|
||||
my $fetchpos = {
|
||||
table => "contenttranspos",
|
||||
fetch => "all",
|
||||
keyfield => "c_id",
|
||||
ct_id => $ct4rel->{$id}->{c_id},
|
||||
};
|
||||
my $cttpos = $dbt->fetch_tablerecord($dbh,$fetchpos);
|
||||
|
||||
my $scol = "itime";
|
||||
my $sum_parts0=0;
|
||||
my $sum_parts7=0;
|
||||
my $sum_parts19=0;
|
||||
#my $diff19 = 100 + $umst1619;
|
||||
my $diff19 = 100 + 19;
|
||||
my $sum_umst7=0;
|
||||
my $sum_umst19=0;
|
||||
my $j=0;
|
||||
my $accounting_start = "";
|
||||
my $accounting_end = "";
|
||||
my $k=0;
|
||||
my $m=0;
|
||||
|
||||
my $capture_condition=1;#1=false
|
||||
|
||||
#loop invoice positions
|
||||
foreach my $id (sort { $cttpos->{$b}->{$scol} cmp $cttpos->{$a}->{$scol} } keys(%$cttpos)){
|
||||
if(($cttpos->{$id}->{int12} && $cttpos->{$id}->{int12} !~ /300005|300024/) || (($cttpos->{$id}->{int10} && $cttpos->{$id}->{int10} == 1) && ($cttpos->{$id}->{int03} && $cttpos->{$id}->{int03} <= 5) && ($cttpos->{$id}->{txt01} && $cttpos->{$id}->{txt01} !~ /fixed|defect/ || ($cttpos->{$id}->{owner_end} && $cttpos->{$id}->{owner_end} > 1000)))){
|
||||
$j++;
|
||||
|
||||
my $cttpos_timestamp = $1 . $2 . $3 . "0000" if($cttpos->{$id}->{itime} =~ /(\d+)\-(\d+)\-(\d+)/);
|
||||
#max. Rechnungspositionen
|
||||
if(($cttpos_timestamp <= $max_timestamp) && ($sum_parts19 <= $max_sum)){
|
||||
$k++;
|
||||
#print "$i (($id: $cttpos_timestamp <= $max_timestamp) && ($sum_parts19 <= $max_sum))<br>";
|
||||
if($k==1){
|
||||
$accounting_end = "$3.$2.$1" if($cttpos->{$id}->{itime} =~ /(\d+)\-(\d+)\-(\d+)/);
|
||||
$accounting_start = $accounting_end;
|
||||
}else{
|
||||
$accounting_start = "$3.$2.$1" if($cttpos->{$id}->{itime} =~ /(\d+)\-(\d+)\-(\d+)/);
|
||||
}
|
||||
|
||||
$capture_condition=0;
|
||||
my $gesamt = 0;
|
||||
my $einzel = $cttpos->{$id}->{int02};
|
||||
my $menge = $cttpos->{$id}->{int03};
|
||||
$gesamt = $einzel * $menge;
|
||||
|
||||
my $rabatt_val = $cttpos->{$id}->{int07} || 0;
|
||||
my $rabatt_eur = 0;
|
||||
my $proz_eur = $cttpos->{$id}->{int08} || 0;
|
||||
if($rabatt_val != 0){
|
||||
$rabatt_eur = $rabatt_val;
|
||||
if($proz_eur != 1){#wenn int08 != 1 alias €
|
||||
$rabatt_eur = $einzel * $menge * $rabatt_val/100;
|
||||
}
|
||||
$gesamt = $einzel * $menge - $rabatt_eur;
|
||||
}
|
||||
$m++ if($gesamt != 0);
|
||||
print FILE "pos gesamt: $gesamt = $einzel * $menge - $rabatt_eur ($rabatt_val|$rabatt_eur)\n";
|
||||
|
||||
$gesamt = $lb->round($gesamt);
|
||||
$gesamt = $lb->cashme($gesamt);
|
||||
$ctf->{txt13} = $1 if($ctf->{txt13} =~ /(\d+)/);
|
||||
if($ct4rel->{$id}->{node_name} && $ct4rel->{$id}->{node_name} =~ /steuerfrei/){
|
||||
$sum_parts0 += $gesamt;
|
||||
}elsif($cttpos->{$id}->{int05} && $cttpos->{$id}->{int05} =~ /\d/){
|
||||
$sum_parts0 += $gesamt if($cttpos->{$id}->{int05} == 0);
|
||||
$sum_parts7 += $gesamt if($cttpos->{$id}->{int05} == 7);
|
||||
$sum_parts19 += $gesamt if($cttpos->{$id}->{int05} >= 16);
|
||||
}else{
|
||||
$sum_parts0 += $gesamt if($ctf->{txt13} == 0);
|
||||
$sum_parts7 += $gesamt if($ctf->{txt13} == 7);
|
||||
$sum_parts19 += $gesamt if($ctf->{txt13} >= 16);
|
||||
}
|
||||
}#end timestamp
|
||||
}else{#end conditons
|
||||
$capture_condition=1;
|
||||
#print "LAST LINE\n";
|
||||
last;
|
||||
}
|
||||
}#end loop invoice positions
|
||||
|
||||
my $sum_paid = $sum_parts0 + $sum_parts7 + $sum_parts19;
|
||||
$sum_paid = $lb->round($sum_paid);
|
||||
my $sum_preauth = $sum_paid || 0;
|
||||
$sum_paid = $lb->cashme($sum_paid,"");
|
||||
my $line_count2 = $m+4;
|
||||
|
||||
print FILE "---> payone_cron capture conditions c_id:$ct4rel->{$id}->{c_id}, capture_condition:$capture_condition, sum_paid:$sum_paid, sum_preauth:$sum_preauth, ($accounting_start - $accounting_end)\n";
|
||||
if($capture_condition==0 && $sum_paid > 0 && $sum_paid <= 50){
|
||||
my $update = {
|
||||
table => "contenttrans",
|
||||
int15 => "$sum_preauth",
|
||||
txt20 => "$accounting_start - $accounting_end",
|
||||
owner => "$owner",#cron
|
||||
int04 => "14.$line_count2",
|
||||
mtime => "now()",
|
||||
};
|
||||
my $record = { c_id => $ct4rel->{$id}->{c_id} };
|
||||
my $rows = $dbt->update_record($dbh,$update,$record) if($record->{c_id} > 0);
|
||||
|
||||
my ($return,$return_text) = $pay->payone_capture(\%varenv,$ctf,$ctadr,$ct4rel->{$id},$sum_paid,$owner);
|
||||
print FILE "---> Payment.pm Modul things: $return_text\nFinally log payone-return-post.log\n";
|
||||
|
||||
sleep 20;
|
||||
}elsif($sum_paid > 0){
|
||||
my $update = {
|
||||
table => "contenttrans",
|
||||
txt22 => "cronjob fail",#also defined in Config.pm
|
||||
owner => "$owner",#cron
|
||||
mtime => "now()",
|
||||
};
|
||||
my $record = { c_id => $ct4rel->{$id}->{c_id} };
|
||||
my $rows = $dbt->update_record($dbh,$update,$record) if($record->{c_id} > 0);
|
||||
print FILE "---> payone_cron c_id:$ct4rel->{$id}->{c_id} conditions fails\n";
|
||||
}else{
|
||||
print FILE "---> payone_cron c_id:$ct4rel->{$id}->{c_id} conditions fails at all, sum_paid: $sum_paid > 0\n";
|
||||
}
|
||||
}#end if $ctadr->{int16}
|
||||
}else{
|
||||
my $update = {
|
||||
table => "contenttrans",
|
||||
#txt22 => "cronjob fail",#disabled to keep fibu saved Bearbeitsungsstatus
|
||||
owner => "$owner",#cron
|
||||
mtime => "now()",
|
||||
};
|
||||
my $record = { c_id => $ct4rel->{$id}->{c_id} };
|
||||
my $rows = $dbt->update_record($dbh,$update,$record) if($record->{c_id} > 0);
|
||||
|
||||
print FILE "---> payone_cron c_id:$ct4rel->{$id}->{c_id} Failure: no ct.int10 or order_stat ct.txt22:$ct4rel->{$id}->{txt22}\n";
|
||||
}
|
||||
}#end loop invoices
|
||||
|
||||
close(FILE);
|
||||
|
1
copri4/main/src/scripts/payone_cron.pl
Symbolic link
1
copri4/main/src/scripts/payone_cron.pl
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../../../../sharee.bike/copri-bike/main/src/scripts/payone_cron.pl
|
|
@ -1,35 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
#
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
|
||||
#
|
||||
#loops sharee operators for payone capture
|
||||
#only primary should do this
|
||||
#
|
||||
#sudo su www-data -c "./src/scripts/payone_operatorsloop.pl 1"
|
||||
#
|
||||
#defined by cronjob
|
||||
#weekly for $ARGV[0]=1
|
||||
#nonthly for $ARGV[0]=2
|
||||
#
|
||||
use lib "/var/www/copri4/shareedms-primary/src";
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use POSIX;
|
||||
use Config::General;
|
||||
|
||||
die if(!$ARGV[0] || ($ARGV[0] != 1 && $ARGV[0] != 2));
|
||||
|
||||
my $globalconf_file = "/var/www/copri4/shareeconf/global.cfg";
|
||||
my $conf = Config::General->new($globalconf_file);
|
||||
my %globalconf = $conf->getall;
|
||||
|
||||
while (my ($key, $value) = each %{ $globalconf{"operator"} }) {
|
||||
if(-d "/var/www/copri4/$value->{syshost}"){
|
||||
`/var/www/copri4/shareedms-primary/src/scripts/payone_cron.pl $value->{syshost} '' $ARGV[0]`;
|
||||
die if($? != 0);
|
||||
}else{
|
||||
print "/var/www/copri4/$value->{syshost} not available\n";
|
||||
}
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
#
|
||||
#Autor ragu@gnu-systems.de
|
||||
#sharee payone POST
|
||||
#
|
||||
#managemandate
|
||||
#sudo su www-data -c "/var/www/copri4/shareeapp-primary/src/scripts/payone_post_Payment.pl shareeapp-fr01 managemandate contentadr 21250"
|
||||
#
|
||||
#captureSEPA
|
||||
#sudo su www-data -c "/var/www/copri4/shareeapp-primary/src/scripts/payone_post_Payment.pl shareeapp-fr01 preauthorizationSEPA contentadr 22027 28845"
|
||||
#sudo su www-data -c "/var/www/copri4/shareeapp-primary/src/scripts/payone_post_Payment.pl shareeapp-fr01 captureSEPA contenttrans '' 28845"
|
||||
#
|
||||
use vars qw($syshost);
|
||||
|
||||
BEGIN {
|
||||
$syshost = $ARGV[0] || die 'syshost not defined';
|
||||
}
|
||||
|
||||
use lib "/var/www/copri-bike/$syshost/src";
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use POSIX;
|
||||
use CGI ':standard';
|
||||
use Lib::Config;
|
||||
use Mod::Libenzdb;
|
||||
use Mod::Payment;
|
||||
use Config::General;
|
||||
|
||||
use Data::Dumper;
|
||||
use Sys::Hostname;
|
||||
my $hostname = hostname;
|
||||
|
||||
my $q = new CGI;
|
||||
my $cf = new Config;
|
||||
my %varenv = $cf->envonline("$syshost");
|
||||
print "$varenv{dbname}\n";
|
||||
|
||||
my $db = new Libenzdb;
|
||||
my $pay = new Payment;
|
||||
my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
|
||||
my $owner = 178;#payone API
|
||||
|
||||
my $todo = $ARGV[1];
|
||||
my $table = $ARGV[2];
|
||||
my $ctadr_id = $ARGV[3];
|
||||
my $ctt_id = $ARGV[4];
|
||||
my $sequenz = $ARGV[5] || 0;
|
||||
my $set_time = $ARGV[6] || "";#no_time
|
||||
my $renewed = $ARGV[7] || "";#for requesting new txid via script loop_payone_capture.pl
|
||||
my $request_state = $ARGV[8] || "";#if request state=occupied , then never delete adr4xml
|
||||
|
||||
my $globalconf_file = "/var/www/copri4/shareeconf/global.cfg";
|
||||
my $conf = Config::General->new($globalconf_file);
|
||||
my %globalconf = $conf->getall;
|
||||
#print Dumper(\%globalconf);
|
||||
|
||||
my $refpre = $globalconf{operator}{$varenv{dbname}}->{oprefix};#FR KN ...
|
||||
my $payone_conf = $globalconf{operator}{$varenv{dbname}}{payone_conf} || $globalconf{payone_conf};
|
||||
|
||||
my $ctadr = { c_id => 0 };
|
||||
my $ctt = { c_id => 0 };
|
||||
$ctadr = $db->get_contentrow("contentadr",$ctadr_id,"","","","","","") if($ctadr_id);
|
||||
$ctt = $db->get_contentrow("contenttrans",$ctt_id,"","","","","","") if($ctt_id);
|
||||
|
||||
#managemandate SEPA
|
||||
#1.
|
||||
#sudo su www-data -c "./src/scripts/payone_post.pl $varenv{syshost} managemandate contentadr $ctadr_id"
|
||||
if($todo eq "managemandate" && $table eq "contentadr" && $ctadr->{c_id} > 0){
|
||||
$pay->managemandate_main(\%varenv,$ctadr,$ctt,$owner);
|
||||
}
|
||||
#preauthorizationSEPA
|
||||
#2.
|
||||
#sudo su www-data -c "./src/scripts/payone_post.pl $varenv{syshost} preauthorizationSEPA contentadr $ctadr_id $ctt_id"
|
||||
if($todo eq "preauthorizationSEPA" && $table eq "contentadr" && $ctadr->{c_id} > 0 && $ctt->{c_id} > 0){
|
||||
$pay->preauthorizationSEPA_main(\%varenv,$ctadr,$ctt,$owner);
|
||||
}
|
||||
#captureSEPA
|
||||
#3.
|
||||
#sudo su www-data -c "./src/scripts/payone_post.pl $varenv{syshost} captureSEPA contenttrans '' $ctt_id"
|
||||
if($todo eq "captureSEPA" && $table eq "contenttrans" && $ctt->{c_id} > 0){
|
||||
$pay->captureSEPA_main(\%varenv,$ctadr,$ctt,$owner);
|
||||
}
|
||||
#preauthorizationCC
|
||||
#1.PayoneCC creditcardcheck ajaxCall
|
||||
#2.
|
||||
#sudo su www-data -c "./src/scripts/payone_post.pl $varenv{syshost} preauthorizationCC contentadr $ctadr_id $ctt_id"
|
||||
if($todo eq "preauthorizationCC" && $table eq "contentadr" && $ctadr->{c_id} > 0 && $ctt->{c_id} > 0){
|
||||
$pay->preauthorizationCC_main(\%varenv,$ctadr,$ctt,$owner);
|
||||
}
|
||||
#captureCC
|
||||
#3.
|
||||
#
|
||||
if($todo eq "captureCC" && $table eq "contenttrans" && $ctt->{c_id} > 0){
|
||||
$pay->captureCC_main(\%varenv,$ctadr,$ctt,$owner);
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue