This commit was generated by cvs2svn to compensate for changes in r11022,
[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 =item cust_main
33
34 Returns the parent customer object (see L<FS::cust_main>).
35
36 =cut
37
38 sub cust_main {
39   my $self = shift;
40   qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
41 }
42
43 =item payby_name
44
45 Returns a name for the payby field.
46
47 =cut
48
49 sub payby_name {
50   my $self = shift;
51   if ( $self->payby eq 'BILL' ) { #kludge
52     'Check';
53   } else {
54     FS::payby->shortname( $self->payby );
55   }
56 }
57
58 =item gatewaynum
59
60 Returns a gatewaynum for the processing gateway.
61
62 =item processor
63
64 Returns a name for the processing gateway.
65
66 =item authorization
67
68 Returns a name for the processing gateway.
69
70 =item order_number
71
72 Returns a name for the processing gateway.
73
74 =cut
75
76 sub gatewaynum    { shift->_parse_paybatch->{'gatewaynum'}; }
77 sub processor     { shift->_parse_paybatch->{'processor'}; }
78 sub authorization { shift->_parse_paybatch->{'authorization'}; }
79 sub order_number  { shift->_parse_paybatch->{'order_number'}; }
80
81 #sucks that this stuff is in paybatch like this in the first place,
82 #but at least other code can start to use new field names
83 #(code nicked from FS::cust_main::realtime_refund_bop)
84 sub _parse_paybatch {
85   my $self = shift;
86
87   $self->paybatch =~ /^((\d+)\-)?(\w+):\s*([\w\-\/ ]*)(:([\w\-]+))?$/
88     or return {};
89               #"Can't parse paybatch for paynum $options{'paynum'}: ".
90               #  $cust_pay->paybatch;
91
92   my( $gatewaynum, $processor, $auth, $order_number ) = ( $2, $3, $4, $6 );
93
94   if ( $gatewaynum ) { #gateway for the payment to be refunded
95
96     my $payment_gateway =
97       qsearchs('payment_gateway', { 'gatewaynum' => $gatewaynum } );
98
99     die "payment gateway $gatewaynum not found" #?
100       unless $payment_gateway;
101
102     $processor = $payment_gateway->gateway_module;
103
104   }
105
106   {
107     'gatewaynum'    => $gatewaynum,
108     'processor'     => $processor,
109     'authorization' => $auth,
110     'order_number'  => $order_number,
111   };
112
113 }
114
115 =back
116
117 =head1 SEE ALSO
118
119 L<FS::payinfo_Mixin>
120
121 =cut
122
123 1;