| 1 | package Business::OnlinePayment::CardFortress; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use base qw( Business::OnlinePayment::HTTPS ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | #use vars qw( $DEBUG $me ); | ||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use File::Slurp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use MIME::Base64; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Crypt::OpenSSL::RSA; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub _info { | ||||||||||||||||||||||||||
|
Subroutine
_info: not called CC=2 SCAR=11.6
| |||||||||||||||||||||||||||||
| 15 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | my $info = { | |||||||||||||||||||||||||||
| 18 | 'info_compat' => '0.01', | ||||||||||||||||||||||||||||
| 19 | 'module_version' => $VERSION, | ||||||||||||||||||||||||||||
| 20 | 'gateway_name' => 'Card Fortress', | ||||||||||||||||||||||||||||
| 21 | 'gateway_url' => 'http://www.cardfortress.com/', | ||||||||||||||||||||||||||||
| 22 | 'supported_types' => [ 'CC' ], | ||||||||||||||||||||||||||||
| 23 | 'supported_actions' => { 'CC' => [ | ||||||||||||||||||||||||||||
| 24 | 'Normal Authorization', | ||||||||||||||||||||||||||||
| 25 | 'Authorization Only', | ||||||||||||||||||||||||||||
| 26 | 'Post Authorization', | ||||||||||||||||||||||||||||
| 27 | 'Void', | ||||||||||||||||||||||||||||
| 28 | 'Credit', | ||||||||||||||||||||||||||||
| 29 | 'Tokenize', | ||||||||||||||||||||||||||||
| 30 | ], | ||||||||||||||||||||||||||||
| 31 | }, | ||||||||||||||||||||||||||||
| 32 | 'token_support' => 1, | ||||||||||||||||||||||||||||
| 33 | }; | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | my $cf_info = $self->cf_info; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 2 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 0 | warn Dumper($cf_info); | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | $info->{$_} = $cf_info->{$_} | ||||||||||||||||||||||||||||
| 41 | 0 | for qw( CC_void_requires_card ECHECK_void_requires_account partial_auth ); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | $info; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 1 | ▶ | sub set_defaults { | ||||||||||||||||||||||||||
|
Subroutine
set_defaults: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 47 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 48 | 1 | my %opts = @_; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1 | ▶ | $self->server('gw.cardfortress.com') unless $self->server; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 1 | ▶ | $self->port('443') unless $self->port; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 1 | ▶ | $self->path('/bop/index.html') unless $self->path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 1 | $self->build_subs(qw( order_number avs_code cvv2_response | |||||||||||||||||||||||||||
| 56 | response_page response_code response_headers | ||||||||||||||||||||||||||||
| 57 | card_token private_key txn_date | ||||||||||||||||||||||||||||
| 58 | )); | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 1 | ▶ | sub submit { | ||||||||||||||||||||||||||
|
Subroutine
submit: called CC=12 SCAR=43.3
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 1 | ▶ | $self->server('test.cardfortress.com') if $self->test_transaction; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 1 | my %content = $self->content; | |||||||||||||||||||||||||||
| 67 | 1 | $content{$_} = $self->$_() for qw( gateway gateway_login gateway_password ); | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 1 | $content{$_} = $self->$_() for grep $self->can($_), qw( bop_options ); | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 1 | my ($page,$server_response,%headers) = $self->https_post(%content); | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 1 | ▶ | die "$server_response\n" unless $server_response =~ /^200/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | my %response = (); | |||||||||||||||||||||||||||
| 76 | #this encoding good enough? wfm... if something's easier for other | ||||||||||||||||||||||||||||
| 77 | #languages they can always use a different URL | ||||||||||||||||||||||||||||
| 78 | 0 | foreach my $line ( grep /^\w+=/, split(/\n/, $page) ) { | |||||||||||||||||||||||||||
| 79 | 0 | ▶ | $line =~ /^(\w+)=(.*)$/ or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | $response{$1} = $2; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | foreach (qw( is_success error_message failure_status | |||||||||||||||||||||||||||
| 84 | authorization order_number | ||||||||||||||||||||||||||||
| 85 | fraud_score fraud_transaction_id | ||||||||||||||||||||||||||||
| 86 | result_code avs_code cvv2_response | ||||||||||||||||||||||||||||
| 87 | card_token | ||||||||||||||||||||||||||||
| 88 | txn_date | ||||||||||||||||||||||||||||
| 89 | )) { | ||||||||||||||||||||||||||||
| 90 | 0 | $self->$_($response{$_}); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | #map these to gateway_response_code, etc? | ||||||||||||||||||||||||||||
| 94 | # response_code() | ||||||||||||||||||||||||||||
| 95 | # response_headers() | ||||||||||||||||||||||||||||
| 96 | # response_page() | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | #handle the challenge/response handshake | ||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if ( $self->error_message eq '_challenge' ) { #XXX infinite loop protection? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | my $private_key = $self->private_key | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | or die "no private key available"; | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | $private_key = read_file($private_key) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $private_key =~ /-----BEGIN/ and -r $private_key
MC/DC0%0/2
not $private_key =~ /-----BEGIN/ and -r $private_key
not $private_key =~ /-----BEGIN/
-r $private_key
Truth table0%0/3
not(A) and B
A= not $private_key =~ /-----BEGIN/B= -r $private_key
| |||||||||||||||||||||||||||||
| 105 | if $private_key !~ /-----BEGIN/ && -r $private_key; | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | #decrypt the challenge with the private key | ||||||||||||||||||||||||||||
| 108 | 0 | my $challenge = decode_base64($response{'card_challenge'}); | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | #here is the hardest part to implement at each client side | ||||||||||||||||||||||||||||
| 111 | 0 | my $rsa_priv = Crypt::OpenSSL::RSA->new_private_key($private_key); | |||||||||||||||||||||||||||
| 112 | 0 | my $response = $rsa_priv->decrypt($challenge); | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | #try the transaction again with the challenge response | ||||||||||||||||||||||||||||
| 115 | # (B:OP could sure use a better way to alter one value) | ||||||||||||||||||||||||||||
| 116 | 0 | my %content = $self->content; | |||||||||||||||||||||||||||
| 117 | 0 | $content{'card_response'} = encode_base64($response, ''); | |||||||||||||||||||||||||||
| 118 | 0 | $self->content(%content); | |||||||||||||||||||||||||||
| 119 | 0 | $self->submit; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | sub cf_info { | ||||||||||||||||||||||||||
|
Subroutine
cf_info: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 125 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | $self->server('test.cardfortress.com') if $self->test_transaction; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | my %content = ( 'gateway_info' => $self->gateway(), ); | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | my ($page,$server_response,%headers) = $self->https_post(%content); | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 0 | ▶ | die "$server_response\n" unless $server_response =~ /^200/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | my %response = (); | |||||||||||||||||||||||||||
| 136 | #this encoding good enough? wfm... if something's easier for other | ||||||||||||||||||||||||||||
| 137 | #languages they can always use a different URL | ||||||||||||||||||||||||||||
| 138 | 0 | foreach my $line ( grep /^\w+=/, split(/\n/, $page) ) { | |||||||||||||||||||||||||||
| 139 | 0 | ▶ | $line =~ /^(\w+)=(.*)$/ or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 0 | $response{$1} = $2; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | \%response; | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 2 | 1; | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | __END__ | ||||||||||||||||||||||||||||