Thanks Alfie,

Would I be correct in preceding the call to Business::PayPal::IPN->new() by
$Business::PayPal::IPN::GTW = 'https://www.sandbox.paypal.com/cgi-bin/webscr
';
or how else do I ensure that it is using the sandbox?

Jim

On 26/02/07, Alfie John <[EMAIL PROTECTED]> wrote:

Hey Jim,
While testing using a sandbox, modifying $Business::PayPal::IPN::GTW is a
good idea. Otherwise it could be expensive since your loosing out on fees
during each transaction.

To give you a bit of an idea on how I used it:

---8<---

use Business::PayPal::IPN;

if ( my $ipn = Business::PayPal::IPN->new() )
{
unless ( $ipn->item_name() )
{
print "Content-type: text/plain\n\nOK";

exit;
}

unless ( $ipn->receiver_email() eq $my_email )
{
die "receiver_email is SUSPICIOUS: " . $ipn->dump();
}

unless ( $ipn->payer_email() )
{
die "payer_email is not a valid email address: " . $ipn->dump();
}

my $payment;

if ( $ipn->payment_gross() )
{
unless ( $ipn->payment_gross() =~ m{ ^ ( \d+ [.]? \d{0,2} ) $ }x )
{
die "payment_gross is not a valid number: " . $ipn->dump();
}

if ( $ipn->payment_fee() )
{
unless ( $ipn->payment_fee() =~ m{ ^ ( \d+ [.]? \d{0,2} ) $ }x )
{
die "payment_fee is not a valid number: " . $ipn->dump();
}
}

$payment = $ipn->payment_gross() - ( $ipn->payment_fee() || 0 );
}
elsif ( $ipn->settle_amount() && $ipn->settle_current() eq 'USD' )
{
unless ( $ipn->settle_amount() =~ m{ ^ ( \d+ [.]? \d{0,2} ) $ }x )
{
die "settle_amount is not a valid number: " . $ipn->dump();
}

$payment = $ipn->settle_amount();
}
else
{
die "currency not in USD: " . $ipn->dump();
}

eval {
My::Class->create(
'transaction_id' => $ipn->txn_id(),
'url'            => $ipn->item_name(),
'email'          => $ipn->payer_email(),
'payment'        => $payment,
'my_custom1'     => ( $ipn->option_selection1() ? 1 : 0 ),
);
};

if ( $@ )
{
unless ( $@ =~ m{ DBD::mysql::db do failed: Duplicate entry } )
{
die "duplicate record found";
}
}
}

--->8---

Alfie John
http://www.freehouse.com.au

On 26/02/2007, at 8:11 PM, Jim Rey wrote:

I've decided using Business::PayPal::IPN, but I first need to test my
process using the paypal sandbox. I have still to setup the sandbox
properly, but in order to use it, may I assume that I have proceed the call
to:

if ($Ipn = new Business::PayPal::IPN ()) {
...
}

by something like:

$Business::PayPal::IPN::GTW = 'https://www.sandbox.paypal.com/cgi-bin/webscr
';

Jim

On 22/02/07, Jim Rey <[EMAIL PROTECTED]> wrote:
>
> Thanks Lionel,
>
> Shortly before you replied I managed to get through to PayPal and
> apparently "pending" applied to payments via a bank account which takes 4 to
> 5 working days here in the UK.  During the time it takes to clear we are
> going to wait for completion.  I'm going to ask PayPay if there is any way
> the PayPal account can be accessed READONLY so I can check the status of
> pending orders for completion, but, initially at least, we will probably
> have to login to see for ourselves.
>
> Jim
>
> On 22/02/07, Lionel MARTIN < [EMAIL PROTECTED]> wrote:
> >
> >  Hi Jim,
> >
> > Normally, when the status is pending, Paypal sends you a new
> > notification when the status becomes completed, if it ever becomes
> > completed. So, from your part, dying here would just be fine. (or store data
> > for your records)
> >
> > Lionel.
> >
> > ----- Original Message -----
> >  *From:* Jim Rey <[EMAIL PROTECTED]>
> > *To:* Alfie John <[EMAIL PROTECTED]>
> > *Cc:* Mason List <mason-users@lists.sourceforge.net>
> > *Sent:* Thursday, February 22, 2007 3:48 PM
> > *Subject:* Re: [Mason] How do I implement PayPal IPN code in Mason?
> >
> > Alfie
> >
> > The code example shows:
> >
> >   my $ipn = new Business::PayPal::IPN() or die 
Business::PayPal::IPN->error();
> >
> >   # if we come this far, we're guaranteed it was a valid transaction.
> >
> >
> >   if ( $ipn->completed() ) {
> >
> >     # means the funds are already in our paypal account.
> >
> >   } elsif ( $ipn->pending() ) {
> >     # the payment was made to your account, but its status is still pending
> >
> >
> >     # $ipn->pending() also returns the reason why it is so.
> >
> >
> >   } elsif ( $ipn->denied() ) {
> >     # the payment denied
> >
> >   } elsif ( $ipn->failed() ) {
> >     # the payment failed
> >
> >   }
> >
> > Obviously, I won't use die because it is generally bad web practice,
> > but if the returned status is pending, what do you do, resubmit at intervals
> > using cron job?
> >
> > Jim
> >
> > On 22/02/07, Jim Rey <[EMAIL PROTECTED]> wrote:
> > >
> > > Alfie
> > >
> > > Thanks
> > >
> > > I'll check it out.
> > >
> > > Jim
> > >
> > > On 22/02/07, Alfie John <[EMAIL PROTECTED]> wrote:
> > > >
> > > > Hey Jim,
> > > > I've used Business::PayPal::IPN in the past and found it very
> > > > reliable.
> > > >
> > > > CPAN is your friend:
> > > > http://search.cpan.org/search?query=paypal+ipn&mode=all
> > > >
> > > > Alfie John
> > > > http://www.freehouse.com.au
> > > >
> > > > On 23/02/2007, at 12:30 AM, Jim Rey wrote:
> > > >
> > > >  Hi
> > > >
> > > > I have downloaded some sample code written in perl from the PayPal
> > > > site, but it appears to handle the POSTed parameters directly rather 
like in
> > > > CGI perl. I use mod_perl2 and Apache2 code. Does anyone have a copy of 
this
> > > > code already converted for Mason2 / mod_perl2 / Apache2?
> > > >
> > > > Jim Rey
> > > >
> > > > The free code provided follows:
> > > >
> > > > #!/usr/bin/perl
> > > >
> > > > #(requires LWP::UserAgent)
> > > >
> > > > # read post from PayPal system and add 'cmd'
> > > > read (STDIN, $query, $ENV{'CONTENT_LENGTH'});
> > > > $query .= '&cmd=_notify-validate';
> > > >
> > > > # post back to PayPal system to validate
> > > > use LWP::UserAgent;
> > > > $ua = new LWP::UserAgent;
> > > > $req = new HTTP::Request 'POST','http://www.paypal.com/cgi-bin/webscr
> > > > ';
> > > > $req->content_type('application/x-www-form-urlencoded');
> > > > $req->content($query);
> > > > $res = $ua->request($req);
> > > >
> > > > # split posted variables into pairs
> > > > @pairs = split(/&/, $query);
> > > > $count = 0;
> > > > foreach $pair (@pairs) {
> > > > ($name, $value) = split(/=/, $pair);
> > > > $value =~ tr/+/ /;
> > > > $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> > > > $variable{$name} = $value;
> > > > $count++;
> > > > }
> > > >
> > > > # assign posted variables to local variables
> > > > $item_name = $variable{'item_name'};
> > > > $item_number = $variable{'item_number'};
> > > > $payment_status = $variable{'payment_status'};
> > > > $payment_amount = $variable{'mc_gross'};
> > > > $payment_currency = $variable{'mc_currency'};
> > > > $txn_id = $variable{'txn_id'};
> > > > $receiver_email = $variable{'receiver_email'};
> > > > $payer_email = $variable{'payer_email'};
> > > >
> > > > if ($res->is_error) {
> > > > # HTTP error
> > > > }
> > > > elsif ($res->content eq 'VERIFIED') {
> > > > # check the $payment_status=Completed
> > > > # check that $txn_id has not been previously processed
> > > > # check that $receiver_email is your Primary PayPal email
> > > > # check that $payment_amount/$payment_currency are correct
> > > > # process payment
> > > > }
> > > > elsif ($res->content eq 'INVALID') {
> > > > # log for manual investigation
> > > > }
> > > > else {
> > > > # error
> > > > }
> > > > print "content-type: text/plain\n\n";
> > > >
> > > >
> > > > --
> > > > Jim Rey
> > > > 48 Laburnum Park
> > > > Bradshaw
> > > > Bolton BL2 3BU
> > > > United Kingdom
> > > > Tel: 01204 593 222
> > > > Mob: 07816 751 874
> > > > 
-------------------------------------------------------------------------
> > > >
> > > > Take Surveys. Earn Cash. Influence the Future of IT
> > > > Join SourceForge.net's Techsay panel and you'll get the chance to
> > > > share your
> > > > opinions on IT & business topics through brief surveys-and earn
> > > > cash
> > > > 
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV_______________________________________________
> > > > Mason-users mailing list
> > > > Mason-users@lists.sourceforge.net
> > > > https://lists.sourceforge.net/lists/listinfo/mason-users
> > > >
> > > >
> > > >
> > >
> > >
> > > --
> > > Jim Rey
> > > 48 Laburnum Park
> > > Bradshaw
> > > Bolton BL2 3BU
> > > United Kingdom
> > > Tel: 01204 593 222
> > > Mob: 07816 751 874
> > >
> >
> >
> >
> > --
> > Jim Rey
> > 48 Laburnum Park
> > Bradshaw
> > Bolton BL2 3BU
> > United Kingdom
> > Tel: 01204 593 222
> > Mob: 07816 751 874
> >
> > ------------------------------
> >
> >
> > -------------------------------------------------------------------------
> > Take Surveys. Earn Cash. Influence the Future of IT
> > Join SourceForge.net's Techsay panel and you'll get the chance to
> > share your
> > opinions on IT & business topics through brief surveys-and earn cash
> > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> >
> > ------------------------------
> >
> > _______________________________________________
> > Mason-users mailing list
> > Mason-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/mason-users
> >
> >
> >
>
>
> --
> Jim Rey
> 48 Laburnum Park
> Bradshaw
> Bolton BL2 3BU
> United Kingdom
> Tel: 01204 593 222
> Mob: 07816 751 874
>



--
Jim Rey
48 Laburnum Park
Bradshaw
Bolton BL2 3BU
United Kingdom
Tel: 01204 593 222
Mob: 07816 751 874





--
Jim Rey
48 Laburnum Park
Bradshaw
Bolton BL2 3BU
United Kingdom
Tel: 01204 593 222
Mob: 07816 751 874
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to