payment check and boni by file

This commit is contained in:
Rainer Gümpelein 2022-01-16 12:17:11 +01:00
parent fd3e14ba7b
commit f7c3ed7b05
5 changed files with 101 additions and 62 deletions

View file

@ -73,7 +73,7 @@ my $response = {
user_group => [],
user_tour => [],
response_state => "OK, nothing todo",
privacy_html => "site/privacy_1.html",
privacy_html => "site/privacy_2.html",
agb_html => "site/agb.html",
impress_html => "site/impress_1.html",
tariff_info_html => "site/tariff_info_1.html",

View file

@ -171,7 +171,7 @@ sub handler {
#create_account. 2. inserts contentadr
my $tinkc_id = $tk->create_account($aowner);
($returnwww,$return) = $tk->save_account($tinkc_id,"",$aowner);
($returnwww,$return) = $tk->save_account($tinkc_id,\%varenv,$aowner);
#Like login_sharee, redundant
my $hw_id = unpack ('H*', pack('Nc', time, $$ % 0xff));#old $co
@ -312,7 +312,7 @@ sub handler {
$delete_key = "delete_adr";
$return = "failure::Datensatz wirklich löschen. ::?base_edit=$delete_key\&exit_box2=1\&c_id=$R::c_id ::löschen";
}elsif($users_dms->{int02} == 2 && $R::c_id && $R::base_edit eq "save_adr"){
($returnwww,$return) = $tk->save_account($R::c_id,$coo,$users_dms->{u_id});
($returnwww,$return) = $tk->save_account($R::c_id,\%varenv,$users_dms->{u_id});
}elsif($users_dms->{int02} == 2 && $R::c_id && $R::base_edit eq "delete_adr"){
$return = $tk->delete_account($R::c_id,$users_dms->{u_id});
}else{
@ -373,7 +373,7 @@ sub handler {
#save_account. 3. updates contentadr
if($users_sharee->{c_id} && $R::sharee_edit && $R::sharee_edit =~ /save_account/){
($returnwww,$return) = $tk->save_account($users_sharee->{c_id},$coo,$aowner);
($returnwww,$return) = $tk->save_account($users_sharee->{c_id},\%varenv,$aowner);
}
if($users_sharee->{c_id} && $R::sharee_edit && $R::sharee_edit =~ /save_transact/){
@ -405,7 +405,7 @@ sub handler {
if($users_sharee->{c_id} && ($R::pseudocardpan || $R::status)){
my $payone_return;
open(FILE,">>$varenv{logdir}/payone-return-post.log");
print FILE "<--- $now_dt from Indextink.pm \nPayone return-way by ajaxCall: $R::status\n";
print FILE "<--- $now_dt from Indexsharee.pm \nPayone return-way by ajaxCall: $R::status\n";
my @keywords = $q->param;
foreach(@keywords){
my $val = $q->param($_);
@ -447,16 +447,28 @@ sub handler {
reference => "$users_sharee->{c_id}_$epoche",
renewed => ''
};
my $payone_txid = "";
$payone_txid = $payone->preauthorizationCC_main(\%varenv,$users_sharee,$ctt,$aowner);
if($payone_txid){
$ctt->{txt16} = "$payone_txid";
$payone_txid = $payone->captureCC_main(\%varenv,$users_sharee,$ctt,$aowner);
##preauthorization and/or capture needs to much time, must be done async!
#$payone_txid = $payone->preauthorizationCC_main(\%varenv,$users_sharee,$ctt,$aowner);
#if($payone_txid)
if(1==1){
#$ctt->{txt16} = "$payone_txid";
#$payone_txid = $payone->captureCC_main(\%varenv,$users_sharee,$ctt,$aowner);
#int12=0 should be set after capture success in payment module
if(($users_sharee->{int04} != 1) && ($users_sharee->{txt08} =~ /\w\@\w/)){
$tk->emailack($users_sharee->{c_id});
}
if(($users_sharee->{int13} != 1) && ($users_sharee->{txt07} =~ /\d{9}/ && length($users_sharee->{txt07}) <= 16)){
$tk->smsack($users_sharee);
}
}else{
$dbt->update_one($dbh,$update_adr,"int12=$vde_on_fail");#Vde
$dbt->update_one($dbh,$update_adr,"int12=$vde_on_fail");#Vde
}
#$tk->emailack($users_sharee->{c_id}) if($users_sharee->{int04} != 1);
$dbt->update_operatorsloop($varenv{dbname},$users_sharee->{c_id},"update");
print redirect("$varenv{wwwhost}/$varenv{mandant}/$varenv{profile}?$returnwww$session_and");
@ -467,7 +479,7 @@ sub handler {
$dbt->update_record($dbh,$update_adr,$users_sharee) if($users_sharee->{c_id} > 0);
$dbt->update_operatorsloop($varenv{dbname},$users_sharee->{c_id},"update");
}
}
}#end payone response with pseudocardpan
}

View file

@ -48,7 +48,6 @@ my $ua = LWP::UserAgent->new(
}
);
$ua->agent("sharee payone POST API");
my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
#ported from payone_post.pl
@ -386,6 +385,7 @@ sub rpc {
#Pass request to the user agent and get a response back
my $res = $ua->request($req);
my $vde_on_fail = $ctadr->{int12} || 1;#keep last or set 1
my $debug=0;
$debug=1;
@ -403,6 +403,7 @@ sub rpc {
};
my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
open(FILE,">>$varenv->{logdir}/payone-return-post.log") if($debug);
print FILE "\n*** $now_dt (ctadr_id:$ctadr->{c_id}, ctt_id:$ctt->{c_id}) from payone_post.pl\n$httpReqServer \n" if($debug);
print FILE "---> request to payone $todo:\n$post\n";
@ -422,7 +423,7 @@ sub rpc {
my $mival = "";
$mival = $1 if($res->content =~ /mandate_identification=(.*)/);
$payoneret = $mival;
print FILE "mival: $mival && $ctadr->{c_id}\n" if($debug);
print FILE "payone MANDATE $now_dt\n mival: $mival && $ctadr->{c_id}\n" if($debug);
if($mival && $ctadr->{c_id}){
foreach(@content){
@ -449,7 +450,7 @@ sub rpc {
if($todo =~ /preauthorization/){
$txidval = $1 if($res->content =~ /txid=(\d+)/);
$payoneret = $txidval;
print FILE "$todo: $txidval && $ctt->{c_id} && $ctadr->{c_id}\n" if($debug);
print FILE "payone PREAUTH $now_dt\n $todo: $txidval && $ctt->{c_id} && $ctadr->{c_id}\n" if($debug);
my $useridval = $1 if($res->content =~ /userid=(\d+)/);#2020-02-11 preauthorization returns payone Debitorennr
$update_ctt->{ct_name} = $ctt->{ct_name} if($ctt->{ct_name});
@ -474,7 +475,7 @@ sub rpc {
if($todo =~ /capture/){
$txidval = $1 if($res->content =~ /txid=(\d+)/);
$payoneret = $txidval;
print FILE "$todo: ($txidval && $ctt->{c_id} && $ctadr->{c_id})\n" if($debug);
print FILE "payone CAPTURE $now_dt\n $todo: txid=$txidval && ctt.c_id=$ctt->{c_id} && ctadr.c_id=$ctadr->{c_id}\n" if($debug);
if($txidval && $ctt->{c_id} && $ctadr->{c_id} && $res->content =~ /settleaccount=/){
#int01 and state will be set by "buchen" via Prelogic
@ -491,7 +492,7 @@ sub rpc {
}
}else{#not APPROVED
print FILE "not APPROVED: ($ctt->{c_id} && $res->content)\n" if($debug);
print FILE "NOT APPROVED $now_dt\n $todo: ctt.c_id=$ctt->{c_id} && ctadr.c_id=$ctadr->{c_id}" . $res->content . "\n" if($debug);
$update_ctt->{int14} = 1 if($ctt->{state} && $ctt->{state} !~ /Zahlungseingang/);;#OPOS
#errormessage=Reference number already exists --> disabled
@ -522,6 +523,7 @@ sub rpc {
}else {
print FILE $res->status_line, "\n" if($debug);
}
print FILE "payone RPC end\n\n" if($debug);
close(FILE) if($debug);
$dbt->update_record($dbh,$update_adr,$ctadr) if($ctadr->{c_id} > 0);
@ -544,6 +546,7 @@ sub pdfmandat {
};
my $ctadr = $dbt->fetch_record($dbh,$authref);
my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
open(EMA, ">> $varenv->{logdir}/SEPA-PDFprint.log");
print EMA "*** $now_dt trying pdf --> $varenv->{basedir}/pdfinvoice/SEPA-Lastschriftmandat-$varenv->{dbname}-$ctadr->{ct_name}.pdf && $ctadr->{txt27}\n";
if((! -f "$varenv->{basedir}/pdfinvoice/SEPA-Lastschriftmandat-$varenv->{dbname}-$ctadr->{ct_name}.pdf") && $ctadr->{txt27} && $ctadr->{txt27} =~ /active|pending/){

View file

@ -288,6 +288,7 @@ sub set_usertarif {
my $dbh = shift;
my $dbname = shift;
my $adr_bonus = shift;
my $bonus_collect = shift || {};
open(FILE,">>$varenv{logdir}/save_account.log") if($debug);
print FILE "\n*Prelib--> $now_dt| c_id: $adr_bonus->{c_id} \n" if($debug);
@ -297,6 +298,8 @@ sub set_usertarif {
my $dbh_operator = $dbt->dbconnect_extern($dbname);#operator connect
if($adr_bonus->{txt15} =~ /\w+/){
if(1==1){
my @new_txt30 = ();
#collect multiple tarif by bonusnr
my $pref_cc = {
table => "content",
keyfield => "c_id",
@ -305,25 +308,27 @@ sub set_usertarif {
int03 => ">::0",
ct_name => $adr_bonus->{txt15},
};
my $record_op = $dbt->fetch_record($dbh_operator,$pref_cc);
my @new_txt30 = ();
foreach my $id (keys (%$record_op)){
$bonus_collect = $dbt->fetch_record($dbh_operator,$pref_cc) if(ref($bonus_collect->{1}) ne "HASH");
#print FILE "Prelib bonus_collect:\n" . Dumper($bonus_collect) . "\n";
foreach my $id (keys (%$bonus_collect)){
print FILE "-1-> txt15: $adr_bonus->{txt15}\n" if($debug);
$i++;
foreach my $sourcetarif (@{$adr_bonus->{txt30_array}}){
print FILE "-1.2-> activeTarif-source:$sourcetarif | Bonus-source:$record_op->{$id}->{int21} | Bonus-target:$record_op->{$id}->{int22}\n" if($debug);
if($sourcetarif eq $record_op->{$id}->{int22}){
print FILE "-2.1-> still activ Bonusnr ct_name: $record_op->{$id}->{ct_name}\n" if($debug);
print FILE "-1.2-> activeTarif-source:$sourcetarif | Bonus-source:$bonus_collect->{$id}->{int21} | Bonus-target:$bonus_collect->{$id}->{int22}\n" if($debug);
if($sourcetarif eq $bonus_collect->{$id}->{int22}){
print FILE "-2.1-> still activ Bonusnr ct_name: $bonus_collect->{$id}->{ct_name}\n" if($debug);
$ret = "success::txt15";
push(@new_txt30,$sourcetarif);
}elsif($record_op->{$id}->{int21} eq $sourcetarif && $record_op->{$id}->{int22}){
$dbt->update_content4comp($dbh_operator,$record_op->{$id}->{c_id},"-","1");
#push(@new_txt30,$sourcetarif);
}elsif($bonus_collect->{$id}->{int21} eq $sourcetarif && $bonus_collect->{$id}->{int22}){
if($id > 3){#means if not file greped with static c_id <= 3
$dbt->update_content4comp($dbh_operator,$bonus_collect->{$id}->{c_id},"-","1");
}
$u_rows = $dbt->update_one($dbh_operator,$adr_bonus,"txt15='$adr_bonus->{txt15}'");
print FILE "-2.2-> match-update Bonusnr ct_name: $record_op->{$id}->{ct_name}\n" if($debug);
print FILE "-2.2-> match-update Bonusnr ct_name: $bonus_collect->{$id}->{ct_name}\n" if($debug);
$ret = "success::txt15";
push(@new_txt30,$record_op->{$id}->{int22});
push(@new_txt30,$bonus_collect->{$id}->{int22});
}else{
print FILE "-2.3-> No matching Bonusnr ct_name: $record_op->{$id}->{ct_name}, keeping sourcetarif\n" if($debug);
print FILE "-2.3-> No matching Bonusnr ct_name: $bonus_collect->{$id}->{ct_name}, keeping sourcetarif\n" if($debug);
push(@new_txt30,$sourcetarif);
#$ret = "failure::txt15#top1";
}
@ -332,6 +337,7 @@ sub set_usertarif {
if(@new_txt30){
print FILE "-3-> txt30: @new_txt30\n" if($debug);
$u_rows = $dbt->update_one($dbh_operator,$adr_bonus,"txt30='@new_txt30'");
$u_rows = $dbt->update_one($dbh_operator,$adr_bonus,"txt15='$adr_bonus->{txt15}'");
}
$ret = "failure::txt30#top2" if(!$adr_bonus->{txt30_array} || $adr_bonus->{txt30_array} !~ /\d/);
}

View file

@ -140,7 +140,7 @@ sub create_account(){
sub save_account(){
my $self = shift;
my $c_id = shift;
my $coo = shift || "";
my $varmerch = shift || "";
my $owner = shift || 0;
my $table = "contentadr";
@ -150,7 +150,8 @@ sub save_account(){
my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
my %varenv = $cf->envonline();
$bw->log("save_account",$q,"");
$bw->log("save_account by varmerchant_id $varmerch->{merchant_id} on dbname $varenv{dbname}",$q,"");
my $debug=1;
my $dbh = "";#keep in mind, empty dbh defaults to local copri-instance dbname
@ -160,10 +161,10 @@ sub save_account(){
#Always on sharee_primary
if($varenv{dbname} ne "sharee_primary"){
$dbh = $dbt->dbconnect_extern("sharee_primary");
print FILE "\n*-->If no-primary connect DB sharee_primary $now_dt| c_id: $c_id \n" if($debug);
print FILE "\n*-->If no-primary connect DB sharee_primary (mvar: $varmerch->{merchant_id}|$varmerch->{dbname}|$varenv{dbname}) $now_dt| c_id: $c_id| owner: $owner\n" if($debug);
}else{
#keep in mind, should be only done by web-app user Formular (primary)
print FILE "\n*-->Else take local copri-Instance DB $varenv{dbname} $now_dt| c_id: $c_id \n" if($debug);
print FILE "\n*-->Else take local copri-Instance DB $varenv{dbname} (mvar: $varmerch->{merchant_id}|$varmerch->{dbname}) $now_dt| c_id: $c_id| owner: $owner\n" if($debug);
}
my $authref = {
@ -215,11 +216,6 @@ sub save_account(){
}
#operators, only if saved by operator DMS
elsif($_ eq "txt17"){
#2021-07-29 post input disabled, because it fails
#my @txt17 = $q->param('txt17');
#@txt17 = grep {!/null/g} @txt17;
#push(@txt17,$varenv{dbname}) if($varenv{dbname} ne "sharee_primary");
#my %txt17 = map {$_ => 1} @txt17;
my %txt17 = ();
if($ctadr->{txt17} =~ /\w\s\w/){
%txt17 = map { $_ => 1 } split(/\s+/,$ctadr->{txt17});
@ -239,26 +235,17 @@ sub save_account(){
#Web-Login|Rabatt|Vde|payone cron-intervall|Ilockit-Admin
#elsif($_ =~ /int05|int07|int12|int16|int19/){
elsif($_ =~ /int05|int07|int16|int19/){
#if($varenv{dbname} ne "sharee_primary"){
#on all $keys which on delete on loop sync
$u_rows = $dbt->update_one("",$update_primary,"$_=$valxx");
# }
}
#user_tour
elsif($_ =~ /txt18/){
#if($varenv{dbname} ne "sharee_primary"){
#on all $keys which on delete on loop sync
my @txt18 = $q->param('txt18');
@txt18 = grep {!/null/} @txt18;
$u_rows = $dbt->update_one("",$update_primary,"$_='@txt18'");
# }
}
#Text Sonstiges
elsif($_ =~ /txt29/){
# if($varenv{dbname} ne "sharee_primary"){
#on all $keys which on delete on loop sync
$u_rows = $dbt->update_one("",$update_primary,"$_='$valxx'");
# }
}
#txt15=Bonus- oder Antragsnummer (falls vorhanden)=15
@ -276,12 +263,18 @@ sub save_account(){
$txt17{$ctadr->{txt17}} = 1;
}
#TODO, check if merchant_id for KN and set $bonus_prefix
if($valxx && ($valxx =~ /^(\w{2,3})-(\w+)/ || $valxx =~ /^(\w{2,3})(\d+)/)){
#accept SWK codes without prefix
if($valxx && $owner && ($owner == 195 || $owner == 185 || $owner == 176 || $varenv{dbname} eq "sharee_kn")){
my $valappend = $valxx;
$valxx = "KN-$valappend";
print FILE "Prepare SWK Bonusnr by prefix $valxx" . "\n" if($debug);
}
if($valxx && ($valxx =~ /^(\w{2,3})-(\w+)/ || $valxx =~ /^(\w{2,3})(\d+)/)){
$valxx =~ s/\s//g;
my $bonus_prefix = uc($1),
my $bonusnr = $2;
my $operator_conf = $dbt->get_operator_conf($bonus_prefix);
my @txt30_op = ();
if(ref($operator_conf) eq "HASH" && $operator_conf->{oprefix} && $operator_conf->{database}->{dbname}){
print FILE "Bonus- oder Antragsnummer $valxx : " . $operator_conf->{oprefix} . " " . $operator_conf->{database}->{dbname} . "\n" if($debug);
@ -295,13 +288,28 @@ sub save_account(){
ct_name => "$bonusnr",
};
my $bonus_record = $dbt->fetch_record($dbh_operator,$pref_bo);
my $bonus_collect = {};#will be hash on matchin SWK bonus
#also if SWK file matches
if(!$bonus_record->{c_id} && $operator_conf->{database}->{dbname} eq "sharee_kn"){
my $swk_code = "";
$swk_code = $lb->grep_filecontent("$varenv{basedir}/ftp/SWK_codes/got_last.csv","$bonusnr");
$bonus_record->{ct_name} = $lb->grep_filecontent("$dbt->{copri_conf}->{basedir}/$operator_conf->{dir_app}/ftp/SWK_codes/got_last.csv","$bonusnr");
if($bonus_record->{ct_name}){
$bonus_record->{c_id} = 1;
$bonus_record->{int21} = 3429;#Stadtrad source Tarif
$bonus_record->{int22} = 3430;#Stadtrad target Tarif
$bonus_collect->{1}->{ct_name} = $bonus_record->{ct_name};
$bonus_collect->{1}->{int21} = 3429;
$bonus_collect->{1}->{int22} = 3430;
$bonus_collect->{2}->{ct_name} = $bonus_record->{ct_name};
$bonus_collect->{2}->{int21} = 3428;
$bonus_collect->{2}->{int22} = 3432;
@txt30_op = ("$bonus_collect->{1}->{int22}","$bonus_collect->{2}->{int22}");
}
print FILE "SWK bonus_collect:\n" . Dumper($bonus_collect) . "\n";
}
#add operators dbname only if Bonusnr matches
print FILE "txt15=$bonusnr requested on web Bonustarif on: $operator_conf->{database}->{dbname} --> barcode:$bonus_record->{barcode} --> txt21:$bonus_record->{int21} --> txt22:$bonus_record->{int22}\n" if($debug);
print FILE "txt15=$bonusnr requested on web Bonustarif on: $operator_conf->{database}->{dbname} --> Bonusnt:$bonus_record->{ct_name} --> int21:$bonus_record->{int21} --> int22:$bonus_record->{int22}\n" if($debug);
if($bonus_record->{c_id}){
$txt17{$operator_conf->{database}->{dbname}} = 1;
my @operators = ();
@ -311,12 +319,13 @@ sub save_account(){
print FILE "txt17 saving operators on primary: @operators\n" if($debug);
$u_rows = $dbt->update_one($dbh,$update_primary,"txt17='@operators'");
#insert adr to operator if it doesn't exist before set operator bonustarif
#collect operator addr with existing tariff setting
my $ctadr_operator = $dbt->fetch_record($dbh_operator,$authref);
my @txt30_op = ();
#multiple select sharee Tarif
@txt30_op = ("$ctadr_operator->{txt30}") if($ctadr_operator->{txt30});
@txt30_op = split(/\s+/,$ctadr_operator->{txt30}) if($ctadr_operator->{txt30} =~ /\w\s+\w/);
#operator request by Bonusnr.
#insert adr to operator if it doesn't exist before set operator bonustarif
if(!$ctadr_operator->{c_id}){
print FILE "Bonus oprefix address INSERT adr from record_primary to operator $operator_conf->{database}->{dbname} , c_id:$ctadr->{c_id}\n";
my $insert_op = {
@ -326,10 +335,12 @@ sub save_account(){
owner => "198",
};
my $c_id_op = $dbt->insert_contentoid($dbh_operator,$insert_op,"reset_adropkeys");
$dbt->update_content4comp($dbh_operator,$bonus_record->{c_id},"-","1");
if($bonus_record->{c_id} > 3){#means if not file greped with static c_id <= 3
$dbt->update_content4comp($dbh_operator,$bonus_record->{c_id},"-","1");
}
@txt30_op = ("$bonus_record->{int22}") if($bonus_record->{int22});
}
#address hash wit bonusnr
my $adr_bonus = {
table => "contentadr",
mtime => "now()",
@ -339,8 +350,8 @@ sub save_account(){
owner => $owner,
ret => $ret,
};
print FILE "adr_bonus preview which will be set if matches\n" . Dumper($adr_bonus) . "\n";
$ret = $pl->set_usertarif($dbh,$operator_conf->{database}->{dbname},$adr_bonus);
print FILE "operator adr update preview with bonusnr:\n" . Dumper($adr_bonus) . "\n";
$ret = $pl->set_usertarif($dbh,$operator_conf->{database}->{dbname},$adr_bonus,$bonus_collect);
}
}else{
$ret = "failure::txt15#top5";
@ -486,11 +497,18 @@ sub save_account(){
reference => "$ctadr->{c_id}_$epoche",
renewed => ''
};
my $payone_txid = "";
$payone_txid = $payone->preauthorizationSEPA_main(\%varenv,$ctadr,$ctt,$owner);
if($payone_txid){
##preauthorization and/or capture needs to much time, must be done async!
#$payone_txid = $payone->preauthorizationSEPA_main(\%varenv,$ctadr,$ctt,$owner);
#if($payone_txid)
if(1==1){
$ctt->{txt16} = "$payone_txid";
$payone_txid = $payone->captureSEPA_main(\%varenv,$ctadr,$ctt,$owner);
$u_rows = $dbt->update_one($dbh,$update_primary,"int12=0");#Vde
#$payone_txid = $payone->captureSEPA_main(\%varenv,$ctadr,$ctt,$owner);
#int12=0 should be set after capture success in payment module
}else{
$u_rows = $dbt->update_one($dbh,$update_primary,"int12=$vde_on_fail");#Vde
}