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 # customer methods that start with 'D' will be interpreted as on-demand
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 => 'billing',
75 shortname => 'Billing',
77 longname => 'Billing',
78 cust_main => '', #no longer a customer type
82 shortname => 'PayPal',
84 cust_main => '', #not yet a customer type, but could be once we can do
85 # invoice presentment via paypal
88 tinyname => 'prepaid card',
89 shortname => 'Prepaid card',
90 longname => 'Prepaid card',
91 cust_main => '', #this is a payment type only
95 shortname => 'Cash', # initial payment, then billing
97 cust_main => '', #this is a payment type only
100 tinyname => 'western union',
101 shortname => 'Western Union', # initial payment, then billing
102 longname => 'Western Union',
103 cust_main => '', #this is a payment type only
107 shortname => 'IDT Payment Services',
108 longname => 'IDT Payment Services',
109 cust_main => '', #this is a payment type only
111 'MCRD' => { #not the same as DCRD
113 shortname => 'Manual credit card', # initial payment, then billing
114 longname => 'Manual credit card',
115 cust_main => '', #this is a payment type only
117 'MCHK' => { #not the same as DCHK
119 shortname => 'Manual electronic check', # initial payment, then billing
120 longname => 'Manual electronic check',
121 cust_main => '', #this is a payment type only
124 tinyname => 'apple store',
125 shortname => 'Apple Store',
126 longname => 'Apple Store',
127 cust_main => '', #this is a payment type only
130 tinyname => 'android market',
131 shortname => 'Android Market',
132 longname => 'Android Market',
133 cust_main => '', #this is a payment type only
137 shortname => 'Electronic Debit (EDI)',
138 longname => 'Electronic Debit (EDI)',
139 cust_main => '', #not a customer type
143 shortname => 'Wire transfer',
144 longname => 'Wire transfer',
145 cust_main => '', #not a customer type
148 tinyname => 'chargeback',
149 shortname => 'Chargeback',
150 longname => 'Chargeback',
151 cust_main => '', # not a customer type
160 my( $self, $table, $payby ) = @_;
162 #return "Illegal payby" unless $hash{$payby};
163 return 0 unless $hash{$payby};
165 $table = 'cust_pay' if $table =~ /^cust_(pay_pending|pay_batch|pay_void|refund)$/;
166 return 0 if exists( $hash{$payby}->{$table} );
171 sub realtime { # can use realtime payment facilities
172 my( $self, $payby ) = @_;
174 return 0 unless $hash{$payby};
175 return 0 unless exists( $hash{$payby}->{realtime} );
177 return $hash{$payby}->{realtime};
180 sub payby2shortname {
182 map { $_ => $hash{$_}->{shortname} } $self->payby;
187 map { $_ => $hash{$_}->{longname} } $self->payby;
191 my( $self, $payby ) = @_;
192 $hash{$payby}->{shortname};
196 my( $self, $payby ) = @_;
197 #$hash{$payby}->{payname} || $hash{$payby}->{shortname};
198 exists($hash{$payby}->{payname})
199 ? $hash{$payby}->{payname}
200 : $hash{$payby}->{shortname};
204 my( $self, $payby ) = @_;
205 $hash{$payby}->{longname};
211 'MCRD' => 'CC', #? but doesn't MCRD mean _offline_ card? i think it got
212 # overloaded for third-party card payments -- but no one is
213 # doing those other than paypal now
218 my( $self, $payby ) = @_;
219 $payby2bop{ $self->payby2payment($payby) };
223 my( $self, $payby ) = @_;
224 $hash{$payby}{'cust_pay'} || $payby;
229 grep { ! exists $hash{$_}->{cust_main} } $self->payby;
232 sub cust_payby2shortname {
234 map { $_ => $hash{$_}->{shortname} } $self->cust_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;
264 =item payment_payby2payname
266 Returns hash, keys are L</payment_payby> types, values are payby payname.
270 sub payment_payby2payname {
272 map { $_ => $self->payname($_) } $self->payment_payby;
279 This should eventually be an actual database table, and all tables that
280 currently have a char payby field should have a foreign key into here instead.