1 # Vend::Payment::BusinessOnlinePayment - Interchange wrapper for
2 # Business::OnlinePayment modules
4 # Copyright (C) 2004 Ivan Kohler. All rights reserved.
6 # This program is free software; you can redistribute it and/or modify it
7 # under the same terms as Perl itself.
9 # Ivan Kohler <ivan-interchange@420.am>
11 package Vend::Payment::BusinessOnlinePayment;
15 Vend::Payment::BusinessOnlinePayment - Interchange wrapper for Business::OnlinePayment
23 [charge mode=onlinepayment param1=value1 param2=value2]
27 Business::OnlinePayment
28 Business::OnlinePayment:: gateway module
30 See L<http://www.420.am/business-onlinepayment/> or
31 L<http://search.cpan.org/search?query=Business%3A%3AOnlinePayment&mode=module>
35 This is a wrapper around Business::OnlinePayment for Interchange.
37 The Vend::Payment::BusinessOnlinePayment module implements the onlinepayment()
38 routine for use with Interchange. It is compatible on a call level with the
39 other Interchange payment modules. In theory (and even usually in practice)
40 you could switch from another gateway to a Business::OnlinePayment supported
41 gateway (or between different Business::OnlinePayment gateways) with a few
42 configuration file changes.
44 Business::OnlinePayment is a set of related Perl modules for processing online
45 payments (credit cards, electronic checks, and other payment systems). It
46 provides a consistant interface for processing online payments, regardless of
47 the gateway backend being used, in the same way that DBI provides an consistant
48 interface to different databases.
50 See L<http://www.420.am/business-onlinepayment/> for more information and
53 It is hoped that a future version of Interchange will do all credit card
54 processing through Business::OnlinePayment, but this is my no means
55 guaranteed and the timeframe is unknown. Think ALSA somewhere around
56 Linux 2.2 and you've got the general idea.
58 Currently this module is recommended for people with gateway processors
59 unsupported by a native Interchange Vend::Payment:: module and for the
64 To enable this module, place this directive in C<interchange.cfg>:
66 Require module Vend::Payment::BusinessOnlinePayment
68 This I<must> be in interchange.cfg or a file included from it.
70 The mode can be named anything, but the C<gateway> parameter must be set
71 to C<onlinepayment>. To make it the default payment gateway for all credit
72 card transactions in a specific catalog, you can set in C<catalog.cfg>:
74 Variable MV_PAYMENT_MODE onlinepayment
76 It uses several of the standard settings from Interchange payment. Any time
77 we speak of a setting, it is obtained either first from the tag/call options,
78 then from an Interchange order Route named for the mode, then finally a
79 default global payment variable, For example, the C<setting> parameter would
82 [charge mode=onlinepayment setting=value]
86 Route onlinepayment setting value
90 Variable MV_PAYMENT_SETTING value
92 The following settings are available:
98 Your Business::OnlinePayment processor.
102 Your Business::OnlinePayment login.
106 Your Busienss::OnlinePayment password.
110 The type of transaction to be run. Valid values are:
112 Interchange Business::OnlinePayment
113 ---------------- -----------------------
114 auth Authorization Only
117 sale Normal Authorization
118 settle Post Authorization
123 Set this true if you wish to operate in test mode. Make sure to verify
124 that your specific Business::OnlinePayment:: gateway module supports a
129 In addition, any other processor options are passed to your gateway. See
130 the documentation for your specific Business::OnlinePayment:: gateway module
131 for details on what options are required, if any.
135 Ivan Kohler <ivan-interchange@420.am>
137 Initial development of this module was sponsored in part by Simply Marketing,
138 Inc. <http://www.simplymarketinginc.com/>.
142 Copyright 2004 Ivan Kohler. All rights reserved.
144 This program is free software; you can redistribute it and/or modify it
145 under the same terms as Perl itself.
151 package Vend::Payment;
153 use vars qw( $VERSION );
154 use Business::OnlinePayment;
158 my $default_avs = q{You must enter the correct billing address of your credit }.
159 q{card. The bank returned the following error: %s};
161 my $default_declined = "error: %s. Please call in your order or try again.";
164 my ($user, $amount) = @_;
172 $secret = $opt->{secret};
175 my $actual = $opt->{actual} || { map_actual() };
177 $user ||= charge_param('id')
178 or return ( MStatus => 'failure-hard',
179 MErrMsg => errmsg('No account id'),
182 $secret ||= charge_param('secret');
184 my $precision = $opt->{precision} || 2;
186 my $referer = $opt->{referer} || charge_param('referer');
188 $actual->{$_} = $opt->{$_}
189 foreach grep defined($opt->{$_}), qw(
192 mv_credit_card_exp_month
193 mv_credit_card_exp_year
194 mv_credit_card_number
197 $actual->{mv_credit_card_exp_month} =~ s/\D//g;
198 $actual->{mv_credit_card_exp_year} =~ s/\D//g;
199 $actual->{mv_credit_card_exp_year} =~ s/\d\d(\d\d)/$1/;
200 $actual->{mv_credit_card_number} =~ s/\D//g;
202 my $exp = sprintf '%02d/%02d', $actual->{mv_credit_card_exp_month},
203 $actual->{mv_credit_card_exp_year};
206 'auth' => 'Authorization Only',
207 'return' => 'Credit',
209 'sale' => 'Normal Authorization',
210 'settle' => 'Post Authorization',
214 my $action = $ic2bop{$opt->{transaction} || 'sale'};
216 $amount = $opt->{total_cost} if $opt->{total_cost};
219 $amount = Vend::Interpolate::total_cost();
220 $amount = Vend::Util::round_to_frac_digits($amount, $precision);
223 my $order_id = gen_order_id($opt);
225 my $processor = charge_param('processor');
228 my %ignore = map { $_=>1 } qw(gateway processor id secret transaction );
229 my %options = map { $_=>1 }
230 grep { !$ignore{$_} } (
232 map { s/^MV_PAYMENT_//; lc($_); }
233 grep { /^MV_PAYMENT_/ }
234 keys %$main::Variable
238 new Business::OnlinePayment ( $processor, %options );
240 $transaction->test_transaction($opt->{test} || charge_param('test'));
242 $actual->{$_} =~ s/[\n\r]//g foreach keys %$actual;
244 $transaction->content(
247 'password' => $secret,
251 'card_number' => $actual->{mv_credit_card_number},
252 'expiration' => $exp,
253 'cvv2' => $actual->{cvv2},
254 'order_number' => $actual->{order_id},
255 'auth_code' => $actual->{auth_code},
257 'invoice_number' => $actual->{mv_order_number},
259 'last_name' => $actual->{b_lname},
260 'first_name' => $actual->{b_fname},
261 'name' => $actual->{b_fname}. ' '. $actual->{b_lname},
262 'company' => $actual->{b_company},
263 'address' => $actual->{b_address},
264 'city' => $actual->{b_city},
265 'state' => $actual->{b_state},
266 'zip' => $actual->{b_zip},
267 'country' => $actual->{b_country},
268 'ship_last_name' => $actual->{lname},
269 'ship_first_name' => $actual->{fname},
270 'ship_name' => $actual->{fname}. ' '. $actual->{lname},
271 'ship_company' => $actual->{company},
272 'ship_address' => $actual->{address},
273 'ship_city' => $actual->{city},
274 'ship_state' => $actual->{state},
275 'ship_zip' => $actual->{zip},
276 'ship_country' => $actual->{country},
277 'referer' => $referer,
278 'email' => $actual->{email},
279 'phone' => $actual->{phone_day},
282 $transaction->submit();
285 if ( $transaction->is_success() ) {
287 $result{MStatus} = 'success';
288 $result{'order-id'} = $transaction->order_number || $opt->{'order_id'};
292 $result{MStatus} = 'failure';
293 delete $result{'order-id'};
295 if ( 0 ) { #need a standard Business::OnlinePayment way to ask about AVS
296 $result{MErrMsg} = errmsg(
297 $opt->{'message_avs'} || $default_avs,
298 $transaction->error_message
301 $result{MErrMsg} = errmsg(
302 $opt->{'message_declined'} || "$processor $default_declined",
303 $transaction->error_message