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...
112 shortname => 'IDT Payment Services',
113 longname => 'IDT Payment Services',
114 cust_main => '', #this is a payment type only
116 'MCRD' => { #not the same as DCRD
118 shortname => 'Manual credit card', # initial payment, then billing
119 longname => 'Manual credit card',
120 cust_main => 'BILL', #this is a payment type only, customers go to BILL...
122 'MCHK' => { #not the same as DCHK
124 shortname => 'Manual electronic check', # initial payment, then billing
125 longname => 'Manual electronic check',
126 cust_main => 'BILL', #this is a payment type only, customers go to BILL...
129 tinyname => 'apple store',
130 shortname => 'Apple Store',
131 longname => 'Apple Store',
132 cust_main => 'BILL', #this is a payment type only, customers go to BILL...
135 tinyname => 'android market',
136 shortname => 'Android Market',
137 longname => 'Android Market',
138 cust_main => 'BILL', #this is a payment type only, customers go to BILL...
142 shortname => 'Electronic Debit (EDI)',
143 longname => 'Electronic Debit (EDI)',
144 cust_main => '', #not a customer type
148 shortname => 'Wire transfer',
149 longname => 'Wire transfer',
150 cust_main => '', #not a customer type
154 shortname => 'Complimentary',
155 longname => 'Complimentary',
156 cust_pay => '', # (free) is depricated as a payment type in cust_pay
159 tinyname => 'chargeback',
160 shortname => 'Chargeback',
161 longname => 'Chargeback',
162 cust_main => '', # not a customer type
171 my( $self, $table, $payby ) = @_;
173 #return "Illegal payby" unless $hash{$payby};
174 return 0 unless $hash{$payby};
176 $table = 'cust_pay' if $table =~ /^cust_(pay_pending|pay_batch|pay_void|refund)$/;
177 return 0 if exists( $hash{$payby}->{$table} );
182 sub realtime { # can use realtime payment facilities
183 my( $self, $payby ) = @_;
185 return 0 unless $hash{$payby};
186 return 0 unless exists( $hash{$payby}->{realtime} );
188 return $hash{$payby}->{realtime};
191 sub payby2shortname {
193 map { $_ => $hash{$_}->{shortname} } $self->payby;
198 map { $_ => $hash{$_}->{longname} } $self->payby;
202 my( $self, $payby ) = @_;
203 $hash{$payby}->{shortname};
207 my( $self, $payby ) = @_;
208 #$hash{$payby}->{payname} || $hash{$payby}->{shortname};
209 exists($hash{$payby}->{payname})
210 ? $hash{$payby}->{payname}
211 : $hash{$payby}->{shortname};
215 my( $self, $payby ) = @_;
216 $hash{$payby}->{longname};
222 'MCRD' => 'CC', #? but doesn't MCRD mean _offline_ card? i think it got
223 # overloaded for third-party card payments -- but no one is
224 # doing those other than paypal now
229 my( $self, $payby ) = @_;
230 $payby2bop{ $self->payby2payment($payby) };
234 my( $self, $payby ) = @_;
235 $hash{$payby}{'cust_pay'} || $payby;
240 grep { ! exists $hash{$_}->{cust_main} } $self->payby;
243 sub cust_payby2longname {
245 map { $_ => $hash{$_}->{longname} } $self->cust_payby;
250 Returns all values of payby that can be used by payments.
256 grep { ! exists $hash{$_}->{cust_pay} } $self->payby;
259 =item payment_payby2longname
261 Returns hash, keys are L</payment_payby> types, values are payby longname.
265 sub payment_payby2longname {
267 map { $_ => $hash{$_}->{longname} } $self->payment_payby;
270 =item payment_payby2payname
272 Returns hash, keys are L</payment_payby> types, values are payby payname.
276 sub payment_payby2payname {
278 map { $_ => $self->payname($_) } $self->payment_payby;
285 This should eventually be an actual database table, and all tables that
286 currently have a char payby field should have a foreign key into here instead.