refactor payment history slightly, add refund receipts, have "unapplied" refunds...
[freeside.git] / FS / FS / payinfo_transaction_Mixin.pm
1 package FS::payinfo_transaction_Mixin;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::payby;
6 use FS::payinfo_Mixin;
7
8 @ISA = qw( FS::payinfo_Mixin );
9
10 =head1 NAME
11
12 FS::payinfo_transaction_Mixin - Mixin class for records in tables that represent transactions.
13
14 =head1 SYNOPSIS
15
16 package FS::some_table;
17 use vars qw(@ISA);
18 @ISA = qw( FS::payinfo_transaction_Mixin FS::Record );
19
20 =head1 DESCRIPTION
21
22 This is a mixin class for records that represent transactions: that contain
23 payinfo and paybatch.  Currently FS::cust_pay and FS::cust_refund
24
25 =head1 METHODS
26
27 =over 4
28
29
30 =item cust_main
31
32 Returns the parent customer object (see L<FS::cust_main>).
33
34 =cut
35
36 sub cust_main {
37   my $self = shift;
38   qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
39 }
40
41 =item payby_name
42
43 Returns a name for the payby field.
44
45 =cut
46
47 sub payby_name {
48   my $self = shift;
49   if ( $self->payby eq 'BILL' ) { #kludge
50     'Check';
51   } else {
52     FS::payby->shortname( $self->payby );
53   }
54 }
55
56 =item gatewaynum
57
58 Returns a gatewaynum for the processing gateway.
59
60 =item processor
61
62 Returns a name for the processing gateway.
63
64 =item authorization
65
66 Returns a name for the processing gateway.
67
68 =item order_number
69
70 Returns a name for the processing gateway.
71
72 =cut
73
74 sub gatewaynum    { shift->_parse_paybatch->{'gatewaynum'}; }
75 sub processor     { shift->_parse_paybatch->{'processor'}; }
76 sub authorization { shift->_parse_paybatch->{'authorization'}; }
77 sub order_number  { shift->_parse_paybatch->{'order_number'}; }
78
79 #sucks that this stuff is in paybatch like this in the first place,
80 #but at least other code can start to use new field names
81 #(code nicked from FS::cust_main::realtime_refund_bop)
82 sub _parse_paybatch {
83   my $self = shift;
84
85   $self->paybatch =~ /^((\d+)\-)?(\w+):\s*([\w\-\/ ]*)(:([\w\-]+))?$/
86     or return {};
87               #"Can't parse paybatch for paynum $options{'paynum'}: ".
88               #  $cust_pay->paybatch;
89
90   my( $gatewaynum, $processor, $auth, $order_number ) = ( $2, $3, $4, $6 );
91
92   if ( $gatewaynum ) { #gateway for the payment to be refunded
93
94     my $payment_gateway =
95       qsearchs('payment_gateway', { 'gatewaynum' => $gatewaynum } );
96
97     die "payment gateway $gatewaynum not found" #?
98       unless $payment_gateway;
99
100     $processor = $payment_gateway->gateway_module;
101
102   }
103
104   {
105     'gatewaynum'    => $gatewaynum,
106     'processor'     => $processor,
107     'authorization' => $auth,
108     'order_number'  => $order_number,
109   };
110
111 }
112
113
114
115
116 =back
117
118 =head1 SEE ALSO
119
120 L<FS::payinfo_Mixin>
121
122 =back