4 use vars qw(%hash %payby2bop);
6 use Business::CreditCard;
11 FS::payby - Object methods for payment type records
19 my @payby = FS::payby->payby;
21 my $bool = FS::payby->can_payby('cust_main', 'CARD');
23 tie my %payby, 'Tie::IxHash', FS::payby->payby2longname
25 my @cust_payby = FS::payby->cust_payby;
27 tie my %payby, 'Tie::IxHash', FS::payby->cust_payby2longname
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)
46 tie %hash, 'Tie::IxHash',
49 shortname => 'Credit card',
50 longname => 'Credit card (automatic)',
55 shortname => 'Credit card',
56 longname => 'Credit card (on-demand)',
57 cust_pay => 'CARD', #this is a customer type only, payments are CARD...
62 shortname => 'Electronic check',
63 longname => 'Electronic check (automatic)',
68 shortname => 'Electronic check',
69 longname => 'Electronic check (on-demand)',
70 cust_pay => 'CHEK', #this is a customer type only, payments are CHEK...
74 tinyname => 'phone bill',
75 shortname => 'Phone bill billing',
76 longname => 'Phone bill billing',
80 tinyname => 'billing',
81 shortname => 'Billing',
83 longname => 'Billing',
87 shortname => 'PayPal',
89 cust_main => '', #not yet a customer type, but could be once we can do
90 # invoice presentment via paypal
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...
100 shortname => 'Cash', # initial payment, then billing
102 cust_main => 'BILL', #this is a payment type only, customers go to BILL...
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...
110 'MCRD' => { #not the same as DCRD
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...
116 'MCHK' => { #not the same as DCHK
118 shortname => 'Manual electronic check', # initial payment, then billing
119 longname => 'Manual electronic check',
120 cust_main => 'BILL', #this is a payment type only, customers go to BILL...
123 tinyname => 'apple store',
124 shortname => 'Apple Store',
125 longname => 'Apple Store',
126 cust_main => 'BILL', #this is a payment type only, customers go to BILL...
129 tinyname => 'android market',
130 shortname => 'Android Market',
131 longname => 'Android Market',
132 cust_main => 'BILL', #this is a payment type only, customers go to BILL...
136 shortname => 'Electronic Debit (EDI)',
137 longname => 'Electronic Debit (EDI)',
138 cust_main => '', #not a customer type
142 shortname => 'Wire transfer',
143 longname => 'Wire transfer',
144 cust_main => '', #not a customer type
148 shortname => 'Complimentary',
149 longname => 'Complimentary',
150 cust_pay => '', # (free) is depricated as a payment type in cust_pay
153 tinyname => 'chargeback',
154 shortname => 'Chargeback',
155 longname => 'Chargeback',
156 cust_main => '', # not a customer type
165 my( $self, $table, $payby ) = @_;
167 #return "Illegal payby" unless $hash{$payby};
168 return 0 unless $hash{$payby};
170 $table = 'cust_pay' if $table =~ /^cust_(pay_pending|pay_batch|pay_void|refund)$/;
171 return 0 if exists( $hash{$payby}->{$table} );
176 sub realtime { # can use realtime payment facilities
177 my( $self, $payby ) = @_;
179 return 0 unless $hash{$payby};
180 return 0 unless exists( $hash{$payby}->{realtime} );
182 return $hash{$payby}->{realtime};
185 sub payby2shortname {
187 map { $_ => $hash{$_}->{shortname} } $self->payby;
192 map { $_ => $hash{$_}->{longname} } $self->payby;
196 my( $self, $payby ) = @_;
197 $hash{$payby}->{shortname};
201 my( $self, $payby ) = @_;
202 #$hash{$payby}->{payname} || $hash{$payby}->{shortname};
203 exists($hash{$payby}->{payname})
204 ? $hash{$payby}->{payname}
205 : $hash{$payby}->{shortname};
209 my( $self, $payby ) = @_;
210 $hash{$payby}->{longname};
216 'MCRD' => 'CC', #? but doesn't MCRD mean _offline_ card? i think it got
217 # overloaded for third-party card payments -- but no one is
218 # doing those other than paypal now
223 my( $self, $payby ) = @_;
224 $payby2bop{ $self->payby2payment($payby) };
228 my( $self, $payby ) = @_;
229 $hash{$payby}{'cust_pay'} || $payby;
234 grep { ! exists $hash{$_}->{cust_main} } $self->payby;
237 sub cust_payby2longname {
239 map { $_ => $hash{$_}->{longname} } $self->cust_payby;
244 Returns all values of payby that can be used by payments.
250 grep { ! exists $hash{$_}->{cust_pay} } $self->payby;
253 =item payment_payby2longname
255 Returns hash, keys are L</payment_payby> types, values are payby longname.
259 sub payment_payby2longname {
261 map { $_ => $hash{$_}->{longname} } $self->payment_payby;
268 This should eventually be an actual database table, and all tables that
269 currently have a char payby field should have a foreign key into here instead.