Ok, so in the end I found out I can use JSON (for some reason the SOAP request just didn't wanna work for me - it kept moaning that I needed to use SOAP11 or SOAP12, which is was!)
Here is what I got working with PayPal Parallel Payments, using the JSON method:
use HTTP::Request::Common;
use LWP::UserAgent;my $user = 'foobar.user';
my $password = '1396280437';
my $signature = 'the secret sig';
my $application_id = 'APP-80W284485P519543T';
my $url = 'https://svcs.sandbox.paypal.com/AdaptivePayments/Pay';
my $ua = LWP::UserAgent->new();
my $headers = HTTP::Headers->new(
'X-PAYPAL-SECURITY-USERID' => $user,
'X-PAYPAL-SECURITY-PASSWORD' => $password,
'X-PAYPAL-SECURITY-SIGNATURE' => $signature,
'X-PAYPAL-APPLICATION-ID' => $application_id,
'X-PAYPAL-DEVICE-IPADDRESS' => $ENV{REMOTE_ADDR},
'X-PAYPAL-REQUEST-DATA-FORMAT' => 'JSON',
'X-PAYPAL-RESPONSE-DATA-FORMAT' => 'JSON'
);
my $json_var = {
requestEnvelope => {
detailLevel => "ReturnAll",
errorLanguage => "en_US",
},
actionType => "PAY",
currencyCode => "USD",
receiverList => {
receiver => [
{
amount => 5,
email => 'testing@gmail.com'
},
{
amount => 15,
email => 'foobar@gmail.com'
}
],
},
returnUrl => 'http://sitexx.com/return.cgi',
cancelUrl => 'http://sitexx.com/cancel.html'
};
use JSON;
my $new_json = JSON::to_json($json_var);
my $request = HTTP::Request->new( 'POST', $url, $headers, $new_json );
my $response = $ua->request( $request );
my $json_returned = decode_json($response->decoded_content);
print qq|Location: https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ap-payment&paykey=$json_returned->{payKey} \n\n|;
The only thing I can't work out, is how to have to provide different shipping prices for each person. Using the normal HTML forms you can just do:
<input type="hidden" name="shipping" value="9">
However, trying to pass in "shipping" as a value, within the "receiver" section, doesn't seem to work. Not sure if anyones got any suggestions on that?
UPDATE:
Mmm actually, maybe its not working. According to this page: https://developer.paypal.com/docs/classic/api/adaptive-payments/SetPaymentOptions_API_Operation/ , the format should be like: &receiverOptions[0].receiver.email=test@test.com&receiverOptions[0].invoiceData.item[0].name=ITEM1&receiverOptions[0].invoiceData.item[0].price=50.0&receiverOptions[0].invoiceData.item[0].itemCount=2&receiverOptions[0].invoiceData.item[0].itemPrice=25.0&receiverOptions[0].invoiceData.totalTax=25.0&receiverOptions[0].invoiceData.totalShipping=25.0
My JSON being passed along comes up as:
{"receiverOptions":[{"receiver":{"email":"andyxxx@gmail.com"},"invoiceData":{"item":[{"name","ITEM1","price",50,"itemCount",2,"itemPrice",25,"totalTax",5,"totalShipping",10}]}},{"receiver":{"email":"foobar@gmail.com"},"invoiceData":{"item":[{"name","ITEM2","price",15,"itemCount",1,"itemPrice",15,"totalTax",0,"totalShipping",20}]}}],"requestEnvelope":{"errorLanguage":"en_US","detailLevel":"ReturnAll"},"payKey":"AP-2LN695598Y955615N"}
The response comes back as:
'responseEnvelope' => {
'correlationId' => '0ba8c3bf33425',
'timestamp' => '2014-04-01T07:10:07.752-07:00',
'ack' => 'Success',
'build' => '10273932'
}
...so its not fataling... but when I goto the payment page, I don't see any shipping, quantity (or anything else I add here). I'm a bit baffled as to why this is the case?
The more pretty version of that JSON (in a perl variable, before converting to JSON), which is easier to read:
receiverOptions => [
{
receiver => {
email => 'andyxxx@gmail.com'
},
invoiceData => {
item => [{
name => "ITEM1",
price => 50,
itemCount => 2,
itemPrice => 25,
totalTax => 5,
totalShipping => 10,
}]
}
},{
receiver => {
email => 'foobar@gmail.com'
},
invoiceData => {
item => [{
name => "ITEM2",
price => 15,
itemCount => 1,
itemPrice => 15,
totalTax => 0,
totalShipping => 20,
}]
}
}
]
Any suggestions?