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
103 'MCRD' => { #not the same as DCRD
105 shortname => 'Manual credit card', # initial payment, then billing
106 longname => 'Manual credit card',
107 cust_main => '', #this is a payment type only
109 'MCHK' => { #not the same as DCHK
111 shortname => 'Manual electronic check', # initial payment, then billing
112 longname => 'Manual electronic check',
113 cust_main => '', #this is a payment type only
116 tinyname => 'apple store',
117 shortname => 'Apple Store',
118 longname => 'Apple Store',
119 cust_main => '', #this is a payment type only
122 tinyname => 'android market',
123 shortname => 'Android Market',
124 longname => 'Android Market',
125 cust_main => '', #this is a payment type only
129 shortname => 'Electronic Debit (EDI)',
130 longname => 'Electronic Debit (EDI)',
131 cust_main => '', #not a customer type
135 shortname => 'Wire transfer',
136 longname => 'Wire transfer',
137 cust_main => '', #not a customer type
140 tinyname => 'chargeback',
141 shortname => 'Chargeback',
142 longname => 'Chargeback',
143 cust_main => '', # not a customer type
152 my( $self, $table, $payby ) = @_;
154 #return "Illegal payby" unless $hash{$payby};
155 return 0 unless $hash{$payby};
157 $table = 'cust_pay' if $table =~ /^cust_(pay_pending|pay_batch|pay_void|refund)$/;
158 return 0 if exists( $hash{$payby}->{$table} );
163 sub realtime { # can use realtime payment facilities
164 my( $self, $payby ) = @_;
166 return 0 unless $hash{$payby};
167 return 0 unless exists( $hash{$payby}->{realtime} );
169 return $hash{$payby}->{realtime};
172 sub payby2shortname {
174 map { $_ => $hash{$_}->{shortname} } $self->payby;
179 map { $_ => $hash{$_}->{longname} } $self->payby;
183 my( $self, $payby ) = @_;
184 $hash{$payby}->{shortname};
188 my( $self, $payby ) = @_;
189 #$hash{$payby}->{payname} || $hash{$payby}->{shortname};
190 exists($hash{$payby}->{payname})
191 ? $hash{$payby}->{payname}
192 : $hash{$payby}->{shortname};
196 my( $self, $payby ) = @_;
197 $hash{$payby}->{longname};
203 'MCRD' => 'CC', #? but doesn't MCRD mean _offline_ card? i think it got
204 # overloaded for third-party card payments -- but no one is
205 # doing those other than paypal now
210 my( $self, $payby ) = @_;
211 $payby2bop{ $self->payby2payment($payby) };
215 my( $self, $payby ) = @_;
216 $hash{$payby}{'cust_pay'} || $payby;
221 grep { ! exists $hash{$_}->{cust_main} } $self->payby;
224 sub cust_payby2shortname {
226 map { $_ => $hash{$_}->{shortname} } $self->cust_payby;
229 sub cust_payby2longname {
231 map { $_ => $hash{$_}->{longname} } $self->cust_payby;
236 Returns all values of payby that can be used by payments.
242 grep { ! exists $hash{$_}->{cust_pay} } $self->payby;
245 =item payment_payby2longname
247 Returns hash, keys are L</payment_payby> types, values are payby longname.
251 sub payment_payby2longname {
253 map { $_ => $hash{$_}->{longname} } $self->payment_payby;
256 =item payment_payby2payname
258 Returns hash, keys are L</payment_payby> types, values are payby payname.
262 sub payment_payby2payname {
264 map { $_ => $self->payname($_) } $self->payment_payby;
271 This should eventually be an actual database table, and all tables that
272 currently have a char payby field should have a foreign key into here instead.