[Catalyst-commits] r6328 - in trunk: . Catalyst-Model-PayPal-IPN
Catalyst-Model-PayPal-IPN/lib Catalyst-Model-PayPal-IPN/lib/Catalyst
Catalyst-Model-PayPal-IPN/lib/Catalyst/Model
Catalyst-Model-PayPal-IPN/lib/Catalyst/Model/PayPal
matthewt at dev.catalyst.perl.org
matthewt at dev.catalyst.perl.org
Sat Apr 28 01:17:18 GMT 2007
Author: matthewt
Date: 2007-04-28 01:17:16 +0100 (Sat, 28 Apr 2007)
New Revision: 6328
Added:
trunk/Catalyst-Model-PayPal-IPN/
trunk/Catalyst-Model-PayPal-IPN/Makefile.PL
trunk/Catalyst-Model-PayPal-IPN/lib/
trunk/Catalyst-Model-PayPal-IPN/lib/Catalyst/
trunk/Catalyst-Model-PayPal-IPN/lib/Catalyst/Model/
trunk/Catalyst-Model-PayPal-IPN/lib/Catalyst/Model/PayPal/
trunk/Catalyst-Model-PayPal-IPN/lib/Catalyst/Model/PayPal/IPN.pm
Log:
initial draft
Added: trunk/Catalyst-Model-PayPal-IPN/Makefile.PL
===================================================================
--- trunk/Catalyst-Model-PayPal-IPN/Makefile.PL (rev 0)
+++ trunk/Catalyst-Model-PayPal-IPN/Makefile.PL 2007-04-28 00:17:16 UTC (rev 6328)
@@ -0,0 +1,12 @@
+use strict;
+use warnings;
+use inc::Module::Install 0.65;
+
+name 'Catalyst-Model-PayPal-IPN';
+all_from 'lib/Catalyst/Model/PayPal/IPN.pm';
+
+requires 'Catalyst::Runtime' => '5.7006';
+requires 'Moose' => '0.20';
+
+auto_install;
+WriteAll;
Added: trunk/Catalyst-Model-PayPal-IPN/lib/Catalyst/Model/PayPal/IPN.pm
===================================================================
--- trunk/Catalyst-Model-PayPal-IPN/lib/Catalyst/Model/PayPal/IPN.pm (rev 0)
+++ trunk/Catalyst-Model-PayPal-IPN/lib/Catalyst/Model/PayPal/IPN.pm 2007-04-28 00:17:16 UTC (rev 6328)
@@ -0,0 +1,101 @@
+package Catalyst::Model::PayPal::IPN;
+
+use Moose;
+use namespace::clean -except => [ 'meta' ];
+use Business::PayPal::IPN;
+
+extends 'Catalyst::Model';
+
+has 'req' => (
+ is => 'rw', required => 1, lazy => 1,
+ default => sub { confess "req not provided before use" }
+);
+
+has 'debug_mode' => (is => 'rw', required => 1, default => sub { 0 });
+
+has 'paypal_gateway' => (
+ is => 'rw', required => 1, lazy => 1,
+ default => sub { shift->build_paypal_gateway },
+);
+
+has '_ipn_object' => (
+ is => 'ro', required => 1, lazy => 1,
+ default => sub { shift->build_ipn_object },
+);
+
+sub ACCEPT_CONTEXT {
+ my ($self, $c) = @_;
+ return $c->stash->{ref($self)} ||= $self->build_context_copy($c);
+}
+
+sub build_context_copy {
+ my ($self, $c) = @_;
+ my $copy = bless({ %$self }, ref($self));
+ my $req = $c->req;
+ $copy->req($req);
+ return $copy;
+}
+
+sub build_paypal_gateway {
+ my $self = shift;
+ return ($self->debug_mode
+ ? 'https://www.sandbox.paypal.com/cgi-bin/webscr'
+ : 'https://www.paypal.com/cgi-bin/webscr');
+}
+
+sub build_ipn_object {
+ my $self = shift;
+ local $Business::PayPal::IPN::GTW = $self->paypal_gateway;
+ my $ipn = Business::PayPal::IPN->new(query => $self->req);
+ unless ($ipn) {
+ $ipn = Catalyst::Model::PayPal::IPN::ErrorHandle->new(
+ error => Business::PayPal::IPN->error
+ );
+ }
+ return $ipn;
+}
+
+sub is_completed {
+ my $self = shift;
+ return $self->_ipn_object->completed;
+}
+
+sub error {
+ my $self = shift;
+ return unless $self->_ipn_object->isa(
+ 'Catalyst::Model::PayPal::IPN::ErrorHandle'
+ );
+ return $self->_ipn_object->error;
+}
+
+# https://www.paypal.com/IntegrationCenter/ic_ipn-pdt-variable-reference.html
+
+sub buyer_info {
+ my $self = shift;
+ return unless $self->is_completed;
+ return {
+ email => $self->req->params->{payer_email},
+ company_name => $self->req->params->{payer_business_name},
+ phone => $self->req->params->{contact_phone},
+ map { ($_ => $self->req->params->{"address_$_"}) }
+ qw/name street city zip state country country_code/
+ };
+}
+
+sub correlation_info {
+ my $self = shift;
+ return {
+ map { ($_ => $self->req->params->{$_}) } qw/invoice custom/
+ };
+}
+
+package Catalyst::Model::PayPal::IPN::ErrorHandle;
+
+use Moose;
+use namespace::clean -except => [ 'meta' ];
+
+has 'error' => (is => 'ro', required => 1);
+
+sub completed { 0 }
+
+1;
More information about the Catalyst-commits
mailing list