+=item payby_payinfo_pretty [ LOCALE ]
+
+Returns payment method and information (suitably masked, if applicable) as
+a human-readable string, such as:
+
+ Card #54xxxxxxxxxxxx32
+
+or
+
+ Check #119006
+
+=cut
+
+sub payby_payinfo_pretty {
+ my $self = shift;
+ my $locale = shift;
+ my $lh = FS::L10N->get_handle($locale);
+ if ( $self->payby eq 'CARD' ) {
+ if ($self->paymask =~ /tokenized/) {
+ $lh->maketext('Tokenized Card');
+ } else {
+ $lh->maketext('Card #') . $self->paymask;
+ }
+ } elsif ( $self->payby eq 'CHEK' ) {
+
+ #false laziness w/view/cust_main/payment_history.html::translate_payinfo
+ my( $account, $aba ) = split('@', $self->paymask );
+
+ if ( $aba =~ /^(\d{5})\.(\d{3})$/ ) { #blame canada
+ my($branch, $routing) = ($1, $2);
+ $lh->maketext("Routing [_1], Branch [_2], Acct [_3]",
+ $routing, $branch, $account);
+ } else {
+ $lh->maketext("Routing [_1], Acct [_2]", $aba, $account);
+ }
+
+ } elsif ( $self->payby eq 'BILL' ) {
+ $lh->maketext('Check #') . $self->payinfo;
+ } elsif ( $self->payby eq 'PREP' ) {
+ $lh->maketext('Prepaid card #') . $self->payinfo;
+ } elsif ( $self->payby eq 'CASH' ) {
+ $lh->maketext('Cash') . ' ' . $self->payinfo;
+ } elsif ( $self->payby eq 'WEST' ) {
+ # does Western Union localize their name?
+ $lh->maketext('Western Union');
+ } elsif ( $self->payby eq 'MCRD' ) {
+ $lh->maketext('Manual credit card');
+ } elsif ( $self->payby eq 'MCHK' ) {
+ $lh->maketext('Manual electronic check');
+ } elsif ( $self->payby eq 'EDI' ) {
+ $lh->maketext('EDI') . ' ' . $self->paymask;
+ } elsif ( $self->payby eq 'PPAL' ) {
+ $lh->maketext('PayPal transaction#') . $self->order_number;
+ } else {
+ $self->payby. ' '. $self->payinfo;
+ }
+}
+
+=item payinfo_used [ PAYINFO ]
+
+Returns 1 if there's an existing payment using this payinfo. This can be
+used to set the 'recurring payment' flag required by some processors.
+
+=cut
+
+sub payinfo_used {
+ my $self = shift;
+ my $payinfo = shift || $self->payinfo;
+ my %hash = (
+ 'custnum' => $self->custnum,
+ 'payby' => $self->payby,
+ );
+
+ return 1
+ if qsearch('cust_pay', { %hash, 'payinfo' => $payinfo } )
+ || qsearch('cust_pay', { %hash, 'paymask' => $self->mask_payinfo } )
+ ;
+
+ return 0;
+}
+
+=item display_status
+
+For transactions that have both 'status' and 'failure_status', shows the
+status in a single, display-friendly string.
+
+=cut
+
+sub display_status {
+ my $self = shift;
+ my %status = (
+ 'done' => 'Approved',
+ 'expired' => 'Card Expired',
+ 'stolen' => 'Lost/Stolen',
+ 'pickup' => 'Pick Up Card',
+ 'nsf' => 'Insufficient Funds',
+ 'inactive' => 'Inactive Account',
+ 'blacklisted' => 'Blacklisted',
+ 'declined' => 'Declined',
+ 'approved' => 'Approved',
+ );
+ if ( $self->failure_status ) {
+ return $status{$self->failure_status};
+ } else {
+ return $status{$self->status};
+ }
+}
+
+=item paydate_monthyear