add payby types for apple store, android market and EDI (bill pay), RT#15309
[freeside.git] / FS / FS / payby.pm
1 package FS::payby;
2
3 use strict;
4 use vars qw(%hash %payby2bop);
5 use Tie::IxHash;
6 use Business::CreditCard;
7
8
9 =head1 NAME
10
11 FS::payby - Object methods for payment type records
12
13 =head1 SYNOPSIS
14
15   use FS::payby;
16
17   #for now...
18
19   my @payby = FS::payby->payby;
20
21   my $bool = FS::payby->can_payby('cust_main', 'CARD');
22
23   tie my %payby, 'Tie::IxHash', FS::payby->payby2longname
24
25   my @cust_payby = FS::payby->cust_payby;
26
27   tie my %payby, 'Tie::IxHash', FS::payby->cust_payby2longname
28
29 =head1 DESCRIPTION
30
31 Payment types.
32
33 =head1 METHODS
34
35 =over 4 
36
37 =item
38
39 =cut
40
41 # paybys can be any/all of:
42 # - a customer payment type (cust_main.payby)
43 # - a payment or refund type (cust_pay.payby, cust_pay_batch.payby, cust_refund.payby)
44 # - an event type (part_bill_event.payby)
45
46 tie %hash, 'Tie::IxHash',
47   'CARD' => {
48     tinyname  => 'card',
49     shortname => 'Credit card',
50     longname  => 'Credit card (automatic)',
51     realtime  => 1,
52   },
53   'DCRD' => {
54     tinyname  => 'card',
55     shortname => 'Credit card',
56     longname  => 'Credit card (on-demand)',
57     cust_pay  => 'CARD', #this is a customer type only, payments are CARD...
58     realtime  => 1,
59   },
60   'CHEK' => {
61     tinyname  => 'check',
62     shortname => 'Electronic check',
63     longname  => 'Electronic check (automatic)',
64     realtime  => 1,
65   },
66   'DCHK' => {
67     tinyname  => 'check',
68     shortname => 'Electronic check',
69     longname  => 'Electronic check (on-demand)',
70     cust_pay  => 'CHEK', #this is a customer type only, payments are CHEK...
71     realtime  => 1,
72   },
73   'LECB' => {
74     tinyname  => 'phone bill',
75     shortname => 'Phone bill billing',
76     longname  => 'Phone bill billing',
77     realtime  => 1,
78   },
79   'BILL' => {
80     tinyname  => 'billing',
81     shortname => 'Billing',
82     payname   => 'Check',
83     longname  => 'Billing',
84   },
85   'PREP' => {
86     tinyname  => 'prepaid card',
87     shortname => 'Prepaid card',
88     longname  => 'Prepaid card',
89     cust_main => 'BILL', #this is a payment type only, customers go to BILL...
90   },
91   'CASH' => {
92     tinyname  => 'cash',
93     shortname => 'Cash', # initial payment, then billing
94     longname  => 'Cash',
95     cust_main => 'BILL', #this is a payment type only, customers go to BILL...
96   },
97   'WEST' => {
98     tinyname  => 'western union',
99     shortname => 'Western Union', # initial payment, then billing
100     longname  => 'Western Union',
101     cust_main => 'BILL', #this is a payment type only, customers go to BILL...
102   },
103   'MCRD' => { #not the same as DCRD
104     tinyname  => 'card',
105     shortname => 'Manual credit card', # initial payment, then billing
106     longname  => 'Manual credit card', 
107     cust_main => 'BILL', #this is a payment type only, customers go to BILL...
108   },
109   'APPL' => {
110     tinyname  => 'apple store',
111     shortname => 'Apple Store',
112     longname  => 'Apple Store',
113     cust_main => 'BILL', #this is a payment type only, customers go to BILL...
114   },
115   'ANRD' => {
116     tinyname  => 'android market',
117     shortname => 'Android Market',
118     longname  => 'Android Market',
119     cust_main => 'BILL', #this is a payment type only, customers go to BILL...
120   },
121   'EDI' => {
122     tinyname  => 'EDI',
123     shortname => 'Electronic Debit',
124     longname  => 'Electronic Debit',
125     cust_main => '', #not a customer type
126   },
127   'COMP' => {
128     tinyname  => 'comp',
129     shortname => 'Complimentary',
130     longname  => 'Complimentary',
131     cust_pay  => '', # (free) is depricated as a payment type in cust_pay
132   },
133   'CBAK' => {
134     tinyname  => 'chargeback',
135     shortname => 'Chargeback',
136     longname  => 'Chargeback',
137     cust_main => '', # not a customer type
138   },
139 ;
140
141 sub payby {
142   keys %hash;
143 }
144
145 sub can_payby {
146   my( $self, $table, $payby ) = @_;
147
148   #return "Illegal payby" unless $hash{$payby};
149   return 0 unless $hash{$payby};
150
151   $table = 'cust_pay' if $table =~ /^cust_(pay_pending|pay_batch|pay_void|refund)$/;
152   return 0 if exists( $hash{$payby}->{$table} );
153
154   return 1;
155 }
156
157 sub realtime {  # can use realtime payment facilities
158   my( $self, $payby ) = @_;
159
160   return 0 unless $hash{$payby};
161   return 0 unless exists( $hash{$payby}->{realtime} );
162
163   return $hash{$payby}->{realtime};
164 }
165
166 sub payby2longname {
167   my $self = shift;
168   map { $_ => $hash{$_}->{longname} } $self->payby;
169 }
170
171 sub shortname {
172   my( $self, $payby ) = @_;
173   $hash{$payby}->{shortname};
174 }
175
176 sub payname {
177   my( $self, $payby ) = @_;
178   #$hash{$payby}->{payname} || $hash{$payby}->{shortname};
179   exists($hash{$payby}->{payname})
180     ? $hash{$payby}->{payname}
181     : $hash{$payby}->{shortname};
182 }
183
184 sub longname {
185   my( $self, $payby ) = @_;
186   $hash{$payby}->{longname};
187 }
188
189 %payby2bop = (
190   'CARD' => 'CC',
191   'CHEK' => 'ECHECK',
192   'MCRD' => 'CC',
193 );
194
195 sub payby2bop {
196   my( $self, $payby ) = @_;
197   $payby2bop{ $self->payby2payment($payby) };
198 }
199
200 sub payby2payment {
201   my( $self, $payby ) = @_;
202   $hash{$payby}{'cust_pay'} || $payby;
203 }
204
205 sub cust_payby {
206   my $self = shift;
207   grep { ! exists $hash{$_}->{cust_main} } $self->payby;
208 }
209
210 sub cust_payby2longname {
211   my $self = shift;
212   map { $_ => $hash{$_}->{longname} } $self->cust_payby;
213 }
214
215 =back
216
217 =head1 BUGS
218
219 This should eventually be an actual database table, and all tables that
220 currently have a char payby field should have a foreign key into here instead.
221
222 =head1 SEE ALSO
223
224 =cut
225
226 1;
227