From 11ed59eb67796099284a635d0efda99c94fc5cfa Mon Sep 17 00:00:00 2001 From: levinse Date: Wed, 1 Jun 2011 05:38:03 +0000 Subject: [PATCH 1/1] initial commit of BOP Cardcom --- Cardcom.pm | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Changes | 4 ++ Makefile.PL | 23 +++++++++ README | 13 +++++ 4 files changed, 202 insertions(+) create mode 100644 Cardcom.pm create mode 100644 Changes create mode 100644 Makefile.PL create mode 100644 README diff --git a/Cardcom.pm b/Cardcom.pm new file mode 100644 index 0000000..2159033 --- /dev/null +++ b/Cardcom.pm @@ -0,0 +1,162 @@ +package Business::OnlinePayment::Cardcom; + +use strict; +use Carp; +use Tie::IxHash; +use Business::OnlinePayment 3; +use Business::OnlinePayment::HTTPS 0.03; +use Data::Dumper; +use vars qw($VERSION $DEBUG @ISA); + +@ISA = qw(Business::OnlinePayment::HTTPS); +$VERSION = '0.01'; +$DEBUG = 0; + +sub set_defaults { + my $self = shift; + + $self->server('secure.cardcom.co.il'); + $self->path('/BillGoldPost.aspx'); + $self->port('443'); +} + +# XXX? +# -CVV +# -Identity number +# -Configurable currency +# -Configurable deal code +# -Refunds or whatever this thing calls them +sub submit { + my($self) = @_; + + $self->remap_fields( + card_number => 'cardnumber', + amount => 'Sum', + login => 'Username', + ); + + die "invalid action" unless + $self->{_content}{'action'} =~ /^\s*normal\s*authorization\s*$/i; + + $self->{_content}{'expiration'} =~ /^(\d+)\D+\d*(\d{2})$/ + or croak "unparsable expiration ". $self->{_content}{expiration}; + my( $month, $year ) = ( $1, $2 ); + $month = '0'. $month if $month =~ /^\d$/; + $self->{_content}{cardvalidityyear} = $year; + $self->{_content}{cardvaliditymonth} = $month; + + $self->{_content}{amount} = sprintf('%.2f', $self->{_content}{amount} ); + $self->{_content}{languages} = 'en'; + + $self->terminalnumber =~ /^\d+$/ or die "invalid TerminalNumber"; + $self->{_content}{TerminalNumber} = $self->terminalnumber; + + tie my %fields, 'Tie::IxHash', $self->get_fields( $self->fields ); + my $post_data = join('&', map "$_=$fields{$_}", keys %fields ); + warn "POSTING: ".$post_data if $DEBUG > 1; + + my( $page, $response, @reply_headers) = $self->https_post( $post_data ); + + if ($response !~ /^200/) { + # Connection error + $response =~ s/[\r\n]+/ /g; # ensure single line + $self->is_success(0); + my $diag_message = $response || "connection error"; + die $diag_message; + } + + $self->server_response($page); + + unless ( $page =~ /^(\d+);(\d+);(.*?)$/ ) { + die "unparsable response received from gateway" . + ( $DEBUG ? ": $page" : '' ); + } + + my $result = $1; + my $authorization = $2; + my $message = $3; + + $self->authorization($authorization); + if ( $result == 0 ) { + $self->is_success(1); + } else { + $self->is_success(0); + $self->error_message($message); + } +} + +sub fields { + my $self = shift; + + qw( + TerminalNumber + Sum + cardnumber + cardvalidityyear + cardvaliditymonth + Username + languages + ); +} + +1; + +__END__ + +=head1 NAME + +Business::OnlinePayment::Cardcom - Cardcom backend module for Business::OnlinePayment + +=head1 SYNOPSIS + + use Business::OnlinePayment::Cardcom; + + #### + # One step transaction, the simple case. + #### + + my $tx = new Business::OnlinePayment("Cardcom"); + $tx->content( + type => 'CC', + login => 'Cardcom Username', + password => 'Cardcom Password', + terminalnumber => 'Cardcom Terminal Number', + action => 'Normal Authorization', + amount => '49.95', + card_number => '4005550000000019', + expiration => '08/06', + ); + $tx->submit(); + + if($tx->is_success()) { + print "Card processed successfully: ".$tx->authorization."\n"; + } else { + print "Card was rejected: ".$tx->error_message."\n"; + } + +=head1 SUPPORTED TRANSACTION TYPES + +=head2 CC + +Content required: type, login, password, action, amount, card_number, expiration, terminalnumber. + +=head1 PREREQUISITES + + URI::Escape + Tie::IxHash + + Net::SSLeay _or_ ( Crypt::SSLeay and LWP ) + +=head1 DESCRIPTION + +For detailed information see L. + +=head1 AUTHOR + +Erik Levinson + +=head1 SEE ALSO + +perl(1). L. + +=cut diff --git a/Changes b/Changes new file mode 100644 index 0000000..d1493f4 --- /dev/null +++ b/Changes @@ -0,0 +1,4 @@ +Revision history for Perl extension Business::OnlinePayment::Cardcom + +0.01 Wed Jun 1 01:24:40 EDT 2011 + - original version diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..5e9573c --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,23 @@ +use ExtUtils::MakeMaker; +# See lib/ExtUtils/MakeMaker.pm for details of how to influence +# the contents of the Makefile that is written. +WriteMakefile( + 'NAME' => 'Business::OnlinePayment::Cardcom', + 'VERSION_FROM' => 'Cardcom.pm', # finds $VERSION + 'AUTHOR' => 'Erik Levinson ', + #'NORECURS' => 1, # dont descend into subdirectories + 'PREREQ_PM' => { + 'Business::OnlinePayment' => 0, + + # for HTTPS (maybe it should be a separate dist?) + 'URI::Escape' => 0, + 'Tie::IxHash' => 0, + + # 'Net::SSLeay' => 0, + # or 'Crypt::SSLeay' => 0, + # 'URI + + }, + #'dist' => {CI => 'ci -l'}, +); + diff --git a/README b/README new file mode 100644 index 0000000..340839e --- /dev/null +++ b/README @@ -0,0 +1,13 @@ +Copyright (c) 2011 Erik Levinson +All rights reserved. This program is free software; you can redistribute it +and/or modify it under the same terms as Perl itself. + +This is Business::OnlinePayment::Cardcom, an Business::OnlinePayment +backend module for the Cardcom gateway. It is only +useful if you have a merchant account with Cardcom: +http://www.cardcom.co.il + +Business::OnlinePayment is a generic interface for processing payments through +online credit card processors, online check acceptance houses, etc. (If you +like buzzwords, call it an "multiplatform ecommerce-enabling middleware +solution"). -- 2.11.0