1 package FS::payment_gateway;
4 use vars qw( @ISA $me $DEBUG );
5 use FS::Record qw( qsearch qsearchs dbh );
7 use FS::agent_payment_gateway;
9 @ISA = qw( FS::option_Common );
10 $me = '[ FS::payment_gateway ]';
15 FS::payment_gateway - Object methods for payment_gateway records
19 use FS::payment_gateway;
21 $record = new FS::payment_gateway \%hash;
22 $record = new FS::payment_gateway { 'column' => 'value' };
24 $error = $record->insert;
26 $error = $new_record->replace($old_record);
28 $error = $record->delete;
30 $error = $record->check;
34 An FS::payment_gateway object represents an payment gateway.
35 FS::payment_gateway inherits from FS::Record. The following fields are
40 =item gatewaynum - primary key
42 =item gateway_namespace - Business::OnlinePayment or Business::OnlineThirdPartyPayment
44 =item gateway_module - Business::OnlinePayment:: module name
46 =item gateway_username - payment gateway username
48 =item gateway_password - payment gateway password
50 =item gateway_action - optional action or actions (multiple actions are separated with `,': for example: `Authorization Only, Post Authorization'). Defaults to `Normal Authorization'.
52 =item disabled - Disabled flag, empty or 'Y'
62 Creates a new payment gateway. To add the payment gateway to the database, see
65 Note that this stores the hash reference, not a distinct copy of the hash it
66 points to. You can ask the object for a copy with the I<hash> method.
70 # the new method can be inherited from FS::Record, if a table method is defined
72 sub table { 'payment_gateway'; }
76 Adds this record to the database. If there is an error, returns the error,
77 otherwise returns false.
81 # the insert method can be inherited from FS::Record
85 Delete this record from the database.
89 # the delete method can be inherited from FS::Record
91 =item replace OLD_RECORD
93 Replaces the OLD_RECORD with this one in the database. If there is an error,
94 returns the error, otherwise returns false.
98 # the replace method can be inherited from FS::Record
102 Checks all fields to make sure this is a valid payment gateway. If there is
103 an error, returns the error, otherwise returns false. Called by the insert
108 # the check method should currently be supplied - FS::Record contains some
109 # data checking routines
115 $self->ut_numbern('gatewaynum')
116 || $self->ut_alpha('gateway_module')
117 || $self->ut_enum('gateway_namespace', ['Business::OnlinePayment',
118 'Business::OnlineThirdPartyPayment',
120 || $self->ut_textn('gateway_username')
121 || $self->ut_anything('gateway_password')
122 || $self->ut_textn('gateway_callback_url') # a bit too permissive
123 || $self->ut_enum('disabled', [ '', 'Y' ] )
124 #|| $self->ut_textn('gateway_action')
126 return $error if $error;
128 if ( $self->gateway_action ) {
129 my @actions = split(/,\s*/, $self->gateway_action);
130 $self->gateway_action(
131 join( ',', map { /^(Normal Authorization|Authorization Only|Credit|Post Authorization)$/
132 or return "Unknown action $_";
139 $self->gateway_action('Normal Authorization');
142 # this little kludge mimics FS::CGI::popurl
143 $self->gateway_callback_url($self->gateway_callback_url. '/')
144 if ( $self->gateway_callback_url && $self->gateway_callback_url !~ /\/$/ );
149 =item agent_payment_gateway
151 Returns any agent overrides for this payment gateway.
155 sub agent_payment_gateway {
157 qsearch('agent_payment_gateway', { 'gatewaynum' => $self->gatewaynum } );
162 Disables this payment gateway: deletes all associated agent_payment_gateway
163 overrides and sets the I<disabled> field to "B<Y>".
170 local $SIG{HUP} = 'IGNORE';
171 local $SIG{INT} = 'IGNORE';
172 local $SIG{QUIT} = 'IGNORE';
173 local $SIG{TERM} = 'IGNORE';
174 local $SIG{TSTP} = 'IGNORE';
175 local $SIG{PIPE} = 'IGNORE';
177 my $oldAutoCommit = $FS::UID::AutoCommit;
178 local $FS::UID::AutoCommit = 0;
181 foreach my $agent_payment_gateway ( $self->agent_payment_gateway ) {
182 my $error = $agent_payment_gateway->delete;
184 $dbh->rollback if $oldAutoCommit;
185 return "error deleting agent_payment_gateway override: $error";
189 $self->disabled('Y');
190 my $error = $self->replace();
192 $dbh->rollback if $oldAutoCommit;
193 return "error disabling payment_gateway: $error";
196 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
201 =item namespace_description
203 returns a friendly name for the namespace
207 my %namespace2description = (
209 'Business::OnlinePayment' => 'Direct',
210 'Business::OnlineThirdPartyPayment' => 'Hosted',
213 sub namespace_description {
214 $namespace2description{shift->gateway_namespace} || 'Unknown';
219 # Used by FS::Upgrade to migrate to a new database.
224 my ($class, %opts) = @_;
227 warn "$me upgrading $class\n" if $DEBUG;
229 foreach ( qsearch( 'payment_gateway', { 'gateway_namespace' => '' } ) ) {
230 $_->gateway_namespace('Business::OnlinePayment'); #defaulting
231 my $error = $_->replace;
232 die "$class had error during upgrade replacement: $error" if $error;
242 L<FS::Record>, schema.html from the base documentation.