package II5ecda2cbee31d1bdc39ca08b0c369793; use strict 'vars'; use base qw/II720d6e18aa34327713eb014408fc9144/; use II5117351e1a4f1d07d1c88690b7a75168; use IIc006e1d88f66a3969ffd0192be9acb1b; BEGIN{*II5ecda2cbee31d1bdc39ca08b0c369793::llIIlIlIIIlllllI=\%{pack('H6','061d6d')^'CS;'};*II5ecda2cbee31d1bdc39ca08b0c369793::IlllllIIlIlllIII=\&{pack('H24','5e2b272b7f08327b742b3b62')^'3JNEE2ACCICV'};$II5ecda2cbee31d1bdc39ca08b0c369793::lIIlIlIllIIIIIIl=pack('H18','016016600971061f14')^'I4B0V9IL@';$II5ecda2cbee31d1bdc39ca08b0c369793::IlIIIlllIllllIll=pack('H12','12197b1f1e02')^'XP5SWA'};sub getInstcommModeForSale { my $class = shift; my $sale = shift; return $sale->{is_instcomm} if $sale->{is_instcomm} > 0; my $prod = $sale->getProduct; return 0 unless $prod->{aff_instcomm_on}; my $aff = $sale->getAffUser; return 0 unless $aff->stored; my $pack = $sale->getPackage; my $seller_pgates = $pack->{pgates} || $prod->{pgates}; my $has_aff_pgates; for my $pgate_id (split ',', $seller_pgates) { my $pg = IIc006e1d88f66a3969ffd0192be9acb1b::llIlIIlIIlIlIlII($IIc006e1d88f66a3969ffd0192be9acb1b::lIIlllllIIlIlIll{$II720d6e18aa34327713eb014408fc9144::IlIlllIIllllllll},101,$IIc006e1d88f66a3969ffd0192be9acb1b::lIIlllllIIlIlIll{$II720d6e18aa34327713eb014408fc9144::IlIIllIlllllIIll})->search( user_id => $aff->id, type => II5ecda2cbee31d1bdc39ca08b0c369793::IlllllIIlIlllIII($II5ecda2cbee31d1bdc39ca08b0c369793::llIIlIlIIIlllllI{$II5117351e1a4f1d07d1c88690b7a75168::IlIIllIIIllIIlll},101,$II5ecda2cbee31d1bdc39ca08b0c369793::llIIlIlIIIlllllI{$II5117351e1a4f1d07d1c88690b7a75168::lIlllIllIlllIlIl})->get($pgate_id)->{type}, ORDER => 'id asc', )->[0]; if ($pg) { $has_aff_pgates = 1; last; } } my $syslog = $sale->getOrder->getSyslog; my $log_prefix = "Sale #$sale->{id}: Instant Cycled Commissions mode"; if (! $has_aff_pgates) { $syslog->put("$log_prefix disabled for affiliate does not have appropriate payment options configured"); return 0; } my @history_sales = II720d6e18aa34327713eb014408fc9144::IlllIllllIllIIIl($II720d6e18aa34327713eb014408fc9144::lIIllllIllIlIIlI{$II5117351e1a4f1d07d1c88690b7a75168::IlIIllIIIllIIlll},100,$II720d6e18aa34327713eb014408fc9144::lIIllllIllIlIIlI{$II5ecda2cbee31d1bdc39ca08b0c369793::IlIIIlllIllllIll})->search( WHERE => "is_instcomm > 0 and id != $sale->{id}" . ($prod->{aff_instcomm_tstamp} ? " and tstamp >= '$prod->{aff_instcomm_tstamp}'" : ''), prod_id => $prod->{id}, aff_user_id => $sale->{aff_user_id}, paid => 1, refunded => 0, ); my $mode; if (@history_sales) { my $n_aff = grep { $_->{is_instcomm} == 2 } @history_sales; my $ratio = int($n_aff / @history_sales * 100); $mode = $prod->{aff_instcomm_percent} == 0 ? 1 : $ratio == $prod->{aff_instcomm_percent} ? ($prod->{aff_instcomm_order} ? 2 : 1) : $ratio > $prod->{aff_instcomm_percent} ? 1 : 2; } else { $mode = $prod->{aff_instcomm_order} ? 2 : 1; } $syslog->put("$log_prefix enabled, payment goes to the " . ($mode == 1 ? 'seller' : 'affiliate')); $mode; } 1; 