Simbiotiq Articles Home Page


in
 Interested in People Search? Try People Search by SSN, Reverse Phone Search or Run a Background Check for FREE! 


PERL PayPal Mass Pay Example
by Oliver Cage, 24-Nov-2008
Visits: 401, Rating: 3.8
 Tags: coding-sitesperl
         

        PayPal offers a way (at least this is the only one i found) to pay someone. This feature is useful when you have affiliates, because you may want to pay them once they subscribe, automaticaly. For this i found usefull the payment method called Mass Pay via the API interface. This method is available only in US, and requires to have a Premier or Business account , and also to feed your account from a bank account. Below there is a simple perl example. Note that the example use USD as transfer currency. In order to use it, you will need to enable API user, and to have a certificate generated by PayPal. Go to Profile->API Access, then create your
account for API, download the certificate, and authorize the API account you created for Mass Payment (note that this API account is NOT the same as your paypal account, it's like a "sub-account").

--- Begin Code ----

#!/usr/bin/perl
use XML::Simple;
use SOAP::Lite;
# use SOAP::Lite +trace; # This is for debug
use strict;

$ENV = "path/to/cert_key_pem.txt";
$ENV = "path/to/cert_key_pem.txt";
my $buff=pp_mass_pay ( '2.0',
                       'Funds Received',
                      'target@mail.addr','2',
                       'Thanks for joining',
                       'paypal.api1.somehost.com',
                       'apiPass',
                       'https://api.paypal.com/2.0/' );
print show_pp_response($buff);


sub pp_mass_pay {
# Subroutine that do the payment
# Usage: pp_mass_pay($ver,$emailsubj,$target,$amount,$note,$apiuser,$apipass,$url)
# $ver = API version (currently 2.0)
# $emailsubj = Subject of the mail PP will send to the customer
# $target = Mail address of the person you are sending the money
# $amount = Amount of USD you are sending
# $note = additional note included in the mail sent to the customer
# $apiuser = Your API username
# $apipass = Your API password
# $url = url of the PP API (currently https://api.paypal.com/2.0/)
# RETURN VALUE: the response of the site (XML Format)

 

my $xmlns = 'urn:ebay:api:PayPalAPI';
my $service = SOAP::Lite
                ->proxy($_[7])
                ->readable(1)
                ->outputxml(1)
                ->uri('urn:ebay:api:PayPalAPI')
                ->on_action(sub{ sprintf "%s%s", @_ });
my $request = SOAP::Data->name( "MassPayRequest" =>
                SOAP::Data->value(
                        SOAP::Data->name(
                                "Version" => $_[0]
                                )->attr(
                                        {xmlns=>"urn:ebay:apis:eBLBaseComponents"}
                                        )->type("xsd:string"),
                        SOAP::Data->name(
                                "EmailSubject" => $_[1]
                                )->type("xsd:string"),
                        SOAP::Data->name(
                                "MassPayItem" =>
                                    SOAP::Data->value(
                                        SOAP::Data->name(
                                            "ReceiverEmail" => $_[2]
                                             )->type("ns:EmailAddressType"),
                                        SOAP::Data->name (
                                            "Amount" => $_[3]
                                             )->attr(
                                                {currencyID=>"USD"}
                                                )->type("cc:BasicAmountType"),
                                        SOAP::Data->name (
                                            "Note" => $_[4]
                                            )->type("xsd:string")
                                            )
                                        )->type("ns:MassPayRequestItemType")
                                )
                        )->type("ns:MassPayRequestType");

# Create the Security Header
my $header = SOAP::Header->name("RequesterCredentials" =>
                SOAP::Header->value(
                        SOAP::Data->name("Credentials" =>
                                SOAP::Data->value(
                                   SOAP::Data->name("Username" => $_[5])->type(""),
                                   SOAP::Data->name("Password" => $_[6])->type(""),
                                   SOAP::Data->name("Subject")->type("")
                                )
                        )->attr({xmlns=>"urn:ebay:apis:eBLBaseComponents"})
                )
              )->attr({xmlns=>$xmlns})->mustUnderstand("1");

# Create the Method
my $method = SOAP::Data
                ->name('MassPayReq')
                ->attr({xmlns=>$xmlns});

 

# Execute the call
return $service->call($header, $method => $request);

}
sub show_pp_response {
# Subroutine that parse the paypal response
# Usage: show_pp_response ($response);
# returns "Successn" if no error, or error, in text format

my $xs = new XML::Simple;
my $r=$xs->XMLin($_[0]);
my $pp_msg="";
return "Success\n"
     if ($r->{'SOAP-ENV:Body'}->{'MassPayResponse'}->{'Ack'}->{'content'} =~ /success/i);

$pp_msg ="Timestamp : ";
$pp_msg.=$r->{'SOAP-ENV:Body'}
                ->{'MassPayResponse'}
                    ->{'Timestamp'}
                        ->{'content'}."\n";
$pp_msg.="Ack State : ";
$pp_msg.=$r->{'SOAP-ENV:Body'}
                ->{'MassPayResponse'}
                    ->{'Ack'}
                        ->{'content'}."\n";
$pp_msg.="CorrelationID : ";
$pp_msg.=$r->{'SOAP-ENV:Body'}
                ->{'MassPayResponse'}
                    ->{'CorrelationID'}
                        ->{'content'}."\n";
$pp_msg.="ShortMessage : ";
$pp_msg.=$r->{'SOAP-ENV:Body'}
                ->{'MassPayResponse'}
                    ->{'Errors'}
                        ->{'ShortMessage'}
                            ->{'content'}."\n";
$pp_msg.="LongMessage : ";
$pp_msg.=$r->{'SOAP-ENV:Body'}
                ->{'MassPayResponse'}
                    ->{'Errors'}
                        ->{'LongMessage'}
                            ->{'content'}."\n";
$pp_msg.="ErrorCode : ";
$pp_msg.=$r->{'SOAP-ENV:Body'}
                ->{'MassPayResponse'}
                    ->{'Errors'}
                        ->{'ErrorCode'}
                            ->{'content'}."\n";
$pp_msg.="SeverityCode : ";
$pp_msg.=$r->{'SOAP-ENV:Body'}
                ->{'MassPayResponse'}
                    ->{'Errors'}
                        ->{'SeverityCode'}
                            ->{'content'}."\n";
return($pp_msg);

}



Oliver Cage is a contributor for http://ikoupon.com and http://simbiotiq.com

 Tags: coding-sitesperl

Related Articles:

  • What Happens When Associations Goes Wrong? by Arvind Singh
  • Defining Phases and Tasks with Microsoft Project by Christine Harrell
  • Spam - Problem Of Vital Importance On The Internet by Julia Gulevich
  • How Do Computers Work ? by Andrew James
  • 5 Powerful And Free Methods That I Use To Speed Up My PC by Mehmet Onatli
  • What Is A Hard Drive? by Victor Epand

 
 Interested in People Search? Try People Search by SSN, Reverse Phone Search or Run a Background Check for FREE! 
 Partners: ikoupon.com  •  tribute4mj.com  •  smartgpt.com  •  my-subtitles.com
© simbiotiq.com, 2007-2010. All rights reserved.
Terms and Conditions  •  Contact-us