X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=OnlinePayment%2FHTTPS.pm;h=cb5190534ae762873a9151cfe244ab2906472521;hb=3a9c1a2ca18dba7df35f29b1404d43c2b6c6e18a;hp=315429797f283eef5b7bb87c0c3b1e4635e7595c;hpb=539664e913f52544a705dcbdaee19c8ef10d38e7;p=Business-OnlinePayment.git diff --git a/OnlinePayment/HTTPS.pm b/OnlinePayment/HTTPS.pm index 3154297..cb51905 100644 --- a/OnlinePayment/HTTPS.pm +++ b/OnlinePayment/HTTPS.pm @@ -6,7 +6,7 @@ use URI::Escape; use Tie::IxHash; use base qw(Business::OnlinePayment); -$VERSION = '0.05'; +$VERSION = '0.09'; $DEBUG = 0; BEGIN { @@ -85,8 +85,8 @@ In the latter case, ordering is preserved (see L to do so when passing a hashref). Returns a list consisting of the page content as a string, the HTTP -response code, and a list of key/value pairs representing the HTTP -response headers. +response code and message (i.e. "200 OK" or "404 Not Found"), and a list of +key/value pairs representing the HTTP response headers. The options hashref supports setting headers and Content-Type: @@ -139,14 +139,31 @@ sub https_get { keys %$post_data ); } + $self->build_subs(qw( response_page response_code response_headers )); + if ( $ssl_module eq 'Net::SSLeay' ) { import Net::SSLeay qw(get_https make_headers); my $headers = make_headers(%headers); - get_https( $self->server, $self->port, $path, $headers, "", - $opts->{"Content-Type"} ); - } - elsif ( $ssl_module eq 'Crypt::SSLeay' ) { + + my( $res_page, $res_code, @res_headers ) = + get_https( $self->server, + $self->port, + $path, + $headers, + "", + $opts->{"Content-Type"}, + ); + + $res_code =~ /^(HTTP\S+ )?(.*)/ and $res_code = $2; + + $self->response_page( $res_page ); + $self->response_code( $res_code ); + $self->response_headers( { @res_headers } ); + + ( $res_page, $res_code, @res_headers ); + + } elsif ( $ssl_module eq 'Crypt::SSLeay' ) { import HTTP::Request::Common qw(GET); @@ -161,14 +178,19 @@ sub https_get { } my $res = $ua->request( GET($url) ); - ( - $res->content, $res->code, - map { $_ => $res->header($_) } $res->header_field_names - ); - } - else { + my @res_headers = map { $_ => $res->header($_) } + $res->header_field_names; + + $self->response_page( $res->content ); + $self->response_code( $res->code. ' '. $res->message ); + $self->response_headers( { @res_headers } ); + + ( $res->content, $res->code. ' '. $res->message, @res_headers ); + + } else { die "unknown SSL module $ssl_module"; } + } =item https_post [ \%options ] SCALAR | HASHREF | FIELD => VALUE, ... @@ -180,8 +202,8 @@ passing a hashref). Also accepts instead a simple scalar containing the raw content. Returns a list consisting of the page content as a string, the HTTP -response code, and a list of key/value pairs representing the HTTP -response headers. +response code and message (i.e. "200 OK" or "404 Not Found"), and a list of +key/value pairs representing the HTTP response headers. The options hashref supports setting headers and Content-Type: @@ -232,6 +254,8 @@ sub https_post { map { " $_ => " . $post_data->{$_} . "\n" } keys %$post_data ); } + $self->build_subs(qw( response_page response_code response_headers )); + if ( $ssl_module eq 'Net::SSLeay' ) { import Net::SSLeay qw(post_https make_headers make_form); @@ -244,10 +268,25 @@ sub https_post { } my $raw_data = ref($post_data) ? make_form(%$post_data) : $post_data; - post_https( $self->server, $self->port, $self->path, $headers, - $raw_data, $opts->{"Content-Type"} ); - } - elsif ( $ssl_module eq 'Crypt::SSLeay' ) { + + my( $res_page, $res_code, @res_headers ) = + post_https( $self->server, + $self->port, + $self->path, + $headers, + $raw_data, + $opts->{"Content-Type"}, + ); + + $res_code =~ /^(HTTP\S+ )?(.*)/ and $res_code = $2; + + $self->response_page( $res_page ); + $self->response_code( $res_code ); + $self->response_headers( { @res_headers } ); + + ( $res_page, $res_code, @res_headers ); + + } elsif ( $ssl_module eq 'Crypt::SSLeay' ) { import HTTP::Request::Common qw(POST); @@ -276,14 +315,19 @@ sub https_post { $res = $ua->request($req); } - ( - $res->content, $res->code, - map { $_ => $res->header($_) } $res->header_field_names - ); - } - else { + my @res_headers = map { $_ => $res->header($_) } + $res->header_field_names; + + $self->response_page( $res->content ); + $self->response_code( $res->code. ' '. $res->message ); + $self->response_headers( { @res_headers } ); + + ( $res->content, $res->code. ' '. $res->message, @res_headers ); + + } else { die "unknown SSL module $ssl_module"; } + } =back