This commit was generated by cvs2svn to compensate for changes in r4407,
[freeside.git] / FS / FS / payment_gateway.pm
1 package FS::payment_gateway;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw( qsearch qsearchs );
6 use FS::option_Common;
7
8 @ISA = qw( FS::option_Common );
9
10 =head1 NAME
11
12 FS::payment_gateway - Object methods for payment_gateway records
13
14 =head1 SYNOPSIS
15
16   use FS::payment_gateway;
17
18   $record = new FS::payment_gateway \%hash;
19   $record = new FS::payment_gateway { 'column' => 'value' };
20
21   $error = $record->insert;
22
23   $error = $new_record->replace($old_record);
24
25   $error = $record->delete;
26
27   $error = $record->check;
28
29 =head1 DESCRIPTION
30
31 An FS::payment_gateway object represents an payment gateway.
32 FS::payment_gateway inherits from FS::Record.  The following fields are
33 currently supported:
34
35 =over 4
36
37 =item gatewaynum - primary key
38
39 =item gateway_module - Business::OnlinePayment:: module name
40
41 =item gateway_username - payment gateway username
42
43 =item gateway_password - payment gateway password
44
45 =item gateway_action - optional action or actions (multiple actions are separated with `,': for example: `Authorization Only, Post Authorization').  Defaults to `Normal Authorization'.
46
47 =item disabled - Disabled flag, empty or 'Y'
48
49 =back
50
51 =head1 METHODS
52
53 =over 4
54
55 =item new HASHREF
56
57 Creates a new payment gateway.  To add the payment gateway to the database, see
58 L<"insert">.
59
60 Note that this stores the hash reference, not a distinct copy of the hash it
61 points to.  You can ask the object for a copy with the I<hash> method.
62
63 =cut
64
65 # the new method can be inherited from FS::Record, if a table method is defined
66
67 sub table { 'payment_gateway'; }
68
69 =item insert
70
71 Adds this record to the database.  If there is an error, returns the error,
72 otherwise returns false.
73
74 =cut
75
76 # the insert method can be inherited from FS::Record
77
78 =item delete
79
80 Delete this record from the database.
81
82 =cut
83
84 # the delete method can be inherited from FS::Record
85
86 =item replace OLD_RECORD
87
88 Replaces the OLD_RECORD with this one in the database.  If there is an error,
89 returns the error, otherwise returns false.
90
91 =cut
92
93 # the replace method can be inherited from FS::Record
94
95 =item check
96
97 Checks all fields to make sure this is a valid payment gateway.  If there is
98 an error, returns the error, otherwise returns false.  Called by the insert
99 and replace methods.
100
101 =cut
102
103 # the check method should currently be supplied - FS::Record contains some
104 # data checking routines
105
106 sub check {
107   my $self = shift;
108
109   my $error = 
110     $self->ut_numbern('gatewaynum')
111     || $self->ut_alpha('gateway_module')
112     || $self->ut_textn('gateway_username')
113     || $self->ut_anything('gateway_password')
114     || $self->ut_enum('disabled', [ '', 'Y' ] )
115     #|| $self->ut_textn('gateway_action')
116   ;
117   return $error if $error;
118
119   if ( $self->gateway_action ) {
120     my @actions = split(/,\s*/, $self->gateway_action);
121     $self->gateway_action(
122       join( ',', map { /^(Normal Authorization|Authorization Only|Credit|Post Authorization)$/
123                          or return "Unknown action $_";
124                        $1
125                      }
126                      @actions
127           )
128    );
129   } else {
130     $self->gateway_action('Normal Authorization');
131   }
132
133   $self->SUPER::check;
134 }
135
136 =back
137
138 =head1 BUGS
139
140 =head1 SEE ALSO
141
142 L<FS::Record>, schema.html from the base documentation.
143
144 =cut
145
146 1;
147