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);
}