RT# 80175 - updated payment gateway override to not drop ACH overrides on upgrade
[freeside.git] / FS / FS / agent_payment_gateway.pm
1 package FS::agent_payment_gateway;
2 use base qw(FS::Record);
3 use FS::Record qw( qsearch );
4
5 use strict;
6
7 =head1 NAME
8
9 FS::agent_payment_gateway - Object methods for agent_payment_gateway records
10
11 =head1 SYNOPSIS
12
13   use FS::agent_payment_gateway;
14
15   $record = new FS::agent_payment_gateway \%hash;
16   $record = new FS::agent_payment_gateway { 'column' => 'value' };
17
18   $error = $record->insert;
19
20   $error = $new_record->replace($old_record);
21
22   $error = $record->delete;
23
24   $error = $record->check;
25
26 =head1 DESCRIPTION
27
28 An FS::agent_payment_gateway object represents a payment gateway override for
29 a specific agent.  FS::agent_payment_gateway inherits from FS::Record.  The
30 following fields are currently supported:
31
32 =over 4
33
34 =item agentgatewaynum - primary key
35
36 =item agentnum - 
37
38 =item gatewaynum - 
39
40 =item cardtype - 
41
42 =item taxclass - 
43
44 =back
45
46 =head1 METHODS
47
48 =over 4
49
50 =item new HASHREF
51
52 Creates a new override.  To add the override to the database, see L<"insert">.
53
54 Note that this stores the hash reference, not a distinct copy of the hash it
55 points to.  You can ask the object for a copy with the I<hash> method.
56
57 =cut
58
59 # the new method can be inherited from FS::Record, if a table method is defined
60
61 sub table { 'agent_payment_gateway'; }
62
63 =item insert
64
65 Adds this record to the database.  If there is an error, returns the error,
66 otherwise returns false.
67
68 =cut
69
70 # the insert method can be inherited from FS::Record
71
72 =item delete
73
74 Delete this record from the database.
75
76 =cut
77
78 # the delete method can be inherited from FS::Record
79
80 =item replace OLD_RECORD
81
82 Replaces the OLD_RECORD with this one in the database.  If there is an error,
83 returns the error, otherwise returns false.
84
85 =cut
86
87 # the replace method can be inherited from FS::Record
88
89 =item check
90
91 Checks all fields to make sure this is a valid override.  If there is
92 an error, returns the error, otherwise returns false.  Called by the insert
93 and replace methods.
94
95 =cut
96
97 # the check method should currently be supplied - FS::Record contains some
98 # data checking routines
99
100 sub check {
101   my $self = shift;
102
103   my $error = 
104     $self->ut_numbern('agentgatewaynum')
105     || $self->ut_foreign_key('agentnum', 'agent', 'agentnum')
106     || $self->ut_foreign_key('gatewaynum', 'payment_gateway', 'gatewaynum' )
107     || $self->ut_textn('cardtype')
108     || $self->ut_textn('taxclass')
109   ;
110   return $error if $error;
111
112   $self->SUPER::check;
113 }
114
115 sub _upgrade_data {
116   # to simplify tokenization upgrades
117   die "Agent taxclass override no longer supported"
118     if qsearch({
119       'table' => 'agent_payment_gateway',
120       'extra_sql' => ' WHERE taxclass IS NOT NULL AND taxclass != \'\'',
121     });
122   die "Non ACH (E-check) Agent cardtype override no longer supported"
123     if qsearch({
124       'table' => 'agent_payment_gateway',
125       'extra_sql' => ' WHERE cardtype IS NOT NULL AND cardtype != \'\' AND cardtype != \'ACH\'',
126     });
127   return '';
128 }
129
130 =item payment_gateway
131
132 =back
133
134 =head1 BUGS
135
136 =head1 SEE ALSO
137
138 L<FS::payment_gateway>, L<FS::agent>, L<FS::Record>, schema.html from the
139 base documentation.
140
141 =cut
142
143 1;
144