respect card-types config in backend (new customer payment types / 4.x), RT#39861
[freeside.git] / FS / FS / cust_payby.pm
1 package FS::cust_payby;
2 use base qw( FS::payinfo_Mixin FS::cust_main_Mixin FS::Record );
3
4 use strict;
5 use Scalar::Util qw( blessed );
6 use Digest::SHA qw( sha512_base64 );
7 use Business::CreditCard qw( validate cardtype );
8 use FS::UID qw( dbh );
9 use FS::Msgcat qw( gettext );
10 use FS::Misc qw( card_types );
11 use FS::Record; #qw( qsearch qsearchs );
12 use FS::payby;
13 use FS::cust_main;
14 use FS::banned_pay;
15
16 our @encrypted_fields = ('payinfo', 'paycvv');
17 sub nohistory_fields { ('payinfo', 'paycvv'); }
18
19 our $ignore_expired_card = 0;
20 our $ignore_banned_card = 0;
21 our $ignore_invalid_card = 0;
22
23 our $conf;
24 install_callback FS::UID sub { 
25   $conf = new FS::Conf;
26   #yes, need it for stuff below (prolly should be cached)
27   $ignore_invalid_card = $conf->exists('allow_invalid_cards');
28 };
29
30 =head1 NAME
31
32 FS::cust_payby - Object methods for cust_payby records
33
34 =head1 SYNOPSIS
35
36   use FS::cust_payby;
37
38   $record = new FS::cust_payby \%hash;
39   $record = new FS::cust_payby { 'column' => 'value' };
40
41   $error = $record->insert;
42
43   $error = $new_record->replace($old_record);
44
45   $error = $record->delete;
46
47   $error = $record->check;
48
49 =head1 DESCRIPTION
50
51 An FS::cust_payby object represents customer stored payment information.
52 FS::cust_payby inherits from FS::Record.  The following fields are currently
53 supported:
54
55 =over 4
56
57 =item custpaybynum
58
59 primary key
60
61 =item custnum
62
63 custnum
64
65 =item weight
66
67 weight
68
69 =item payby
70
71 payby
72
73 =item payinfo
74
75 payinfo
76
77 =item paycvv
78
79 paycvv
80
81 =item paymask
82
83 paymask
84
85 =item paydate
86
87 paydate
88
89 =item paystart_month
90
91 paystart_month
92
93 =item paystart_year
94
95 paystart_year
96
97 =item payissue
98
99 payissue
100
101 =item payname
102
103 payname
104
105 =item paystate
106
107 paystate
108
109 =item paytype
110
111 paytype
112
113 =item payip
114
115 payip
116
117
118 =back
119
120 =head1 METHODS
121
122 =over 4
123
124 =item new HASHREF
125
126 Creates a new record.  To add the record to the database, see L<"insert">.
127
128 Note that this stores the hash reference, not a distinct copy of the hash it
129 points to.  You can ask the object for a copy with the I<hash> method.
130
131 =cut
132
133 # the new method can be inherited from FS::Record, if a table method is defined
134
135 sub table { 'cust_payby'; }
136
137 =item insert
138
139 Adds this record to the database.  If there is an error, returns the error,
140 otherwise returns false.
141
142 =cut
143
144 sub insert {
145   my $self = shift;
146
147   local $SIG{HUP} = 'IGNORE';
148   local $SIG{INT} = 'IGNORE';
149   local $SIG{QUIT} = 'IGNORE';
150   local $SIG{TERM} = 'IGNORE';
151   local $SIG{TSTP} = 'IGNORE';
152   local $SIG{PIPE} = 'IGNORE';
153
154   my $oldAutoCommit = $FS::UID::AutoCommit;
155   local $FS::UID::AutoCommit = 0;
156   my $dbh = dbh;
157
158   my $error =  $self->check_payinfo_cardtype
159             || $self->SUPER::insert;
160   if ( $error ) {
161     $dbh->rollback if $oldAutoCommit;
162     return $error;
163   }
164
165   if ( $self->payby =~ /^(CARD|CHEK)$/ ) {
166     # new auto card/check info, want to retry realtime_ invoice events
167     #  (new customer?  that's okay, they won't have any)
168     my $error = $self->cust_main->retry_realtime;
169     if ( $error ) {
170       $dbh->rollback if $oldAutoCommit;
171       return $error;
172     }
173   }
174
175   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
176   '';
177
178 }
179
180 =item delete
181
182 Delete this record from the database.
183
184 =item replace OLD_RECORD
185
186 Replaces the OLD_RECORD with this one in the database.  If there is an error,
187 returns the error, otherwise returns false.
188
189 =cut
190
191 sub replace {
192   my $self = shift;
193
194   my $old = ( blessed($_[0]) && $_[0]->isa('FS::Record') )
195               ? shift
196               : $self->replace_old;
197
198   if ( length($old->paycvv) && $self->paycvv =~ /^\s*[\*x]*\s*$/ ) {
199     $self->paycvv($old->paycvv);
200   }
201
202   if ( $self->payby =~ /^(CARD|DCRD)$/
203        && (    $self->payinfo =~ /xx/
204             || $self->payinfo =~ /^\s*N\/A\s+\(tokenized\)\s*$/
205           )
206      )
207   {
208
209     $self->payinfo($old->payinfo);
210
211   } elsif ( $self->payby =~ /^(CHEK|DCHK)$/ && $self->payinfo =~ /xx/ ) {
212     #fix for #3085 "edit of customer's routing code only surprisingly causes
213     #nothing to happen...
214     # this probably won't do the right thing when we don't have the
215     # public key (can't actually get the real $old->payinfo)
216     my($new_account, $new_aba) = split('@', $self->payinfo);
217     my($old_account, $old_aba) = split('@', $old->payinfo);
218     $new_account = $old_account if $new_account =~ /xx/;
219     $new_aba     = $old_aba     if $new_aba     =~ /xx/;
220     $self->payinfo($new_account.'@'.$new_aba);
221   }
222
223   local($ignore_expired_card) = 1
224     if $old->payby  =~ /^(CARD|DCRD)$/
225     && $self->payby =~ /^(CARD|DCRD)$/
226     && ( $old->payinfo eq $self->payinfo || $old->paymask eq $self->paymask );
227
228   local($ignore_banned_card) = 1
229     if (    $old->payby  =~ /^(CARD|DCRD)$/ && $self->payby =~ /^(CARD|DCRD)$/
230          || $old->payby  =~ /^(CHEK|DCHK)$/ && $self->payby =~ /^(CHEK|DCHK)$/ )
231     && ( $old->payinfo eq $self->payinfo || $old->paymask eq $self->paymask );
232
233   if (    $self->payby =~ /^(CARD|DCRD)$/
234        && $old->payinfo ne $self->payinfo
235        && $old->paymask ne $self->paymask )
236   {
237     my $error = $self->check_payinfo_cardtype;
238     return $error if $error;
239   }
240
241   local $SIG{HUP} = 'IGNORE';
242   local $SIG{INT} = 'IGNORE';
243   local $SIG{QUIT} = 'IGNORE';
244   local $SIG{TERM} = 'IGNORE';
245   local $SIG{TSTP} = 'IGNORE';
246   local $SIG{PIPE} = 'IGNORE';
247
248   my $oldAutoCommit = $FS::UID::AutoCommit;
249   local $FS::UID::AutoCommit = 0;
250   my $dbh = dbh;
251
252   my $error = $self->SUPER::replace($old);
253   if ( $error ) {
254     $dbh->rollback if $oldAutoCommit;
255     return $error;
256   }
257
258   if ( $self->payby =~ /^(CARD|CHEK)$/
259        && ( ( $self->get('payinfo') ne $old->get('payinfo')
260               && $self->get('payinfo') !~ /^99\d{14}$/ 
261             )
262             || grep { $self->get($_) ne $old->get($_) } qw(paydate payname)
263           )
264      )
265   {
266
267     # card/check/lec info has changed, want to retry realtime_ invoice events
268     my $error = $self->cust_main->retry_realtime;
269     if ( $error ) {
270       $dbh->rollback if $oldAutoCommit;
271       return $error;
272     }
273   }
274
275   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
276   '';
277
278 }
279
280 =item check
281
282 Checks all fields to make sure this is a valid record.  If there is
283 an error, returns the error, otherwise returns false.  Called by the insert
284 and replace methods.
285
286 =cut
287
288 sub check {
289   my $self = shift;
290
291   my $error = 
292     $self->ut_numbern('custpaybynum')
293     || $self->ut_foreign_key('custnum', 'cust_main', 'custnum')
294     || $self->ut_numbern('weight')
295     #encrypted #|| $self->ut_textn('payinfo')
296     #encrypted #|| $self->ut_textn('paycvv')
297 #    || $self->ut_textn('paymask') #XXX something
298     #later #|| $self->ut_textn('paydate')
299     || $self->ut_numbern('paystart_month')
300     || $self->ut_numbern('paystart_year')
301     || $self->ut_numbern('payissue')
302 #    || $self->ut_textn('payname') #XXX something
303     || $self->ut_alphan('paystate')
304     || $self->ut_textn('paytype')
305     || $self->ut_ipn('payip')
306   ;
307   return $error if $error;
308
309   ### from cust_main
310
311   FS::payby->can_payby($self->table, $self->payby)
312     or return "Illegal payby: ". $self->payby;
313
314   # If it is encrypted and the private key is not availaible then we can't
315   # check the credit card.
316   my $check_payinfo = ! $self->is_encrypted($self->payinfo);
317
318   # Need some kind of global flag to accept invalid cards, for testing
319   # on scrubbed data.
320   #XXX if ( !$import && $check_payinfo && $self->payby =~ /^(CARD|DCRD)$/ ) {
321   if ( !$ignore_invalid_card && 
322     $check_payinfo && $self->payby =~ /^(CARD|DCRD)$/ ) {
323
324     my $payinfo = $self->payinfo;
325     $payinfo =~ s/\D//g;
326     $payinfo =~ /^(\d{13,16}|\d{8,9})$/
327       or return gettext('invalid_card'); #. ": ". $self->payinfo;
328     $payinfo = $1;
329     $self->payinfo($payinfo);
330     validate($payinfo)
331       or return gettext('invalid_card'); # . ": ". $self->payinfo;
332
333     return gettext('unknown_card_type')
334       if $self->payinfo !~ /^99\d{14}$/ #token
335       && cardtype($self->payinfo) eq "Unknown";
336
337     unless ( $ignore_banned_card ) {
338       my $ban = FS::banned_pay->ban_search( %{ $self->_banned_pay_hashref } );
339       if ( $ban ) {
340         if ( $ban->bantype eq 'warn' ) {
341           #or others depending on value of $ban->reason ?
342           return '_duplicate_card'.
343                  ': disabled from'. time2str('%a %h %o at %r', $ban->_date).
344                  ' until '.         time2str('%a %h %o at %r', $ban->_end_date).
345                  ' (ban# '. $ban->bannum. ')'
346             unless $self->override_ban_warn;
347         } else {
348           return 'Banned credit card: banned on '.
349                  time2str('%a %h %o at %r', $ban->_date).
350                  ' by '. $ban->otaker.
351                  ' (ban# '. $ban->bannum. ')';
352         }
353       }
354     }
355
356     if (length($self->paycvv) && !$self->is_encrypted($self->paycvv)) {
357       if ( cardtype($self->payinfo) eq 'American Express card' ) {
358         $self->paycvv =~ /^(\d{4})$/
359           or return "CVV2 (CID) for American Express cards is four digits.";
360         $self->paycvv($1);
361       } else {
362         $self->paycvv =~ /^(\d{3})$/
363           or return "CVV2 (CVC2/CID) is three digits.";
364         $self->paycvv($1);
365       }
366     } else {
367       $self->paycvv('');
368     }
369
370     my $cardtype = cardtype($payinfo);
371     if ( $cardtype =~ /^(Switch|Solo)$/i ) {
372
373       return "Start date or issue number is required for $cardtype cards"
374         unless $self->paystart_month && $self->paystart_year or $self->payissue;
375
376       return "Start month must be between 1 and 12"
377         if $self->paystart_month
378            and $self->paystart_month < 1 || $self->paystart_month > 12;
379
380       return "Start year must be 1990 or later"
381         if $self->paystart_year
382            and $self->paystart_year < 1990;
383
384       return "Issue number must be beween 1 and 99"
385         if $self->payissue
386           and $self->payissue < 1 || $self->payissue > 99;
387
388     } else {
389       $self->paystart_month('');
390       $self->paystart_year('');
391       $self->payissue('');
392     }
393
394   } elsif ( !$ignore_invalid_card && 
395     $check_payinfo && $self->payby =~ /^(CHEK|DCHK)$/ ) {
396
397     my $payinfo = $self->payinfo;
398     $payinfo =~ s/[^\d\@\.]//g;
399     if ( $conf->config('echeck-country') eq 'CA' ) {
400       $payinfo =~ /^(\d+)\@(\d{5})\.(\d{3})$/
401         or return 'invalid echeck account@branch.bank';
402       $payinfo = "$1\@$2.$3";
403     } elsif ( $conf->config('echeck-country') eq 'US' ) {
404       $payinfo =~ /^(\d+)\@(\d{9})$/ or return 'invalid echeck account@aba';
405       $payinfo = "$1\@$2";
406     } else {
407       $payinfo =~ /^(\d+)\@(\d+)$/ or return 'invalid echeck account@routing';
408       $payinfo = "$1\@$2";
409     }
410     $self->payinfo($payinfo);
411     $self->paycvv('');
412
413     unless ( $ignore_banned_card ) {
414       my $ban = FS::banned_pay->ban_search( %{ $self->_banned_pay_hashref } );
415       if ( $ban ) {
416         if ( $ban->bantype eq 'warn' ) {
417           #or others depending on value of $ban->reason ?
418           return '_duplicate_ach' unless $self->override_ban_warn;
419         } else {
420           return 'Banned ACH account: banned on '.
421                  time2str('%a %h %o at %r', $ban->_date).
422                  ' by '. $ban->otaker.
423                  ' (ban# '. $ban->bannum. ')';
424         }
425       }
426     }
427
428 #  } elsif ( $self->payby eq 'PREPAY' ) {
429 #
430 #    my $payinfo = $self->payinfo;
431 #    $payinfo =~ s/\W//g; #anything else would just confuse things
432 #    $self->payinfo($payinfo);
433 #    $error = $self->ut_alpha('payinfo');
434 #    return "Illegal prepayment identifier: ". $self->payinfo if $error;
435 #    return "Unknown prepayment identifier"
436 #      unless qsearchs('prepay_credit', { 'identifier' => $self->payinfo } );
437 #    $self->paycvv('');
438
439   }
440
441   if ( $self->payby =~ /^(CHEK|DCHK)$/ ) {
442
443     $self->paydate('');
444
445   } elsif ( $self->payby =~ /^(CARD|DCRD)$/ ) {
446
447     # shouldn't payinfo_check do this?
448     return "Expiration date required"
449       if $self->paydate eq '' || $self->paydate eq '-';
450
451     my( $m, $y );
452     if ( $self->paydate =~ /^(\d{1,2})[\/\-](\d{2}(\d{2})?)$/ ) {
453       ( $m, $y ) = ( $1, length($2) == 4 ? $2 : "20$2" );
454     } elsif ( $self->paydate =~ /^19(\d{2})[\/\-](\d{1,2})[\/\-]\d+$/ ) {
455       ( $m, $y ) = ( $2, "19$1" );
456     } elsif ( $self->paydate =~ /^(20)?(\d{2})[\/\-](\d{1,2})[\/\-]\d+$/ ) {
457       ( $m, $y ) = ( $3, "20$2" );
458     } else {
459       return "Illegal expiration date: ". $self->paydate;
460     }
461     $m = sprintf('%02d',$m);
462     $self->paydate("$y-$m-01");
463     my($nowm,$nowy)=(localtime(time))[4,5]; $nowm++; $nowy+=1900;
464     return gettext('expired_card')
465       if #XXX !$import
466       #&&
467          !$ignore_expired_card 
468       && ( $y<$nowy || ( $y==$nowy && $1<$nowm ) );
469
470   }
471
472   if ( $self->payname eq '' && $self->payby !~ /^(CHEK|DCHK)$/ &&
473        ( ! $conf->exists('require_cardname')
474          || $self->payby !~ /^(CARD|DCRD)$/  ) 
475   ) {
476     $self->payname( $self->first. " ". $self->getfield('last') );
477   } else {
478
479     if ( $self->payby =~ /^(CHEK|DCHK)$/ ) {
480       $self->payname =~ /^([\w \,\.\-\']*)$/
481         or return gettext('illegal_name'). " payname: ". $self->payname;
482       $self->payname($1);
483     } else {
484       $self->payname =~ /^([\w \,\.\-\'\&]*)$/
485         or return gettext('illegal_name'). " payname: ". $self->payname;
486       $self->payname($1);
487     }
488
489   }
490
491   ###
492
493   $self->SUPER::check;
494 }
495
496 sub check_payinfo_cardtype {
497   my $self = shift;
498
499   my $payinfo = $self->payinfo;
500   $payinfo =~ s/\D//g;
501
502   return '' if $payinfo =~ /^99\d{14}$/; #token
503
504   my %bop_card_types = map { $_=>1 } values %{ card_types() };
505   my $cardtype = cardtype($payinfo);
506
507   return "$cardtype not accepted" unless $bop_card_types{$cardtype};
508
509   '';
510
511 }
512
513 sub _banned_pay_hashref {
514   my $self = shift;
515
516   my %payby2ban = (
517     'CARD' => 'CARD',
518     'DCRD' => 'CARD',
519     'CHEK' => 'CHEK',
520     'DCHK' => 'CHEK'
521   );
522
523   {
524     'payby'   => $payby2ban{$self->payby},
525     'payinfo' => $self->payinfo,
526     #don't ever *search* on reason! #'reason'  =>
527   };
528 }
529
530 sub _new_banned_pay_hashref {
531   my $self = shift;
532   my $hr = $self->_banned_pay_hashref;
533   $hr->{payinfo_hash} = 'SHA512';
534   $hr->{payinfo} = sha512_base64($hr->{payinfo});
535   $hr;
536 }
537
538 =item paydate_mon_year
539
540 Returns a two element list consisting of the paydate month and year.
541
542 =cut
543
544 sub paydate_mon_year {
545   my $self = shift;
546
547   my $date = $self->paydate; # || '12-2037';
548
549   #false laziness w/elements/select-month_year.html
550   if ( $date  =~ /^(\d{4})-(\d{1,2})-\d{1,2}$/ ) { #PostgreSQL date format
551     ( $2, $1 );
552   } elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) {
553     ( $1, $3 );
554   } else {
555     warn "unrecognized expiration date format: $date";
556     ( '', '' );
557   }
558
559 }
560
561 =item realtime_bop
562
563 =cut
564
565 sub realtime_bop {
566   my( $self, %opt ) = @_;
567
568   $opt{$_} = $self->$_() for qw( payinfo payname paydate );
569
570   if ( $self->locationnum ) {
571     my $cust_location = $self->cust_location;
572     $opt{$_} = $cust_location->$_() for qw( address1 address2 city state zip );
573   }
574
575   $self->cust_main->realtime_bop({
576     'method' => FS::payby->payby2bop( $self->payby ),
577     %opt,
578   });
579
580 }
581
582 =item paytypes
583
584 Returns a list of valid values for the paytype field (bank account type for
585 electronic check payment).
586
587 =cut
588
589 sub paytypes {
590   #my $class = shift;
591
592   ('', 'Personal checking', 'Personal savings', 'Business checking', 'Business savings');
593 }
594
595 =item cgi_cust_payby_fields
596
597 Returns the field names used in the web interface (including some pseudo-fields).
598
599 =cut
600
601 sub cgi_cust_payby_fields {
602   #my $class = shift;
603   [qw( payby payinfo paydate_month paydate_year paycvv payname weight
604        payinfo1 payinfo2 payinfo3 paytype paystate payname_CHEK )];
605 }
606
607 =item cgi_hash_callback HASHREF OLD
608
609 Subroutine (not a class or object method).  Processes a hash reference
610 of web interface contet (transfers the data from pseudo-fields to real fields).
611
612 If OLD object is passed, also preserves locationnum, paystart_month, paystart_year,
613 payissue and payip.  If the new field is blank but the old is not, the old field 
614 will be preserved.
615
616 =cut
617
618 sub cgi_hash_callback {
619   my $hashref = shift;
620   my $old = shift;
621
622   my %noauto = (
623     'CARD' => 'DCRD',
624     'CHEK' => 'DCHK',
625   );
626   $hashref->{payby} = $noauto{$hashref->{payby}}
627     if ! $hashref->{weight} && exists $noauto{$hashref->{payby}};
628
629   if ( $hashref->{payby} =~ /^(CHEK|DCHK)$/ ) {
630
631     unless ( grep $hashref->{$_}, qw(payinfo1 payinfo2 payinfo3 payname_CHEK)) {
632       %$hashref = ();
633       return;
634     }
635
636     $hashref->{payinfo} = $hashref->{payinfo1}. '@';
637     $hashref->{payinfo} .= $hashref->{payinfo3}.'.' 
638       if $conf->config('echeck-country') eq 'CA';
639     $hashref->{payinfo} .= $hashref->{'payinfo2'};
640
641     $hashref->{payname} = $hashref->{'payname_CHEK'};
642
643   } elsif ( $hashref->{payby} =~ /^(CARD|DCRD)$/ ) {
644
645     unless ( grep $hashref->{$_}, qw( payinfo paycvv payname ) ) {
646       %$hashref = ();
647       return;
648     }
649
650   }
651
652   $hashref->{paydate}= $hashref->{paydate_month}. '-'. $hashref->{paydate_year};
653
654   if ($old) {
655     foreach my $field ( qw(locationnum paystart_month paystart_year payissue payip) ) {
656       next if $hashref->{$field};
657       next unless $old->get($field);
658       $hashref->{$field} = $old->get($field);
659     }
660   }
661
662 }
663
664 =item search_sql
665
666 Class method.
667
668 Returns a qsearch hash expression to search for parameters specified in HASHREF.
669 Valid paramters are:
670
671 =over 4
672
673 =item payby
674
675 listref
676
677 =item paydate_year
678
679 =item paydate_month
680
681
682 =back
683
684 =cut
685
686 sub search_sql {
687   my ($class, $params) = @_;
688
689   my @where = ();
690   my $orderby;
691
692   # initialize these to prevent warnings
693   $params = {
694     'paydate_year'  => '',
695     %$params
696   };
697
698   ###
699   # payby
700   ###
701
702   if ( $params->{'payby'} ) {
703
704     my @payby = ref( $params->{'payby'} )
705                   ? @{ $params->{'payby'} }
706                   :  ( $params->{'payby'} );
707
708     @payby = grep /^([A-Z]{4})$/, @payby;
709     my $in_payby = 'IN(' . join(',', map {"'$_'"} @payby) . ')';
710     push @where, "cust_payby.payby $in_payby"
711       if @payby;
712   }
713
714   ###
715   # paydate_year / paydate_month
716   ###
717
718   if ( $params->{'paydate_year'} =~ /^(\d{4})$/ ) {
719     my $year = $1;
720     $params->{'paydate_month'} =~ /^(\d\d?)$/
721       or die "paydate_year without paydate_month?";
722     my $month = $1;
723
724     push @where,
725       'cust_payby.paydate IS NOT NULL',
726       "cust_payby.paydate != ''",
727       "CAST(cust_payby.paydate AS timestamp) < CAST('$year-$month-01' AS timestamp )"
728 ;
729   }
730   ##
731   # setup queries, subs, etc. for the search
732   ##
733
734   $orderby ||= 'ORDER BY custnum';
735
736   # here is the agent virtualization
737   push @where,
738     $FS::CurrentUser::CurrentUser->agentnums_sql(table => 'cust_main');
739
740   my $extra_sql = scalar(@where) ? ' WHERE '. join(' AND ', @where) : '';
741
742   my $addl_from = ' LEFT JOIN cust_main USING ( custnum ) ';
743   # always make address fields available in results
744   for my $pre ('bill_', 'ship_') {
745     $addl_from .= 
746       ' LEFT JOIN cust_location AS '.$pre.'location '.
747       'ON (cust_main.'.$pre.'locationnum = '.$pre.'location.locationnum) ';
748   }
749
750   my $count_query = "SELECT COUNT(*) FROM cust_payby $addl_from $extra_sql";
751
752   my @select = ( 'cust_payby.*',
753                  #'cust_main.custnum',
754                  # there's a good chance that we'll need these
755                  'cust_main.bill_locationnum',
756                  'cust_main.ship_locationnum',
757                  FS::UI::Web::cust_sql_fields($params->{'cust_fields'}),
758                );
759
760   my $select = join(', ', @select);
761
762   my $sql_query = {
763     'table'         => 'cust_payby',
764     'select'        => $select,
765     'addl_from'     => $addl_from,
766     'hashref'       => {},
767     'extra_sql'     => $extra_sql,
768     'order_by'      => $orderby,
769     'count_query'   => $count_query,
770   };
771   $sql_query;
772
773 }
774
775 =back
776
777 =head1 BUGS
778
779 =head1 SEE ALSO
780
781 L<FS::Record>, schema.html from the base documentation.
782
783 =cut
784
785 1;
786