| 1 | package Business::OnlinePayment::NMI; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | 3 | ▶ | use Carp; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 5 | 3 | ▶ | use Business::OnlinePayment 3; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 6 | 3 | ▶ | use Business::OnlinePayment::HTTPS; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 7 | 3 | ▶ | use Digest::MD5 qw(md5_hex); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 8 | 3 | ▶ | use URI::Escape; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 9 | 3 | ▶ | use vars qw($VERSION @ISA $DEBUG); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 10 | |||||||||||||||||||
| 11 | 3 | @ISA = qw(Business::OnlinePayment::HTTPS); | |||||||||||||||||
| 12 | 3 | $VERSION = '0.03'; | |||||||||||||||||
| 13 | |||||||||||||||||||
| 14 | 3 | $DEBUG = 0; | |||||||||||||||||
| 15 | |||||||||||||||||||
| 16 | 0 | ▶ | sub _info { | ||||||||||||||||
|
Subroutine
_info: not called CC=1 SCAR=6.9
| |||||||||||||||||||
| 17 | { | ||||||||||||||||||
| 18 | 0 | 'info_compat' => '0.01', | |||||||||||||||||
| 19 | 'gateway_name' => 'Network Merchants', | ||||||||||||||||||
| 20 | 'gateway_url' => 'https://www.nmi.com', | ||||||||||||||||||
| 21 | 'module_version' => $VERSION, | ||||||||||||||||||
| 22 | 'supported_types' => [ 'CC', 'ECHECK' ], | ||||||||||||||||||
| 23 | 'supported_actions' => { | ||||||||||||||||||
| 24 | CC => [ | ||||||||||||||||||
| 25 | 'Normal Authorization', | ||||||||||||||||||
| 26 | 'Authorization Only', | ||||||||||||||||||
| 27 | 'Post Authorization', | ||||||||||||||||||
| 28 | 'Credit', | ||||||||||||||||||
| 29 | 'Void', | ||||||||||||||||||
| 30 | ], | ||||||||||||||||||
| 31 | ECHECK => [ | ||||||||||||||||||
| 32 | 'Normal Authorization', | ||||||||||||||||||
| 33 | 'Credit', | ||||||||||||||||||
| 34 | 'Void', | ||||||||||||||||||
| 35 | ], | ||||||||||||||||||
| 36 | }, | ||||||||||||||||||
| 37 | }; | ||||||||||||||||||
| 38 | } | ||||||||||||||||||
| 39 | |||||||||||||||||||
| 40 | 3 | my %actions = ( | |||||||||||||||||
| 41 | 'normal authorization' => 'sale', | ||||||||||||||||||
| 42 | 'authorization only' => 'auth', | ||||||||||||||||||
| 43 | 'post authorization' => 'capture', | ||||||||||||||||||
| 44 | 'credit' => 'refund', | ||||||||||||||||||
| 45 | 'void' => 'void', | ||||||||||||||||||
| 46 | ); | ||||||||||||||||||
| 47 | 3 | my %types = ( | |||||||||||||||||
| 48 | 'cc' => 'creditcard', | ||||||||||||||||||
| 49 | 'echeck' => 'check', | ||||||||||||||||||
| 50 | ); | ||||||||||||||||||
| 51 | |||||||||||||||||||
| 52 | 3 | my %fields = ( | |||||||||||||||||
| 53 | # NMI Direct Post API, June 2007 | ||||||||||||||||||
| 54 | action => 'type', # special | ||||||||||||||||||
| 55 | login => 'username', | ||||||||||||||||||
| 56 | password => 'password', | ||||||||||||||||||
| 57 | card_number => 'ccnumber', | ||||||||||||||||||
| 58 | expiration => 'ccexp', | ||||||||||||||||||
| 59 | name => 'checkname', | ||||||||||||||||||
| 60 | routing_code => 'checkaba', | ||||||||||||||||||
| 61 | account_number => 'checkaccount', | ||||||||||||||||||
| 62 | account_holder_type => 'account_holder_type', | ||||||||||||||||||
| 63 | account_type => 'account_type', | ||||||||||||||||||
| 64 | amount => 'amount', | ||||||||||||||||||
| 65 | cvv2 => 'cvv', | ||||||||||||||||||
| 66 | payment => 'payment', # special | ||||||||||||||||||
| 67 | description => 'orderdescription', | ||||||||||||||||||
| 68 | invoice_number => 'orderid', | ||||||||||||||||||
| 69 | customer_ip => 'ipaddress', | ||||||||||||||||||
| 70 | tax => 'tax', | ||||||||||||||||||
| 71 | freight => 'shipping', | ||||||||||||||||||
| 72 | po_number => 'ponumber', | ||||||||||||||||||
| 73 | first_name => 'firstname', | ||||||||||||||||||
| 74 | last_name => 'lastname', | ||||||||||||||||||
| 75 | company => 'company', | ||||||||||||||||||
| 76 | address => 'address1', | ||||||||||||||||||
| 77 | city => 'city', | ||||||||||||||||||
| 78 | state => 'state', | ||||||||||||||||||
| 79 | zip => 'zip', | ||||||||||||||||||
| 80 | country => 'country', | ||||||||||||||||||
| 81 | order_number => 'transactionid', # used for capture/void/refund | ||||||||||||||||||
| 82 | ); | ||||||||||||||||||
| 83 | |||||||||||||||||||
| 84 | $fields{"ship_$_"} = 'shipping_'.$fields{$_} | ||||||||||||||||||
| 85 | 3 | foreach(qw(first_name last_name company address city state zip country)) ; | |||||||||||||||||
| 86 | |||||||||||||||||||
| 87 | 3 | my %required = ( | |||||||||||||||||
| 88 | 'ALL' => [ qw( type username password payment ) ], | ||||||||||||||||||
| 89 | 'sale' => [ 'amount' ], | ||||||||||||||||||
| 90 | 'sale:creditcard' => [ 'ccnumber', 'ccexp' ], | ||||||||||||||||||
| 91 | 'sale:check' => [ qw( checkname checkaba checkaccount account_holder_type account_type ) ], | ||||||||||||||||||
| 92 | 'auth:creditcard' => [ qw( amount ccnumber ccexp ) ], | ||||||||||||||||||
| 93 | 'capture' => [ 'amount', 'transactionid' ], | ||||||||||||||||||
| 94 | 'refund' => [ 'amount', 'transactionid' ], | ||||||||||||||||||
| 95 | 'void' => [ 'transactionid' ], | ||||||||||||||||||
| 96 | # not supported: update | ||||||||||||||||||
| 97 | ), | ||||||||||||||||||
| 98 | |||||||||||||||||||
| 99 | my %optional = ( | ||||||||||||||||||
| 100 | 'ALL' => [], | ||||||||||||||||||
| 101 | 'sale' => [ qw( orderdescription orderid ipaddress tax | ||||||||||||||||||
| 102 | shipping ponumber firstname lastname company | ||||||||||||||||||
| 103 | address1 city state zip country phone fax email | ||||||||||||||||||
| 104 | shipping_firstname shipping_lastname | ||||||||||||||||||
| 105 | shipping_company shipping_address1 shipping_city | ||||||||||||||||||
| 106 | shipping_state shipping_zip shipping_country | ||||||||||||||||||
| 107 | ) ], | ||||||||||||||||||
| 108 | 'sale:creditcard' => [ 'cvv' ], | ||||||||||||||||||
| 109 | 'sale:check' => [], | ||||||||||||||||||
| 110 | 'auth:creditcard' => [ qw( orderdescription orderid ipaddress tax | ||||||||||||||||||
| 111 | shipping ponumber firstname lastname company | ||||||||||||||||||
| 112 | address1 city state zip country phone fax email | ||||||||||||||||||
| 113 | shipping_firstname shipping_lastname | ||||||||||||||||||
| 114 | shipping_company shipping_address1 shipping_city | ||||||||||||||||||
| 115 | shipping_state shipping_zip shipping_country | ||||||||||||||||||
| 116 | cvv ) ], | ||||||||||||||||||
| 117 | 'capture' => [ 'orderid' ], | ||||||||||||||||||
| 118 | 'refund' => [ 'amount' ], | ||||||||||||||||||
| 119 | ); | ||||||||||||||||||
| 120 | |||||||||||||||||||
| 121 | 3 | my %failure_status = ( | |||||||||||||||||
| 122 | 200 => 'decline', | ||||||||||||||||||
| 123 | 201 => 'decline', | ||||||||||||||||||
| 124 | 202 => 'nsf', | ||||||||||||||||||
| 125 | 203 => 'nsf', | ||||||||||||||||||
| 126 | 223 => 'expired', | ||||||||||||||||||
| 127 | 250 => 'pickup', | ||||||||||||||||||
| 128 | 252 => 'stolen', | ||||||||||||||||||
| 129 | # add others here as needed; very little code uses failure_status at present | ||||||||||||||||||
| 130 | ); | ||||||||||||||||||
| 131 | |||||||||||||||||||
| 132 | 9 | ▶ | sub set_defaults { | ||||||||||||||||
|
Subroutine
set_defaults: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||
| 133 | 9 | my $self = shift; | |||||||||||||||||
| 134 | 9 | $self->server('secure.networkmerchants.com'); | |||||||||||||||||
| 135 | 9 | $self->port('443'); | |||||||||||||||||
| 136 | 9 | $self->path('/api/transact.php'); | |||||||||||||||||
| 137 | 9 | $self->build_subs(qw(avs_code cvv2_response failure_status)); | |||||||||||||||||
| 138 | } | ||||||||||||||||||
| 139 | |||||||||||||||||||
| 140 | 9 | ▶ | sub map_fields { | ||||||||||||||||
|
Subroutine
map_fields: called CC=7 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||
| 141 | 9 | my($self) = shift; | |||||||||||||||||
| 142 | |||||||||||||||||||
| 143 | 9 | my %content = $self->content(); | |||||||||||||||||
| 144 | |||||||||||||||||||
| 145 | 9 | ▶ | if($self->test_transaction) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 146 | # Public test account. | ||||||||||||||||||
| 147 | 0 | $content{'login'} = 'demo'; | |||||||||||||||||
| 148 | 0 | $content{'password'} = 'password'; | |||||||||||||||||
| 149 | } | ||||||||||||||||||
| 150 | |||||||||||||||||||
| 151 | 9 | ▶ | $content{'payment'} = $types{lc($content{'type'})} or die "Payment method '$content{type}' not supported.\n"; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 152 | 9 | ▶ | $content{'action'} = $actions{lc($content{'action'})} or die "Transaction type '$content{action}' not supported.\n"; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 153 | |||||||||||||||||||
| 154 | 9 | ▶ | $content{'expiration'} =~ s/\D//g if defined($content{'expiration'}); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 155 | |||||||||||||||||||
| 156 | 9 | ▶ | $content{'account_type'} ||= 'personal checking'; | ||||||||||||||||
|
Condition50%1/2
$content{"account_type"} ||= "personal checking"
MC/DC0%0/1
$content{"account_type"} ||= "personal checking"
$content{"account_type"}
Truth table50%1/2
A
A= $content{"account_type"}
| |||||||||||||||||||
| 157 | @content{'account_holder_type', 'account_type'} = | ||||||||||||||||||
| 158 | 9 | map {lc} split /\s/, $content{'account_type'}; | |||||||||||||||||
| 159 | $content{'ship_name'} = $content{'ship_first_name'} ? | ||||||||||||||||||
| 160 | 9 | ▶ | ($content{'ship_first_name'}.' '.$content{'ship_last_name'}) : ''; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 161 | 9 | $self->content(%content); | |||||||||||||||||
| 162 | } | ||||||||||||||||||
| 163 | |||||||||||||||||||
| 164 | 9 | ▶ | sub submit { | ||||||||||||||||
|
Subroutine
submit: called CC=18 SCAR=31.8
Pod
documented
| |||||||||||||||||||
| 165 | 9 | my($self) = @_; | |||||||||||||||||
| 166 | |||||||||||||||||||
| 167 | 9 | $self->map_fields(); | |||||||||||||||||
| 168 | |||||||||||||||||||
| 169 | 9 | $self->remap_fields(%fields); | |||||||||||||||||
| 170 | |||||||||||||||||||
| 171 | 9 | my %content = $self->content; | |||||||||||||||||
| 172 | 9 | my $type = $content{'type'}; # what we call "action" | |||||||||||||||||
| 173 | 9 | my $payment = $content{'payment'}; # what we call "type" | |||||||||||||||||
| 174 | 9 | ▶ | if ( $DEBUG >= 3 ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 175 | 0 | warn "content:$_ => $content{$_}\n" foreach keys %content; | |||||||||||||||||
| 176 | } | ||||||||||||||||||
| 177 | |||||||||||||||||||
| 178 | 9 | my @required_fields = ( @{$required{'ALL'}} ); | |||||||||||||||||
| 179 | 9 | ▶ | push @required_fields, @{$required{$type}} if exists($required{$type}); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 180 | 9 | ▶ | push @required_fields, @{$required{"$type:$payment"}} if exists($required{"$type:$payment"}); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 181 | |||||||||||||||||||
| 182 | 9 | $self->required_fields(@required_fields); | |||||||||||||||||
| 183 | |||||||||||||||||||
| 184 | 9 | my @allowed_fields = @required_fields; | |||||||||||||||||
| 185 | 9 | push @allowed_fields, @{$optional{'ALL'}}; | |||||||||||||||||
| 186 | 9 | ▶ | push @allowed_fields, @{$optional{$type}} if exists($optional{$type}); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 187 | 9 | ▶ | push @allowed_fields, @{$optional{"$type:$payment"}} if exists($required{"$type:$payment"}); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 188 | |||||||||||||||||||
| 189 | 9 | my %post_data = $self->get_fields(@allowed_fields); | |||||||||||||||||
| 190 | |||||||||||||||||||
| 191 | 9 | ▶ | if ( $DEBUG ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 192 | 0 | warn "post_data:$_ => $post_data{$_}\n" foreach keys %post_data; | |||||||||||||||||
| 193 | } | ||||||||||||||||||
| 194 | |||||||||||||||||||
| 195 | 9 | my($page,$server_response) = $self->https_post(\%post_data); | |||||||||||||||||
| 196 | 9 | ▶ | if ( $DEBUG ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 197 | 0 | warn "response page: $page\n"; | |||||||||||||||||
| 198 | } | ||||||||||||||||||
| 199 | |||||||||||||||||||
| 200 | 9 | my $response; | |||||||||||||||||
| 201 | 9 | ▶ | if ($server_response =~ /200/){ | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 202 | 9 | $response = {map { split '=', $_, 2 } split '&', $page}; | |||||||||||||||||
| 203 | } | ||||||||||||||||||
| 204 | else { | ||||||||||||||||||
| 205 | 0 | die "HTTPS error: '$server_response'\n"; | |||||||||||||||||
| 206 | } | ||||||||||||||||||
| 207 | |||||||||||||||||||
| 208 | 0 | $response->{$_} =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg | |||||||||||||||||
| 209 | 9 | foreach keys %$response; | |||||||||||||||||
| 210 | |||||||||||||||||||
| 211 | 9 | ▶ | if ( $DEBUG ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 212 | 0 | warn "response:$_ => $response->{$_}\n" foreach keys %$response; | |||||||||||||||||
| 213 | } | ||||||||||||||||||
| 214 | |||||||||||||||||||
| 215 | 9 | $self->is_success(0); | |||||||||||||||||
| 216 | 9 | my $error; | |||||||||||||||||
| 217 | 9 | ▶ | if( $response->{response} == 1 ) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 218 | 0 | $self->is_success(1); | |||||||||||||||||
| 219 | } | ||||||||||||||||||
| 220 | elsif( $response->{response} == 2 ) { | ||||||||||||||||||
| 221 | 0 | $error = $response->{responsetext}; | |||||||||||||||||
| 222 | 0 | my $code = $response->{response_code}; | |||||||||||||||||
| 223 | 0 | ▶ | $self->failure_status($failure_status{$code}) if exists($failure_status{$code}); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 224 | } | ||||||||||||||||||
| 225 | elsif( $response->{response} == 3 ) { | ||||||||||||||||||
| 226 | 9 | $error = "Transaction error: '".$response->{responsetext}."'"; | |||||||||||||||||
| 227 | } | ||||||||||||||||||
| 228 | else { | ||||||||||||||||||
| 229 | 0 | $error = "Could not interpret server response: '$page'"; | |||||||||||||||||
| 230 | } | ||||||||||||||||||
| 231 | 9 | $self->order_number($response->{transactionid}); | |||||||||||||||||
| 232 | 9 | $self->authorization($response->{authcode}); | |||||||||||||||||
| 233 | 9 | $self->avs_code($response->{avsresponse}); | |||||||||||||||||
| 234 | 9 | $self->cvv2_response($response->{cvvresponse}); | |||||||||||||||||
| 235 | 9 | $self->result_code($response->{response_code}); | |||||||||||||||||
| 236 | 9 | $self->error_message($error); | |||||||||||||||||
| 237 | 9 | $self->server_response($response); | |||||||||||||||||
| 238 | } | ||||||||||||||||||
| 239 | |||||||||||||||||||
| 240 | 3 | 1; | |||||||||||||||||
| 241 | __END__ | ||||||||||||||||||