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;
27 $me = '[FS::ClientAPI::Signup]';
30 warn "$me clear_cache called\n" if $DEBUG;
31 my $cache = new FS::ClientAPI_SessionCache( {
32 'namespace' => 'FS::ClientAPI::Signup',
41 warn "$me signup_info called on $packet\n" if $DEBUG;
43 my $conf = new FS::Conf;
44 my $svc_x = $conf->config('signup_server-service') || 'svc_acct';
46 my $cache = new FS::ClientAPI_SessionCache( {
47 'namespace' => 'FS::ClientAPI::Signup',
49 my $signup_info_cache = $cache->get('signup_info_cache');
51 if ( $signup_info_cache ) {
53 warn "$me loading cached signup info\n" if $DEBUG > 1;
57 warn "$me populating signup info cache\n" if $DEBUG > 1;
59 my $agentnum2part_pkg =
63 my $href = $agent->pkgpart_hashref;
66 map { { 'payby' => [ $_->payby ],
67 'freq_pretty' => $_->freq_pretty,
68 'options' => { $_->options },
71 grep { $_->svcpart($svc_x)
72 && ( $href->{ $_->pkgpart }
74 && $_->agentnum == $agent->agentnum
78 qsearch( 'part_pkg', { 'disabled' => '' } )
80 } qsearch('agent', { 'disabled' => '' })
83 my $msgcat = { map { $_=>gettext($_) }
84 qw( passwords_dont_match invalid_card unknown_card_type
85 not_a empty_password illegal_or_empty_text )
87 warn "msgcat: ". Dumper($msgcat). "\n" if $DEBUG > 2;
89 my $label = { map { $_ => FS::Msgcat::_gettext($_) }
90 qw( stateid stateid_state )
92 warn "label: ". Dumper($label). "\n" if $DEBUG > 2;
94 my @agent_fields = qw( agentnum agent );
96 my @bools = qw( emailinvoiceonly security_phrase );
98 my @signup_bools = qw( no_company recommend_daytime recommend_email );
100 my @signup_server_scalars = qw( default_pkgpart default_svcpart );
102 my @selfservice_textareas = qw( head body_header body_footer );
104 my @selfservice_scalars = qw(
105 body_bgcolor box_bgcolor
106 text_color link_color vlink_color hlink_color alink_color
107 font title_color title_align title_size menu_bgcolor menu_fontsize
110 #XXX my @selfservice_bools = qw(
111 # menu_skipblanks menu_skipheadings menu_nounderline
114 #my $selfservice_binaries = qw(
115 # title_left_image title_right_image
116 # menu_top_image menu_body_image menu_bottom_image
119 $signup_info_cache = {
121 'cust_main_county' => [ map $_->hashref,
122 qsearch('cust_main_county', {} )
125 'agent' => [ map { my $agent = $_;
126 +{ map { $_ => $agent->get($_) } @agent_fields }
128 qsearch('agent', { 'disabled' => '' } )
131 'part_referral' => [ map $_->hashref,
132 qsearch('part_referral', { 'disabled' => '' } )
135 'agentnum2part_pkg' => $agentnum2part_pkg,
137 'svc_acct_pop' => [ map $_->hashref, qsearch('svc_acct_pop',{} ) ],
139 'emailinvoiceonly' => $conf->exists('emailinvoiceonly'),
141 'security_phrase' => $conf->exists('security_phrase'),
143 'nomadix' => $conf->exists('signup_server-nomadix'),
145 'payby' => [ $conf->config('signup_server-payby') ],
147 'payby_longname' => [ map { FS::payby->longname($_) }
148 $conf->config('signup_server-payby') ],
150 'card_types' => card_types(),
152 ( map { $_ => $conf->exists("signup-$_") } @signup_bools ),
154 ( map { $_ => scalar($conf->config("signup_server-$_")) }
155 @signup_server_scalars
158 ( map { $_ => join("\n", $conf->config("selfservice-$_")) }
159 @selfservice_textareas
161 ( map { $_ => scalar($conf->config("selfservice-$_")) }
165 #( map { $_ => scalar($conf->config_binary("selfservice-$_")) }
166 # @selfservice_binaries
169 'agentnum2part_pkg' => $agentnum2part_pkg,
170 'svc_acct_pop' => [ map $_->hashref, qsearch('svc_acct_pop',{} ) ],
171 'nomadix' => $conf->exists('signup_server-nomadix'),
172 'payby' => [ $conf->config('signup_server-payby') ],
173 'card_types' => card_types(),
174 'paytypes' => [ @FS::cust_main::paytypes ],
176 'stateid_enabled' => $conf->exists('show_stateid'),
177 'paystate_enabled' => $conf->exists('show_bankstate'),
181 'statedefault' => scalar($conf->config('statedefault')) || 'CA',
182 'countrydefault' => scalar($conf->config('countrydefault')) || 'US',
183 'refnum' => scalar($conf->config('signup_server-default_refnum')),
184 'signup_service' => $svc_x,
185 'company_name' => scalar($conf->config('company_name')),
187 'agent_ship_address' => scalar($conf->exists('agent-ship_address')),
188 'require_phone' => scalar($conf->exists('cust_main-require_phone')),
189 'logo' => scalar($conf->config_binary('logo.png')),
190 'prepaid_template_custnum' => $conf->exists('signup_server-prepaid-template-custnum'),
193 $cache->set('signup_info_cache', $signup_info_cache);
197 my $signup_info = { %$signup_info_cache };
198 warn "$me signup info loaded\n" if $DEBUG > 1;
199 warn Dumper($signup_info). "\n" if $DEBUG > 2;
201 my @addl = qw( signup_server-classnum2 signup_server-classnum3 );
203 if ( grep { $conf->exists($_) } @addl ) {
205 $signup_info->{optional_packages} = [];
207 foreach my $addl ( @addl ) {
209 warn "$me adding optional package info\n" if $DEBUG > 1;
211 my $classnum = $conf->config($addl) or next;
214 'freq_pretty' => $_->freq_pretty,
215 'options' => { $_->options },
219 qsearch( 'part_pkg', { classnum => $classnum } );
221 push @{$signup_info->{optional_packages}}, \@pkgs;
223 warn "$me done adding opt. package info for $classnum\n" if $DEBUG > 1;
229 my $agentnum = $packet->{'agentnum'}
230 || $conf->config('signup_server-default_agentnum');
231 $agentnum =~ /^(\d*)$/ or die "illegal agentnum";
235 if ( exists $packet->{'session_id'} ) {
237 warn "$me loading agent session\n" if $DEBUG > 1;
238 my $cache = new FS::ClientAPI_SessionCache( {
239 'namespace' => 'FS::ClientAPI::Agent',
241 $session = $cache->get($packet->{'session_id'});
243 $agentnum = $session->{'agentnum'};
245 return { 'error' => "Can't resume session" }; #better error message
247 warn "$me done loading agent session\n" if $DEBUG > 1;
249 } elsif ( exists $packet->{'customer_session_id'} ) {
251 warn "$me loading customer session\n" if $DEBUG > 1;
252 my $cache = new FS::ClientAPI_SessionCache( {
253 'namespace' => 'FS::ClientAPI::MyAccount',
255 $session = $cache->get($packet->{'customer_session_id'});
257 my $custnum = $session->{'custnum'};
258 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum });
259 return { 'error' => "Can't find your customer record" } unless $cust_main;
260 $agentnum = $cust_main->agentnum;
262 return { 'error' => "Can't resume session" }; #better error message
264 warn "$me done loading customer session\n" if $DEBUG > 1;
268 $signup_info->{'part_pkg'} = [];
270 if ( $packet->{'reg_code'} ) {
272 warn "$me setting package list via reg_code\n" if $DEBUG > 1;
274 $signup_info->{'part_pkg'} =
275 [ map { { 'payby' => [ $_->payby ],
276 'freq_pretty' => $_->freq_pretty,
277 'options' => { $_->options },
281 grep { $_->svcpart($svc_x) }
283 qsearchs( 'reg_code', { 'code' => $packet->{'reg_code'},
284 'agentnum' => $agentnum, } )
288 $signup_info->{'error'} = 'Unknown registration code'
289 unless @{ $signup_info->{'part_pkg'} };
291 warn "$me done setting package list via reg_code\n" if $DEBUG > 1;
293 } elsif ( $packet->{'promo_code'} ) {
295 warn "$me setting package list via promo_code\n" if $DEBUG > 1;
297 $signup_info->{'part_pkg'} =
298 [ map { { 'payby' => [ $_->payby ],
299 'freq_pretty' => $_->freq_pretty,
300 'options' => { $_->options },
303 grep { $_->svcpart($svc_x) }
304 qsearch( 'part_pkg', { 'promo_code' => {
306 value=>$packet->{'promo_code'}
308 'disabled' => '', } )
311 $signup_info->{'error'} = 'Unknown promotional code'
312 unless @{ $signup_info->{'part_pkg'} };
314 warn "$me done setting package list via promo_code\n" if $DEBUG > 1;
319 warn "$me setting agent-specific payment flag\n" if $DEBUG > 1;
320 my $agent = qsearchs('agent', { 'agentnum' => $agentnum } )
321 or return { 'error' => "Self-service agent #$agentnum does not exist" };
322 warn "$me has agent $agent\n" if $DEBUG > 1;
323 my @paybys = @{ $signup_info->{'payby'} };
324 $signup_info->{'hide_payment_fields'} = [];
326 my $gatewaynum = $conf->config('selfservice-payment_gateway');
329 $force_gateway = qsearchs('payment_gateway', { gatewaynum => $gatewaynum });
330 warn "using forced gateway #$gatewaynum - " .
331 $force_gateway->gateway_username . '@' . $force_gateway->gateway_module
333 die "configured gatewaynum $gatewaynum not found!" if !$force_gateway;
335 foreach my $payby (@paybys) {
336 warn "$me checking $payby payment fields\n" if $DEBUG > 1;
338 if ( FS::payby->realtime($payby) ) {
339 my $gateway = $force_gateway ||
340 $agent->payment_gateway( 'method' => FS::payby->payby2bop($payby),
343 if ( $gateway && $gateway->gateway_namespace
344 eq 'Business::OnlineThirdPartyPayment'
346 warn "$me hiding $payby payment fields\n" if $DEBUG > 1;
350 push @{$signup_info->{'hide_payment_fields'}}, $hide;
352 warn "$me done setting agent-specific payment flag\n" if $DEBUG > 1;
354 warn "$me setting agent-specific package list\n" if $DEBUG > 1;
355 $signup_info->{'part_pkg'} = $signup_info->{'agentnum2part_pkg'}{$agentnum}
356 unless @{ $signup_info->{'part_pkg'} };
357 warn "$me done setting agent-specific package list\n" if $DEBUG > 1;
359 warn "$me setting agent-specific adv. source list\n" if $DEBUG > 1;
360 $signup_info->{'part_referral'} =
364 'table' => 'part_referral',
365 'hashref' => { 'disabled' => '' },
366 'extra_sql' => "AND ( agentnum = $agentnum ".
367 " OR agentnum IS NULL ) ",
371 warn "$me done setting agent-specific adv. source list\n" if $DEBUG > 1;
373 $signup_info->{'agent_name'} = $agent->agent;
375 $signup_info->{'company_name'} = $conf->config('company_name', $agentnum);
377 if ( $signup_info->{'agent_ship_address'} && $agent->agent_custnum ) {
378 my $cust_main = $agent->agent_cust_main;
379 my $prefix = length($cust_main->ship_last) ? 'ship_' : '';
380 $signup_info->{"ship_$_"} = $cust_main->get("$prefix$_")
381 foreach qw( address1 city county state zip country );
384 #some of the above could probably be cached, too
386 my $signup_info_cache_agent = $cache->get("signup_info_cache_agent$agentnum");
388 if ( $signup_info_cache_agent ) {
390 warn "$me loading cached signup info for agentnum $agentnum\n"
395 warn "$me populating signup info cache for agentnum $agentnum\n"
398 $signup_info_cache_agent = {
399 #( map { $_ => scalar( $conf->config($_, $agentnum) ) }
400 # qw( company_name ) ),
401 ( map { $_ => scalar( $conf->config("selfservice-$_", $agentnum ) ) }
402 qw( body_bgcolor box_bgcolor menu_bgcolor ) ),
403 ( map { $_ => join("\n", $conf->config("selfservice-$_", $agentnum ) ) }
404 qw( head body_header body_footer ) ),
407 $cache->set("signup_info_cache_agent$agentnum", $signup_info_cache_agent);
411 $signup_info->{$_} = $signup_info_cache_agent->{$_}
412 foreach keys %$signup_info_cache_agent;
416 # delete $signup_info->{'part_pkg'};
419 warn "$me sorting package list\n" if $DEBUG > 1;
420 $signup_info->{'part_pkg'} = [ sort { $a->{pkg} cmp $b->{pkg} } # case?
421 @{ $signup_info->{'part_pkg'} }
423 warn "$me done sorting package list\n" if $DEBUG > 1;
425 if ( exists $packet->{'session_id'} ) {
426 my $agent_signup_info = { %$signup_info };
427 delete $agent_signup_info->{agentnum2part_pkg};
428 $agent_signup_info->{'agent'} = $session->{'agent'};
429 return $agent_signup_info;
431 elsif ( exists $packet->{'keys'} ) {
432 my @keys = @{ $packet->{'keys'} };
433 return { map { $_ => $signup_info->{$_} } @keys };
441 sub domain_select_hash {
446 if ($packet->{pkgpart}) {
447 my $part_pkg = qsearchs('part_pkg' => { 'pkgpart' => $packet->{pkgpart} } );
448 #$packet->{svcpart} = $part_pkg->svcpart('svc_acct')
449 $packet->{svcpart} = $part_pkg->svcpart
453 if ($packet->{svcpart}) {
454 my $part_svc = qsearchs('part_svc' => { 'svcpart' => $packet->{svcpart} } );
455 $response->{'domsvc'} = $part_svc->part_svc_column('domsvc')->columnvalue
456 if ($part_svc && $part_svc->part_svc_column('domsvc')->columnflag eq 'D');
459 $response->{'domains'}
460 = { domain_select_hash FS::svc_acct( map { $_ => $packet->{$_} }
470 my $conf = new FS::Conf;
471 my $svc_x = $conf->config('signup_server-service') || 'svc_acct';
473 if ( $svc_x eq 'svc_acct' ) {
475 #things that aren't necessary in base class, but are for signup server
476 #return "Passwords don't match"
477 # if $hashref->{'_password'} ne $hashref->{'_password2'}
478 return { 'error' => gettext('empty_password') }
479 unless length($packet->{'_password'});
480 # a bit inefficient for large numbers of pops
481 return { 'error' => gettext('no_access_number_selected') }
482 unless $packet->{'popnum'} || !scalar(qsearch('svc_acct_pop',{} ));
485 elsif ( $svc_x eq 'svc_pbx' ) {
486 #possibly some validation will be needed
490 if ( exists $packet->{'session_id'} ) {
491 my $cache = new FS::ClientAPI_SessionCache( {
492 'namespace' => 'FS::ClientAPI::Agent',
494 my $session = $cache->get($packet->{'session_id'});
496 $agentnum = $session->{'agentnum'};
498 return { 'error' => "Can't resume session" }; #better error message
501 $agentnum = $packet->{agentnum}
502 || $conf->config('signup_server-default_agentnum');
505 #shares some stuff with htdocs/edit/process/cust_main.cgi... take any
506 # common that are still here and library them.
507 my $template_custnum = $conf->config('signup_server-prepaid-template-custnum');
509 if ( $template_custnum && $packet->{prepaid_shortform} ) {
511 my $template_cust = qsearchs('cust_main', { 'custnum' => $template_custnum } );
512 return { 'error' => 'Configuration error' } unless $template_cust;
513 $cust_main = new FS::cust_main ( {
514 'agentnum' => $agentnum,
515 'refnum' => $packet->{refnum}
516 || $conf->config('signup_server-default_refnum'),
518 ( map { $_ => $template_cust->$_ } qw(
519 last first company address1 address2
520 city county state zip country
523 ship_last ship_first ship_company ship_address1 ship_address2
524 ship_city ship_county ship_state ship_zip ship_country
525 ship_daytime ship_night ship_fax
529 ( map { $_ => $packet->{$_} } qw(
530 ss stateid stateid_state
533 payinfo paycvv paydate payname paystate paytype
534 paystart_month paystart_year payissue
537 referral_custnum comments
545 $cust_main = new FS::cust_main ( {
547 'agentnum' => $agentnum,
548 'refnum' => $packet->{refnum}
549 || $conf->config('signup_server-default_refnum'),
551 map { $_ => $packet->{$_} } qw(
553 last first ss company address1 address2
554 city county state zip country
555 daytime night fax stateid stateid_state
557 ship_last ship_first ship_ss ship_company ship_address1 ship_address2
558 ship_city ship_county ship_state ship_zip ship_country
559 ship_daytime ship_night ship_fax
562 payinfo paycvv paydate payname paystate paytype
563 paystart_month paystart_year payissue
566 referral_custnum comments
572 my $agent = qsearchs('agent', { 'agentnum' => $agentnum } );
573 if ( $conf->exists('agent_ship_address') && $agent->agent_custnum ) {
574 my $agent_cust_main = $agent->agent_cust_main;
575 my $prefix = length($agent_cust_main->ship_last) ? 'ship_' : '';
576 $cust_main->set("ship_$_", $agent_cust_main->get("$prefix$_") )
577 foreach qw( address1 city county state zip country );
579 $cust_main->set("ship_$_", $cust_main->get($_))
580 foreach qw( last first );
585 return { 'error' => "Illegal payment type" }
586 unless grep { $_ eq $packet->{'payby'} }
587 $conf->config('signup_server-payby');
589 if (FS::payby->realtime($packet->{payby})
590 and not $conf->exists('signup_server-third_party_as_card')) {
591 my $payby = $packet->{payby};
593 my $agent = qsearchs('agent', { 'agentnum' => $agentnum });
594 return { 'error' => "Unknown reseller" }
598 my $gatewaynum = $conf->config('selfservice-payment_gateway');
600 $gw = qsearchs('payment_gateway', { gatewaynum => $gatewaynum });
601 die "configured gatewaynum $gatewaynum not found!" if !$gw;
604 $gw = $agent->payment_gateway( 'method' => FS::payby->payby2bop($payby),
609 $cust_main->payby('BILL') # MCRD better?
610 if $gw && $gw->gateway_namespace eq 'Business::OnlineThirdPartyPayment';
613 $cust_main->payinfo($cust_main->daytime)
614 if $cust_main->payby eq 'LECB' && ! $cust_main->payinfo;
616 my @invoicing_list = $packet->{'invoicing_list'}
617 ? split( /\s*\,\s*/, $packet->{'invoicing_list'} )
620 $packet->{'pkgpart'} =~ /^(\d+)$/ or '' =~ /^()$/;
622 return { 'error' => 'Please select a package' } unless $pkgpart; #msgcat
625 qsearchs( 'part_pkg', { 'pkgpart' => $pkgpart } )
626 or return { 'error' => "WARNING: unknown pkgpart: $pkgpart" };
627 my $svcpart = $part_pkg->svcpart($svc_x);
630 if ( $packet->{'reg_code'} ) {
631 $reg_code = qsearchs( 'reg_code', { 'code' => $packet->{'reg_code'},
632 'agentnum' => $agentnum, } )
633 or return { 'error' => 'Unknown registration code' };
636 my $cust_pkg = new FS::cust_pkg ( {
637 #later#'custnum' => $custnum,
638 'pkgpart' => $packet->{'pkgpart'},
639 'promo_code' => $packet->{'promo_code'},
640 'reg_code' => $packet->{'reg_code'},
642 #my $error = $cust_pkg->check;
643 #return { 'error' => $error } if $error;
645 #should be all auto-magic and shit
647 if ( $svc_x eq 'svc_acct' ) {
649 my $svc = new FS::svc_acct {
650 'svcpart' => $svcpart,
651 map { $_ => $packet->{$_} }
652 qw( username _password sec_phrase popnum ),
657 while ( exists($packet->{"snarf_machine$snarfnum"})
658 && length($packet->{"snarf_machine$snarfnum"}) ) {
659 my $acct_snarf = new FS::acct_snarf ( {
660 'machine' => $packet->{"snarf_machine$snarfnum"},
661 'protocol' => $packet->{"snarf_protocol$snarfnum"},
662 'username' => $packet->{"snarf_username$snarfnum"},
663 '_password' => $packet->{"snarf_password$snarfnum"},
666 push @acct_snarf, $acct_snarf;
668 $svc->child_objects( \@acct_snarf );
671 } elsif ( $svc_x eq 'svc_phone' ) {
673 push @svc, new FS::svc_phone ( {
674 'svcpart' => $svcpart,
675 map { $_ => $packet->{$_} }
676 qw( countrycode phonenum sip_password pin ),
679 } elsif ( $svc_x eq 'svc_pbx' ) {
681 push @svc, new FS::svc_pbx ( {
682 'svcpart' => $svcpart,
683 map { $_ => $packet->{$_} }
688 die "unknown signup service $svc_x";
691 if ($packet->{'mac_addr'} && $conf->exists('signup_server-mac_addr_svcparts'))
694 my %mac_addr_svcparts = map { $_ => 1 }
695 $conf->config('signup_server-mac_addr_svcparts');
696 my @pkg_svc = grep { $_->quantity && $mac_addr_svcparts{$_->svcpart} }
697 $cust_pkg->part_pkg->pkg_svc;
699 return { 'error' => 'No service defined to assign mac address' }
702 my $svc = new FS::svc_acct {
703 'svcpart' => $pkg_svc[0]->svcpart, #multiple matches? alas..
704 'username' => $packet->{'mac_addr'},
705 '_password' => '', #blank as requested (set passwordmin to 0)
712 foreach my $svc ( @svc ) {
713 my $y = $svc->setdefault; # arguably should be in new method
714 return { 'error' => $y } if $y && !ref($y);
715 #$error = $svc->check;
716 #return { 'error' => $error } if $error;
719 #setup a job dependancy to delay provisioning
720 my $placeholder = new FS::queue ( {
721 'job' => 'FS::ClientAPI::Signup::__placeholder',
722 'status' => 'locked',
724 my $error = $placeholder->insert;
725 return { 'error' => $error } if $error;
728 tie my %hash, 'Tie::RefHash';
729 %hash = ( $cust_pkg => \@svc );
731 $error = $cust_main->insert(
734 'depend_jobnum' => $placeholder->jobnum,
737 my $perror = $placeholder->delete;
738 $error .= " (Additionally, error removing placeholder: $perror)" if $perror;
739 return { 'error' => $error };
742 if ( $conf->exists('signup_server-realtime') ) {
744 #warn "$me Billing customer...\n" if $Debug;
746 my $bill_error = $cust_main->bill( 'depend_jobnum'=>$placeholder->jobnum );
747 #warn "$me error billing new customer: $bill_error"
750 $bill_error = $cust_main->apply_payments_and_credits;
751 #warn "$me error applying payments and credits for".
752 # " new customer: $bill_error"
755 $bill_error = $cust_main->realtime_collect(
756 method => FS::payby->payby2bop( $packet->{payby} ),
757 depend_jobnum => $placeholder->jobnum,
760 #warn "$me error collecting from new customer: $bill_error"
763 if ($bill_error && ref($bill_error) eq 'HASH') {
764 return { 'error' => '_collect',
765 ( map { $_ => $bill_error->{$_} }
766 qw(popup_url reference collectitems)
768 amount => $cust_main->balance,
772 $bill_error = $cust_main->apply_payments_and_credits;
773 #warn "$me error applying payments and credits for".
774 # " new customer: $bill_error"
777 if ( $cust_main->balance > 0 ) {
779 #this makes sense. credit is "un-doing" the invoice
780 $cust_main->credit( $cust_main->balance, 'signup server decline',
781 'reason_type' => $conf->config('signup_credit_type'),
783 $cust_main->apply_credits;
785 #should check list for errors...
786 #$cust_main->suspend;
787 local $FS::svc_Common::noexport_hack = 1;
788 $cust_main->cancel('quiet'=>1);
790 my $perror = $placeholder->depended_delete;
791 warn "error removing provisioning jobs after decline: $perror" if $perror;
793 $perror = $placeholder->delete;
794 warn "error removing placeholder after decline: $perror" if $perror;
797 return { 'error' => '_decline' };
803 $error = $reg_code->delete;
804 return { 'error' => $error } if $error;
807 $error = $placeholder->delete;
808 return { 'error' => $error } if $error;
810 my %return = ( 'error' => '',
811 'signup_service' => $svc_x,
812 'custnum' => $cust_main->custnum,
817 $return{'svcnum'} = $svc[0]->svcnum;
819 if ( $svc_x eq 'svc_acct' ) {
820 $return{$_} = $svc[0]->$_() for qw( username _password );
821 } elsif ( $svc_x eq 'svc_phone' ) {
822 $return{$_} = $svc[0]->$_() for qw(countrycode phonenum sip_password pin);
823 } elsif ( $svc_x eq 'svc_pbx' ) {
824 #$return{$_} = $svc[0]->$_() for qw( ) #nothing yet
826 return {'error' => "configuration error: unknown signup service $svc_x"};
827 #die "unknown signup service $svc_x";
828 # return an error that's visible to someone somewhere
837 sub capture_payment {
840 warn "$me capture_payment called on $packet\n" if $DEBUG;
843 # identify processor/gateway from called back URL
846 my $conf = new FS::Conf;
849 if ( my $gwnum = $conf->config('selfservice-payment_gateway') ) {
850 $payment_gateway = qsearchs('payment_gateway', { 'gatewaynum' => $gwnum })
851 or die "configured gatewaynum $gwnum not found!";
854 my $url = $packet->{url};
856 $payment_gateway = qsearchs('payment_gateway',
857 { 'gateway_callback_url' => popurl(0, $url) }
859 if (!$payment_gateway) {
861 my ( $processor, $login, $password, $action, @bop_options ) =
862 $conf->config('business-onlinepayment');
863 $action ||= 'normal authorization';
864 pop @bop_options if scalar(@bop_options) % 2 && $bop_options[-1] =~ /^\s*$/;
865 die "No real-time processor is enabled - ".
866 "did you set the business-onlinepayment configuration value?\n"
869 $payment_gateway = new FS::payment_gateway( {
870 gateway_namespace => $conf->config('business-onlinepayment-namespace'),
871 gateway_module => $processor,
872 gateway_username => $login,
873 gateway_password => $password,
874 gateway_action => $action,
875 options => [ ( @bop_options ) ],
880 die "No real-time third party processor is enabled - ".
881 "did you set the business-onlinepayment configuration value?\n*"
882 unless $payment_gateway->gateway_namespace eq 'Business::OnlineThirdPartyPayment';
885 # locate pending transaction
888 eval "use Business::OnlineThirdPartyPayment";
892 new Business::OnlineThirdPartyPayment( $payment_gateway->gateway_module,
893 @{ [ $payment_gateway->options ] },
896 my $paypendingnum = $transaction->reference($packet->{data});
898 my $cust_pay_pending =
899 qsearchs('cust_pay_pending', { paypendingnum => $paypendingnum } );
901 unless ($cust_pay_pending) {
902 my $bill_error = "No payment is being processed with id $paypendingnum".
903 "; Transaction aborted.";
904 return { error => '_decline', bill_error => $bill_error };
907 if ($cust_pay_pending->status ne 'pending') {
908 my $bill_error = "Payment with id $paypendingnum is not pending, but ".
909 $cust_pay_pending->status. "; Transaction aborted.";
910 return { error => '_decline', bill_error => $bill_error };
913 my $cust_main = $cust_pay_pending->cust_main;
915 $cust_main->realtime_botpp_capture( $cust_pay_pending,
920 return { 'error' => ( $bill_error->{bill_error} ? '_decline' : '' ),