1 package Business::OnlinePayment::IPPay;
10 use HTTP::Request::Common qw (POST);
11 use Date::Calc qw(Add_Delta_YM Add_Delta_Days);
12 use Business::OnlinePayment;
13 use Business::OnlinePayment::HTTPS;
14 use vars qw($VERSION $DEBUG @ISA $me);
16 @ISA = qw(Business::OnlinePayment::HTTPS);
19 $me = 'Business::OnlinePayment::IPPay';
25 # standard B::OP methods/data
26 $self->server('test1.jetpay.com') unless $self->server;
27 $self->port('443') unless $self->port;
28 $self->path('/jetpay') unless $self->path;
30 $self->build_subs(qw( order_number avs_code cvv2_response
31 response_page response_code response_headers
34 # module specific data
36 $self->debug( $opts{debug} );
41 foreach my $key (keys %opts) {
42 $key =~ /^default_(\w*)$/ or next;
43 $_defaults{$1} = $opts{$key};
46 $self->{_defaults} = \%_defaults;
52 my %content = $self->content();
55 my %types = ( 'visa' => 'CC',
57 'american express' => 'CC',
61 $content{'type'} = $types{lc($content{'type'})} || $content{'type'};
62 $self->transaction_type($content{'type'});
65 my $action = lc($content{'action'});
67 ( 'normal authorization' => 'SALE',
68 'authorization only' => 'AUTHONLY',
69 'post authorization' => 'CAPT',
74 ( 'normal authorization' => 'CHECK',
76 'credit' => 'REVERSAL',
78 if ($self->transaction_type eq 'CC') {
79 $content{'TransactionType'} = $actions{$action} || $action;
80 }elsif ($self->transaction_type eq 'ECHECK') {
81 $content{'TransactionType'} = $check_actions{$action} || $action;
86 my %account_types = ('personal checking' => 'Checking',
87 'personal savings' => 'Savings',
88 'business checking' => 'BusinessCk',
90 $content{'account_type'} = $account_types{lc($content{'account_type'})}
91 || $content{'account_type'};
93 $content{Origin} = 'RECURRING'
94 if ($content{recurring_billing} &&$content{recurring_billing} eq 'YES' );
96 # stuff it back into %content
97 $self->content(%content);
102 my ($self, $exp) = (shift, shift);
104 if ( defined($exp) and $exp =~ /^(\d+)\D+\d*\d{2}$/ ) {
105 $month = sprintf( "%02d", $1 );
106 }elsif ( defined($exp) and $exp =~ /^(\d{2})\d{2}$/ ) {
107 $month = sprintf( "%02d", $1 );
113 my ($self, $exp) = (shift, shift);
115 if ( defined($exp) and $exp =~ /^\d+\D+\d*(\d{2})$/ ) {
116 $year = sprintf( "%02d", $1 );
117 }elsif ( defined($exp) and $exp =~ /^\d{2}(\d{2})$/ ) {
118 $year = sprintf( "%02d", $1 );
125 tie my(%map), 'Tie::IxHash', @_;
126 my %content = $self->content();
129 if ( ref( $map{$_} ) eq 'HASH' ) {
130 $value = $map{$_} if ( keys %{ $map{$_} } );
131 }elsif( ref( $map{$_} ) ) {
132 $value = ${ $map{$_} };
133 }elsif( exists( $content{ $map{$_} } ) ) {
134 $value = $content{ $map{$_} };
137 if (defined($value)) {
148 $self->is_success(0);
151 my @required_fields = qw(action login type);
153 my $action = lc($self->{_content}->{action});
154 my $type = $self->transaction_type();
155 if ( $action eq 'normal authorization'
156 || $action eq 'credit'
157 || $action eq 'authorization only' && $type eq 'CC')
159 push @required_fields, qw( amount );
161 push @required_fields, qw( card_number expiration )
164 push @required_fields,
165 qw( routing_code account_number name ) # account_type
166 if ($type eq "ECHECK");
168 }elsif ( $action eq 'post authorization' && $type eq 'CC') {
169 push @required_fields, qw( order_number );
170 }elsif ( $action eq 'void') {
171 push @required_fields, qw( order_number amount );
173 push @required_fields, qw( authorization card_number )
176 push @required_fields,
177 qw( routing_code account_number name ) # account_type
178 if ($type eq "ECHECK");
181 croak "$me can't handle transaction type: ".
182 $self->{_content}->{action}. " for ".
183 $self->transaction_type();
186 my %content = $self->content();
187 foreach ( keys ( %{($self->{_defaults})} ) ) {
188 $content{$_} = $self->{_defaults}->{$_} unless exists($content{$_});
190 $self->content(%content);
192 $self->required_fields(@required_fields);
194 my $transaction_id = $content{'order_number'};
195 unless ($transaction_id) {
196 my ($page, $server_response, %headers) = $self->https_get('dummy' => 1);
197 return unless $server_response=~ /^200/;
198 $transaction_id = $page;
201 my $cardexpmonth = $self->expdate_month($content{expiration});
202 my $cardexpyear = $self->expdate_year($content{expiration});
203 my $cardstartmonth = $self->expdate_month($content{card_start});
204 my $cardstartyear = $self->expdate_year($content{card_start});
207 if (defined($content{amount})) {
208 $amount = sprintf("%.2f", $content{amount});
212 my $check_number = $content{check_number} || "100" # make one up
213 if($content{account_number});
215 my $terminalid = $content{login} if $type eq 'CC';
216 my $merchantid = $content{login} if $type eq 'ECHECK';
218 tie my %ach, 'Tie::IxHash',
219 $self->revmap_fields(
220 #AccountType => 'account_type',
221 AccountNumber => 'account_number',
222 ABA => 'routing_code',
223 CheckNumber => \$check_number,
226 tie my %industryinfo, 'Tie::IxHash',
227 $self->revmap_fields(
228 Type => 'IndustryInfo',
231 tie my %shippingaddr, 'Tie::IxHash',
232 $self->revmap_fields(
233 Address => 'ship_address',
235 StateProv => 'ship_state',
236 Country => 'ship_country',
237 Phone => 'ship_phone',
240 tie my %shippinginfo, 'Tie::IxHash',
241 $self->revmap_fields(
242 CustomerPO => 'CustomerPO',
243 ShippingMethod => 'ShippingMethod',
244 ShippingName => 'ship_name',
245 ShippingAddr => \%shippingaddr,
248 tie my %req, 'Tie::IxHash',
249 $self->revmap_fields(
250 TransactionType => 'TransactionType',
251 TerminalID => 'login',
252 # TerminalID => \$terminalid,
253 # MerchantID => \$merchantid,
254 TransactionID => \$transaction_id,
255 RoutingCode => 'RoutingCode',
256 Approval => 'authorization',
257 BatchID => 'BatchID',
259 Password => 'password',
260 OrderNumber => 'invoice_number',
261 CardNum => 'card_number',
263 Issue => 'issue_number',
264 CardExpMonth => \$cardexpmonth,
265 CardExpYear => \$cardexpyear,
266 CardStartMonth => \$cardstartmonth,
267 CardStartYear => \$cardstartyear,
272 DispositionType => 'DispositionType',
273 TotalAmount => \$amount,
274 FeeAmount => 'FeeAmount',
275 TaxAmount => 'TaxAmount',
276 BillingAddress => 'address',
277 BillingCity => 'city',
278 BillingStateProv => 'state',
279 BillingPostalCode => 'zip',
280 BillingCountry => 'country',
281 BillingPhone => 'phone',
283 UserIPAddr => 'customer_ip',
284 UserHost => 'UserHost',
285 UDField1 => 'UDField1',
286 UDField2 => 'UDField2',
287 UDField3 => 'UDField3',
288 ActionCode => 'ActionCode',
289 IndustryInfo => \%industryinfo,
290 ShippingInfo => \%shippinginfo,
294 my $writer = new XML::Writer( OUTPUT => \$post_data,
297 ENCODING => 'us-ascii',
300 $writer->startTag('JetPay');
301 foreach ( keys ( %req ) ) {
302 $self->_xmlwrite($writer, $_, $req{$_});
304 $writer->endTag('JetPay');
307 if ($self->test_transaction()) {
308 $self->server('test1.jetpay.com');
310 $self->path('/jetpay');
313 warn "$post_data\n" if $DEBUG;
315 my ($page,$server_response,%headers) = $self->https_post($post_data);
317 warn "$page\n" if $DEBUG;
320 if ($server_response =~ /^200/){
321 $response = XMLin($page);
322 if ( exists($response->{ActionCode}) && !exists($response->{ErrMsg})) {
323 $self->error_message($response->{ResponseText});
325 $self->error_message($response->{Errmsg});
328 # $self->error_message("Server Failed");
331 $self->result_code($response->{ActionCode} || '');
332 $self->order_number($response->{TransactionID} || '');
333 $self->authorization($response->{Approval} || '');
334 $self->cvv2_response($response->{CVV2} || '');
335 $self->avs_code($response->{AVS} || '');
337 $self->is_success($self->result_code() eq '000' ? 1 : 0);
339 unless ($self->is_success()) {
340 unless ( $self->error_message() ) { #additional logging information
341 $self->error_message(
342 "(HTTPS response: $server_response) ".
344 join(", ", map { "$_ => ". $headers{$_} } keys %headers ). ") ".
345 "(Raw HTTPS content: $page)"
353 my ($self, $writer, $item, $value) = @_;
354 $writer->startTag($item);
355 if ( ref( $value ) eq 'HASH' ) {
356 foreach ( keys ( %$value ) ) {
357 $self->_xmlwrite($writer, $_, $value->{$_});
360 $writer->characters($value);
362 $writer->endTag($item);
370 Business::OnlinePayment::IPPay - IPPay backend for Business::OnlinePayment
374 use Business::OnlinePayment;
377 new Business::OnlinePayment( "IPPay",
378 'default_Origin' => 'PHONE ORDER',
382 login => 'testdrive',
383 password => '', #password
384 action => 'Normal Authorization',
385 description => 'Business::OnlinePayment test',
387 customer_id => 'tfb',
388 name => 'Tofu Beast',
389 address => '123 Anystreet',
393 card_number => '4007000000027',
394 expiration => '09/02',
395 cvv2 => '1234', #optional
399 if($tx->is_success()) {
400 print "Card processed successfully: ".$tx->authorization."\n";
402 print "Card was rejected: ".$tx->error_message."\n";
405 =head1 SUPPORTED TRANSACTION TYPES
407 =head2 CC, Visa, MasterCard, American Express, Discover
409 Content required: type, login, action, amount, card_number, expiration.
413 Content required: type, login, action, amount, name, account_number, routing_code.
417 For detailed information see L<Business::OnlinePayment>.
419 =head1 METHODS AND FUNCTIONS
421 See L<Business::OnlinePayment> for the complete list. The following methods either override the methods in L<Business::OnlinePayment> or provide additional functions.
425 Returns the response error code.
429 Returns the response error description text.
431 =head2 server_response
433 Returns the complete response from the server.
435 =head1 Handling of content(%content) data:
439 The following actions are valid
447 =head1 Setting IPPay parameters from content(%content)
449 The following rules are applied to map data to IPPay parameters
450 from content(%content):
452 # param => $content{<key>}
453 TransactionType => 'TransactionType',
454 TerminalID => 'login',
455 TransactionID => 'order_number',
456 RoutingCode => 'RoutingCode',
457 Approval => 'authorization',
458 BatchID => 'BatchID',
460 Password => 'password',
461 OrderNumber => 'invoice_number',
462 CardNum => 'card_number',
464 Issue => 'issue_number',
465 CardExpMonth => \( $month ), # MM from MM(-)YY(YY) of 'expiration'
466 CardExpYear => \( $year ), # YY from MM(-)YY(YY) of 'expiration'
467 CardStartMonth => \( $month ), # MM from MM(-)YY(YY) of 'card_start'
468 CardStartYear => \( $year ), # YY from MM(-)YY(YY) of 'card_start'
472 AccountNumber => 'account_number',
473 ABA => 'routing_code',
474 CheckNumber => 'check_number',
476 DispositionType => 'DispositionType',
477 TotalAmount => 'amount' reformatted into cents
478 FeeAmount => 'FeeAmount',
479 TaxAmount => 'TaxAmount',
480 BillingAddress => 'address',
481 BillingCity => 'city',
482 BillingStateProv => 'state',
483 BillingPostalCode => 'zip',
484 BillingCountry => 'country',
485 BillingPhone => 'phone',
487 UserIPAddr => 'customer_ip',
488 UserHost => 'UserHost',
489 UDField1 => 'UDField1',
490 UDField2 => 'UDField2',
491 UDField3 => 'UDField3',
492 ActionCode => 'ActionCode',
494 Type => 'IndustryInfo',
496 CustomerPO => 'CustomerPO',
497 ShippingMethod => 'ShippingMethod',
498 ShippingName => 'ship_name',
500 Address => 'ship_address',
502 StateProv => 'ship_state',
503 Country => 'ship_country',
504 Phone => 'ship_phone',
510 Business::OnlinePayment::IPPay uses IPPay XML Product Specifications version
513 See http://www.ippay.com/ for more information.
517 Jeff Finucane, ippay@weasellips.com
521 perl(1). L<Business::OnlinePayment>.