Add beginning of introspection interface for processor modules.
[Business-OnlinePayment.git] / OnlinePayment.pm
index a249981..7cdc10e 100644 (file)
@@ -1,7 +1,7 @@
 package Business::OnlinePayment;
 
 use strict;
-use vars qw($VERSION);
+use vars qw($VERSION %_info_handler);
 use Carp;
 
 require 5.005;
@@ -35,6 +35,47 @@ my @methods = qw(
     response_page
 );
 
+#fallback
+sub _info {
+  my $class = shift;
+  ( my $gw = $class ) =~ s/^Business::OnlinePayment:://;
+  {
+    'info_compat'    => '0.00',
+    'gateway_name'   => $gw,
+    'module_notes'   => "Module does not yet provide info.",
+  };
+}
+
+#allow classes to declare info in a flexible way, but return normalized info
+%_info_handler = (
+  'supported_types'   => sub {
+    my( $class, $v ) = @_;
+    my $types = ref($v) ? $v : [ $v ];
+    $types = { map { $_=>1 } @$types } if ref($v) eq 'ARRAY';
+    $types;
+  },
+  'supported_actions' => sub {
+    my( $class, $v ) = @_;
+    return $v if ref($v) eq 'HASH';
+    $v = [ $v ] unless ref($v);
+    my $types = $class->info('supported_types');
+    { map { $_ => $v } keys %$types };
+  },
+);
+
+sub info {
+  my $class = shift;
+  my $info = $class->_info;
+  if ( @_ ) {
+    my $key = shift;
+    exists($_info_handler{$key})
+      ? &{ $_info_handler{$key} }( $class, $info->{$key} )
+      : $info->{$key};
+  } else {
+    wantarray ? ( keys %$info ) : [ keys %$info ];
+  }
+}
+
 sub new {
     my($class,$processor,%data) = @_;
 
@@ -294,10 +335,27 @@ processors support all transaction types.
 
 =item action
 
-What to do with the transaction (currently available are: Normal
-Authorization, Authorization Only, Credit, Post Authorization,
-Recurring Authorization, Modify Recurring Authorization,
-Cancel Recurring Authorization)
+What action being taken by this transaction. Currently available are:
+
+=over 8
+
+=item Normal Authorization
+
+=item Authorization Only
+
+=item Post Authorization
+
+=item Void
+
+=item Credit
+
+=item Recurring Authorization
+
+=item Modify Recurring Authorization
+
+=item Cancel Recurring Authorization
+
+=back
 
 =item amount
 
@@ -678,9 +736,13 @@ Use this for handling boolean content like tax_exempt.
 
 =head1 AUTHORS
 
+(v2 series)
+
 Jason Kohles, email@jasonkohles.com
 
-(v3 rewrite) Ivan Kohler <ivan-business-onlinepayment@420.am>
+(v3 rewrite)
+
+Ivan Kohler <ivan-business-onlinepayment@420.am>
 
 Phil Lobbes E<lt>phil at perkpartners dot comE<gt>