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