display apple and android store payments by name
[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   'PPAL' => {
86     tinyname  => 'PayPal',
87     shortname => 'PayPal',
88     longname  => 'PayPal',
89     cust_main => '', #not yet a customer type, but could be once we can do
90                      # invoice presentment via paypal
91   },
92   'PREP' => {
93     tinyname  => 'prepaid card',
94     shortname => 'Prepaid card',
95     longname  => 'Prepaid card',
96     cust_main => 'BILL', #this is a payment type only, customers go to BILL...
97   },
98   'CASH' => {
99     tinyname  => 'cash',
100     shortname => 'Cash', # initial payment, then billing
101     longname  => 'Cash',
102     cust_main => 'BILL', #this is a payment type only, customers go to BILL...
103   },
104   'WEST' => {
105     tinyname  => 'western union',
106     shortname => 'Western Union', # initial payment, then billing
107     longname  => 'Western Union',
108     cust_main => 'BILL', #this is a payment type only, customers go to BILL...
109   },
110   'MCRD' => { #not the same as DCRD
111     tinyname  => 'card',
112     shortname => 'Manual credit card', # initial payment, then billing
113     longname  => 'Manual credit card', 
114     cust_main => 'BILL', #this is a payment type only, customers go to BILL...
115   },
116   'APPL' => {
117     tinyname  => 'apple store',
118     shortname => 'Apple Store',
119     longname  => 'Apple Store',
120     cust_main => 'BILL', #this is a payment type only, customers go to BILL...
121   },
122   'ANRD' => {
123     tinyname  => 'android market',
124     shortname => 'Android Market',
125     longname  => 'Android Market',
126     cust_main => 'BILL', #this is a payment type only, customers go to BILL...
127   },
128   'EDI' => {
129     tinyname  => 'EDI',
130     shortname => 'Electronic Debit',
131     longname  => 'Electronic Debit',
132     cust_main => '', #not a customer type
133   },
134   'WIRE' => {
135     tinyname  => 'Wire',
136     shortname => 'Wire transfer',
137     longname  => 'Wire transfer',
138     cust_main => '', #not a customer type
139   },
140   'COMP' => {
141     tinyname  => 'comp',
142     shortname => 'Complimentary',
143     longname  => 'Complimentary',
144     cust_pay  => '', # (free) is depricated as a payment type in cust_pay
145   },
146   'CBAK' => {
147     tinyname  => 'chargeback',
148     shortname => 'Chargeback',
149     longname  => 'Chargeback',
150     cust_main => '', # not a customer type
151   },
152 ;
153
154 sub payby {
155   keys %hash;
156 }
157
158 sub can_payby {
159   my( $self, $table, $payby ) = @_;
160
161   #return "Illegal payby" unless $hash{$payby};
162   return 0 unless $hash{$payby};
163
164   $table = 'cust_pay' if $table =~ /^cust_(pay_pending|pay_batch|pay_void|refund)$/;
165   return 0 if exists( $hash{$payby}->{$table} );
166
167   return 1;
168 }
169
170 sub realtime {  # can use realtime payment facilities
171   my( $self, $payby ) = @_;
172
173   return 0 unless $hash{$payby};
174   return 0 unless exists( $hash{$payby}->{realtime} );
175
176   return $hash{$payby}->{realtime};
177 }
178
179 sub payby2shortname {
180   my $self = shift;
181   map { $_ => $hash{$_}->{shortname} } $self->payby;
182 }
183
184 sub payby2longname {
185   my $self = shift;
186   map { $_ => $hash{$_}->{longname} } $self->payby;
187 }
188
189 sub shortname {
190   my( $self, $payby ) = @_;
191   $hash{$payby}->{shortname};
192 }
193
194 sub payname {
195   my( $self, $payby ) = @_;
196   #$hash{$payby}->{payname} || $hash{$payby}->{shortname};
197   exists($hash{$payby}->{payname})
198     ? $hash{$payby}->{payname}
199     : $hash{$payby}->{shortname};
200 }
201
202 sub longname {
203   my( $self, $payby ) = @_;
204   $hash{$payby}->{longname};
205 }
206
207 %payby2bop = (
208   'CARD' => 'CC',
209   'CHEK' => 'ECHECK',
210   'MCRD' => 'CC',
211 );
212
213 sub payby2bop {
214   my( $self, $payby ) = @_;
215   $payby2bop{ $self->payby2payment($payby) };
216 }
217
218 sub payby2payment {
219   my( $self, $payby ) = @_;
220   $hash{$payby}{'cust_pay'} || $payby;
221 }
222
223 sub cust_payby {
224   my $self = shift;
225   grep { ! exists $hash{$_}->{cust_main} } $self->payby;
226 }
227
228 sub cust_payby2longname {
229   my $self = shift;
230   map { $_ => $hash{$_}->{longname} } $self->cust_payby;
231 }
232
233 =back
234
235 =head1 BUGS
236
237 This should eventually be an actual database table, and all tables that
238 currently have a char payby field should have a foreign key into here instead.
239
240 =head1 SEE ALSO
241
242 =cut
243
244 1;
245