1 package FS::payment_gateway;
5 use FS::Record qw( qsearch qsearchs dbh );
7 use FS::agent_payment_gateway;
9 @ISA = qw( FS::option_Common );
13 FS::payment_gateway - Object methods for payment_gateway records
17 use FS::payment_gateway;
19 $record = new FS::payment_gateway \%hash;
20 $record = new FS::payment_gateway { 'column' => 'value' };
22 $error = $record->insert;
24 $error = $new_record->replace($old_record);
26 $error = $record->delete;
28 $error = $record->check;
32 An FS::payment_gateway object represents an payment gateway.
33 FS::payment_gateway inherits from FS::Record. The following fields are
38 =item gatewaynum - primary key
40 =item gateway_module - Business::OnlinePayment:: module name
42 =item gateway_username - payment gateway username
44 =item gateway_password - payment gateway password
46 =item gateway_action - optional action or actions (multiple actions are separated with `,': for example: `Authorization Only, Post Authorization'). Defaults to `Normal Authorization'.
48 =item disabled - Disabled flag, empty or 'Y'
58 Creates a new payment gateway. To add the payment gateway to the database, see
61 Note that this stores the hash reference, not a distinct copy of the hash it
62 points to. You can ask the object for a copy with the I<hash> method.
66 # the new method can be inherited from FS::Record, if a table method is defined
68 sub table { 'payment_gateway'; }
72 Adds this record to the database. If there is an error, returns the error,
73 otherwise returns false.
77 # the insert method can be inherited from FS::Record
81 Delete this record from the database.
85 # the delete method can be inherited from FS::Record
87 =item replace OLD_RECORD
89 Replaces the OLD_RECORD with this one in the database. If there is an error,
90 returns the error, otherwise returns false.
94 # the replace method can be inherited from FS::Record
98 Checks all fields to make sure this is a valid payment gateway. If there is
99 an error, returns the error, otherwise returns false. Called by the insert
104 # the check method should currently be supplied - FS::Record contains some
105 # data checking routines
111 $self->ut_numbern('gatewaynum')
112 || $self->ut_alpha('gateway_module')
113 || $self->ut_textn('gateway_username')
114 || $self->ut_anything('gateway_password')
115 || $self->ut_enum('disabled', [ '', 'Y' ] )
116 #|| $self->ut_textn('gateway_action')
118 return $error if $error;
120 if ( $self->gateway_action ) {
121 my @actions = split(/,\s*/, $self->gateway_action);
122 $self->gateway_action(
123 join( ',', map { /^(Normal Authorization|Authorization Only|Credit|Post Authorization)$/
124 or return "Unknown action $_";
131 $self->gateway_action('Normal Authorization');
137 =item agent_payment_gateway
139 Returns any agent overrides for this payment gateway.
143 sub agent_payment_gateway {
145 qsearch('agent_payment_gateway', { 'gatewaynum' => $self->gatewaynum } );
150 Disables this payment gateway: deletes all associated agent_payment_gateway
151 overrides and sets the I<disabled> field to "B<Y>".
158 local $SIG{HUP} = 'IGNORE';
159 local $SIG{INT} = 'IGNORE';
160 local $SIG{QUIT} = 'IGNORE';
161 local $SIG{TERM} = 'IGNORE';
162 local $SIG{TSTP} = 'IGNORE';
163 local $SIG{PIPE} = 'IGNORE';
165 my $oldAutoCommit = $FS::UID::AutoCommit;
166 local $FS::UID::AutoCommit = 0;
169 foreach my $agent_payment_gateway ( $self->agent_payment_gateway ) {
170 my $error = $agent_payment_gateway->delete;
172 $dbh->rollback if $oldAutoCommit;
173 return "error deleting agent_payment_gateway override: $error";
177 $self->disabled('Y');
178 my $error = $self->replace();
180 $dbh->rollback if $oldAutoCommit;
181 return "error disabling payment_gateway: $error";
184 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
195 L<FS::Record>, schema.html from the base documentation.