4 use vars qw(%hash %payby2bop);
6 use Business::CreditCard;
10 FS::payby - Object methods for payment type records
18 my @payby = FS::payby->payby;
20 my $bool = FS::payby->can_payby('cust_main', 'CARD');
22 tie my %payby, 'Tie::IxHash', FS::payby->payby2longname
24 my @cust_payby = FS::payby->cust_payby;
26 tie my %payby, 'Tie::IxHash', FS::payby->cust_payby2longname
40 # paybys can be any/all of:
41 # - a customer saved payment type (cust_payby.payby)
42 # - a payment or refund type (cust_pay.payby, cust_pay_batch.payby, cust_refund.payby)
44 tie %hash, 'Tie::IxHash',
47 shortname => 'Credit card',
48 longname => 'Credit card (automatic)',
53 shortname => 'Credit card',
54 longname => 'Credit card (on-demand)',
55 cust_pay => 'CARD', #this is a customer type only, payments are CARD...
60 shortname => 'Electronic check',
61 longname => 'Electronic check (automatic)',
66 shortname => 'Electronic check',
67 longname => 'Electronic check (on-demand)',
68 cust_pay => 'CHEK', #this is a customer type only, payments are CHEK...
72 tinyname => 'billing',
73 shortname => 'Billing',
75 longname => 'Billing',
76 cust_main => '', #no longer a customer type
80 shortname => 'PayPal',
82 cust_main => '', #not yet a customer type, but could be once we can do
83 # invoice presentment via paypal
86 tinyname => 'prepaid card',
87 shortname => 'Prepaid card',
88 longname => 'Prepaid card',
89 cust_main => '', #this is a payment type only
93 shortname => 'Cash', # initial payment, then billing
95 cust_main => '', #this is a payment type only
98 tinyname => 'western union',
99 shortname => 'Western Union', # initial payment, then billing
100 longname => 'Western Union',
101 cust_main => '', #this is a payment type only
105 shortname => 'IDT Payment Services',
106 longname => 'IDT Payment Services',
107 cust_main => '', #this is a payment type only
109 'MCRD' => { #not the same as DCRD
111 shortname => 'Manual credit card', # initial payment, then billing
112 longname => 'Manual credit card',
113 cust_main => '', #this is a payment type only
115 'MCHK' => { #not the same as DCHK
117 shortname => 'Manual electronic check', # initial payment, then billing
118 longname => 'Manual electronic check',
119 cust_main => '', #this is a payment type only
122 tinyname => 'apple store',
123 shortname => 'Apple Store',
124 longname => 'Apple Store',
125 cust_main => '', #this is a payment type only
128 tinyname => 'android market',
129 shortname => 'Android Market',
130 longname => 'Android Market',
131 cust_main => '', #this is a payment type only
135 shortname => 'Electronic Debit (EDI)',
136 longname => 'Electronic Debit (EDI)',
137 cust_main => '', #not a customer type
141 shortname => 'Wire transfer',
142 longname => 'Wire transfer',
143 cust_main => '', #not a customer type
146 tinyname => 'chargeback',
147 shortname => 'Chargeback',
148 longname => 'Chargeback',
149 cust_main => '', # not a customer type
158 my( $self, $table, $payby ) = @_;
160 #return "Illegal payby" unless $hash{$payby};
161 return 0 unless $hash{$payby};
163 $table = 'cust_pay' if $table =~ /^cust_(pay_pending|pay_batch|pay_void|refund)$/;
164 return 0 if exists( $hash{$payby}->{$table} );
169 sub realtime { # can use realtime payment facilities
170 my( $self, $payby ) = @_;
172 return 0 unless $hash{$payby};
173 return 0 unless exists( $hash{$payby}->{realtime} );
175 return $hash{$payby}->{realtime};
178 sub payby2shortname {
180 map { $_ => $hash{$_}->{shortname} } $self->payby;
185 map { $_ => $hash{$_}->{longname} } $self->payby;
189 my( $self, $payby ) = @_;
190 $hash{$payby}->{shortname};
194 my( $self, $payby ) = @_;
195 #$hash{$payby}->{payname} || $hash{$payby}->{shortname};
196 exists($hash{$payby}->{payname})
197 ? $hash{$payby}->{payname}
198 : $hash{$payby}->{shortname};
202 my( $self, $payby ) = @_;
203 $hash{$payby}->{longname};
209 'MCRD' => 'CC', #? but doesn't MCRD mean _offline_ card? i think it got
210 # overloaded for third-party card payments -- but no one is
211 # doing those other than paypal now
216 my( $self, $payby ) = @_;
217 $payby2bop{ $self->payby2payment($payby) };
221 my( $self, $payby ) = @_;
222 $hash{$payby}{'cust_pay'} || $payby;
227 grep { ! exists $hash{$_}->{cust_main} } $self->payby;
230 sub cust_payby2shortname {
232 map { $_ => $hash{$_}->{shortname} } $self->cust_payby;
235 sub cust_payby2longname {
237 map { $_ => $hash{$_}->{longname} } $self->cust_payby;
242 Returns all values of payby that can be used by payments.
248 grep { ! exists $hash{$_}->{cust_pay} } $self->payby;
251 =item payment_payby2longname
253 Returns hash, keys are L</payment_payby> types, values are payby longname.
257 sub payment_payby2longname {
259 map { $_ => $hash{$_}->{longname} } $self->payment_payby;
262 =item payment_payby2payname
264 Returns hash, keys are L</payment_payby> types, values are payby payname.
268 sub payment_payby2payname {
270 map { $_ => $self->payname($_) } $self->payment_payby;
277 This should eventually be an actual database table, and all tables that
278 currently have a char payby field should have a foreign key into here instead.