RT# 77332 - Fixed error where all packages updated with new next bill date, instead...
[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 realtime result fields (gatewaynum, processor, authorization,
27 order_number).  Currently FS::cust_pay, FS::cust_refund, and FS::cust_pay_void.
28
29 =head1 METHODS
30
31 =over 4
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 # We keep _parse_paybatch just because the upgrade needs it.
60
61 sub _parse_paybatch {
62   my $self = shift;
63
64   $self->paybatch =~ /^((\d+)\-)?(\w+):\s*([\w\-\/ ]*)(:([\w\-]+))?$/
65     or return {};
66               #"Can't parse paybatch for paynum $options{'paynum'}: ".
67               #  $cust_pay->paybatch;
68
69   my( $gatewaynum, $processor, $auth, $order_number ) = ( $2, $3, $4, $6 );
70
71   if ( $gatewaynum ) { #gateway for the payment to be refunded
72
73     my $payment_gateway =
74       qsearchs('payment_gateway', { 'gatewaynum' => $gatewaynum } );
75
76     $processor = $payment_gateway->gateway_module if $payment_gateway;
77
78   }
79
80   {
81     'gatewaynum'    => $gatewaynum,
82     'processor'     => $processor,
83     'authorization' => $auth,
84     'order_number'  => $order_number,
85   };
86
87 }
88
89 # because we can't actually name the field 'authorization' (reserved word)
90 sub authorization {
91   my $self = shift;
92   $self->auth(@_);
93 }
94
95 =item payinfo_check
96
97 Checks the validity of the realtime payment fields (gatewaynum, processor,
98 auth, and order_number) as well as payby and payinfo
99
100 =cut
101
102 sub payinfo_check {
103   my $self = shift;
104
105   # All of these can be null, so in principle this could go in payinfo_Mixin.
106
107   $self->SUPER::payinfo_check()
108   || $self->ut_numbern('gatewaynum')
109   # not ut_foreign_keyn, it causes upgrades to fail
110   || $self->ut_alphan('processor')
111   || $self->ut_textn('auth')
112   || $self->ut_textn('order_number')
113   || '';
114 }
115
116 =back
117
118 =head1 SEE ALSO
119
120 L<FS::payinfo_Mixin>
121
122 =cut
123
124 1;