[Catalyst-commits] r6332 - in trunk/Catalyst-Model-PayPal-IPN: . lib/Catalyst/Model/PayPal

matthewt at dev.catalyst.perl.org matthewt at dev.catalyst.perl.org
Sat Apr 28 17:10:30 GMT 2007


Author: matthewt
Date: 2007-04-28 17:10:26 +0100 (Sat, 28 Apr 2007)
New Revision: 6332

Modified:
   trunk/Catalyst-Model-PayPal-IPN/Makefile.PL
   trunk/Catalyst-Model-PayPal-IPN/lib/Catalyst/Model/PayPal/IPN.pm
Log:
add form field return code

Modified: trunk/Catalyst-Model-PayPal-IPN/Makefile.PL
===================================================================
--- trunk/Catalyst-Model-PayPal-IPN/Makefile.PL	2007-04-28 15:37:33 UTC (rev 6331)
+++ trunk/Catalyst-Model-PayPal-IPN/Makefile.PL	2007-04-28 16:10:26 UTC (rev 6332)
@@ -7,6 +7,7 @@
 
 requires 'Catalyst::Runtime' => '5.7006';
 requires 'Moose' => '0.20';
+requires 'namespace::clean' => '0.04';
 
 auto_install;
 WriteAll;

Modified: trunk/Catalyst-Model-PayPal-IPN/lib/Catalyst/Model/PayPal/IPN.pm
===================================================================
--- trunk/Catalyst-Model-PayPal-IPN/lib/Catalyst/Model/PayPal/IPN.pm	2007-04-28 15:37:33 UTC (rev 6331)
+++ trunk/Catalyst-Model-PayPal-IPN/lib/Catalyst/Model/PayPal/IPN.pm	2007-04-28 16:10:26 UTC (rev 6332)
@@ -11,6 +11,46 @@
   default => sub { confess "req not provided before use" }
 );
 
+has 'business_email' => (
+  is => 'rw', required => 1, lazy => 1,
+  default => sub { confess "business_email not provided before use" }
+);
+
+has 'currency_code' => (
+  is => 'rw', required => 1, lazy => 1,
+  default => sub { confess "currency_code not provided before use" }
+);
+
+has 'postback_action' => (
+  is => 'rw', required => 1, lazy => 1,
+  default => sub { confess "postback_action not provided before use" }
+);
+
+has 'postback_url' => (
+  is => 'rw', required => 1, lazy => 1,
+  default => sub { confess "postback_url not provided before use" }
+);
+
+has 'cancellation_action' => (
+  is => 'rw', required => 1, lazy => 1,
+  default => sub { confess "cancellation_action not provided before use" }
+);
+
+has 'cancellation_url' => (
+  is => 'rw', required => 1, lazy => 1,
+  default => sub { confess "cancellation_url not provided before use" }
+);
+
+has 'completion_action' => (
+  is => 'rw', required => 1, lazy => 1,
+  default => sub { confess "completion_action not provided before use" }
+);
+
+has 'completion_url' => (
+  is => 'rw', required => 1, lazy => 1,
+  default => sub { confess "completion_url not provided before use" }
+);
+
 has 'debug_mode' => (is => 'rw', required => 1, default => sub { 0 });
 
 has 'paypal_gateway' => (
@@ -33,9 +73,21 @@
   my $copy = bless({ %$self }, ref($self));
   my $req = $c->req;
   $copy->req($req);
+  $copy->fill_action($c, $_) for qw/postback completion cancellation/;
   return $copy;
 }
 
+sub fill_action {
+  my ($self, $c, $fill) = @_;
+  my $url_meth = "${fill}_url";
+  my $args_meth = "${fill}_action";
+  my @args = @{$self->$args_meth};
+  my ($controller, $action_name) = (shift(@args), shift(@args));
+  my $action = $c->controller($controller)->action_for($action_name);
+  my $uri = $c->uri_for($action => @args);
+  $self->$url_meth("${uri}");
+}
+
 sub build_paypal_gateway {
   my $self = shift;
   return ($self->debug_mode
@@ -85,10 +137,27 @@
 sub correlation_info {
   my $self = shift;
   return {
+    amount => $self->req->params->{mc_gross},
     map { ($_ => $self->req->params->{$_}) } qw/invoice custom/
   };
 }
 
+sub form_info {
+  my ($self, $args) = @_;
+  foreach my $key (qw/amount item_name/) {
+    confess "${key} must be defined" unless defined($args->{$key});
+  }
+  return {
+    business => $self->business_email,
+    postback_url => $self->postback_url,
+    return => $self->completion_url,
+    cancel_return => $self->cancellation_url,
+    cmd => '_ext-enter',
+    redirect_cms => '_xclick',
+    %$args
+  };
+}
+
 package Catalyst::Model::PayPal::IPN::ErrorHandle;
 
 use Moose;




More information about the Catalyst-commits mailing list