Award Winning PayPal Developer
Posted by Andrew Angell on Nov 4, 2011 in Blog, PayPal, PayPal, PHP, Videos | 78 comments
This video is a quick demonstration of how to use the Angell EYE PHP Class Library for PayPal.
Is it possible to integrate to a Zend framework project?
Sure. It’s an object-oriented class library, so you can use it within any other framework you want. For example, I have a version specific to CodeIgniter. I’ve been meaning to make one specific to Zend but just haven’t had the time. I’m sure you can do it without much effort, though, or even just use it as-is within a Zend project.
have u shared the codeigniter one?
I don’t have a video for it specifically, but I have shared the CodeIgniter version of the PayPal library.
hello i was using your angelleye-paypal-class-library in php mvc frame work customized by us.
but angelleye-paypal-class-library it is not working with that can you help me please.
[Errors] => Array
 => Array
[Category] => Application
[Domain] => PLATFORM
[ErrorID] => 580046
[Message] => An invoice already exists for the merchant with this invoice number: 11111111s
[Parameter] => 11111111s
[Severity] => Error
[Subdomain] => Application
[Ack] => Failure
[Build] => 7236486
[CorrelationID] => 26ac6dcbee1a1
[Timestamp] => 2013-08-07T00:30:07.390-07:00
[XMLRequest] => ReturnAllen_USndudevi@email@example.com
1036 Crawford StDetroitMI48209US
1036 Crawford StUS
[XMLResponse] => 2013-08-07T00:30:07.390-07:00Failure26ac6dcbee1a17236486580046PLATFORMApplicationErrorApplicationAn invoice already exists for the merchant with this invoice number: 11111111s11111111s
Looks like it’s working just fine, but you got an error because the invoice number you sent in the request has already been used in your PayPal account and can’t be used again. I am a little confused, though, because the values look blank in the request. Did you attempt to populate those and your values aren’t carrying over or did you mean to leave them empty, but you get this error when they’re empty..??
Hey Thanks for this Its really helping me out. Your the Best!
No problem. Glad it’s working for ya!
this is a great lib!
but i have one problem with ‘setExpressCheckout’ and parallel payments.
testing only in sandbox.
it always show the error : “Instant Update API callback is not supported for parallel payments.”
but i dont set callback
There must be something in your request data that’s causing it to include those in the call to PayPal. If you want to send me a sample of the page you’re working with I’ll take a look and let you know what the problem is.
I have sent you the link to the code per contact form.
I’m similarly having the same problem. Was this ever resolved?
Yes, you need to make sure things like the survey question, shipping options, etc. aren’t enabled in the SEC request. If you want to send me your SEC file I’ll take a look and help you figure out what’s causing it.
My SEC fields are as follows (http://pastebin.com/QpKuV3N4):
$SECFields = array(
‘token’ => ”,
‘maxamt’ => ”,
‘returnurl’ => $domain . ‘paypal/class/DoExpressCheckoutPayment.php’,
‘cancelurl’ => $domain . ‘paymentfail.html’,
‘callback’ => ”,
‘callbacktimeout’ => ”,
‘callbackversion’ => ”,
‘reqconfirmshipping’ => ”,
‘noshipping’ => ”,
‘allownote’ => ’1′,
‘addroverride’ => ”,
‘localecode’ => ”,
‘pagestyle’ => ”,
‘hdrimg’ => ”,
‘hdrbordercolor’ => ”,
‘hdrbackcolor’ => ”,
‘payflowcolor’ => ”,
‘skipdetails’ => ’1′,
‘email’ => ”,
‘solutiontype’ => ‘Mark’,
‘landingpage’ => ‘Billing’,
‘channeltype’ => ”,
‘giropaysuccessurl’ => ”,
‘giropaycancelurl’ => ”,
‘banktxnpendingurl’ => ”,
‘brandname’ => ‘Zookie’,
‘customerservicenumber’ => ”,
‘giftmessageenable’ => ”,
‘giftreceiptenable’ => ”,
‘giftwrapenable’ => ”,
‘giftwrapname’ => ”,
‘giftwrapamount’ => ”,
‘buyeremailoptionenable’ => ’1′,
‘surveyquestion’ => ”,
‘surveyenable’ => ”,
‘buyerid’ => ”,
‘buyerusername’ => ”,
‘buyerregistrationdate’ => ”,
‘allowpushfunding’ => ”
Try removing the value for buyeremailoptionenable. If that alone doesn’t work try also removing the value for brandname.
I tried removing buyeremailoptionenable and then brandname also with no success.
Is there anything else it could be or anything else I could try? I’m quite desperate to resolve this
Hmmm…everything else is pretty straight forward. Send me a copy of your SetExpressCheckout.php and I’ll see if I can reproduce the problem. You may need to double check $PayPalRequest array to make sure the survey questions, shipping options, etc. aren’t being passed in there.
Just as I was in the process of sending it to you, I spotted the problem!
The problem was although I did not enable a survey, I was setting SurveyChoices and passing them to the PaypalRequest. Didn’t notice it initially because it is outside the setting of the SEC fields. But I have removed it and everything appears to be working correctly now.
Thank you for your help and in particular your quick responses, very much appreciated.
Glad you got it worked out! Let me know if you run into any other issues.
I really want to use your class in drupal CMS. For this i have to make a custom module for the same.
Can you give me an idea about how i use this script for PayPal adaptive payments…means which exact files i have to call for the same to process chained based payment. I have downloaded your script from php classes.org but there are so many files. I want to use process PayPal adaptive payments so please mentioned the required files which i need to integrate.
Please help me
Thanks in advance
For Adaptive Payments you’ll just the Pay API, so the Pay.php file is really all you’ll need to work with other than filling in your credentials in the config.php file.
Let me know if you have troubles and I’m happy to help further.
Thanks for the class!
Is this project somewhere on github?
I just have some optimalization that you might want.
No problem, glad you like it. It’s not Github yet. I’ve been meaning to get it up there but I just haven’t learned enough to Git yet to make it work well for me. If you want to send me your adjustments I’ll take a look and maybe add them to my original stuff. Eventually I will indeed get it on Github.
I have been trying to figure out the GetBasicPersonalData.php file, but all it ever returns is
[Errors] => Array
 => Array
[Category] => Application
[Domain] => PLATFORM
[ErrorID] => 500000
[Message] => Internal Error
[Severity] => Error
[Subdomain] => Application
This is in sandbox, could you tell me how to use this one
I think I may have missed a step in the headers being sent for these Permissions API calls. Unfortunately, the documentation links for Permissions at x.com are returning 404 not found right now, so I can’t look to see what it might be.
I’ll update here again once I get more info on what could be going on here. You might also want to submit a ticket to MTS at http://www.paypal.com/mts. You can provide the XML request and response (which the library makes available to you) and they can help us figure out what’s going wrong with it.
Please delete my last message, now I know how to work with your class aleady My I ask you how we solve those problem below:
- Credit card doesn’t have enough money to pay for orders
- Credit card has an invalid account number
- Credit card has been expired date
- Credit card has an invalid security digits
In any of those situations the API would simply return an error that the payment failed. Address verification and CVV data can be adjusted in your Fraud Management Filters within your PayPal account.
Hope that helps.
Hi, my compliments for your great Job with this class. It helped me a lot to setup my mind about how to integrate paypal in ecommerce solutions.
I have a point of discussion. Using your class for a setExpress Checkout action Method. I’ve found that on the very first call on setExpressCheckOut a Notice will be displayed on line 1481. Saying thet “TOKEN” index is not defined in the HASH used to set up the redirect URL:
Here’s my changes to manage the notice.
if(isset($NVPResponse['TOKEN']) && $NVPResponse['TOKEN'] != ”)
$NVPResponseArray['REDIRECTURL'] = ‘https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&’ . $SkipDetailsOption . ((isset($NVPResponseArray['TOKEN']) && $NVPResponseArray['TOKEN'] != ”)?’&token=’ . $NVPResponseArray['TOKEN']:”);
$NVPResponseArray['REDIRECTURL'] = ‘https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&’ . $SkipDetailsOption . ((isset($NVPResponseArray['TOKEN']) && $NVPResponseArray['TOKEN'] != ”)?’&token=’ . $NVPResponseArray['TOKEN']:”);
Please let me know if this helps, or if I’ve misunderstood the intended usage of your class.
(In my opinion the Token isn’t set in the first call of setExpressCheckout, it will be populated after the first response by Paypal, so I can’t pass a token value at first API call)
I noticed that myself and it’s actually fixed in this next version I’ll be releasing before too much longer. It only happens if your SEC call fails for some reason and no TOKEN is available, and it’s only a warning so it wouldn’t cause the app to halt at all. Again, though, I have fixed it so this warning doesn’t occur. I just need to tie up some more loose ends and then I’ll get this new version released.
Thanks for the feedback, though! Always appreciated. I’m sure I have other little mistakes in there, too, so if you find them please let me know.
This php library will support paypal payments advanced ?
Not right now, no. It’s for API’s only. Payments Advanced is just a basic form post directly to PayPal so you don’t have to put together request strings and parse response strings, etc. I may include it in the library at some point, but it’s not something I’ve focused on yet. Sorry.
First off thanks a lot for your library of code its awesome!
So my overall goal for using your library of code is to embed a paypal iframe in my site for users to make payments through paypal. I’m currently following this tutorial https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_APIntro.
If you ctrl+f “Setting Up Web Pages to Invoke the Embedded Payment Flow Using a Lightbox”, you will see the step by step instructions I’m following.
So I’ve successfully used your library’s pay.php file to get an api pay key. But when I try to use this key in the form
“action” link. I receive the error in paypal” Your payment session has expired. Please return to the participating website and try again.”
Any idea what’s going on? I’m lost.
Thanks in advance for your help and once again thanks for the awesome library of code. It really makes up for paypal’s poor documentation.
The first thing I would do is get it all setup and working outside of the lightbox. Make sure you can call the Pay API which will give you back your PayKey and a ReturnURL generated for you by the library. See if you can load this RedirectURL without any problems or if you get the same problem there.
Could you please help me how to use your class files in yii framework.
Actually I want creating recurring payment profiles for each user while registration.
Thanks in advance.
I’m not familiar with the Yii framework, but upon quick review it looks like a standard MVC framework which means my library should plug into rather easily. It’s all object oriented so it should just be matter of extending the Yii classes to turn these into custom Yii libraries.
Great stuff no doubt and many thanks for building it and making it available.
I want to do chained payments and I have made it work perfectly in sandbox. Im just wondering, when I create the payment on a live server, do I need to send it on a secure line to prevent eavesdropping?
Because I see I need to put in the paypal password in the config file, is that something that is sent over to paypal when I create the payment before redirecting the user to the login. Or do I only need secure line if Im doing some of the more advanced stuff like preapproval or something?
The API endpoint is an https:// server so everything you post is encrypted. You only need SSL certs if you’re processing credit cards directly on your server. With the majority of PayPal’s services it’s optional because they’re handling the processing for you.
Thanks for the classes but i still seem to be confused with what i am trying to do. There is quite a lot of information there.
I am trying to process an Adaptive Payment on my site. I want buyers to be able to pay multiple sellers for multiple items all at one go from their shopping basket. I would like this to be a direct payment. I took a look at your classes but i am unable to see the the classes to use to process adaptive parallel payments.
Much appreciated, Thanks
You’ll be utilizing the Pay API with multiple receivers. If you want parallel (where the buyer will see the split) you don’t need to set a primary receiver. If you’d rather do chained payments (where the split will be hidden from the buyer) you’ll need to set one of the receivers as primary in your Pay request.
Thanks, Which of the classes do i start with?
I have setup a social network that just needs to accept a single payment that gets split between two paypal business accounts. How much would you charge me to program this for me. If you are interested in doing this can you call 817-773-7062 and if I can not answer please leave a message and a time when I can call you back.
I’ll give you a call today or tomorrow. Need to finish up some projects before discussing something new.
Hi Andrew. Thanks for your response to my paypal question earlier today. It looks like the only file I’ll end up using is Pay.php — but I’ll keep them all close at hand!
Ok, so Pay.php includes the config.php and the paypal.class.php (which includes the adaptive classes), so I just include the file Pay.php where I need access to your classes. This looks good.
I’m editing the config.php file now. I’m wondering about the $developer_account_email. It says this is needed only for Adaptive Payments. Is that my real developer/sandbox email? Or is that my sandbox fake business account email? I guess it just seems odd that paypal requires any sandbox info to work.
Am I mis-reading that?
Hmm. Wait.. I thought at first each file was its own class with associated functions. Am I supposed to include Pay.php in my code, or do I just include the paypal.class.php (and config)? It looks like the Pay.php file (and all the others are really samples of usage. Is that right?
If you’re simply going to use the library directly you’d just include config.php and the paypal.class.php. This would give you access to all of the methods included with the library.
All of the files included, like Pay.php, are simply empty template files prepared for that particular API request. It just gives you a real quick starting point for every call. You can either work directly from those files or from your own, but you’ll need all of those request arrays one way or another.
Let me know if you still have more questions about that.
$developer_account_email is the email address you use to login to http://developer.paypal.com. It gets passed into the header of Adaptive Payments requests, and I’m pretty sure it’s just used as a way for PayPal to track where things are coming from. Looks like you’ve got a follow-up comment here regarding which files to include so I’ll respond with more detail there.
Sandbox: recurring profile not start payment charge
I have several days trying to make it run the payment instruction
after you create the profile but this never happens.
I use your library for this propose:
There is an example of the way I am creating the profile:
2. Click here to continue.
3. In login form I use:
4. After login and confirm this redirect to:
5. The profile is created with start date today, but the payment is never charge.
Where I am wrong, why not start charging paypal,
if I do the same process with the buttons on subscriptions
payment is executed after creating the profile
I’m very sorry for the delay getting back with you. I would need to get a look at your actual requests/responses in order to help you troubleshoot this.
Please update me how to use it for PAYFLOW PRO.
You just need to add your credentials to the config.php file and then open up the PayFlowTransaction.php file and fill in the parameters accordingly.
HI, I just want to ask some help,how can i use this php class library for paypal, does this will work in sandbox,because i am just using sandbox and i want to try using IPN in my localhost,please help me i am newbie on this,please provide me how to start using this to achieve my goal to test IPN in localhost.
Yes, the library is designed to work easily with both the PayPal sandbox and production servers. You simply pass in a true/false value for sandbox when you create the class object. My library does not have IPN built in to it, though. Also, when using IPN you can’t use “localhost”. You’ll need to use your public IP or setup a domain name that points to it.
does these library support Paypal Standard?
Right now the library supports some of the Button Manager API calls, but it doesn’t handle Payments Standard any other way. I do have plans of adding it, but it will be a few weeks before I’m able to get that done and release an update.
hi ..i am new in phhp…i want devlope chain payment system of paypal …when sender send $100 then 1st primary reciver recive only $90 & 2nd rec Recive $10 … how i can do that plz help me
You would use the Adaptive Payments platform for that, specifically the Pay API. You can set it up as a Parallel or Chained payment, the difference being that with parallel payments the payer would see the split that will happen, but with a chained payment that would be hidden and they would only see a single receiver.
Basically, though, you would just create the Pay call with multiple receivers in the request. Each receiver would be set to the amount they should receive in the payment and the library will handle the rest.
There is a Pay.php file included in the samples folder. You might want to look at the PayWithOptions sample, too, as that allows you to provide more details with the request. It actually combines both Pay (CREATE) and SetPaymentOptions in a single method.
Great work — you’ve served many, many people. Very impressive!
I’m having a few issues though. I’m using the Adaptive payments as you mentioned in the post I’m replying to. Currently, when a user clicks to ‘Pay’ on my website, a popup appears and they must then enter their PayPal email address.
In addition, the auction listings that a user creates on our marketplace can be in either $ (USD) or £ (GBP), but it seems that if the user creates a listing that isn’t in their main PayPal currency, they can’t receive payment.
Is the PayPal email popup necessary and can we allow users to receive payments in currencies other than their main PayPal currency?
Thanks for the kind words. I think I answered you on StackOverflow..??
I have a question about the delayed chained payment. And I read quite a lot of your posts on StackOverflow. That’s been very helpful. The thing is how I can create a delayed chained payment with a customized set of payment details? Because I wanna store the information of the item that the buyer wanted and when I got the IPN from PayPal and update it in the database. I think that the setPaymentOptions works on activeType=>Pay but not pay_primary. Thanks a lot!
You would actually call Pay with an actiontype of CREATE and then call SetPaymentOptions behind that to add in the details prior to redirecting the user to PayPal. If you’re using my class library there’s a separate file called PayWithOptions that combines these to make it easier.
Thanks for the reply.
When I’m using your class library from GitHub, I got a require_once error.
And I commended out the unnessary require_once and run the PayWithOptions.php.
I still got an error which is Undefined variable: ResponseDataArray in …/includes/paypal.adaptive.class.php on line 668
Am I missing anything?
I got the idea of create and setPaymentOptions then make a delayed chained payment call but think that using your library is more convinient to do it.
What “unnecessary require_once” are you referring to? You should be requiring the include.php, paypal.class.php, and paypal.adaptive.class.php at the top of your PayWithOptions.php file. You can click here to see the same sample script on my test server and it runs just fine.
I want to convert currency in chained payment using paypal……
but i need to include AdaptivePayment.php but this file i am not found anywhere.
Please help me.
There isn’t an AdaptivePayment.php. It would be Pay.php, Preapproval.php, etc. depending on which API in the Adaptive Payments platform you’re attempting to use.
//”I am use this code for convert currency but this file want to include AdaptivePayments.php”
detailLevel = 0;
$requestEnvelope->errorLanguage = ‘en_US’;
// Our base amount, in other words the currency we want to convert to
// other currency type. It’s very straighforward, just have a public
// prop. to hold de amount and the current code.
$baseAmountList = new CurrencyList();
$baseAmountList->currency = array( ‘amount’ => 15, ‘code’ => ‘USD’ );
// Our target currency type. Given that I’m from Mexico I would like to
// see it in mexican pesos. Again, just need to provide the code of the
// currency. On the docs you’ll have access to the complete list of codes
$convertToCurrencyList = new CurrencyCodeList();
$convertToCurrencyList->currencyCode = ‘MXN’;
// Now create a instance of the ConvertCurrencyRequest object, which is
// the one necessary to handle this request.
// This object takes as parameters the ones we previously created, which
// are our base currency, our target currency, and the req. envelop
$ccReq = new ConvertCurrencyRequest();
$ccReq->baseAmountList = $baseAmountList;
$ccReq->convertToCurrencyList = $convertToCurrencyList;
$ccReq->requestEnvelope = $requestEnvelope;
// And finally we call the ConvertCurrency method on our AdaptivePayment object,
// and assign whatever result we get to our variable
$result = $ap->ConvertCurrency($ccReq);
// Given that our result should be a ConvertCurrencyResponse object, we can
// look into its properties for further display/processing purposes
$resultingCurrencyList = $result->estimatedAmountTable->currencyConversionList;
$baseAmount = $resultingCurrencyList->baseAmount->amount;
$baseAmountCode = $resultingCurrencyList->baseAmount->code;
$convertedAmount = $resultingCurrencyList->currencyList->currency->amount;
$convertedAmountCode = $resultingCurrencyList->currencyList->currency->code;
echo ‘ $’ . $baseAmount . ‘ ‘ . $baseAmountCode . ‘ is $’ . $convertedAmount . ‘ ‘ . $convertedAmountCode;
// And here just for the sake of knowing how we get the result from Paypal’s API
I was wandering if you can help me with my dilemma. I have been beating my head against the wall for over few days already trying to figure out why my embedded payments don’t work. I have been searching and searching everywhere online hoping to get something I am looking for but none of them relate to the same problems I am having.
I am using your library to for chained payments and I can successfully get a payKey. However, I always get different errors when the iframe on my website shows up. Sometimes I get an error which says: “this transaction has already been approved paypal…”. Sometimes it says: “our payment session has expired. Please return to the participating website and try again”. And sometimes it says that it cannot be processed. I follow all the examples I find on the internet but I have never gotten a successful login screen. Please help me.
The error about “transaction has already been approved” means that you included a Preapproval key with your Pay request. When you do that there is no request to PayPal necessary to complete the payment as the payment happens immediately based on the preapproval key. As such, if you send the user to PayPal to login using the PayKey you got back from a payment that already happened because of Preapproval you’ll get that error.
Payment session has expired sounds like you’re using a bad PayKey in the redirect over to PayPal…one that was generated but you then waited too long to use it. It’s not something I’ve run into so without seeing your code and running a demo myself it’s tough to say for sure what’s going on there. Same with the 3rd error you mentioned. Hard to say without seeing your stuff.
I’d just make sure you understand how Preapprovals work first and from there you’ll probably get things straightened out.
I am currently using paywithoptions but I need to do something very special.
How can I pay the primary, then pay a secondary, then delay for a third affiliate. So basically if a vendor sells a product, he as the primary gets full payment. From there the secondary, gets a small commission. Then the vendor can either send instant payments which your paywithoptions allow or delay on that third. How can I do this, as I do not see any option that will allow for it, but I know it is possible as another company is doing it.
The delayed chained payments system only allows you to delay all of the secondary receivers and release them all at once. Any system where you’re collecting funds and then paying out to secondary receivers at different times would most likely be using Preapproved Payments or Billing Agreements / Reference Transactions, which are separate API’s altogether.
I was just testing your Paypal PHP library. Almost all the functions are there, but I couldn’t find the GetPaymentDetails functionality in the library. Is it missing? I downloaded from GitHub.
I’m not aware of any GetPaymentDetails API on the PayPal platform. I don’t see it in the classic API reference (which is what my library is based on) and I don’t see it in the new REST API either (which is not yet included in my library).
You might be thinking of GetTransactionDetails..?? That is indeed part of the API and is included with my library. There is also a GetPaymentOptions that is part of the Adaptive Payments platform, but again, no GetPaymentDetails that I’m aware of at the moment. If you can point me to a doc that mentions it maybe I’ll be able to help more.
I have released a new version of my library recently, but Github hasn’t yet been updated. If you want the latest one you can grab it here. It performs a little better because I removed the child classes from the parent class so they don’t always load when you’re not using them. When you need them you just need to include both the parent and the child class in your script.
I was talking about the following:
Isn’t this a part of the classic API?
Ok, yeah, it’s called PaymentDetails, not GetPaymentDetails. It is included in the Adaptive Payments API and is part of my library. There is a template file called PaymentDetails.php that’s all setup and ready to go for you. Let me know if you can’t find it.
Thanks a lot Andrew! Got everything I needed!
I have an application which simply uses SetExpressCheckout, GetExpressCheckoutDetails and DoExpressCheckout to do parallel payments. I set this all up using your library, and everything worked as expected with sandbox. However, I went live with my application recently and am now having the problem where normal payments work, however parallel payments to 2 different receivers does not work.
Do you have any idea what the problem might be?
I am trying to use your pay chained example and I keep getting “Your payment can’t be completed. Please return to the participating website and try again.” When I make a payment. Any insights?
Do you have it setup with your own sandbox account?
Got it. Thanks for a great library Andrew.
Your email address will not be published. Required fields are marked *
You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
© Copywrite 2013 Angell EYE