1 package FS::ClientAPI::Signup;
4 use vars qw( $DEBUG $me );
8 use FS::Record qw(qsearch qsearchs dbdef);
9 use FS::CGI qw(popurl);
10 use FS::Msgcat qw(gettext);
11 use FS::Misc qw(card_types);
12 use FS::ClientAPI_SessionCache;
14 use FS::cust_main_county;
28 $me = '[FS::ClientAPI::Signup]';
31 warn "$me clear_cache called\n" if $DEBUG;
32 my $cache = new FS::ClientAPI_SessionCache( {
33 'namespace' => 'FS::ClientAPI::Signup',
42 warn "$me signup_info called on $packet\n" if $DEBUG;
44 my $conf = new FS::Conf;
45 my $svc_x = $conf->config('signup_server-service') || 'svc_acct';
47 my $cache = new FS::ClientAPI_SessionCache( {
48 'namespace' => 'FS::ClientAPI::Signup',
50 my $signup_info_cache = $cache->get('signup_info_cache');
52 if ( $signup_info_cache ) {
54 warn "$me loading cached signup info\n" if $DEBUG > 1;
58 warn "$me populating signup info cache\n" if $DEBUG > 1;
60 my $agentnum2part_pkg =
64 my $href = $agent->pkgpart_hashref;
67 map { { 'payby' => [ $_->payby ],
68 'freq_pretty' => $_->freq_pretty,
69 'options' => { $_->options },
72 grep { $_->svcpart($svc_x)
73 && ( $href->{ $_->pkgpart }
75 && $_->agentnum == $agent->agentnum
79 qsearch( 'part_pkg', { 'disabled' => '' } )
81 } qsearch('agent', { 'disabled' => '' })
84 my $msgcat = { map { $_=>gettext($_) }
85 qw( passwords_dont_match invalid_card unknown_card_type
86 not_a empty_password illegal_or_empty_text )
88 warn "msgcat: ". Dumper($msgcat). "\n" if $DEBUG > 2;
90 my $label = { map { $_ => FS::Msgcat::_gettext($_) }
91 qw( stateid stateid_state )
93 warn "label: ". Dumper($label). "\n" if $DEBUG > 2;
95 my @agent_fields = qw( agentnum agent );
97 my @bools = qw( emailinvoiceonly security_phrase );
99 my @signup_bools = qw( no_company recommend_daytime recommend_email );
101 my @signup_server_scalars = qw( default_pkgpart default_svcpart );
103 my @selfservice_textareas = qw( head body_header body_footer );
105 my @selfservice_scalars = qw(
106 body_bgcolor box_bgcolor
107 text_color link_color vlink_color hlink_color alink_color
108 font title_color title_align title_size menu_bgcolor menu_fontsize
111 #XXX my @selfservice_bools = qw(
112 # menu_skipblanks menu_skipheadings menu_nounderline
115 #my $selfservice_binaries = qw(
116 # title_left_image title_right_image
117 # menu_top_image menu_body_image menu_bottom_image
120 $signup_info_cache = {
122 'cust_main_county' => [ map $_->hashref,
123 qsearch('cust_main_county', {} )
126 'agent' => [ map { my $agent = $_;
127 +{ map { $_ => $agent->get($_) } @agent_fields }
129 qsearch('agent', { 'disabled' => '' } )
132 'part_referral' => [ map $_->hashref,
133 qsearch('part_referral', { 'disabled' => '' } )
136 'agentnum2part_pkg' => $agentnum2part_pkg,
138 'svc_acct_pop' => [ map $_->hashref, qsearch('svc_acct_pop',{} ) ],
140 'emailinvoiceonly' => $conf->exists('emailinvoiceonly'),
142 'security_phrase' => $conf->exists('security_phrase'),
144 'nomadix' => $conf->exists('signup_server-nomadix'),
146 'payby' => [ $conf->config('signup_server-payby') ],
148 'payby_longname' => [ map { FS::payby->longname($_) }
149 $conf->config('signup_server-payby') ],
151 'card_types' => card_types(),
153 ( map { $_ => $conf->exists("signup-$_") } @signup_bools ),
155 ( map { $_ => scalar($conf->config("signup_server-$_")) }
156 @signup_server_scalars
159 ( map { $_ => join("\n", $conf->config("selfservice-$_")) }
160 @selfservice_textareas
162 ( map { $_ => scalar($conf->config("selfservice-$_")) }
166 #( map { $_ => scalar($conf->config_binary("selfservice-$_")) }
167 # @selfservice_binaries
170 'agentnum2part_pkg' => $agentnum2part_pkg,
171 'svc_acct_pop' => [ map $_->hashref, qsearch('svc_acct_pop',{} ) ],
172 'nomadix' => $conf->exists('signup_server-nomadix'),
173 'payby' => [ $conf->config('signup_server-payby') ],
174 'card_types' => card_types(),
175 'paytypes' => [ @FS::cust_main::paytypes ],
177 'stateid_enabled' => $conf->exists('show_stateid'),
178 'paystate_enabled' => $conf->exists('show_bankstate'),
182 'statedefault' => scalar($conf->config('statedefault')) || 'CA',
183 'countrydefault' => scalar($conf->config('countrydefault')) || 'US',
184 'refnum' => scalar($conf->config('signup_server-default_refnum')),
185 'signup_service' => $svc_x,
186 'company_name' => scalar($conf->config('company_name')),
188 'agent_ship_address' => scalar($conf->exists('agent-ship_address')),
189 'require_phone' => scalar($conf->exists('cust_main-require_phone')),
190 'logo' => scalar($conf->config_binary('logo.png')),
191 'prepaid_template_custnum' => $conf->exists('signup_server-prepaid-template-custnum'),
194 $cache->set('signup_info_cache', $signup_info_cache);
198 my $signup_info = { %$signup_info_cache };
199 warn "$me signup info loaded\n" if $DEBUG > 1;
200 warn Dumper($signup_info). "\n" if $DEBUG > 2;
202 my @addl = qw( signup_server-classnum2 signup_server-classnum3 );
204 if ( grep { $conf->exists($_) } @addl ) {
206 $signup_info->{optional_packages} = [];
208 foreach my $addl ( @addl ) {
210 warn "$me adding optional package info\n" if $DEBUG > 1;
212 my $classnum = $conf->config($addl) or next;
215 'freq_pretty' => $_->freq_pretty,
216 'options' => { $_->options },
220 qsearch( 'part_pkg', { classnum => $classnum } );
222 push @{$signup_info->{optional_packages}}, \@pkgs;
224 warn "$me done adding opt. package info for $classnum\n" if $DEBUG > 1;
230 my $agentnum = $packet->{'agentnum'}
231 || $conf->config('signup_server-default_agentnum');
232 $agentnum =~ /^(\d*)$/ or die "illegal agentnum";
236 if ( exists $packet->{'session_id'} ) {
238 warn "$me loading agent session\n" if $DEBUG > 1;
239 my $cache = new FS::ClientAPI_SessionCache( {
240 'namespace' => 'FS::ClientAPI::Agent',
242 $session = $cache->get($packet->{'session_id'});
244 $agentnum = $session->{'agentnum'};
246 return { 'error' => "Can't resume session" }; #better error message
248 warn "$me done loading agent session\n" if $DEBUG > 1;
250 } elsif ( exists $packet->{'customer_session_id'} ) {
252 warn "$me loading customer session\n" if $DEBUG > 1;
253 my $cache = new FS::ClientAPI_SessionCache( {
254 'namespace' => 'FS::ClientAPI::MyAccount',
256 $session = $cache->get($packet->{'customer_session_id'});
258 my $custnum = $session->{'custnum'};
259 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum });
260 return { 'error' => "Can't find your customer record" } unless $cust_main;
261 $agentnum = $cust_main->agentnum;
263 return { 'error' => "Can't resume session" }; #better error message
265 warn "$me done loading customer session\n" if $DEBUG > 1;
269 $signup_info->{'part_pkg'} = [];
271 if ( $packet->{'reg_code'} ) {
273 warn "$me setting package list via reg_code\n" if $DEBUG > 1;
275 $signup_info->{'part_pkg'} =
276 [ map { { 'payby' => [ $_->payby ],
277 'freq_pretty' => $_->freq_pretty,
278 'options' => { $_->options },
282 grep { $_->svcpart($svc_x) }
284 qsearchs( 'reg_code', { 'code' => $packet->{'reg_code'},
285 'agentnum' => $agentnum, } )
289 $signup_info->{'error'} = 'Unknown registration code'
290 unless @{ $signup_info->{'part_pkg'} };
292 warn "$me done setting package list via reg_code\n" if $DEBUG > 1;
294 } elsif ( $packet->{'promo_code'} ) {
296 warn "$me setting package list via promo_code\n" if $DEBUG > 1;
298 $signup_info->{'part_pkg'} =
299 [ map { { 'payby' => [ $_->payby ],
300 'freq_pretty' => $_->freq_pretty,
301 'options' => { $_->options },
304 grep { $_->svcpart($svc_x) }
305 qsearch( 'part_pkg', { 'promo_code' => {
307 value=>$packet->{'promo_code'}
309 'disabled' => '', } )
312 $signup_info->{'error'} = 'Unknown promotional code'
313 unless @{ $signup_info->{'part_pkg'} };
315 warn "$me done setting package list via promo_code\n" if $DEBUG > 1;
320 warn "$me setting agent-specific payment flag\n" if $DEBUG > 1;
321 my $agent = qsearchs('agent', { 'agentnum' => $agentnum } )
322 or return { 'error' => "Self-service agent #$agentnum does not exist" };
323 warn "$me has agent $agent\n" if $DEBUG > 1;
324 my @paybys = @{ $signup_info->{'payby'} };
325 $signup_info->{'hide_payment_fields'} = [];
327 my $gatewaynum = $conf->config('selfservice-payment_gateway');
330 $force_gateway = qsearchs('payment_gateway', { gatewaynum => $gatewaynum });
331 warn "using forced gateway #$gatewaynum - " .
332 $force_gateway->gateway_username . '@' . $force_gateway->gateway_module
334 die "configured gatewaynum $gatewaynum not found!" if !$force_gateway;
336 foreach my $payby (@paybys) {
337 warn "$me checking $payby payment fields\n" if $DEBUG > 1;
339 if ( FS::payby->realtime($payby) ) {
340 my $gateway = $force_gateway ||
341 $agent->payment_gateway( 'method' => FS::payby->payby2bop($payby),
344 if ( $gateway && $gateway->gateway_namespace
345 eq 'Business::OnlineThirdPartyPayment'
347 warn "$me hiding $payby payment fields\n" if $DEBUG > 1;
351 push @{$signup_info->{'hide_payment_fields'}}, $hide;
353 warn "$me done setting agent-specific payment flag\n" if $DEBUG > 1;
355 warn "$me setting agent-specific package list\n" if $DEBUG > 1;
356 $signup_info->{'part_pkg'} = $signup_info->{'agentnum2part_pkg'}{$agentnum}
357 unless @{ $signup_info->{'part_pkg'} };
358 warn "$me done setting agent-specific package list\n" if $DEBUG > 1;
360 warn "$me setting agent-specific adv. source list\n" if $DEBUG > 1;
361 $signup_info->{'part_referral'} =
365 'table' => 'part_referral',
366 'hashref' => { 'disabled' => '' },
367 'extra_sql' => "AND ( agentnum = $agentnum ".
368 " OR agentnum IS NULL ) ",
372 warn "$me done setting agent-specific adv. source list\n" if $DEBUG > 1;
374 $signup_info->{'agent_name'} = $agent->agent;
376 $signup_info->{'company_name'} = $conf->config('company_name', $agentnum);
378 if ( $signup_info->{'agent_ship_address'} && $agent->agent_custnum ) {
379 my $cust_main = $agent->agent_cust_main;
380 my $prefix = length($cust_main->ship_last) ? 'ship_' : '';
381 $signup_info->{"ship_$_"} = $cust_main->get("$prefix$_")
382 foreach qw( address1 city county state zip country );
385 #some of the above could probably be cached, too
387 my $signup_info_cache_agent = $cache->get("signup_info_cache_agent$agentnum");
389 if ( $signup_info_cache_agent ) {
391 warn "$me loading cached signup info for agentnum $agentnum\n"
396 warn "$me populating signup info cache for agentnum $agentnum\n"
399 $signup_info_cache_agent = {
400 #( map { $_ => scalar( $conf->config($_, $agentnum) ) }
401 # qw( company_name ) ),
402 ( map { $_ => scalar( $conf->config("selfservice-$_", $agentnum ) ) }
403 qw( body_bgcolor box_bgcolor menu_bgcolor ) ),
404 ( map { $_ => join("\n", $conf->config("selfservice-$_", $agentnum ) ) }
405 qw( head body_header body_footer ) ),
408 $cache->set("signup_info_cache_agent$agentnum", $signup_info_cache_agent);
412 $signup_info->{$_} = $signup_info_cache_agent->{$_}
413 foreach keys %$signup_info_cache_agent;
417 # delete $signup_info->{'part_pkg'};
420 warn "$me sorting package list\n" if $DEBUG > 1;
421 $signup_info->{'part_pkg'} = [ sort { $a->{pkg} cmp $b->{pkg} } # case?
422 @{ $signup_info->{'part_pkg'} }
424 warn "$me done sorting package list\n" if $DEBUG > 1;
426 if ( exists $packet->{'session_id'} ) {
427 my $agent_signup_info = { %$signup_info };
428 delete $agent_signup_info->{agentnum2part_pkg};
429 $agent_signup_info->{'agent'} = $session->{'agent'};
430 return $agent_signup_info;
432 elsif ( exists $packet->{'keys'} ) {
433 my @keys = @{ $packet->{'keys'} };
434 return { map { $_ => $signup_info->{$_} } @keys };
442 sub domain_select_hash {
447 if ($packet->{pkgpart}) {
448 my $part_pkg = qsearchs('part_pkg' => { 'pkgpart' => $packet->{pkgpart} } );
449 #$packet->{svcpart} = $part_pkg->svcpart('svc_acct')
450 $packet->{svcpart} = $part_pkg->svcpart
454 if ($packet->{svcpart}) {
455 my $part_svc = qsearchs('part_svc' => { 'svcpart' => $packet->{svcpart} } );
456 $response->{'domsvc'} = $part_svc->part_svc_column('domsvc')->columnvalue
457 if ($part_svc && $part_svc->part_svc_column('domsvc')->columnflag eq 'D');
460 $response->{'domains'}
461 = { domain_select_hash FS::svc_acct( map { $_ => $packet->{$_} }
471 my $conf = new FS::Conf;
472 my $svc_x = $conf->config('signup_server-service') || 'svc_acct';
474 if ( $svc_x eq 'svc_acct' ) {
476 #things that aren't necessary in base class, but are for signup server
477 #return "Passwords don't match"
478 # if $hashref->{'_password'} ne $hashref->{'_password2'}
479 return { 'error' => gettext('empty_password') }
480 unless length($packet->{'_password'});
481 # a bit inefficient for large numbers of pops
482 return { 'error' => gettext('no_access_number_selected') }
483 unless $packet->{'popnum'} || !scalar(qsearch('svc_acct_pop',{} ));
486 elsif ( $svc_x eq 'svc_pbx' ) {
487 #possibly some validation will be needed
491 if ( exists $packet->{'session_id'} ) {
492 my $cache = new FS::ClientAPI_SessionCache( {
493 'namespace' => 'FS::ClientAPI::Agent',
495 my $session = $cache->get($packet->{'session_id'});
497 $agentnum = $session->{'agentnum'};
499 return { 'error' => "Can't resume session" }; #better error message
502 $agentnum = $packet->{agentnum}
503 || $conf->config('signup_server-default_agentnum');
506 #shares some stuff with htdocs/edit/process/cust_main.cgi... take any
507 # common that are still here and library them.
508 my $template_custnum = $conf->config('signup_server-prepaid-template-custnum');
510 if ( $template_custnum && $packet->{prepaid_shortform} ) {
512 my $template_cust = qsearchs('cust_main', { 'custnum' => $template_custnum } );
513 return { 'error' => 'Configuration error' } unless $template_cust;
514 $cust_main = new FS::cust_main ( {
515 'agentnum' => $agentnum,
516 'refnum' => $packet->{refnum}
517 || $conf->config('signup_server-default_refnum'),
519 ( map { $_ => $template_cust->$_ } qw(
520 last first company address1 address2
521 city county state zip country
524 ship_last ship_first ship_company ship_address1 ship_address2
525 ship_city ship_county ship_state ship_zip ship_country
526 ship_daytime ship_night ship_fax
530 ( map { $_ => $packet->{$_} } qw(
531 ss stateid stateid_state
534 payinfo paycvv paydate payname paystate paytype
535 paystart_month paystart_year payissue
538 referral_custnum comments
546 $cust_main = new FS::cust_main ( {
548 'agentnum' => $agentnum,
549 'refnum' => $packet->{refnum}
550 || $conf->config('signup_server-default_refnum'),
552 map { $_ => $packet->{$_} } qw(
554 last first ss company address1 address2
555 city county state zip country
556 daytime night fax stateid stateid_state
558 ship_last ship_first ship_ss ship_company ship_address1 ship_address2
559 ship_city ship_county ship_state ship_zip ship_country
560 ship_daytime ship_night ship_fax
563 payinfo paycvv paydate payname paystate paytype
564 paystart_month paystart_year payissue
568 referral_custnum comments
574 my $agent = qsearchs('agent', { 'agentnum' => $agentnum } );
575 if ( $conf->exists('agent_ship_address') && $agent->agent_custnum ) {
576 my $agent_cust_main = $agent->agent_cust_main;
577 my $prefix = length($agent_cust_main->ship_last) ? 'ship_' : '';
578 $cust_main->set("ship_$_", $agent_cust_main->get("$prefix$_") )
579 foreach qw( address1 city county state zip country );
581 $cust_main->set("ship_$_", $cust_main->get($_))
582 foreach qw( last first );
587 return { 'error' => "Illegal payment type" }
588 unless grep { $_ eq $packet->{'payby'} }
589 $conf->config('signup_server-payby');
591 if (FS::payby->realtime($packet->{payby})
592 and not $conf->exists('signup_server-third_party_as_card')) {
593 my $payby = $packet->{payby};
595 my $agent = qsearchs('agent', { 'agentnum' => $agentnum });
596 return { 'error' => "Unknown reseller" }
600 my $gatewaynum = $conf->config('selfservice-payment_gateway');
602 $gw = qsearchs('payment_gateway', { gatewaynum => $gatewaynum });
603 die "configured gatewaynum $gatewaynum not found!" if !$gw;
606 $gw = $agent->payment_gateway( 'method' => FS::payby->payby2bop($payby),
611 $cust_main->payby('BILL') # MCRD better?
612 if $gw && $gw->gateway_namespace eq 'Business::OnlineThirdPartyPayment';
615 $cust_main->payinfo($cust_main->daytime)
616 if $cust_main->payby eq 'LECB' && ! $cust_main->payinfo;
618 my @invoicing_list = $packet->{'invoicing_list'}
619 ? split( /\s*\,\s*/, $packet->{'invoicing_list'} )
622 $packet->{'pkgpart'} =~ /^(\d+)$/ or '' =~ /^()$/;
624 return { 'error' => 'Please select a package' } unless $pkgpart; #msgcat
627 qsearchs( 'part_pkg', { 'pkgpart' => $pkgpart } )
628 or return { 'error' => "WARNING: unknown pkgpart: $pkgpart" };
629 my $svcpart = $part_pkg->svcpart($svc_x);
632 if ( $packet->{'reg_code'} ) {
633 $reg_code = qsearchs( 'reg_code', { 'code' => $packet->{'reg_code'},
634 'agentnum' => $agentnum, } )
635 or return { 'error' => 'Unknown registration code' };
638 my $cust_pkg = new FS::cust_pkg ( {
639 #later#'custnum' => $custnum,
640 'pkgpart' => $packet->{'pkgpart'},
641 'promo_code' => $packet->{'promo_code'},
642 'reg_code' => $packet->{'reg_code'},
644 #my $error = $cust_pkg->check;
645 #return { 'error' => $error } if $error;
647 #should be all auto-magic and shit
649 if ( $svc_x eq 'svc_acct' ) {
651 my $svc = new FS::svc_acct {
652 'svcpart' => $svcpart,
653 map { $_ => $packet->{$_} }
654 qw( username _password sec_phrase popnum ),
659 while ( exists($packet->{"snarf_machine$snarfnum"})
660 && length($packet->{"snarf_machine$snarfnum"}) ) {
661 my $acct_snarf = new FS::acct_snarf ( {
662 'machine' => $packet->{"snarf_machine$snarfnum"},
663 'protocol' => $packet->{"snarf_protocol$snarfnum"},
664 'username' => $packet->{"snarf_username$snarfnum"},
665 '_password' => $packet->{"snarf_password$snarfnum"},
668 push @acct_snarf, $acct_snarf;
670 $svc->child_objects( \@acct_snarf );
673 } elsif ( $svc_x eq 'svc_phone' ) {
675 push @svc, new FS::svc_phone ( {
676 'svcpart' => $svcpart,
677 map { $_ => $packet->{$_} }
678 qw( countrycode phonenum sip_password pin ),
681 } elsif ( $svc_x eq 'svc_pbx' ) {
683 push @svc, new FS::svc_pbx ( {
684 'svcpart' => $svcpart,
685 map { $_ => $packet->{$_} }
690 die "unknown signup service $svc_x";
693 if ($packet->{'mac_addr'} && $conf->exists('signup_server-mac_addr_svcparts'))
696 my %mac_addr_svcparts = map { $_ => 1 }
697 $conf->config('signup_server-mac_addr_svcparts');
698 my @pkg_svc = grep { $_->quantity && $mac_addr_svcparts{$_->svcpart} }
699 $cust_pkg->part_pkg->pkg_svc;
701 return { 'error' => 'No service defined to assign mac address' }
704 my $svc = new FS::svc_acct {
705 'svcpart' => $pkg_svc[0]->svcpart, #multiple matches? alas..
706 'username' => $packet->{'mac_addr'},
707 '_password' => '', #blank as requested (set passwordmin to 0)
714 foreach my $svc ( @svc ) {
715 my $y = $svc->setdefault; # arguably should be in new method
716 return { 'error' => $y } if $y && !ref($y);
717 #$error = $svc->check;
718 #return { 'error' => $error } if $error;
721 #setup a job dependancy to delay provisioning
722 my $placeholder = new FS::queue ( {
723 'job' => 'FS::ClientAPI::Signup::__placeholder',
724 'status' => 'locked',
726 my $error = $placeholder->insert;
727 return { 'error' => $error } if $error;
730 tie my %hash, 'Tie::RefHash';
731 %hash = ( $cust_pkg => \@svc );
733 $error = $cust_main->insert(
736 'depend_jobnum' => $placeholder->jobnum,
739 my $perror = $placeholder->delete;
740 $error .= " (Additionally, error removing placeholder: $perror)" if $perror;
741 return { 'error' => $error };
744 if ( $conf->exists('signup_server-realtime') ) {
746 #warn "$me Billing customer...\n" if $Debug;
748 my $bill_error = $cust_main->bill( 'depend_jobnum'=>$placeholder->jobnum );
749 #warn "$me error billing new customer: $bill_error"
752 $bill_error = $cust_main->apply_payments_and_credits;
753 #warn "$me error applying payments and credits for".
754 # " new customer: $bill_error"
757 $bill_error = $cust_main->realtime_collect(
758 method => FS::payby->payby2bop( $packet->{payby} ),
759 depend_jobnum => $placeholder->jobnum,
762 #warn "$me error collecting from new customer: $bill_error"
765 if ($bill_error && ref($bill_error) eq 'HASH') {
766 return { 'error' => '_collect',
767 ( map { $_ => $bill_error->{$_} }
768 qw(popup_url reference collectitems)
770 amount => $cust_main->balance,
774 $bill_error = $cust_main->apply_payments_and_credits;
775 #warn "$me error applying payments and credits for".
776 # " new customer: $bill_error"
779 if ( $cust_main->balance > 0 ) {
781 #this makes sense. credit is "un-doing" the invoice
782 $cust_main->credit( $cust_main->balance, 'signup server decline',
783 'reason_type' => $conf->config('signup_credit_type'),
785 $cust_main->apply_credits;
787 #should check list for errors...
788 #$cust_main->suspend;
789 local $FS::svc_Common::noexport_hack = 1;
790 $cust_main->cancel('quiet'=>1);
792 my $perror = $placeholder->depended_delete;
793 warn "error removing provisioning jobs after decline: $perror" if $perror;
795 $perror = $placeholder->delete;
796 warn "error removing placeholder after decline: $perror" if $perror;
799 return { 'error' => '_decline' };
805 $error = $reg_code->delete;
806 return { 'error' => $error } if $error;
809 $error = $placeholder->delete;
810 return { 'error' => $error } if $error;
812 if ( $conf->exists('signup-duplicate_cc-warn_hours') ) {
813 my $hours = $conf->config('signup-duplicate_cc-warn_hours');
814 my $ban = new FS::banned_pay $cust_main->_new_banned_pay_hashref;
815 $ban->end_date( int( time + $hours*3600 ) );
816 $ban->bantype('warn');
817 $ban->reason('signup-duplicate_cc-warn_hours');
818 $error = $ban->insert;
819 warn "WARNING: error inserting temporary banned_pay for ".
820 " signup-duplicate_cc-warn_hours (proceeding anyway): $error"
824 my %return = ( 'error' => '',
825 'signup_service' => $svc_x,
826 'custnum' => $cust_main->custnum,
831 $return{'svcnum'} = $svc[0]->svcnum;
833 if ( $svc_x eq 'svc_acct' ) {
834 $return{$_} = $svc[0]->$_() for qw( username _password );
835 } elsif ( $svc_x eq 'svc_phone' ) {
836 $return{$_} = $svc[0]->$_() for qw(countrycode phonenum sip_password pin);
837 } elsif ( $svc_x eq 'svc_pbx' ) {
838 #$return{$_} = $svc[0]->$_() for qw( ) #nothing yet
840 return {'error' => "configuration error: unknown signup service $svc_x"};
841 #die "unknown signup service $svc_x";
842 # return an error that's visible to someone somewhere
851 sub capture_payment {
854 warn "$me capture_payment called on $packet\n" if $DEBUG;
857 # identify processor/gateway from called back URL
860 my $conf = new FS::Conf;
863 if ( my $gwnum = $conf->config('selfservice-payment_gateway') ) {
864 $payment_gateway = qsearchs('payment_gateway', { 'gatewaynum' => $gwnum })
865 or die "configured gatewaynum $gwnum not found!";
868 my $url = $packet->{url};
870 $payment_gateway = qsearchs('payment_gateway',
871 { 'gateway_callback_url' => popurl(0, $url) }
873 if (!$payment_gateway) {
875 my ( $processor, $login, $password, $action, @bop_options ) =
876 $conf->config('business-onlinepayment');
877 $action ||= 'normal authorization';
878 pop @bop_options if scalar(@bop_options) % 2 && $bop_options[-1] =~ /^\s*$/;
879 die "No real-time processor is enabled - ".
880 "did you set the business-onlinepayment configuration value?\n"
883 $payment_gateway = new FS::payment_gateway( {
884 gateway_namespace => $conf->config('business-onlinepayment-namespace'),
885 gateway_module => $processor,
886 gateway_username => $login,
887 gateway_password => $password,
888 gateway_action => $action,
889 options => [ ( @bop_options ) ],
894 die "No real-time third party processor is enabled - ".
895 "did you set the business-onlinepayment configuration value?\n*"
896 unless $payment_gateway->gateway_namespace eq 'Business::OnlineThirdPartyPayment';
899 # locate pending transaction
902 eval "use Business::OnlineThirdPartyPayment";
906 new Business::OnlineThirdPartyPayment( $payment_gateway->gateway_module,
907 @{ [ $payment_gateway->options ] },
910 my $paypendingnum = $transaction->reference($packet->{data});
912 my $cust_pay_pending =
913 qsearchs('cust_pay_pending', { paypendingnum => $paypendingnum } );
915 unless ($cust_pay_pending) {
916 my $bill_error = "No payment is being processed with id $paypendingnum".
917 "; Transaction aborted.";
918 return { error => '_decline', bill_error => $bill_error };
921 if ($cust_pay_pending->status ne 'thirdparty') {
922 my $bill_error = "Payment with id $paypendingnum is not thirdparty, but ".
923 $cust_pay_pending->status. "; Transaction aborted.";
924 return { error => '_decline', bill_error => $bill_error };
927 my $cust_main = $cust_pay_pending->cust_main;
929 $cust_main->realtime_botpp_capture( $cust_pay_pending,
934 return { 'error' => ( $bill_error->{bill_error} ? '_decline' : '' ),