1 package Business::OnlinePayment::HTTPS;
4 use base qw(Business::OnlinePayment);
5 use vars qw($VERSION $DEBUG);
7 use Net::HTTPS::Any 0.10;
14 Business::OnlinePayment::HTTPS - Base class for HTTPS payment APIs
18 package Business::OnlinePayment::MyProcessor;
19 use base qw(Business::OnlinePayment::HTTPS);
26 # pass a list (order is preserved, if your gateway needs that)
27 ( $page, $response, %reply_headers )
28 = $self->https_get( field => 'value', ... );
31 my %hash = ( field => 'value', ... );
32 ( $page, $response_code, %reply_headers )
33 = $self->https_get( \%hash );
40 This is a base class for HTTPS based gateways, providing useful code
41 for implementors of HTTPS payment APIs.
43 It depends on Net::HTTPS::Any, which in turn depends on
44 Net::SSLeay _or_ ( Crypt::SSLeay and LWP::UserAgent ).
50 =item https_get [ \%options ] HASHREF | FIELD => VALUE, ...
52 Accepts parameters as either a hashref or a list of fields and values.
53 In the latter case, ordering is preserved (see L<Tie::IxHash> to do so
54 when passing a hashref).
56 Returns a list consisting of the page content as a string, the HTTP
57 response code and message (i.e. "200 OK" or "404 Not Found"), and a list of
58 key/value pairs representing the HTTP response headers.
60 The options hashref supports setting headers:
63 headers => { 'X-Header1' => 'value', ... },
68 # Content-Type => 'text/namevalue',
73 # handle optional options hashref
75 if ( scalar(@_) > 1 and ref( $_[0] ) eq "HASH" ) {
79 # accept a hashref or a list (keep it ordered)
81 if ( ref( $_[0] ) eq 'HASH' ) {
83 } elsif ( scalar(@_) > 1 ) {
84 tie my %hash, 'Tie::IxHash', @_;
86 } elsif ( scalar(@_) == 1 ) {
89 die "https_get called with no params\n";
92 $self->build_subs(qw( response_page response_code response_headers ));
94 my( $res_page, $res_code, @res_headers) = Net::HTTPS::Any::https_get(
95 'host' => $self->server,
96 'path' => $self->path,
97 'headers' => $opts->{headers},
102 $self->response_page( $res_page );
103 $self->response_code( $res_code );
104 $self->response_headers( { @res_headers } );
106 ( $res_page, $res_code, @res_headers );
110 =item https_post [ \%options ] SCALAR | HASHREF | FIELD => VALUE, ...
112 Accepts form fields and values as either a hashref or a list. In the
113 latter case, ordering is preserved (see L<Tie::IxHash> to do so when
116 Also accepts instead a simple scalar containing the raw content.
118 Returns a list consisting of the page content as a string, the HTTP
119 response code and message (i.e. "200 OK" or "404 Not Found"), and a list of
120 key/value pairs representing the HTTP response headers.
122 The options hashref supports setting headers and Content-Type:
125 headers => { 'X-Header1' => 'value', ... },
126 Content-Type => 'text/namevalue',
134 # handle optional options hashref
136 if ( scalar(@_) > 1 and ref( $_[0] ) eq "HASH" ) {
141 'host' => $self->server,
142 'path' => $self->path,
143 'headers' => $opts->{headers},
144 'Content-Type' => $opts->{'Content-Type'},
148 # accept a hashref or a list (keep it ordered)
151 if ( ref( $_[0] ) eq 'HASH' ) {
152 $post{'args'} = shift;
153 } elsif ( scalar(@_) > 1 ) {
154 tie my %hash, 'Tie::IxHash', @_;
155 $post{'args'} = \%hash;
156 } elsif ( scalar(@_) == 1 ) {
157 $post{'content'} = shift;
159 die "https_post called with no params\n";
162 $self->build_subs(qw( response_page response_code response_headers ));
164 my( $res_page, $res_code, @res_headers)= Net::HTTPS::Any::https_post(%post);
166 $self->response_page( $res_page );
167 $self->response_code( $res_code );
168 $self->response_headers( { @res_headers } );
170 ( $res_page, $res_code, @res_headers );
178 L<Business::OnlinePayment>, L<Net::HTTPS::Any>