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...
73 shortname => 'PayPal',
75 cust_main => '', #not yet a customer type, but could be once we can do
76 # invoice presentment via paypal
79 tinyname => 'prepaid card',
80 shortname => 'Prepaid card',
81 longname => 'Prepaid card',
82 cust_main => 'BILL', #this is a payment type only, customers go to BILL...
86 shortname => 'Cash', # initial payment, then billing
88 cust_main => 'BILL', #this is a payment type only, customers go to BILL...
91 tinyname => 'western union',
92 shortname => 'Western Union', # initial payment, then billing
93 longname => 'Western Union',
94 cust_main => 'BILL', #this is a payment type only, customers go to BILL...
96 'MCRD' => { #not the same as DCRD
98 shortname => 'Manual credit card', # initial payment, then billing
99 longname => 'Manual credit card',
100 cust_main => 'BILL', #this is a payment type only, customers go to BILL...
102 'MCHK' => { #not the same as DCHK
104 shortname => 'Manual electronic check', # initial payment, then billing
105 longname => 'Manual electronic check',
106 cust_main => 'BILL', #this is a payment type only, customers go to BILL...
109 tinyname => 'apple store',
110 shortname => 'Apple Store',
111 longname => 'Apple Store',
112 cust_main => 'BILL', #this is a payment type only, customers go to BILL...
115 tinyname => 'android market',
116 shortname => 'Android Market',
117 longname => 'Android Market',
118 cust_main => 'BILL', #this is a payment type only, customers go to BILL...
122 shortname => 'Electronic Debit (EDI)',
123 longname => 'Electronic Debit (EDI)',
124 cust_main => '', #not a customer type
128 shortname => 'Wire transfer',
129 longname => 'Wire transfer',
130 cust_main => '', #not a customer type
133 tinyname => 'chargeback',
134 shortname => 'Chargeback',
135 longname => 'Chargeback',
136 cust_main => '', # not a customer type
145 my( $self, $table, $payby ) = @_;
147 #return "Illegal payby" unless $hash{$payby};
148 return 0 unless $hash{$payby};
150 $table = 'cust_pay' if $table =~ /^cust_(pay_pending|pay_batch|pay_void|refund)$/;
151 return 0 if exists( $hash{$payby}->{$table} );
156 sub realtime { # can use realtime payment facilities
157 my( $self, $payby ) = @_;
159 return 0 unless $hash{$payby};
160 return 0 unless exists( $hash{$payby}->{realtime} );
162 return $hash{$payby}->{realtime};
165 sub payby2shortname {
167 map { $_ => $hash{$_}->{shortname} } $self->payby;
172 map { $_ => $hash{$_}->{longname} } $self->payby;
176 my( $self, $payby ) = @_;
177 $hash{$payby}->{shortname};
181 my( $self, $payby ) = @_;
182 #$hash{$payby}->{payname} || $hash{$payby}->{shortname};
183 exists($hash{$payby}->{payname})
184 ? $hash{$payby}->{payname}
185 : $hash{$payby}->{shortname};
189 my( $self, $payby ) = @_;
190 $hash{$payby}->{longname};
196 'MCRD' => 'CC', #? but doesn't MCRD mean _offline_ card? i think it got
197 # overloaded for third-party card payments -- but no one is
198 # doing those other than paypal now
203 my( $self, $payby ) = @_;
204 $payby2bop{ $self->payby2payment($payby) };
208 my( $self, $payby ) = @_;
209 $hash{$payby}{'cust_pay'} || $payby;
214 grep { ! exists $hash{$_}->{cust_main} } $self->payby;
217 sub cust_payby2shortname {
219 map { $_ => $hash{$_}->{shortname} } $self->cust_payby;
222 sub cust_payby2longname {
224 map { $_ => $hash{$_}->{longname} } $self->cust_payby;
229 Returns all values of payby that can be used by payments.
235 grep { ! exists $hash{$_}->{cust_pay} } $self->payby;
238 =item payment_payby2longname
240 Returns hash, keys are L</payment_payby> types, values are payby longname.
244 sub payment_payby2longname {
246 map { $_ => $hash{$_}->{longname} } $self->payment_payby;
253 This should eventually be an actual database table, and all tables that
254 currently have a char payby field should have a foreign key into here instead.