summaryrefslogtreecommitdiff
path: root/BatchPayment/Transport/HTTPS.pm
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2012-07-11 00:08:15 -0700
committerIvan Kohler <ivan@freeside.biz>2012-07-11 00:08:15 -0700
commit3c5cccf1bf74f2e60482fe62cfbcbe06722da1f5 (patch)
treed0bfc425deb44dbaa0cad9f272cd2023407ebd05 /BatchPayment/Transport/HTTPS.pm
initial commit
Diffstat (limited to 'BatchPayment/Transport/HTTPS.pm')
-rw-r--r--BatchPayment/Transport/HTTPS.pm58
1 files changed, 58 insertions, 0 deletions
diff --git a/BatchPayment/Transport/HTTPS.pm b/BatchPayment/Transport/HTTPS.pm
new file mode 100644
index 0000000..c40a78f
--- /dev/null
+++ b/BatchPayment/Transport/HTTPS.pm
@@ -0,0 +1,58 @@
+package Business::BatchPayment::Transport::HTTPS;
+
+=head2 HTTPS transport
+
+Sends a request by HTTPS POST, and downloads the response the same way.
+Options are 'server', 'port', 'get_path', 'put_path', optionally
+'content_type'.
+
+=cut
+
+use Net::HTTPS::Any 0.10;
+use Moose;
+with 'Business::BatchPayment::Transport';
+
+has [ qw( host port get_path put_path ) ] => (
+ is => 'ro',
+ isa => 'Str'
+);
+
+has 'content_type' => (
+ is => 'rw',
+ isa => 'Str',
+ default => 'text/plain'
+);
+
+sub https_post {
+ my $self = shift;
+ my $path = shift;
+ my $content = shift;
+
+ warn "starting https_post...\n" if $self->debug;
+ my ( $page, $response, %reply_headers ) = Net::HTTPS::Any::https_post(
+ host => $self->host,
+ port => $self->port,
+ path => $path,
+ content => $content,
+ debug => ($self->debug >= 3),
+ );
+ warn "PAGE:\n$page\n\nRESPONSE:\n$response\n\n" if $self->debug >= 2;
+ return ($page, $response, %reply_headers);
+}
+
+sub upload {
+ my $self = shift;
+ my $content = shift;
+ $self->https_post($self->put_path, $content);
+}
+
+sub download {
+ # will probably need to be overridden in most cases
+ my $self = shift;
+ my ($page, $response, %reply_headers) = $self->https_post($self->get_path);
+ $page;
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;