1 package Business::OnlinePayment::IPPay;
9 use Business::OnlinePayment;
10 use Business::OnlinePayment::HTTPS;
11 use vars qw($VERSION $DEBUG @ISA $me);
13 @ISA = qw(Business::OnlinePayment::HTTPS);
15 $VERSION = eval $VERSION; # modperlstyle: convert the string into a number
18 $me = 'Business::OnlinePayment::IPPay';
22 'info_version' => '0.01',
23 'module_version' => $VERSION,
24 'supported_types' => [ qw( CC ECHECK ) ],
25 'supported_actions' => { 'CC' => [
26 'Normal Authorization',
33 'Normal Authorization',
38 'CC_void_requires_card' => 1,
39 'ECHECK_void_requires_account' => 1,
47 # standard B::OP methods/data
48 $self->server('gateway17.jetpay.com') unless $self->server;
49 $self->port('443') unless $self->port;
50 $self->path('/jetpay') unless $self->path;
52 $self->build_subs(qw( order_number avs_code cvv2_response
53 response_page response_code response_headers
56 # module specific data
58 $self->debug( $opts{debug} );
63 foreach my $key (keys %opts) {
64 $key =~ /^default_(\w*)$/ or next;
65 $_defaults{$1} = $opts{$key};
68 $self->{_defaults} = \%_defaults;
74 my %content = $self->content();
77 my %types = ( 'visa' => 'CC',
79 'american express' => 'CC',
83 $content{'type'} = $types{lc($content{'type'})} || $content{'type'};
84 $self->transaction_type($content{'type'});
87 my $action = lc($content{'action'});
89 ( 'normal authorization' => 'SALE',
90 'authorization only' => 'AUTHONLY',
91 'post authorization' => 'CAPT',
96 ( 'normal authorization' => 'CHECK',
98 'credit' => 'REVERSAL',
100 if ($self->transaction_type eq 'CC') {
101 $content{'TransactionType'} = $actions{$action} || $action;
102 }elsif ($self->transaction_type eq 'ECHECK') {
103 $content{'TransactionType'} = $check_actions{$action} || $action;
108 my %account_types = ('personal checking' => 'Checking',
109 'personal savings' => 'Savings',
110 'business checking' => 'BusinessCk',
112 $content{'account_type'} = $account_types{lc($content{'account_type'})}
113 || $content{'account_type'};
115 $content{Origin} = 'RECURRING'
116 if ($content{recurring_billing} &&$content{recurring_billing} eq 'YES' );
118 # stuff it back into %content
119 $self->content(%content);
124 my ($self, $exp) = (shift, shift);
126 if ( defined($exp) and $exp =~ /^(\d+)\D+\d*\d{2}$/ ) {
127 $month = sprintf( "%02d", $1 );
128 }elsif ( defined($exp) and $exp =~ /^(\d{2})\d{2}$/ ) {
129 $month = sprintf( "%02d", $1 );
135 my ($self, $exp) = (shift, shift);
137 if ( defined($exp) and $exp =~ /^\d+\D+\d*(\d{2})$/ ) {
138 $year = sprintf( "%02d", $1 );
139 }elsif ( defined($exp) and $exp =~ /^\d{2}(\d{2})$/ ) {
140 $year = sprintf( "%02d", $1 );
147 tie my(%map), 'Tie::IxHash', @_;
148 my %content = $self->content();
151 if ( ref( $map{$_} ) eq 'HASH' ) {
152 $value = $map{$_} if ( keys %{ $map{$_} } );
153 }elsif( ref( $map{$_} ) ) {
154 $value = ${ $map{$_} };
155 }elsif( exists( $content{ $map{$_} } ) ) {
156 $value = $content{ $map{$_} };
159 if (defined($value)) {
170 $self->is_success(0);
173 my @required_fields = qw(action login type);
175 my $action = lc($self->{_content}->{action});
176 my $type = $self->transaction_type();
177 if ( $action eq 'normal authorization'
178 || $action eq 'credit'
179 || $action eq 'authorization only' && $type eq 'CC')
181 push @required_fields, qw( amount );
183 push @required_fields, qw( card_number expiration )
186 push @required_fields,
187 qw( routing_code account_number name ) # account_type
188 if ($type eq "ECHECK");
190 }elsif ( $action eq 'post authorization' && $type eq 'CC') {
191 push @required_fields, qw( order_number );
192 }elsif ( $action eq 'void') {
193 push @required_fields, qw( order_number amount );
195 push @required_fields, qw( authorization card_number )
198 push @required_fields,
199 qw( routing_code account_number name ) # account_type
200 if ($type eq "ECHECK");
203 croak "$me can't handle transaction type: ".
204 $self->{_content}->{action}. " for ".
205 $self->transaction_type();
208 my %content = $self->content();
209 foreach ( keys ( %{($self->{_defaults})} ) ) {
210 $content{$_} = $self->{_defaults}->{$_} unless exists($content{$_});
212 $self->content(%content);
214 $self->required_fields(@required_fields);
216 if ($self->test_transaction()) {
217 $self->server('test1.jetpay.com');
219 $self->path('/jetpay');
222 my $transaction_id = $content{'order_number'};
223 unless ($transaction_id) {
224 my ($page, $server_response, %headers) = $self->https_get('dummy' => 1);
225 warn "fetched transaction id: (HTTPS response: $server_response) ".
227 join(", ", map { "$_ => ". $headers{$_} } keys %headers ). ") ".
228 "(Raw HTTPS content: $page)"
230 return unless $server_response=~ /^200/;
231 $transaction_id = $page;
234 my $cardexpmonth = $self->expdate_month($content{expiration});
235 my $cardexpyear = $self->expdate_year($content{expiration});
236 my $cardstartmonth = $self->expdate_month($content{card_start});
237 my $cardstartyear = $self->expdate_year($content{card_start});
240 if (defined($content{amount})) {
241 $amount = sprintf("%.2f", $content{amount});
245 my $check_number = $content{check_number} || "100" # make one up
246 if($content{account_number});
248 my $terminalid = $content{login} if $type eq 'CC';
249 my $merchantid = $content{login} if $type eq 'ECHECK';
251 my $country = country2code( $content{country}, LOCALE_CODE_ALPHA_3 );
252 $country = country_code2code( $content{country},
257 $country = $content{country}
259 $country = uc($country) if $country;
262 country2code( $content{ship_country}, LOCALE_CODE_ALPHA_3 );
263 $ship_country = country_code2code( $content{ship_country},
267 unless $ship_country;
268 $ship_country = $content{ship_country}
269 unless $ship_country;
270 $ship_country = uc($ship_country) if $ship_country;
272 tie my %ach, 'Tie::IxHash',
273 $self->revmap_fields(
274 #AccountType => 'account_type',
275 AccountNumber => 'account_number',
276 ABA => 'routing_code',
277 CheckNumber => \$check_number,
280 tie my %industryinfo, 'Tie::IxHash',
281 $self->revmap_fields(
282 Type => 'IndustryInfo',
285 tie my %shippingaddr, 'Tie::IxHash',
286 $self->revmap_fields(
287 Address => 'ship_address',
289 StateProv => 'ship_state',
290 Country => \$ship_country,
291 Phone => 'ship_phone',
294 unless ( $type ne 'CC' || keys %shippingaddr ) {
295 tie %shippingaddr, 'Tie::IxHash',
296 $self->revmap_fields(
297 Address => 'address',
299 StateProv => 'state',
300 Country => \$country,
305 tie my %shippinginfo, 'Tie::IxHash',
306 $self->revmap_fields(
307 CustomerPO => 'CustomerPO',
308 ShippingMethod => 'ShippingMethod',
309 ShippingName => 'ship_name',
310 ShippingAddr => \%shippingaddr,
313 tie my %req, 'Tie::IxHash',
314 $self->revmap_fields(
315 TransactionType => 'TransactionType',
316 TerminalID => 'login',
317 # TerminalID => \$terminalid,
318 # MerchantID => \$merchantid,
319 TransactionID => \$transaction_id,
320 RoutingCode => 'RoutingCode',
321 Approval => 'authorization',
322 BatchID => 'BatchID',
324 Password => 'password',
325 OrderNumber => 'invoice_number',
326 CardNum => 'card_number',
328 Issue => 'issue_number',
329 CardExpMonth => \$cardexpmonth,
330 CardExpYear => \$cardexpyear,
331 CardStartMonth => \$cardstartmonth,
332 CardStartYear => \$cardstartyear,
337 DispositionType => 'DispositionType',
338 TotalAmount => \$amount,
339 FeeAmount => 'FeeAmount',
340 TaxAmount => 'TaxAmount',
341 BillingAddress => 'address',
342 BillingCity => 'city',
343 BillingStateProv => 'state',
344 BillingPostalCode => 'zip',
345 BillingCountry => \$country,
346 BillingPhone => 'phone',
348 UserIPAddr => 'customer_ip',
349 UserHost => 'UserHost',
350 UDField1 => 'UDField1',
351 UDField2 => 'UDField2',
352 UDField3 => 'UDField3',
353 ActionCode => 'ActionCode',
354 IndustryInfo => \%industryinfo,
355 ShippingInfo => \%shippinginfo,
359 my $writer = new XML::Writer( OUTPUT => \$post_data,
362 ENCODING => 'us-ascii',
365 $writer->startTag('JetPay');
366 foreach ( keys ( %req ) ) {
367 $self->_xmlwrite($writer, $_, $req{$_});
369 $writer->endTag('JetPay');
372 warn "$post_data\n" if $DEBUG;
374 my ($page,$server_response,%headers) = $self->https_post($post_data);
376 warn "$page\n" if $DEBUG;
379 if ($server_response =~ /^200/){
380 $response = XMLin($page);
381 if ( exists($response->{ActionCode}) && !exists($response->{ErrMsg})) {
382 $self->error_message($response->{ResponseText});
384 $self->error_message($response->{Errmsg});
387 # $self->error_message("Server Failed");
390 $self->result_code($response->{ActionCode} || '');
391 $self->order_number($response->{TransactionID} || '');
392 $self->authorization($response->{Approval} || '');
393 $self->cvv2_response($response->{CVV2} || '');
394 $self->avs_code($response->{AVS} || '');
396 $self->is_success($self->result_code() eq '000' ? 1 : 0);
398 unless ($self->is_success()) {
399 unless ( $self->error_message() ) { #additional logging information
400 $self->error_message(
401 "(HTTPS response: $server_response) ".
403 join(", ", map { "$_ => ". $headers{$_} } keys %headers ). ") ".
404 "(Raw HTTPS content: $page)"
412 my ($self, $writer, $item, $value) = @_;
413 $writer->startTag($item);
414 if ( ref( $value ) eq 'HASH' ) {
415 foreach ( keys ( %$value ) ) {
416 $self->_xmlwrite($writer, $_, $value->{$_});
419 $writer->characters($value);
421 $writer->endTag($item);
430 Business::OnlinePayment::IPPay - IPPay backend for Business::OnlinePayment
434 use Business::OnlinePayment;
437 new Business::OnlinePayment( "IPPay",
438 'default_Origin' => 'PHONE ORDER',
442 login => 'testdrive',
443 password => '', #password
444 action => 'Normal Authorization',
445 description => 'Business::OnlinePayment test',
447 customer_id => 'tfb',
448 name => 'Tofu Beast',
449 address => '123 Anystreet',
453 card_number => '4007000000027',
454 expiration => '09/02',
455 cvv2 => '1234', #optional
459 if($tx->is_success()) {
460 print "Card processed successfully: ".$tx->authorization."\n";
462 print "Card was rejected: ".$tx->error_message."\n";
465 =head1 SUPPORTED TRANSACTION TYPES
467 =head2 CC, Visa, MasterCard, American Express, Discover
469 Content required: type, login, action, amount, card_number, expiration.
473 Content required: type, login, action, amount, name, account_number, routing_code.
477 For detailed information see L<Business::OnlinePayment>.
479 =head1 METHODS AND FUNCTIONS
481 See L<Business::OnlinePayment> for the complete list. The following methods either override the methods in L<Business::OnlinePayment> or provide additional functions.
485 Returns the response error code.
489 Returns the response error description text.
491 =head2 server_response
493 Returns the complete response from the server.
495 =head1 Handling of content(%content) data:
499 The following actions are valid
507 =head1 Setting IPPay parameters from content(%content)
509 The following rules are applied to map data to IPPay parameters
510 from content(%content):
512 # param => $content{<key>}
513 TransactionType => 'TransactionType',
514 TerminalID => 'login',
515 TransactionID => 'order_number',
516 RoutingCode => 'RoutingCode',
517 Approval => 'authorization',
518 BatchID => 'BatchID',
520 Password => 'password',
521 OrderNumber => 'invoice_number',
522 CardNum => 'card_number',
524 Issue => 'issue_number',
525 CardExpMonth => \( $month ), # MM from MM(-)YY(YY) of 'expiration'
526 CardExpYear => \( $year ), # YY from MM(-)YY(YY) of 'expiration'
527 CardStartMonth => \( $month ), # MM from MM(-)YY(YY) of 'card_start'
528 CardStartYear => \( $year ), # YY from MM(-)YY(YY) of 'card_start'
532 AccountNumber => 'account_number',
533 ABA => 'routing_code',
534 CheckNumber => 'check_number',
536 DispositionType => 'DispositionType',
537 TotalAmount => 'amount' reformatted into cents
538 FeeAmount => 'FeeAmount',
539 TaxAmount => 'TaxAmount',
540 BillingAddress => 'address',
541 BillingCity => 'city',
542 BillingStateProv => 'state',
543 BillingPostalCode => 'zip',
544 BillingCountry => 'country', # forced to ISO-3166-alpha-3
545 BillingPhone => 'phone',
547 UserIPAddr => 'customer_ip',
548 UserHost => 'UserHost',
549 UDField1 => 'UDField1',
550 UDField2 => 'UDField2',
551 UDField3 => 'UDField3',
552 ActionCode => 'ActionCode',
554 Type => 'IndustryInfo',
556 CustomerPO => 'CustomerPO',
557 ShippingMethod => 'ShippingMethod',
558 ShippingName => 'ship_name',
560 Address => 'ship_address',
562 StateProv => 'ship_state',
563 Country => 'ship_country', # forced to ISO-3166-alpha-3
564 Phone => 'ship_phone',
570 Business::OnlinePayment::IPPay uses IPPay XML Product Specifications version
573 See http://www.ippay.com/ for more information.
577 Jeff Finucane, ippay@weasellips.com
581 perl(1). L<Business::OnlinePayment>.