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')),
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 warn "$me has agent $agent\n" if $DEBUG > 1;
322 if ( $agent ) { #else complain loudly?
323 $signup_info->{'hide_payment_fields'} = [];
324 my $gatewaynum = $conf->config('selfservice-payment_gateway');
326 my $pg = qsearchs('payment_gateway', { gatewaynum => $gatewaynum });
327 die "configured gatewaynum $gatewaynum not found!" if !$pg;
328 my $hide = $pg->gateway_namespace eq 'Business::OnlineThirdPartyPayment';
329 $signup_info->{'hide_payment_fields'} = [
330 map { $hide } @{$signup_info->{'payby'}}
334 foreach my $payby (@{$signup_info->{payby}}) {
335 warn "$me checking $payby payment fields\n" if $DEBUG > 1;
337 if ( FS::payby->realtime($payby) ) {
338 my $payment_gateway =
339 $agent->payment_gateway( 'method' => FS::payby->payby2bop($payby),
342 if ( $payment_gateway
343 && $payment_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;
354 warn "$me done setting agent-specific payment flag\n" if $DEBUG > 1;
356 warn "$me setting agent-specific package list\n" if $DEBUG > 1;
357 $signup_info->{'part_pkg'} = $signup_info->{'agentnum2part_pkg'}{$agentnum}
358 unless @{ $signup_info->{'part_pkg'} };
359 warn "$me done setting agent-specific package list\n" if $DEBUG > 1;
361 warn "$me setting agent-specific adv. source list\n" if $DEBUG > 1;
362 $signup_info->{'part_referral'} =
366 'table' => 'part_referral',
367 'hashref' => { 'disabled' => '' },
368 'extra_sql' => "AND ( agentnum = $agentnum ".
369 " OR agentnum IS NULL ) ",
373 warn "$me done setting agent-specific adv. source list\n" if $DEBUG > 1;
375 $signup_info->{'agent_name'} = $agent->agent;
377 $signup_info->{'company_name'} = $conf->config('company_name', $agentnum);
379 if ( $signup_info->{'agent_ship_address'} && $agent->agent_custnum ) {
380 my $cust_main = $agent->agent_cust_main;
381 my $prefix = length($cust_main->ship_last) ? 'ship_' : '';
382 $signup_info->{"ship_$_"} = $cust_main->get("$prefix$_")
383 foreach qw( address1 city county state zip country );
386 #some of the above could probably be cached, too
388 my $signup_info_cache_agent = $cache->get("signup_info_cache_agent$agentnum");
390 if ( $signup_info_cache_agent ) {
392 warn "$me loading cached signup info for agentnum $agentnum\n"
397 warn "$me populating signup info cache for agentnum $agentnum\n"
400 $signup_info_cache_agent = {
401 #( map { $_ => scalar( $conf->config($_, $agentnum) ) }
402 # qw( company_name ) ),
403 ( map { $_ => scalar( $conf->config("selfservice-$_", $agentnum ) ) }
404 qw( body_bgcolor box_bgcolor menu_bgcolor ) ),
405 ( map { $_ => join("\n", $conf->config("selfservice-$_", $agentnum ) ) }
406 qw( head body_header body_footer ) ),
409 $cache->set("signup_info_cache_agent$agentnum", $signup_info_cache_agent);
413 $signup_info->{$_} = $signup_info_cache_agent->{$_}
414 foreach keys %$signup_info_cache_agent;
418 # delete $signup_info->{'part_pkg'};
421 warn "$me sorting package list\n" if $DEBUG > 1;
422 $signup_info->{'part_pkg'} = [ sort { $a->{pkg} cmp $b->{pkg} } # case?
423 @{ $signup_info->{'part_pkg'} }
425 warn "$me done sorting package list\n" if $DEBUG > 1;
427 if ( exists $packet->{'session_id'} ) {
428 my $agent_signup_info = { %$signup_info };
429 delete $agent_signup_info->{agentnum2part_pkg};
430 $agent_signup_info->{'agent'} = $session->{'agent'};
431 return $agent_signup_info;
433 elsif ( exists $packet->{'keys'} ) {
434 my @keys = @{ $packet->{'keys'} };
435 return { map { $_ => $signup_info->{$_} } @keys };
443 sub domain_select_hash {
448 if ($packet->{pkgpart}) {
449 my $part_pkg = qsearchs('part_pkg' => { 'pkgpart' => $packet->{pkgpart} } );
450 #$packet->{svcpart} = $part_pkg->svcpart('svc_acct')
451 $packet->{svcpart} = $part_pkg->svcpart
455 if ($packet->{svcpart}) {
456 my $part_svc = qsearchs('part_svc' => { 'svcpart' => $packet->{svcpart} } );
457 $response->{'domsvc'} = $part_svc->part_svc_column('domsvc')->columnvalue
458 if ($part_svc && $part_svc->part_svc_column('domsvc')->columnflag eq 'D');
461 $response->{'domains'}
462 = { domain_select_hash FS::svc_acct( map { $_ => $packet->{$_} }
472 my $conf = new FS::Conf;
473 my $svc_x = $conf->config('signup_server-service') || 'svc_acct';
475 if ( $svc_x eq 'svc_acct' ) {
477 #things that aren't necessary in base class, but are for signup server
478 #return "Passwords don't match"
479 # if $hashref->{'_password'} ne $hashref->{'_password2'}
480 return { 'error' => gettext('empty_password') }
481 unless length($packet->{'_password'});
482 # a bit inefficient for large numbers of pops
483 return { 'error' => gettext('no_access_number_selected') }
484 unless $packet->{'popnum'} || !scalar(qsearch('svc_acct_pop',{} ));
487 elsif ( $svc_x eq 'svc_pbx' ) {
488 #possibly some validation will be needed
492 if ( exists $packet->{'session_id'} ) {
493 my $cache = new FS::ClientAPI_SessionCache( {
494 'namespace' => 'FS::ClientAPI::Agent',
496 my $session = $cache->get($packet->{'session_id'});
498 $agentnum = $session->{'agentnum'};
500 return { 'error' => "Can't resume session" }; #better error message
503 $agentnum = $packet->{agentnum}
504 || $conf->config('signup_server-default_agentnum');
507 #shares some stuff with htdocs/edit/process/cust_main.cgi... take any
508 # common that are still here and library them.
509 my $cust_main = new FS::cust_main ( {
511 'agentnum' => $agentnum,
512 'refnum' => $packet->{refnum}
513 || $conf->config('signup_server-default_refnum'),
515 map { $_ => $packet->{$_} } qw(
517 last first ss company address1 address2
518 city county state zip country
519 daytime night fax stateid stateid_state
521 ship_last ship_first ship_ss ship_company ship_address1 ship_address2
522 ship_city ship_county ship_state ship_zip ship_country
523 ship_daytime ship_night ship_fax
526 payinfo paycvv paydate payname paystate paytype
527 paystart_month paystart_year payissue
530 referral_custnum comments
535 my $agent = qsearchs('agent', { 'agentnum' => $agentnum } );
536 if ( $conf->exists('agent_ship_address') && $agent->agent_custnum ) {
537 my $agent_cust_main = $agent->agent_cust_main;
538 my $prefix = length($agent_cust_main->ship_last) ? 'ship_' : '';
539 $cust_main->set("ship_$_", $agent_cust_main->get("$prefix$_") )
540 foreach qw( address1 city county state zip country );
542 $cust_main->set("ship_$_", $cust_main->get($_))
543 foreach qw( last first );
548 return { 'error' => "Illegal payment type" }
549 unless grep { $_ eq $packet->{'payby'} }
550 $conf->config('signup_server-payby');
552 if (FS::payby->realtime($packet->{payby})) {
553 my $payby = $packet->{payby};
555 my $agent = qsearchs('agent', { 'agentnum' => $agentnum });
556 return { 'error' => "Unknown reseller" }
560 my $gatewaynum = $conf->config('selfservice-payment_gateway');
562 $gw = qsearchs('payment_gateway', { gatewaynum => $gatewaynum });
563 die "configured gatewaynum $gatewaynum not found!" if !$gw;
566 $gw = $agent->payment_gateway( 'method' => FS::payby->payby2bop($payby),
571 $cust_main->payby('BILL') # MCRD better?
572 if $gw && $gw->gateway_namespace eq 'Business::OnlineThirdPartyPayment';
575 $cust_main->payinfo($cust_main->daytime)
576 if $cust_main->payby eq 'LECB' && ! $cust_main->payinfo;
578 my @invoicing_list = $packet->{'invoicing_list'}
579 ? split( /\s*\,\s*/, $packet->{'invoicing_list'} )
582 $packet->{'pkgpart'} =~ /^(\d+)$/ or '' =~ /^()$/;
584 return { 'error' => 'Please select a package' } unless $pkgpart; #msgcat
587 qsearchs( 'part_pkg', { 'pkgpart' => $pkgpart } )
588 or return { 'error' => "WARNING: unknown pkgpart: $pkgpart" };
589 my $svcpart = $part_pkg->svcpart($svc_x);
592 if ( $packet->{'reg_code'} ) {
593 $reg_code = qsearchs( 'reg_code', { 'code' => $packet->{'reg_code'},
594 'agentnum' => $agentnum, } )
595 or return { 'error' => 'Unknown registration code' };
598 my $cust_pkg = new FS::cust_pkg ( {
599 #later#'custnum' => $custnum,
600 'pkgpart' => $packet->{'pkgpart'},
601 'promo_code' => $packet->{'promo_code'},
602 'reg_code' => $packet->{'reg_code'},
604 #my $error = $cust_pkg->check;
605 #return { 'error' => $error } if $error;
607 #should be all auto-magic and shit
609 if ( $svc_x eq 'svc_acct' ) {
611 my $svc = new FS::svc_acct {
612 'svcpart' => $svcpart,
613 map { $_ => $packet->{$_} }
614 qw( username _password sec_phrase popnum ),
619 while ( exists($packet->{"snarf_machine$snarfnum"})
620 && length($packet->{"snarf_machine$snarfnum"}) ) {
621 my $acct_snarf = new FS::acct_snarf ( {
622 'machine' => $packet->{"snarf_machine$snarfnum"},
623 'protocol' => $packet->{"snarf_protocol$snarfnum"},
624 'username' => $packet->{"snarf_username$snarfnum"},
625 '_password' => $packet->{"snarf_password$snarfnum"},
628 push @acct_snarf, $acct_snarf;
630 $svc->child_objects( \@acct_snarf );
633 } elsif ( $svc_x eq 'svc_phone' ) {
635 push @svc, new FS::svc_phone ( {
636 'svcpart' => $svcpart,
637 map { $_ => $packet->{$_} }
638 qw( countrycode phonenum sip_password pin ),
641 } elsif ( $svc_x eq 'svc_pbx' ) {
643 push @svc, new FS::svc_pbx ( {
644 'svcpart' => $svcpart,
645 map { $_ => $packet->{$_} }
650 die "unknown signup service $svc_x";
653 if ($packet->{'mac_addr'} && $conf->exists('signup_server-mac_addr_svcparts'))
656 my %mac_addr_svcparts = map { $_ => 1 }
657 $conf->config('signup_server-mac_addr_svcparts');
658 my @pkg_svc = grep { $_->quantity && $mac_addr_svcparts{$_->svcpart} }
659 $cust_pkg->part_pkg->pkg_svc;
661 return { 'error' => 'No service defined to assign mac address' }
664 my $svc = new FS::svc_acct {
665 'svcpart' => $pkg_svc[0]->svcpart, #multiple matches? alas..
666 'username' => $packet->{'mac_addr'},
667 '_password' => '', #blank as requested (set passwordmin to 0)
674 foreach my $svc ( @svc ) {
675 my $y = $svc->setdefault; # arguably should be in new method
676 return { 'error' => $y } if $y && !ref($y);
677 #$error = $svc->check;
678 #return { 'error' => $error } if $error;
681 #setup a job dependancy to delay provisioning
682 my $placeholder = new FS::queue ( {
683 'job' => 'FS::ClientAPI::Signup::__placeholder',
684 'status' => 'locked',
686 my $error = $placeholder->insert;
687 return { 'error' => $error } if $error;
690 tie my %hash, 'Tie::RefHash';
691 %hash = ( $cust_pkg => \@svc );
693 $error = $cust_main->insert(
696 'depend_jobnum' => $placeholder->jobnum,
699 my $perror = $placeholder->delete;
700 $error .= " (Additionally, error removing placeholder: $perror)" if $perror;
701 return { 'error' => $error };
704 if ( $conf->exists('signup_server-realtime') ) {
706 #warn "$me Billing customer...\n" if $Debug;
708 my $bill_error = $cust_main->bill;
709 #warn "$me error billing new customer: $bill_error"
712 $bill_error = $cust_main->apply_payments_and_credits;
713 #warn "$me error applying payments and credits for".
714 # " new customer: $bill_error"
717 $bill_error = $cust_main->realtime_collect(
718 method => FS::payby->payby2bop( $packet->{payby} ),
719 depend_jobnum => $placeholder->jobnum,
722 #warn "$me error collecting from new customer: $bill_error"
725 if ($bill_error && ref($bill_error) eq 'HASH') {
726 return { 'error' => '_collect',
727 ( map { $_ => $bill_error->{$_} }
728 qw(popup_url reference collectitems)
730 amount => $cust_main->balance,
734 $bill_error = $cust_main->apply_payments_and_credits;
735 #warn "$me error applying payments and credits for".
736 # " new customer: $bill_error"
739 if ( $cust_main->balance > 0 ) {
741 #this makes sense. credit is "un-doing" the invoice
742 $cust_main->credit( $cust_main->balance, 'signup server decline',
743 'reason_type' => $conf->config('signup_credit_type'),
745 $cust_main->apply_credits;
747 #should check list for errors...
748 #$cust_main->suspend;
749 local $FS::svc_Common::noexport_hack = 1;
750 $cust_main->cancel('quiet'=>1);
752 my $perror = $placeholder->depended_delete;
753 warn "error removing provisioning jobs after decline: $perror" if $perror;
755 $perror = $placeholder->delete;
756 warn "error removing placeholder after decline: $perror" if $perror;
759 return { 'error' => '_decline' };
765 $error = $reg_code->delete;
766 return { 'error' => $error } if $error;
769 $error = $placeholder->delete;
770 return { 'error' => $error } if $error;
772 my %return = ( 'error' => '',
773 'signup_service' => $svc_x,
774 'custnum' => $cust_main->custnum,
779 $return{'svcnum'} = $svc[0]->svcnum;
781 if ( $svc_x eq 'svc_acct' ) {
782 $return{$_} = $svc[0]->$_() for qw( username _password );
783 } elsif ( $svc_x eq 'svc_phone' ) {
784 $return{$_} = $svc[0]->$_() for qw(countrycode phonenum sip_password pin);
785 } elsif ( $svc_x eq 'svc_pbx' ) {
786 #$return{$_} = $svc[0]->$_() for qw( ) #nothing yet
788 return {'error' => "configuration error: unknown signup service $svc_x"};
789 #die "unknown signup service $svc_x";
790 # return an error that's visible to someone somewhere
799 sub capture_payment {
802 warn "$me capture_payment called on $packet\n" if $DEBUG;
805 # identify processor/gateway from called back URL
808 my $conf = new FS::Conf;
811 if ( my $gwnum = $conf->config('selfservice-payment_gateway') ) {
812 $payment_gateway = qsearchs('payment_gateway', { 'gatewaynum' => $gwnum })
813 or die "configured gatewaynum $gwnum not found!";
816 my $url = $packet->{url};
818 $payment_gateway = qsearchs('payment_gateway',
819 { 'gateway_callback_url' => popurl(0, $url) }
821 if (!$payment_gateway) {
823 my ( $processor, $login, $password, $action, @bop_options ) =
824 $conf->config('business-onlinepayment');
825 $action ||= 'normal authorization';
826 pop @bop_options if scalar(@bop_options) % 2 && $bop_options[-1] =~ /^\s*$/;
827 die "No real-time processor is enabled - ".
828 "did you set the business-onlinepayment configuration value?\n"
831 $payment_gateway = new FS::payment_gateway( {
832 gateway_namespace => $conf->config('business-onlinepayment-namespace'),
833 gateway_module => $processor,
834 gateway_username => $login,
835 gateway_password => $password,
836 gateway_action => $action,
837 options => [ ( @bop_options ) ],
842 die "No real-time third party processor is enabled - ".
843 "did you set the business-onlinepayment configuration value?\n*"
844 unless $payment_gateway->gateway_namespace eq 'Business::OnlineThirdPartyPayment';
847 # locate pending transaction
850 eval "use Business::OnlineThirdPartyPayment";
854 new Business::OnlineThirdPartyPayment( $payment_gateway->gateway_module,
855 @{ [ $payment_gateway->options ] },
858 my $paypendingnum = $transaction->reference($packet->{data});
860 my $cust_pay_pending =
861 qsearchs('cust_pay_pending', { paypendingnum => $paypendingnum } );
863 unless ($cust_pay_pending) {
864 my $bill_error = "No payment is being processed with id $paypendingnum".
865 "; Transaction aborted.";
866 return { error => '_decline', bill_error => $bill_error };
869 if ($cust_pay_pending->status ne 'pending') {
870 my $bill_error = "Payment with id $paypendingnum is not pending, but ".
871 $cust_pay_pending->status. "; Transaction aborted.";
872 return { error => '_decline', bill_error => $bill_error };
875 my $cust_main = $cust_pay_pending->cust_main;
877 $cust_main->realtime_botpp_capture( $cust_pay_pending,
882 return { 'error' => ( $bill_error->{bill_error} ? '_decline' : '' ),