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