Jump to content


Photo

Problem in calling Masspay API using PHP


  • This topic is locked This topic is locked
1 reply to this topic

#1 ranabir

ranabir

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 27 January 2006 - 09:55 AM

Hello,

I want to use the Masspay API using php. I tried to make the API call using SOAP and CURL but all in vain since it takes me to paypal.com's index page. My guess is i have messed up the xml part. Here is the xml part:
/*********************************************/

<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<SOAP-ENV:Envelope
xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\"
xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"
xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\"
SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">
<SOAP-ENV:Header>
<RequesterCredentials
xmlns=\"urn:ebay:api:PayPalAPI\"
SOAP-ENV:mustUnderstand=\"1\">
<Credentials xmlns=\"urn:ebay:apis:eBLBaseComponents\">
<Username>$username</Username>
<Password>$password</Password>
<Subject/>
</Credentials>
</RequesterCredentials>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<MassPayReq xmlns=\"urn:ebay:api:PayPalAPI\">
<MassPayRequest xsi:type=\"ns:MassPayRequestType\">
<Version xmlns=\"urn:ebay:apis:eBLBaseComponents\" xsi:type=\"xsd:string\">1.0</Version>
<EmailSubject xsi:type=\"xsd:string\">Your payment is here! (Rhesus Monkey Society affiliate program)</EmailSubject>
<MassPayItem xsi:type=\"ns:MassPayRequestItemType\">
<ReceiverEmail xsi:type=\"ns:EmailAddressType\">$recipient</ReceiverEmail>
<Amount currencyID=\"USD\" xsl:type=\"cc:BasicAmountType\">0.20</Amount>
<UniqueID xsi:type=\"xs:string\">$identifier</UniqueID>
<Note xsl:type=\"xsd:string\">This is your payment.</Note>
</MassPayItem>
</MassPayRequest>
</MassPayReq>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
/*********************************************/

Can somebody help me out from this situation.

Thanks in advance.

Ranabir

#2 joshcrad

joshcrad

    Newbie

  • Members
  • Pip
  • 9 posts

Posted 20 February 2006 - 06:21 AM

Here's what I have. It works when you load the script in the browser, but for some reason, I cannot get it to work properly when called from another script. Hope it helps you though.



<?php

# Set the temp file name to a string based on the process ID
$tempfile = "/home/domain/tempfile";
$apiusername = "username_api1.hotmail.com";
$apipw = "password";
$certpath = "sb_cert_key.pem";
$receiver = "address1@hotmail.com";

$SOAPrequest = <<< End_Of_Quote
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header>
<RequesterCredentials
xmlns="urn:ebay:api:PayPalAPI"
SOAP-ENV:mustUnderstand="1">
<Credentials xmlns="urn:ebay:apis:eBLBaseComponents">
<Username>$apiusername</Username>
<Password>$apipw</Password>
<Subject/>
</Credentials>
</RequesterCredentials>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<MassPayReq xmlns="urn:ebay:api:PayPalAPI">
<MassPayRequest xsi:type="ns:MassPayRequestType">
<Version xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="xsd:string">1.0</Version>
<EmailSubject xsi:type="xsd:string">Your payment is here!</EmailSubject>
<MassPayItem xsi:type="ns:MassPayRequestItemType">
<ReceiverEmail xsi:type="ns:EmailAddressType">$receiver</ReceiverEmail>
<Amount currencyID="USD" xsl:type="cc:BasicAmountType">10.00</Amount>
<Note xsl:type="xsd:string">This is your payment.</Note>
</MassPayItem>
</MassPayRequest>
</MassPayReq>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

End_Of_Quote;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.sandbox.paypal.com/2.0/");
curl_setopt($ch, CURLOPT_SSLCERT, $certpath);
curl_setopt($ch, CURLOPT_POSTFIELDS, $SOAPrequest);

curl_exec ($ch);
if (curl_error($ch))
printf("Error %s: %s", curl_errno($ch), curl_error($ch));
curl_close ($ch);

?>


This script is pointed at sandbox. If you want it to point at the live site, take out sandbox to look like this line:

curl_setopt($ch, CURLOPT_URL,"https://api.paypal.com/2.0/");

I haven't tried it on the live site yet.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users