PayPal PHP SDK Download
Video Demo
Download and Contribute
If you are working with Composer you may wish to browse the Packagist directory instead. Otherwise, you can grab the latest version of the PayPal PHP SDK from our GitHub repo.
Documentation / Tutorial
This guide provides details for installing the PayPal PHP SDK download as well as basic usage information.
Looking for Live Help?
Schedule a live meeting with Drew Angell, PayPal Certified Developer, and get all of your questions or concerns answered.
Featured PayPal Products and Services
-
PayPal Support
$100.00 -
PayPal for WooCommerce
FREE! -
WooCommerce Multiple PayPal Accounts Plugin
FREE! -
PayPal Shipment Tracking for WooCommerce
$49.99 -
Offers for WooCommerce
$59.99 -
WordPress PayPal Invoice Plugin
$20.00 -
PayPal Webhooks for WordPress
$79.99 -
Sale!
PayPal IPN for WordPress
Original price was: $59.99.$49.99Current price is: $49.99.
Hey Andrew,
I know you are super-busy, but I am hoping you can help me out real quick.
I am using the latest version of your API (using Paypal v84.0), and am getting an “Internal Error” message returned fro Paypal when using the GetAccessToken API. This happens both in the sandbox and on the live server, and both using the sample script you have included and my own script that I wrote.
The RequestPermissions functionality is working great, but I just can’t get the token/secret back.
Please help! 🙂
Looks like I had a bug in my library for that call. Thanks for bringing this to my attention, and sorry for the trouble!
Open up paypal.class.php and replace lines 6315-6317 with the following.
$Token = isset($GetAccessTokenFields['Token']) ? $GetAccessTokenFields['Token'] : '';
$Verifier = isset($GetAccessTokenFields['Verifier']) ? $GetAccessTokenFields['Verifier'] : '';
$SubjectAlias = isset($GetAccessTokenFields['SubjectAlias']) ? $GetAccessTokenFields['SubjectAlias'] : '';
Just tested to confirm that fixes the problem. Sorry again for the trouble. I’ll make sure to include this in a bug fix release before long.
Hi angelleye, i have downloaded your library v.84 today, and i want to ask you if it’s necessary to apply this patch…
Open up paypal.class.php and replace lines 6315-6317 with the following.
in my lines this is the code:
6315 }
6316
6317
Thanks.
I’m not sure what you’re talking about here, but you shouldn’t have to do anything to the class file.
hi angelleye,
tnx for your good API, i have a quick question, i want use your API paypal payment but how i use this script in datalife engine ?
tnx
I’m not familiar with DataLife Engine but if it’s just a PHP framework you can probably convert this to an actual library/module for DataLife or you should also be able to just include the library as-is into your project and use it accordingly.
My library is just like any other object-oriented PHP class so it should work just fine for you one way or another.
Hi
I am using your module for create recurring payment. Create recurring payment using Credit Card working fine, but thru express checkout it is showing invalid token.
The first two steps are (Initiating token and go to paypal website and login) but for last step (CreateRecurringPaymentsProfile) it shows invalid token ?
do u know why this error coming ?
Thanks
Prajosh
Hi
I fixed the issue
Thanks
Prajosh
I was just about to respond with a sample set of API calls that works for you to compare with your own, but it sounds like you’ve got it. Good deal!
what did u do to fix the issue? im having the same issue and its bugging me!
Prajosh outlined some things he did on server specifically, but usually when I see people run into this it’s just because they didn’t include the billing agreement/recurring payment fields in the SetExpressCheckout, therefore, the token that is generated isn’t acceptable when you call CreateRecurringPaymentsProfile. Here’s a sample set of a flow that works successfully: http://www.angelleye.com/temp/sample-set.php
Thanks for this great class.
I did have to make a few small changes to get it to work on my environment that may be tough for others (they were for me)
1) I had to make both curlRequests in paypal.class.php compatible to deal with the strict standards set on my VPS
2) I had to add this option to both curlRequests:
curl_setopt($curl, CURLOPT_SSLVERSION, 3);
because I was getting no response from Paypal and this error in my Apache2 logs:
Not something I’ve run into. Glad you got it working!
Hi,
I already checked out paypal.class.php ($api_version = ‘85.0’;) with “wrong” data, in order to get “some failure” responses. It seem to be a little typo problem at the line 1477. I changed “if(isset($NVPResponse[‘TOKEN’]) && $NVPResponse[‘TOKEN’] != ”)” with “if(isset($NVPResponseArray[‘TOKEN’]) && $NVPResponseArray[‘TOKEN’] != ”)” and the class worked fine for me
Best regards,
Vali Green
That’s in the latest version that you downloaded from my site..?? I’m not seeing that problem in my local copy. Thanks for letting me know, though. I’ll have to double check what I have posted I guess.
Hi,
I’m using the samples/pay.php, when I make payment for more than one receiver, the description are all the same?
How do I change the description?
thanks
Hi Teddy,
You’ll need to use SetPaymentsOptions to add more details to the payment(s).
Hi,
I tried to call SetPaymentoptions() before the Pay() function call, but the description are still the same.
I intend to do parallel payment and I’m using samples/pay.php script.
Could you help me show the example to set the description for each receiver?
thanks a lot!
Hi,
Thanks for your class and a How-to you posted on x.commerce , I have got my chained payment working in sandbox no probs!
Trouble is, when running in production I’m getting this error :
[ErrorID] => 550001
[Message] => You do not have permission to constrain funding sources
I’ve looked for help on the x.commerce forum but no one’s answered.
Hoping you may be able to shed some light!
Thank you,
Barry
I’m glad you like it. Thanks!
Have you submitted your app to PayPal for approval? If so, they should give you a live App ID for use with their live servers that would provide the permissions necessary to complete your tasks. If you do have a Live ID but it’s still giving you this, they must not have understood exactly what all you needed for some reason. You’ll just need to contact PayPal and let them know what’s happening. As long as they don’t have a problem with your application model they’ll enable the features you need and this error will go away.
Hope that helps.
Andrew
Thanks Andrew.
My live app is “Approved Conditionally” perhaps this is the problem?
It has been Approved Conditionally since February!
have contacted PayPal Merchant Technical Support… will see what they say.
I am trying to setup the preapproval adaptive payments paypal function using this class but am getting the following error and not sure why? Note I replaced some of the root directory and web urls with * symbols just for privacy issues 🙂
Notice: Undefined index: ClientDetails in /home/****/public_html/***/***/includes/paypal.class.php on line 3613
Array
(
[Errors] => Array
(
[0] => Array
(
[Receiver] =>
[Category] => Application
[Domain] => PLATFORM
[ErrorID] => 580001
[ExceptionID] =>
[Message] => Invalid request: {0}
[Parameter] =>
[Severity] => Error
[Subdomain] => Application
)
)
[Ack] => Failure
[Build] => DEV
[CorrelationID] => fe3d776a07575
[Timestamp] => 2012-07-08T08:29:28.840-07:00
[PreapprovalKey] =>
[RedirectURL] =>
[XMLRequest] => ReturnAllen_UShttp://www.*******.org/*****/cancelled.phpAPP-80W284485P519543T24.185.52.248USD2012-08-03http://www.*******.org/*****/paypal/Ipn_process.php?vid=7&amount=5.005.0015.00NOT_REQUIREDhttp://www.*****.org/*****/thankyou.php2012-07-08
[XMLResponse] => 2012-07-08T08:29:28.840-07:00Failurefe3d776a07575DEV580001PLATFORMApplicationErrorApplicationInvalid request: {0}
)
Hi Jason,
Sorry for the delay getting back to you. The Result array that you’ve given me here actually has XML embedded in it, but it doesn’t read like XML unless you View Source and copy from there. Could you please do that so I can see the actual XML request and response that you’re getting?
Hi I’m a student I have the same problem could you pls give me a sample
Which problem are you referring to?
I provided the correct api details. It still giving me some error as follows.
[0] => Array
(
[Receiver] =>
[Category] => Application
[Domain] => PLATFORM
[ErrorID] => 520003
[ExceptionID] =>
[Message] => Authentication failed. API credentials are incorrect.
[Parameter] =>
[Severity] => Error
[Subdomain] => Application
)
You need to make sure $sandbox is evaluating correctly in your config file. If you’re using sandbox credentials but $sandbox is evaluating to false, then it would be sending sandbox credentials to the production endpoint and that would cause this error. Same thing the other way around.
One way or another your credentials are incorrect (probably just the wrong end point if you’re sure about the values you’re using) so you just need to get that resolved.
Thank you,
It worked great.
Its a definately good library for paypal, However, I am not able to get any read me or documentation file. So I have some questions, hope you will helped me out.
a)I am not using adaptive payments, Will this library helpful for me just for permissions service ?
b)Will I need to create one application just for using permissions services functions ?
c)Can you please explain me what should be the flow of the customer in this process ? i.e. In which sequence I should use the methods ? like 1) RequestPermission 2) GetAccessToken next step
a) There are actually 2 sets of Permissions API’s. SetAccessPermissions will work fine for you if you’ve been approved to use the Permissions API’s, but they’re not documenting that API anymore. Now they’re using RequestPermissions, and while I have the majority of this built in, I am unfortunately missing the OAuth stuff that is necessary for these new API’s. I plan to get it added ASAP.
b) You can use Permissions services from within any application you want. You don’t have to make one specific for it. It’s just a matter of having it approved on the PayPal account for which API credentials you’re using.
c) Again, these services aren’t 100% ready in my library, however, if you’re approved for Permissions you can use SetAccessPermissions and that will accomplish the same thing except that it doesn’t use a token. Instead you’ll need to supply the user’s PayPal email address or Payer ID in the SUBJECT parameter of your API requests.
When using your preapproval.php file if I send a “CustomerID” value in the api call to paypal does paypal send the value back and if so how would I get the value back to use in my API notification php file? I read somewhere that CustomerID is an old field that is not used anymore? although your php class requires their to be a value in there?
The CustomerID is optional and is still included in the latest documentation. Unfortunately, I don’t see anything about it in the IPN documentation for Adaptive Payments, so I’m really not sure what to tell you about getting it back on the other end.
That would be a good example of something I’d probably post to MTS if you’re really needing it back outside of your app. You could always store it in session data for easy access within your app, or store it in your database with the Preapproval key that you get back so you can look it up later based on that.
well I am still I guess unclear that when a user comes to my website during the preapproval.php process doesn’t the user ultimately get brought to the paypal.com web page to provide their payment credentials after which they come back to my page? If so then when the user comes back I need to know who they are.
Yes, they’ll be sent to PayPal to approve the application, and then they’ll be sent back to the ReturnURL you specify in the request.
I would just save the customer ID in a session variable so it’s available when the user gets back to your application. At that point you’d also have the Paykey so you could save this paykey in your database along with the rest of that user’s data.
Then any time a payment is ever made with that pay key you’ll know who it belonged to by looking up that customer record with that key.
I have setup the php class and have the config file set to sandbox with my sandbox credentials in there
Now when I try to go through the preapproval.php file shouldn’t I be brought to the paypal.com webpage where I would need to enter in my paypal email address etc ? I ask because right now the file just generates a approval key but how does it know who I am.
Even when I hard code a preapprovalkey that I had generated with the preapproval.php it still does not send me to the paypal page because the pay.php page says “The preapproval key hasn’t been authorized yet” so again I am not sure why my preapproval.php page is not sending me to the paypal website?
not sure what I missed?
Suggestions
You should be getting a RedirectURL back from the library. You need to redirect the user to this URL in order for them to login and explicitly approve the app.
Hi Andrew ..
How do u get a reference to your custom Order or Invoice # sent back in the PP response?? Next to the transaction status this seems like the most obvious thing needed in the response but is not mentioned in the 200page PP dev guide or videos or articles??
What has replaced the old ‘IPN’ script in the new PP API?? ie. How does the webapp get notified of a txn’s success or failure if the customer closes their browser b4 the response arrives or there is a delay in processing??
First, IPN still exists and can be utilized with any payment option you’re using at PayPal. Nothing has replaced it. It’s an addon for any payment you receive and is still very much in use.
Most of the payment requests you send to PayPal will include a field for an invoice number. For example, the NVP API uses the INVNUM parameter where-as the standard HTML buttons use a field called invoice. Either way, IPN, PDT, etc. would all return this value.
Hope that helps.
Andrew
Yes that does help alot .. basically I’d just like to continue using IPN but with ‘PP Payments Advanced’ or ‘Pro’ instead of ‘PP Payments Standard’
Thanks for your reply
Adam – Great work on the API, I have it working on the DoDirectPayment.php, but on the CreateRecurringPaymentsProfile.php, I am getting a “DPRP is disabled for this merchant” error, I have recurring payments enabled in the Paypal Manager. I am trying to set up recurring billing for the user, and charge for the first month.
Seems I am missing something, any suggestions?
It sounds like you’re confusing the PayFlow API with the PayPal Direct API. Enabling it in your account at http://manager.paypal.com is different from http://www.paypal.com. If you’re going to use the DirectPayment API with Recurring Payments you have to get that enabled on top of Payments Pro itself. You’ll end up paying $60/mo for that…$30/mo for Pro and another $30/mo for Recurring Payments.
Recurring Payments with Express Checkout is free. If you do indeed need to use the PayFlow API’s, this library won’t do it for you. I do have a separate library for PayFlow, but it’s not quite as complete as this one and I haven’t officially released it. I’ve been meaning to add it as an extended class of this library, but just haven’t gotten around to that. If you want it, contact me directly and I can send it your way.
thanks for job!
i found error?
when i try to execute
$paypal = new PayPal_Adaptive($config);
$response = $paypal->GetPaymentOptions($pay_key);
i got “Call to a member function getElementsByTagName() on a non-object in”
and this line is in
$InstitutionCustomer = $DOM->getElementsByTagName(‘institutionCustomer’)->length > 0 ? $DOM->getElementsByTagName(‘institutionCustomer’)->item(0)->nodeValue : ”;
in function GetPaymentOptions($PayKey)
Thanks for pointing that out! I found the problem and got it fixed. I’ll email you a copy of the current library file, and of course this fix will be included in the next official release.
Would it be possible for me to get a copy of the most recent library as well?
I had the class files set up and integrated into our site, then it suddenly started giving me Invalid request: {0} errors.
Any idea what could cause this error out of (seemingly) nowhere?
Yes, contact me directly at service@angelleye.com and I’ll send you the updated copy of the library. If you want to send me what you’re working with I’ll see if I can reproduce the problem you’re having and help you fix it.
Andrew
I’m probably blind, but I don’t see any licence information. Does that mean the intent was public domain?
It is open-source. Feel free to use and play with it all you want.
Hi Andrew,
thanks so mush for this API , I know my question is stupid , but can you tell me if there’s a tuto explaining step by step , how to implement this with website .
Note: I’m new to this stuff also I get confused with this numbers of files included with the API . Thanks for your help again (-_-)
All I really have right now is the basic overview video which covers how to make calls with the library. All the calls work the same way, so it’s just a matter of knowing which calls you want to make and in what order you need to make them. If you want to let me know your overall goal I can guide you more directly.
Hi Andrew,loving your Paypal class. I’ve almost got it all working, I’m using your expresscheckout scripts. I keep getting [CHECKOUTSTATUS] => PaymentActionNotInitiated and if I log into the business store I get Payment status under review. Ive used your sample files, and like you Ive posted the PaypalResult in a session etc, but just can’t get the thing to complete. Any ideas what I havent set or where the problem lies. I’ll go through your sample files again
Actually if I scroll down, further to the DoExpressCheckoutPayment, I get the following in my array:
[PAYMENTINFO_0_PAYMENTSTATUS] => Pending
[PAYMENTINFO_0_PENDINGREASON] => paymentreview
[PAYMENTINFO_0_REASONCODE] => None
Any ideas how to rectify this.
Thanks
Same thing…the DECP response is just showing you what the PayPal account is also showing you. Again, need to find more details about why exactly the payment is under review, which you should be able to see in the transaction details page.
This would have something to do with your PayPal account settings. Do the transaction details in the account provide any details about why the payment is under review? It could be from Fraud Management Filters you have configured, for example. The transaction details should give you a better idea.
Thanks Andrew,
I’ve disabled Payment Review for my business sandbox account. Payments seem to be accepted straightaway. I wonder if this option is available n the real paypal site…
Now I’ve got the samples working, going to start getting it working with my real code
Hello, were there any changes to Paypal library? Because now I get
Strict Standards: Declaration of PayPal_Adaptive::CURLRequest() should be compatible with PayPal::CURLRequest($Request) in /domains/xxx/public_html/xxxx/angelleye2013/includes/paypal.adaptive.class.php on line 4336 Notice: Undefined index: TOKEN in /domains/xxxx/public_html/test/angelleye2013/samples/DoExpressCheckoutPayment.php on line 16
And
[L_ERRORCODE0] => 10410
[L_SHORTMESSAGE0] => Invalid token
[L_LONGMESSAGE0] => Invalid token.
Hello,
what is the different between the code you provided here and this here:
http://www.angelleye.com/paypal-payments-pro-php-class/
Nothing, actually. I just renamed the file at one point but didn’t get all of my links fixed up. The contents of each is the same, though. They’re both 179KB in size. I’ve been meaning to setup a redirect from one to the other and just haven’t gotten it done yet. Sorry for the confusion.
I am new to this, I have the library working and I can successfully set permissions, but I cannot see how I can get a User’s info without submitting the “Subject”. I cannot get the “Subject” (email) without getting the Basic Info, and I can’t trust the user to enter the correct email . . .?
I’m sorry, but my library is not quite 100% up-to-date with the new permissions API yet. When they first launched the Permissions API it worked with RequestPermissions but required that you use SUBJECT like you mention. I have the new API calls (SetAccessPermissions, etc.) included in my library, but I’ve yet to get all of the token stuff implemented. Sorry for the confusion. I plan to get that done soon, but until then you’ll probably need to use PayPal’s libraries for that.
Hi Angell,
have you considered putting your code on github to allow pull requests?
Thanks
Jonathan
Yes, I would love to do that. I actually do have a version on there right now: https://github.com/angelleye/paypal
Unfortunately, I’m just not familiar enough with the workflow involved with using Git confidently. I’d pay you for some training on that if you’re interested..??
Hi,
Im a freelance developer and I tangled with your paypal api version. Im using only the getbalance but I have a problem with your files paypal.access.class.php that is nowhere to be found on your include files. Could you tell me if this file is needed?
Thanks
You can just remove that include. I do have a separate child class for PayPal Access, which is what that’s for, but it’s not quite done yet and should have been removed from that parent class file. Sorry about that.
if i removed this line in Access.php
require_once(‘../includes/paypal.access.class.php’);
this line will crash
$ppaccess = new PayPalAccess($ppaccess_config);
what do i do?
thks
Yes, if you want to strip that out you just need to make sure and remove both lines. You can’t use new PayPalAccess() if you don’t include the child class, so simply comment out that line and you’ll be good to go.
HI, can yo help me please, is this will work in sandbox and in localhost,becaus i want to test my ipn in localhost.please provide me some steps.
You can’t use “localhost” when testing stuff like that. “localhost” to PayPal’s server is their own server, so if you tell them to send data to “localhost” they’ll send it to themselves. You need to use your public IP or a domain name setup to point to it.
Hi Andrew, Thank you for the quick response,.Yes i tried the public IP and i use the port 80 and it is open. I tried the IPN simulator in sandbox but the error is IPN Delivery Failed. HTTP error code 401: Unauthorized…By the way can you please give some steps how to set up in the config.php ,sorry i am a newbie in your software i just want to try how this will work…I tried to look your video tutorial but i could not clearly see the video and i could not see those parameters that you inputted or what are neeeded in order to run your program. also please provide some steps or example how to set up your IPN solutions program… I apologize again for my english and i am still newbie in this integration in paypal.I hope you do understand.
Fatal error: Call to undefined method PayPal::APIName() in C:\xampp\htdocs\tras\template.php on line 20
Which API are you trying to use? Which file are you working from? I don’t think I included a general template.php with my library did I..??
PayPal::APIName() indeed would not exist. APIName needs to be the name of the actual you’re trying to use. There are methods for each API in the library. For example, PayPal->DoDirectPayment().
Hello I have downloaded Angell EYE PHP Class Library for PayPal(version 84.0). I have uploaded the sample of DoDirectPayment into two different servers with same configuration.
http://www.hangover-cured.com/test/ —hosted in ipage
http://newdigha.com/soumya-test/DoDirectPayment.php –hosted in justhost
I am not able to get why am I not getting any responses in 1st link( which is hosted in ipage).Second links is working fine.Is there any issue with the host.
I am in a trouble.If you can then please help me.
I will be waiting for your reply.
Thanks
You need to make sure CURL is enabled on your server.
Do you have any idea how to enable curl in Ipage host.I have never used ipage.Totally new to this host.
Thanks for reply.
It’s something you do within the php.ini file, so you’ll need access to that. Here’s a guide you can follow.
If you don’t have access to edit the php.ini file on your server you’ll need to submit a support ticket to iPage and request that they enable it for you.
Thanks a lot.I have submitted a ticket to enable curl.
I have enabled the Curl in the server.But still I am not getting any responses from paypal.Is there anything more that I have to enable?
I am in trouble.I have to submit it by today.Not getting what to do. I think the problem is in host.If you can then please help me.
Thanks
Create a file on your server and put nothing but the following inside it.
Here it shows my server php version.
http://www.hangover-cured.com/test/
I dont see the protocols here.Can you just tell me whether its possible to integrate angeleye sdk in this server or not? If it is not possible then I will let the client know.Or should I have to contact server administrator?
I have used this sdk in lots of server.I have not faced this kind of problems in my experience.
Extremely sorry for giving you trouble.Thanks for all your help.
Yes it’s possible, but the server needs to be configured correctly with CURL. If you don’t see Protocols in there something must be wrong.
I have upgraded my php version to 5.3.13.Now I can see the protocols there as well as my curl is enabled.Is there any more settings that I have to enable.
I can’t figure it out why this is not working in this server.
You can see the php info here: http://boozcloozcom.ipage.com/testinfo.php
Please help.I am in trouble.
Thanks
Are you still getting a blank response back or what exactly is curl returning? Check curl_error() to see what could be coming back there as well.
I am getting an ‘Invalid Token’ error when executing the CreateAndSendInvoice sample. any ideas why? I have verified I am using my correct test credentials
That’s an interesting error to be getting with CreateAndSendInvoice as there is no token included in that request. Are you sure you’ve got the correct call setup? That sounds like it would be involving Express Checkout, but that’s separate from invoicing, so I’m a little confused about what you’re doing. Are you working directly from the CreateAndSendInvoice.php file included? If you want to send me your file I’ll take a look and see what you’ve got going on.
Hi,
Thanks for your class, I am using pay() method of Paypal_adaptive class in CodeIgniter, its working fine on SANDBOX mode but having issue on LIVE mode while My live app is “Approved Conditionally”.
[ErrorID] => 550001
[Message] => You do not have permission to constrain funding sources
Hoping you may be able to shed some light!
Thank you
Shrikant Dhyani
The funding source options have to be specifically approved for your app in order to be used. In most cases, though, those options aren’t necessary. I would just remove them from your request and that should fix your issue.
So should i talk to Paypal for approval? or anything need to fix in my code?
Just remove the funding constraints parameters from your request and that’ll fix it.
Sorry i am not able to getting you, which funding constraints ?
which line i need to modify?
This one
$FundingTypes = array(‘ECHECK’, ‘BALANCE’, ‘CREDITCARD’);
Or
$PayRequestFields = array(
‘ActionType’ => ‘PAY’,
Ohh i got your point, i removed $FundingTypes = array(‘ECHECK’, ‘BALANCE’, ‘CREDITCARD’);
but now showing error – The email account Receiver not in receive money enabled country is based in a country that isn’t enabled to receive payments, Receiver not in receive money enabled country
What’s the exact error code and message? What country is the account that you’re paying based in?
Showing error –
[Receiver] =>
[Category] => Application
[Domain] => PLATFORM
[ErrorID] => 539041
[ExceptionID] =>
[Message] => The email account Receiver not in receive money enabled country is based in a country that isn’t enabled to receive payments
[Parameter] => Receiver not in receive money enabled country
[Severity] => Error
[Subdomain] => Application
Account is USA based and now it showing the below error –
550001 – You do not have permission to constrain funding sources
What happened? Any Idea?
You just need to remove the funding sources from the request. In the $PayPalRequest array at the bottom that combines everything, remove the FundingTypes => $Funding types line.
Thanks for your prompt response, I removed funding source but now i got the below error –
[ErrorID] => 550001
[Message] => You do not have permission to execute this payment implicitly
Don’t know why i am still getting so many errors. Please help me if i did something wrong.
Thank you
Hi Andrew,
I am using your class library for Paypal SetCustomerBillingAgreement method. I setup library in my local system and try to test but found “error: Invalid argument”. can you please help me for that.
Send me a copy of the file you’re working with and I’ll see if I can reproduce the issue.
file name : SetCustomerBillingAgreement.php
$sandbox, ‘APIUsername’ => ‘chintanv.patel-facilitator_api1.indianic.com’, ‘APIPassword’ => ‘1369903572’, ‘APISignature’ => ‘AFcWxV21C7fd0v3bYYYRCpSSRl31A3eFirPG9VliSDhU51SaP.95nkLD’);
$PayPal = new PayPal($PayPalConfig);
// Prepare request arrays
$SCBAFields = array(
‘returnurl’ => ‘http://localhost/paypal/GetBillingAgreementCustomerDetails.php’, // Required. URL to which the customer’s browser is returned after chooing to pay with PayPal.
‘cancelurl’ => ‘http://localhost/paypal/GetBillingAgreementCustomerDetails.php’, // Required. URL to which the customer is returned if he does not approve the use of PayPal to pay you.
‘localcode’ => ”, // Local of pages displayed by PayPal during checkout.
‘pagestyle’ => ”, // Sets the custom payment page style for payment pages associated with this button/link.
‘hdrimg’ => ”, // A URL for the image you want to appear at the top, left of the payment page. Max size 750 x 90
‘hdrbordercolor’ => ”, // Sets the border color around the header of the payment page.
‘hdrbackcolor’ => ”, // Sets the background color for the header of the payments page.
‘payflowcolor’ => ”, // Sets the background color for the payment page.
’email’ => ” // Email address of the buyer as entered during checkout. Will be pre-filled if included.
);
$BillingAgreements = array();
$Item = array(
‘l_billingtype’ => ‘MerchantInitiatedBillingSingleAgreement’, // Required. Type of billing agreement. For recurring payments it must be RecurringPayments. You can specify up to ten billing agreements. For reference transactions, this field must be either: MerchantInitiatedBilling, or MerchantInitiatedBillingSingleSource
‘l_billingagreementdescription’ => ‘mobile services’, // Required for recurring payments. Description of goods or services associated with the billing agreement.
‘l_paymenttype’ => ”, // Specifies the type of PayPal payment you require for the billing agreement. Any or IntantOnly
‘l_billingagreementcustom’ => ” // Custom annotation field for your own use. 256 char max.
);
array_push($BillingAgreements, $Item);
$PayPalRequestData = array(
‘SCBAFields’ => $SCBAFields,
‘BillingAgreements’ => $BillingAgreements
);
// Pass data into class for processing with PayPal and load the response array into $PayPalResult
$PayPalResult = $PayPal->SetCustomerBillingAgreement($PayPalRequestData);
// Write the contents of the response array to the screen for demo purposes.
echo ”;
print_r($PayPalResult);
?>
Hi Andrew,
I want to develop paypal Billing Agreement functionality like https://www.odesk.com/ site.
Hi Andrew,
I am developing a site which has buyers and sellers. Seller upload their product and buyer buy product. When buyer pay after purchase the payment will go to direct seller paypal account.
Seller will not share any api credentials to my site.They just give their paypal id. I tried to use permission api and i got access token from paypal but i could not find any process to use this access token in express checkout.
Is it possible buyer can pay direct to sellers paypal account?
I tried to use Access.php in sample folder but it gives an error.
Please help.
I’ve always worked with the older version of the Permissions API which uses the SUBJECT parameter in your API request along with USER, PASS, SIGNATURE. The tokens should work just fine, though, and I’m pretty sure you just pass it in the headers of your API request. You could also have the site owner do it manually within their PayPal account and use the subject parameter like I mentioned.
Many many thanks for reply. I used your module and i get access token by using GetAccessToken.php in sample and paypal return me a access token.
Now how i can use this access token in express check out to send buyer payment to seller paypal account.
My goal is buyer payment will go to seller account directly.
Please guide me.
hi Andrew,
Thanks for Great Library.
i have integrated Paypal Adaptive parallel payments in sandbox environment and it works fine also i have obtained LiveID from https://apps.paypal.com but when i go live it’s giving me following error
[Receiver] =>
[Category] => Application
[Domain] => PLATFORM
[ErrorID] => 550001
[ExceptionID] =>
[Message] => User is not allowed to perform this action
[Parameter] =>
[Severity] => Error
[Subdomain] => Application
why is it so ? i haven’t verified my PayPal account yet. is it necessary to verify account ?
Yes, you’ll need to verify your account, and I would also recommend confirming it with a credit card, but I don’t think that’s required. If you continue to get the error after that it’s probably got something to do with the APP ID you’re using not having the permissions you require.
Paypal is Working Fine on Live Now.. After verification.
Thanks…
Your Lib. Saved my Time..
Thanks for Great Lib..
Glad to hear it! Let me know if you need any other help.
Awesome work Andrew!
I’m looking through and don’t see an example of chained payments on a subscription. Is that supported? If “yes” can you tell me the function flow I need to do to get that to work? I’m happy to bang my head on the exact details, I just need a quick “call this to set it up, then this to set the chained recipients, then this to do the transaction” type thing.
It’d be really cool if I could do it all embedded too…
Oh, one last thing, haven’t looked for this one yet – does adaptive still do IPN? That’s the easiest way I can think of getting notified of future actions on the subscription.
Thanks boss!
For chained payments with a subscription model you’d have to use Preapproval profiles and basically build your own subscription system that triggers payments accordingly using the preapproval profiles.
So, let’s say I click to subscribe with your service. You could call the Preapproval API and I would log in to PayPal with my account to review and approve the Preapproval profile getting created. You’ll get a Preapproval Key back in that response that you can then use for future payments on my behalf without further approval.
So now that you have that Preapproval Key for me you can immediately call the Pay API to setup the payment using that preapproval key, and go ahead and include a primary and secondary receivers to setup the chain accordingly.
You’ll need to track your subscriptions in your own database and setup some sort of a CRON job or something on your server to automatically trigger payments that are due each day using the subscriber’s preapproval key they got when they first subscribed, so you’ll need to save all of that info in your DB.
Again, you’re basically building your own subscription model with the use of preapproval keys for your subscribers so that you can make Pay calls any time you need to without further approval on their part.
Make sense?
Makes 100% sense! This explains why I’ve never found an example that showed chained & subscription. I figured it just couldn’t be done, but then I’ve seen places that say they can do it (like ezchain), and I never understood how they were doing it.
I’ve already handled the subscription-style coding with a cron and all that. Now I’ll just have to think about if it’s easier for me to do this myself or farm it out to someone like ezchain.
Thanks for your help!
My library makes it real simple for you to just do it yourself. Their fee structure looks a little funky, especially in the lower dollar amounts. Why give somebody a bite if you don’t need to?
Andrew,
I see on the Pre-Approval API the endingDate can’t be further out than a year, and I understand the reasoning behind that.
In my case I’m doing webhosting and their domain name-purchase is right at a year.
Can you shed any insight on the following:
1. Can I have the member renew their endingDate by just sending them over for “another” Pre-Approval? If “yes”, does that in effect just freshen the current one, or does it delete and create a new one?
2. I see that we can request from Paypal to not set a endingDate, do you have any experience on how easy/hard it is to get that approved or under what conditions Paypal typically will/won’t grant such a request?
Thanks!
1) You can send the user over to create a new preapproval at any time. It would indeed be a new one, though, that you would replace the old one with. It wouldn’t just update or extend the existing one. All you have to do, though, is update the preapproval key in your database for the user and use that one from then on.
2) I really can’t give you much info on that, sorry. I know PayPal wants to make their system as open as possible to you, but they have to account for risk/reward. All I can say is go ahead and submit the application, give them a clear and concise argument for why your application needs an open ended preapproval profile, and they may very well let you do it.
I have to say this lib is impressive.
Going to be including it in a site I am developing for a client of mine.
The idea is to send the merchant a percentage of the sale of items customers are selling on their site.
It would presumably be a paychain wouldn’t it? Please correct me if I am wrong here.
Thanks,
Jeremy.
Thanks, glad you like what you see. There are a number of ways you could do that, but yes, a chained payment is one of them that would work just fine. You would use the Pay API with a primary and secondary receiver.
Hello Andrew,
I am getting the error that “DPRP” is disabled for this merchant while using the recurring payment on live. I am using DO DIRECT PAyment for this.Please suggest what is required for this.
Thanks & Regards,
Jayant Kumar
Unfortunately, it looks like you may be running in a very common problem I’m seeing these days due to the lousy naming convention that PayPal has used with their products. If you’re signed up for Payments Pro, that could mean you have access to the DoDirectPayment and CreateRecurringPaymentsProfile API’s, or it could mean that you have access to PayFlow API’s. If you’re on Payments Pro 2.0, which means you have a login at both http://www.paypal.com and manager.paypal.com, then you have to use the PayFlow gateway instead of CRPP.
So it sounds like you’ve gotten everything developed using CRPP but now you’re finding out your version of Pro doesn’t support that. Your options at this point are to re-integrate using PayFlow (which my library does support) or create a new PayPal account that is setup with “Website Payments Pro 3.0” with recurring payments enabled. This would allow you to use your existing integration that is working with CRPP.
Hello! You really are my last hope.
I am using your great class to build a web application (it’s actually a WP plugin) that would allow blog admins to pay their writers. Now, it’s clear that I give the code and they put the money, meaning that it’s from *their* own accounts that money should be drawn.
So, what I did was to register an application on PayPal with my own account, of which I have the APP ID now. But turns out that if I use that APP ID with the live API credentials of another user, they don’t work. It just says that the app is not authorized for the user. But hey, it’s just Adaptive Payments, they need no permissions.
It may be something silly, but I’ve been struggling with this for weeks. I can pay for your time if you feel I should.
Hoping to hearing soon from you,
Stefano
When using your own App ID to allow others to send money to each other you either need to have them grant permissions for your app or setup a preapproval profile. The preapproval would probably be the easiest thing.
When users install your plugin they can go through that process, which simply involves a call to Preapproval and redirecting them over to PayPal to approve your application. You’ll get a preapproval key back that you can store for the user, and then when they need to pay people in the future you can call Pay with the preapproval key and it will work.
Hope that helps. If you need more details you can contact me directly and we can schedule a consult.
That’s great advice! (I don’t know where one would be supposed to get to know such a thing, I’ve been reading PayPal documentation for days!)
I have set up a Preapproval request, but now I am getting a failed authentication due to wrong API credentials. Happens both in the sandbox and live, and seems given by the API_subject field. I set it with the merchant email address (the API credentials are the ones of the merchant, as they should be, right?). I inferred the problem id due to the API_subject because getting rid of it results in a “The application is not authorized for the user”.
Hope you can help me with this hopefully, final one 🙂
Thanks for all your hard work on this excellent class, Andrew. Glad to see you updated it recently too. I’ve implemented it on several custom-built eCommerce sites and it is working well.
Is your system able to make REST API calls or does it use the Classic API? Specifically, would I be able to use the Vault functionality described here:
https://developer.paypal.com/docs/integration/direct/store-a-credit-card/
If so, could you please send me in the right direction?
Thank you in advance!
Glad to hear you’re making good use of it.
The library uses the Classic API, so it won’t do that specific vaulting the way the REST API does, but you can accomplish essentially the same thing by making use of reference transactions. You would need Payments Pro in order to make it work (unless you do it with Express Checkout) but then you just use the DoReferenceTransaction API to process future payments. So, for example, if you process a payment using DoDirectPayment (or PayFlow) you would save that transaction ID you get back from that (it also works with Authorization only transactions.) Then you would pass that transaction ID along with a new amount to process into DoReferenceTransaction. PayPal will use the data they have stored on their server to process the payment accordingly, so it’s essentially the same thing that’s going on with the REST API’s vault feature.
Hi, Andrew – love the script, but running into a few issues.
I’m trying to setup to grab preapproved payments. I tested everything out and the samples seem to work alright OOB. But when I plugin my details and use the templates, I get the 580001 error (Invalid request {0}). The XML is below, replaced private info with **):
2014-02-23T23:09:01.029-08:00Failure9d0549f5131309641252
580001
PLATFORM
Application
Error
Application
Invalid request: {0}
Any ideas? I’ve replaced all variables with static values for testing purposes, and still coming up with the same error code. Thanks in advance for any tips or help you can offer!
Hi Andrew,
Contact me directly and I can help you better with this. The best thing is for me to get a copy of the template file that you’re working with so I can see if I can reproduce the problem here and then figure out what’s causing it.
Wow, that was a fast reply 🙂 I got the initial issue figured out – it was a problem with the date format – but do still have a couple of questions/issues to ask. Will shoot you an email shortly!
Thanks 🙂
Hi-
I have upgraded my files to the newest 109.0 versions…
(DoDirectPayments.php)..
I have edtied my config.php file..
as well as the DoDirectPayments.php… file..
I am not getting:
Notice: Undefined index: ACK in /forms/donation.php on line 37
Notice: Undefined index: L_LONGMESSAGE0 in /forms/donation.php on line 39
whic h is this:
if($PayPalResult[‘ACK’] != “Success”) {
and this:
echo $PayPalResult[‘L_LONGMESSAGE0’];
respectively.. ..what has changed that this would fail? (I am still pointing to Sandbox mode/url) but not sure where I’m going wrong here? Thanks!
Yikes! forgot to add this…
I am also NOT Getting a RAWRESPONSE? Its looks empty:
[RAWRESPONSE] =>
Any help is appreciated.
thanks!
I’m looking to accepting Paypal payments for courses, so I’ve no actual deliverable and I don’t want to accept credit card details directly – I’d just like to hand the user over to paypal, and get a confirmation that they paid (or didn’t). Your video and documentation talks about making an API call and then getting a result from Paypal. However, how does this integrate into the workflow from a webpage? The user may take an arbitrarily long time to complete the paypal transaction, and surely whatever has been called after the user clicks submit may time out?
Reading the Paypal docs it looks like express payment is the way to go for me, but your sample app. for that seems to assume that there’s an ebay item involved, which is not the case for me.
Apologies in advance if this seems like a very basic question . . .
It sounds like Express Checkout would indeed be the way to go. The API does include optional parameters for handling eBay payments but you don’t have to use them if you’re not dealing with eBay items.
When the user clicks your buy button you’ll make the call to SetExpressCheckout which will generate a token. The class will return a RedirectURL that you can use to send the user to (which sends them to PayPal) where they login and agree to continue the order. Then they’re sent back to your application where you can call GetExpressCheckoutDetails to obtain details about the buyer like their shipping address and display a final review page if you want to. Then you can call DoExpressCheckoutPayment to finalize the whole thing.
Hello Andrew,
I am sometimes getting the following errors:
Warning: DOMDocument::loadXML() [domdocument.loadxml]: Empty string supplied as input in paypal.adaptive.class.php on line 393
Warning: DOMDocument::loadXML() [domdocument.loadxml]: Empty string supplied as input in paypal.adaptive.class.php on line 166
I’m trying to run a PAY request with a Preapproval key. Any clues on what reason might be causing this? Thanks!
Please contact me directly and send me a copy of the file you’re working with so I can try to reproduce it here.
It looks like it was due to too frequent requests (I was testing)… The real problem is that even though I get to the payment approval PayPal reports that “This transaction has already been approved. Please visit your PayPal Account Overview to see the details” even though no, I didn’t approve it before. Is there a specific cause for this? Thanks!
When using a Preapproval Key in the Pay request the payment happens immediatly. The Preapproval key is the only authentication it needs in those cases, so the payment is processed immediately when the Pay request is made.
As such, when you try to redirect for authentication you’re getting that message that the payment was already approved. It was, via the Preapproval Key.
Oh, got it, thanks! I really appreciate the time you are taking to reply.
One more thing, how come when trying to get the preapproval in the live environment PayPal returns “The application is not authorized for the user” (the application has been approved by the PayPal team, though it belongs to another user, which is the reason I am running the preapproval)? Thanks!
Not sure I follow what you’re trying to do. If the App ID belongs to another user the API credentials should be their’s too. Is that the case?
Well, yes. It’s a WP plugin which allows admins to pay their writers, so other people must be able to use it, and my plugin must be able to issue payments on their behalf (given their API credentials and the preapproval they grant it).
So I set up the application on my PayPal account and put the app ID in my plugin, which is then used both for the preapproval request and the Adaptive Payments PAY.
Am I doing this wrong?
Hi!
First off thanks so much for all youve done. Great great library!
I do have one issue though. Im trying to turn your Pay-Preapproval.php into a CRON job to automatically bill out several hundred people in a loop.
The first problem I faced was with $_SERVER[‘REMOTE_ADDR’]; till I just manually gave it ‘127.0.0.1’ and SERVER_PORT I just set to true.
Now Im getting
DOMDocument::loadXML(): Empty string supplied as input in /src/angelleye/PayPal/Adaptive.php on line 158.
I really got to get this thing working. Any ideas?
Tough to say without seeing what you’re working. I’m happy to help, but this would fall under premium support. If you want to use that link to submit an order you’ll be close to the top of my current que so I could take a look pretty quickly.
Hello Andrew,
I have used this class CreateRecurringPaymentsProfile and i have configured in LIVE, i will recieve email from paypal and that is “Your automatic payment was unsuccessful”.
Is there any way to do payment at the same time and deduct amount from the account and then it will create the profile and deduct as per the payment cycle?
Any Ideas????
Thanks
If you have the profile start date set to the current day and you’re not using a trial period or anything like that then you should see the first payment come through on that first day. Sometimes it can be a little delayed, but it should come through on that day. If you’re getting a message that the payment is failing then there must be a problem with the funding source(s) that you’re attempting to use on the buyer side.
Hi. I am using the pay-chained.php template and everything is working fine for my app. The only thing is the “Cancel payment and return to MY NAME” URL on the paypal payment page is showing my name and not the name of the company who I build the app for.
Is there any way to change this value?
Are you still working in the sandbox or have you already moved it to the live server with their live account? It should pull that value from the PayPal account that the API credentials were pulled from.
It it the live environment now.
If you’re using your API credentials, but want their name shown there instead, you can add the SetPaymentOptions API call to your flow. Within that, you can set a HeaderImageURL and a BusinessName to brand that page however you need to.
The Pay-Chained.php sample included with the library is not making use of SetPaymentOptions, so you’ll need to make an adjustment. If you use the PayWithOptions.php sample/template, that one does tie everything together into a single script to make it easy, but you’ll need to adjust the parameters to match what Pay-Chained is doing in order to make it a chained payment.
If you compare the two it should be pretty easy to figure out, but let me know if you have any problems.
Ok, I’ll try that tomorrow. Thanks very much!
I tried that and it doesn’t seem to make a difference, my name is still displayed in the line “Cancel Payment and return to Stuart Cusack”.
I set:
‘BusinessName’ => ‘My clients name’
and passed it to the PaypalRequestData array.
Ah, yes, that parameter seems to control the value displayed at the top, left of the page, where the logo would typically go, but it’s not adjusting the cancel URL like I was thinking it would.
Unfortunately, I’m not seeing any other parameter documented that would do that. From what I can tell that’s simply going to default to whatever the business name of the receiver PayPal account is.
I know the Express Checkout API does let you control that cancel URL value directly, so you could think about switching to that if it’s that important to you, unless you specifically need Adaptive Payments for some reason.
You could always try submitting a ticket directly to PayPal MTS (http://www.paypal.com/mts/) and see if they can help, too. It’s possible there’s an undocumented way to handle it.
[Message] => You do not have permission to constrain funding sources
i’m getting this error message. help me to sort out this error…
That option is a specific add-on you have to get enabled on your PayPal account. In the request you’ll see the $FundingConstraints array getting included in the $PayPalRequest. Just remove that and this error will go away.
Hi Andrew-
I have been using your classes for the last year or two. Mostly for DoDirectPayments, but also set-up (at one point) for PayFlow.
I am still using version 109 I believe it states in the config.php file.
I had another project that needed the PayFlow template…
So copied over the files.. and edited to match my form/credentials.
When I test the form (still on Sandbox mode) I get the following error:
Strict Standards: Declaration of PayPal_PayFlow::CURLRequest() should be compatible with PayPal::CURLRequest($Request = ”, $APIName = ”, $APIOperation = ”)
From what I gathered you addressed this ‘bug’ years prior?
Do I some how have a mix of versions?
How can this error be fixed? (I’d rather not just try and ‘hide’ the error, but fix the class itself?)
Please advise.
Thanks!
The version 109 you are referring is the PayPal API version. The current release of our SDK is version 2.0.4. Sounds like you must be using an older version. I would grab the latest version from GitHub and I think that will solve your problem. Of course, make sure to test on a test site before updating your live site.