Setup PayPal PHP SDK
If you are using Composer you can get going quickly through our Packagist repo.
If you are not using Composer you can simply download the class library and add it to your project.
If you would like more details on either of these methods take a look at our install guide.
How to Make PayPal API Calls
- Open the template file that corresponds to the API call you’d like to make.
- Example: If we want to make a call to the RefundTransaction API we open /templates/RefundTransaction.php
- You may leave the file here or save this file to the location on your web server where you’d like this call to be made.
- I like to save the files to a separate location and keep the ones included with the library as empty templates.
- When working within an MVC framework, it’s a good idea to copy/paste the template functionality into a Model method.
- Each template file includes PHP arrays for every parameter available to that particular API. Simply fill in the array parameters with your own dynamic (or static) data. This data may come from…
- Session Variables
- PHP Variables
- Database Recordsets
- Static Values
- Etc.
- When you run the file you will get a
$PayPalResult
array that consists of all the response parameters from PayPal, original request parameters sent to PayPal, and raw request/response info for troubleshooting.- You may refer to the PayPal API Reference Guide for details about what response parameters you can expect to get back from any successful API request.
- Example: When working with RefundTransaction, I can see that PayPal will return a REFUNDTRANSACTIONID, FEEREFUNDAMT, etc. As such, I know that those values will be included in
$PayPalResult['REFUNDTRANSACTIONID']
and$PayPalResult['FEEREFUNDAMT']
respectively.
- Example: When working with RefundTransaction, I can see that PayPal will return a REFUNDTRANSACTIONID, FEEREFUNDAMT, etc. As such, I know that those values will be included in
- You may refer to the PayPal API Reference Guide for details about what response parameters you can expect to get back from any successful API request.
- If errors occur they will be available in
$PayPalResult['ERRORS']
.
Video Demo
General PayPal PHP Integration Tips
- The result of the API call will come back in
$PayPalResult['ACK']
.- Remember when checking the value that it could be Success, Failure, SuccessWithWarning, or FailureWithWarning. Simply checking for Success isn’t enough.
- You may use
$PayPal->APICallSuccessful($Ack)
to do this for you.
Tips for Testing in the PayPal Sandbox
- Create an account at http://developer.paypal.com
- Create at least one sandbox Seller account and one sandbox Buyer account from within your developer account.
- These accounts can be used to go through the entire process of buying items within your application, and reviewing what each party involved will see in their PayPal account when the transaction is completed.
Tips for Going Live
- Review PayPal’s Going Live Information
- Move /includes/config.php to a directory outside your web root.
- When you do this you’ll need to make sure any scripts where the config is included are updated to use the system path instead of the site path.
PayPal Developer Resources
- PayPal Developer Site
- This is where you can setup your own PayPal developer account.
- Within your developer account you can then create PayPal sandbox accounts. These can be used to send and receive money within the PayPal sandbox so that you can fully test your applications.
- PayPal REST API Documentation
- Here you can review all of the details about PayPal’s REST API web services.
- This will give you the raw details, but our library will simplify much of this for you.
- PayPal REST API Explorer
- This tool allows you to run API calls in a demo format to help see how JSON strings are constructed for various calls.
- Our library simplifies all of this for you, so that you don’t need to study this, but it’s still a good tool for general review.
- PayPal Classic API Payment Products
- Here you can review all of the products that PayPal offers with their Classic APIs.
- PayPal Classic API Integration Guides
- These guides can point you in the right direction if you have questions about which particular API calls you should be using to accomplish your goal.
- Within the integration guides you will find details about the API calls you will be working with. You can then refer to the API reference for details about those individual API calls.
- PayPal Classic API Reference
- The Classic API is PayPal’s original platform which works with a variety of NVP or SOAP web services.
- This reference is a great resource for reviewing all of the APIs available.
- This PayPal PHP SDK supports all of the APIs you will find listed in the API reference.
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.
Thanks for providing this class library. I would like to set up my websites to do chained payments. Does your api support this? I am having trouble finding a example for chained payments where my app is the primary receiver and the money is sent to another receiver.
Yes, the library supports this and makes it pretty simple. If you open up /samples/Pay-Chained.php you’ll see a good example of how it works. Let me know if you don’t see that or still have questions after reviewing it.
Hello,
Can I use it to provide PayPal Website Pro on my website? I would like to use a iframe with API to do the payment job on Paypal side, is it supported?
No, that’s not what this is. This is for Payments Pro, but what you’re talking about is Payments Advanced. That’s where you embed the PayPal checkout in an iframe on your site.
Hi Andrew,
Great thanks for the library…It is just amazing…
I have a scenario like below….
I want subscribers in my system to be able to withdraw the commissions earned (as credit points in my system) to their PayPal account at any point of time…
What type of PayPal API would be suited for this task to be automated?
But I am unclear what type of request I need to make to enable users in my system to withdraw the amount they specified…
I tried using the preapproval operation so that my main account is preapproved so that my subscribers use Pay operation to withdraw money from my main account… But maximum preapproved total amount is limited to 2000 USD in a period if i understood the documentation correct… Is there any alternative so that my subscribers can withdraw amount they earned as they wish(at any time)…
Thanks
If you’re paying out from your own account you don’t need to setup any Preapproval profile. You can just setup a Pay request using your credentials so that it’s implicitly approved.
Thank you very much Andrew… Your library is just amazing… Thank you very much…
Hi,
First of all thank you for developing such a great extension. I am testing chained payment, after inserting my test credentials it only shows me success/error but does not redirect to paypal. I am only asking how can i make proper payment using your extension.
Waiting for your kind and quick reply.
Thanks
The class will not do the redirect for you. You have to do that yourself, but it will return $PayPalResult[‘RedirectURL’] which holds the redirect URL value already put together for you so you don’t have to worry about building it.
Hai Andrew,
Thank you very much for this amazing library!
Now i am working with chained payment system .Actually I need a redirect operation to paypal page. Can you please show me that sample code?.
The library will return $PayPalResult[‘RedirectURL’] so you can simply use a header() redirect: header(‘Location: ‘.$PayPalResult[‘RedirectURL’]);
Ok…Thanks !
Ok…Thanks ! I have one more doubt….
Is there any option for delayed chain payment option?
I’ve been using your library most specifically your Pay-Chained.php and have attempted to use PayPal’s IPN feature to get information about the payment (using my own IPN listener script), but this has not been working so far.
All I really need to do is do a check that the PayPal payment has gone through successfully (then alter a record in my database). How would you recommend checking if a paypal payment has gone through using your libraries?
Any help would be appreciated as I am finding PayPal quite difficult to work with
The API response itself will give you some basic info about whether the payment was successful or not, but IPN will indeed have more detail. You just need to make sure IPN is configured in the account you’re working with (make sure if you’re using the sandbox that you’ve got your sandbox account configured, and if you’re using live you’ve got that one configured) and that your listener doesn’t have any problems with it. You can check the IPN History of the account you’re working with to see if the IPN’s are being sent or not, and you can check your web server logs to see what errors are causing the script to fail if it is getting hit.
Hi,
Been implementing your dodirectpayment.php and so far so good, do you have any information on Implementing 3-D Secure Transactions (UK Only) or will it need building into your library.
Kind Regards
The parameters for those are included in the library already, so you just need to populate the values accordingly and you should be good to go.
Thank you for your reply,
I take it I still need to use Cardinal Centinel to get the values passed across to dodirectpayment or is there another way?
Kind Regards
Thanks for the great Lib and making it available.
Can I use your Lib with Embedded Payment Flow Using Adaptive Payments described here https://developer.paypal.com/webapps/developer/docs/classic/adaptive-payments/ht_ap-embeddedPayment-curl-etc/ .
If yes can you please guide me after obtaining PayKey with pay.php I replaced it over her as shown in the sample code . But when I click on the pay now button gives this error Payment can’t be completed. This feature is currently unavailable. in lightbox. What could be the problem.
Yes, you can do that with this library, but the javascript stuff for the light box isn’t really tied in. What I always do is set everything up the “regular” way using my library so that you can go through the whole flow with the default redirects. Then follow the instructions in their documentation to apply the javascript and adjustments necessary to get it working in a lightbox.
Thank for your library first .
Everything working fine except one case .
I used delayed chain system . I wish to refund all credit .When i try to refund from multiple person i got this array .
Ack] => Success
[Build] => 7935900
[CorrelationID] => c6dd19fe948f8
[Timestamp] => 2013-10-10T00:30:26.430-07:00
[EncryptedTransactionID] =>
[RefundFeeAmount] =>
[RefundGrossAmount] =>
[RefundHasBecomeFull] =>
[RefundNetAmount] =>
[RefundStatus] => NO_API_ACCESS_TO_RECEIVER
[RefundTransactionStatus] =>
[TotalOfAllRefunds] =>
[Receiver] => Array
(
[Amount] => 2.00
[Email] => test@xxxxxxx.com
[InvoiceID] =>
[PaymentType] =>
[Primary] =>
)
The refund status always time
[RefundStatus] => NO_API_ACCESS_TO_RECEIVER
can you please give your suggestion ?
That particular error looks like you need API permissions for the account. You can have users set that up in their profile or you can tie it into your application using the Permissions API.
Thank for your library first .
I am using php class library,and…
In adaptive payment integration I want to specify Custom variable where do i set it in which file ??
Do i have to set it in Pay.php if yes then where ??
The Adaptive Payments API’s don’t have a specific CUSTOM parameter like the classic API’s do, but if you look at PayWithOptions.php you’ll find you can pass in a lot more info. The flow would be calling Pay with CREATE, and then calling SetPaymentOptions behind that. PayWithOptions.php combines these into a single function call for you to make it a little easier. Take a look and see if you can make it work with the extra details you have access to.
what i want is In response Array of IPN there is a ‘custom’ variable like this..
first_name = buyer
payer_id = CVLSCXX5MWN6A
receiver_id = V33X3DVTJEZ5S
item_number =
payment_status = Completed
payment_fee =
mc_fee = 3.32
mc_gross = 126.00
custom =
charset = windows-1252
notify_version = 3.7
ipn_track_id = c2a8cca917edf
so in which Page i set this variable , actually i want to track my OrderId of customer.
That doesn’t look like an IPN from an Adaptive Payment API call. What was the txn_type on the one you pulled this from? It seems incomplete..?? With an actual Pay API request you’ll get a different type of IPN and I don’t think it will include the custom parameter at all, but instead it would include the parameters you can pass into that particular call or series of calls.
i got this array if i write
if($status==”Complete”){add array to Database}
which is this..
transaction = Array
log_default_shipping_address_in_transaction = false
action_type = PAY
ipn_notification_url = http://www.pavansgroup.com/development/development2/ForsterDive/notify.php?custom=13
charset = windows-1252
transaction_type = Adaptive Payment PAY
notify_version = UNVERSIONED
cancel_url = http://pavansgroup.com/development/development2/ForsterDive/cancel.php
verify_sign = An5ns1Kso7MWUdW4ErQKJJJ4qi4-Aj6XcRi0dyQ2YsSCh54QwwV82jTo
sender_email = dhruv_buyer@gmail.com
fees_payer = EACHRECEIVER
return_url = http://pavansgroup.com/development/development2/ForsterDive/return.php
reverse_all_parallel_payments_on_error = false
pay_key = AP-9H601573NX8242145
status = COMPLETED
test_ipn = 1
payment_request_date = Fri Oct 25 01:28:09 PDT 2013
but when i write if($payment_status==”Completed”){add array to Database}
which is this..
transaction_subject =
payment_date = 00:32:35 Oct 25, 2013 PDT
txn_type = web_accept
last_name = Patel
residence_country = AU
item_name =
payment_gross =
mc_currency = AUD
business = dhruv_seller@gmail.com
payment_type = instant
protection_eligibility = Ineligible
verify_sign = AGTmrdEVkbHREioZvWZclNZ0sKovAgC-r-416-8.nOCVihawktFb9RzB
payer_status = verified
test_ipn = 1
tax = 0.00
payer_email = dhruv_buyer@gmail.com
txn_id = 40P05832UJ9124236
quantity = 0
receiver_email = dhruv_seller@gmail.com
first_name = buyer
payer_id = CVLSCXX5MWN6A
receiver_id = V33X3DVTJEZ5S
item_number =
payment_status = Completed
payment_fee =
mc_fee = 3.32
mc_gross = 126.00
custom =
charset = windows-1252
notify_version = 3.7
ipn_track_id = c2a8cca917edf
so which array i have to use to check that my payment is completed or not ?
I would look at payment_status = Completed
Thanks it works. 🙂
Thanks for you library first.
I have PayPal Payments Pro account and trying to create recurring profile with credit card using your library. But I am getting “DPRP is disabled for this merchant” error. When I contact PayPal I got the response as “It sounds like you may have integrated the old API’s (legacy) based off of our Website Payments Pro product. Your account is associated with our newest platform of PayPal Payments Pro (Payflow platform). Recurring payments are enabled for your account. In order to determine the integration method please contact your shopping cart provider. “.
Please help me to resolve this issue.
Regards
Satheesh
Hi Satheesh,
The “old” Payments Pro used the DoDirectPayment API, which was PayPal’s own gateway. The “new” Payments Pro uses the PayFlow Gateway that they acquired from Verisign a few years back.
What the PayPal person told you is correct…you integrated with “Website Payments Pro” which uses DDP instead of “Payments Pro” which uses PayFlow. So you have a couple of options. You can either redevelop your stuff using PayFlow (which is included with my library as PayFlowTransaction.php) or you can call them back and tell them, yes, I did indeed integrate with Website Payments Pro – DoDirectPayment, and request that they enable this for you. They can do it for you, but depending on who you talk to they might act like they can’t. Just be polite the whole time, let them know that you don’t want to spend the time and money to re-develop so you just want to use DDP, and if they keep giving you trouble request to escalate the call to a manager.
If you can’t get anybody to help you let me know and I can reach out to one of my direct contacts there who can definitely get it done for you.
Thanks Andrew. I will contact PayPal again and keep you updated.
Hi Andrew,
once again i need your help.
i integrated Paypal Adaptive Payment (parallel payment) using Pay API and in SandBox it works fine,
in which in config.php file i defined only one Developer’s PayPal Gateway API Credentials.
so my question is do i have to also defined or add other receivers merchant account details(PayPal Gateway API Credentials) in that config file ?
Hi (posted once the other day? dont see it?..maybe it didnt get accepted yet?)
Anyways.. I’m trying to use you Paypal PHP class (thanks!)..
and Im getting an error..
When I print out the $PayPalResult object: (print_r($PayPalResult);)
I see I am getting an error.. but not sure how to debug from here?
Her are the parts from the return that I think will help:
[L_ERRORCODE0] => 10001
[L_SHORTMESSAGE0] => Internal Error
[L_LONGMESSAGE0] => Internal Error
[L_SEVERITYCODE0] => Error
The errors seems kinda ‘vague’..so Im not clear on where to begin with debugging? Can you give me some direction/help?
Thanks!
-O1K
Yeah, that is a tricky error. Sometimes it means the PayPal servers are timing out or not working properly, and that was actually a big problem in the sandbox for awhile, but that seems to have cleared up and I haven’t run into it for about a year or so now. So, when I see this error now it typically means something is wrong with the request in a way that their server couldn’t even give you a better error.
Make sure your config file is setup properly, and double check all the request parameters you used make sense. If you keep getting this put a copy of the entire output of $PayPalResult, not just the error, so I can get a look at the request parameters and everything you’re sending.
(cant edit posts?)
update: I am getting this error:
Please use a different payment card
10752
but I am using the info given by PayPal for my ‘sandbox’ accounts.. (confused!?) Any help is appreciated.
thanks!
-n1k
Are you trying to setup Payments Pro, or what exactly? If Pro, are you using DoDirectPayment or PayFlow?
yes, I am using the DoDirectPayment ‘template’ (all filled in)..
and yes, I believe I am trying to set-up payments pro…
(take name/adresss/CC info all ‘on-site’)
The last error I was getting was this: 10752
Use another card for payment (or close, Im going from memory right now)
but I can be sure if I am doing something else wrong…?? or what? 🙂
thanks for the reply!..
Are you working in the sandbox or live? That particular error shows the following: “The transaction was declined by the issuing bank, not PayPal. The merchant should attempt another card.” That’s an odd error to get in the sandbox, so I’m assuming you must be attempting to process the card on the live server. If that’s the case, and that’s actually what you’re meaning to do, you’ll need to call the bank and ask them why they’re declining the transaction.
oh..no!.. Im 100% ‘trying’ to be in the sandbox! LOL..
I even have set to sandbox set to TRUE….
but I believe I using sandbox.paypal.com as the address…
once I get back I’ll check the config file again…
Love your PHP class! Makes life so much simpler. I am running into a problem though.
Using the CreateAccount like you have it setup in the sample, with info from my form. Everything that is required is there, but PayPal Sandbox is returning that the line1 and countryCode parameters are missing.
The XMLRequest in the $PayPalResult array shows both line1 and countryCode as being populated. Just to make sure I had my bases covered, I even populated all of the business addresses, even though I am attempting to create a Premier account.
Any suggestions?
Not sure what it is, but I used the layout in the Samples folder rather than the layout in the Templates folder, and that seemed to do the trick.
Ah, ok, that’s interesting. I guess I’ll have to double check the empty template to see what could be wrong with it.
I’ve have to get a look at the file you’re using so I can try to troubleshoot. If you want to send it to me I’ll do that.
Hi Andrew, thanks for your previous help with my chained payment and account confusion. I need to be able to refund Delayed Chained Payments. I was looking at the RefundTransaction template and see that it requires transactionId, but I don’t see transactionId coming back from the initial payment creation. Is there a way to access the transactionId once a chained payment has been created, even if it has yet to be executed?
Thanks again!
Actually, with Adaptive Payments you would use the Refund.php template instead of RefundTransaction.php. Within that you’ll see it accepts a PayKey, and you do get that back from an Adaptive response.
Ok, that makes a bit more sense. But now I’m a little confused about which email to put in the “Email” field in the Receiver object. When I use the original sender, I get “The refund’s receiver {email} wasn’t part of the payment request.” When I use the original primary receiver’s email, it goes through, but I don’t see the funds post back to the original sender’s funds in their sandbox profile.
Thanks again.
Whoops, just figured it out. I needed to grant API access for the sandbox account.
I have this tool integrated for our website and fore the most part it is great. I have been capturing logs due to complaints from PayPal users that continue to receive an error. When capturing the logs I see quite often an error of invalid token. what has been your experience when receiving this error?
Are you working with recurring payments? The only time I’ve ever seen that particular error is if you’re using Express Checkout with Recurring Payments but you forget to include the billing agreement parameters in your SetExpressCheckout request. Without those params the token you get is not valid for recurring payments, and then that error gets returned when you call CreateRecurringPaymentsProfile.
Does that sound like what could be happening? If not, do you have logs of your API requests and responses you can send me? Are you sure the token is getting passed correctly into your DoExpressCheckoutPayment request?
Hi, I am not doing recurring payments. I am not calling the CreateRecurringPaymentsProfile.php. I believe the token is being passed correctly because I get some successful transactions. I am capturing logs of the API requests and responses. How do I send that to you?
I’m not sure I understand what you’re saying here, but you can submit an order for premium support and I can help you directly.
Hi, thanks a bunch for the great Library! I was just wondering if I can use this on a local Wampserver? If so how would I go about it because I keep getting this error when I try using the pay-chained.php file.
Undefined property: angelleye\PayPal\Adaptive::$BetaSandbox in C:\wamp\www\Ultimate Refer\paypal\src\angelleye\PayPal\Adaptive.php on line 409
&
Authentication failed. API credentials are incorrect.
Thanks again,
Chris
Hi Chris,
Yes, you can use it on a local server no problem. Just need to make sure you have CURL enabled. This error you’re getting about the BetaSandbox looks like something I just need to get removed. I meant to strip the library of all that BetaSandbox stuff because they no longer have the beta sandbox. It looks like I missed a few things in the Adaptive library. It won’t effect the usability, though. I’ll get it fixed in an update soon.
The auth failure you’re getting means that your API credentials are simply incorrect. You need to make sure you’ve got the config file setup correctly so that $sandbox is evaluating to true or false correctly (maybe even set it manually) and then double check the credentials you have set for both live and sandbox values.
Ah great thanks! I have now set the sandbox & domain values manually in the config file like so…
$sandbox = TRUE;
$domain = ‘http://192.168.1.2/Ultimate%20Refer/paypal/samples/’;
I am now getting this error message…
Invalid request parameter: email myemail-facilitator@hotmail.com is invalid
I have made 2 extra sandbox accounts on top of the one they give you and i have put there emails in the receiver and sender arrays. Don’t know where i am going wrong
Thanks,
Chris
Hi again, just sending a nudge as i still haven’t been able to sort it out.
Cheers,
Chris
Contact me directly so you can send me your files and I can help you figure out the problem.
I just uploaded the library to my server, but when I try and open the Pay-Chained.php file, I get a white screen with these errors:
Warning: Unexpected character in input: ‘\’ (ASCII=92) state=1 in /home/ideaweb/public_html/projects/paypal/samples/Pay-Chained.php on line 20
Parse error: syntax error, unexpected T_STRING in /home/ideaweb/public_html/projects/paypal/samples/Pay-Chained.php on line 20
Do you have any idea why this might be happening?
Hi Danielle,
It seems to be running fine from my server, and that’s the exact file included with the library. Can you confirm what version of PHP you’re running? It needs to be 5.3 or higher. I’m guessing you’re on a previous version so it doesn’t know how to treat the namepsacing, which is where the \’s come into play.
Hi,
I am using PAY adaptive payment. I used it and payment is successfull but how should i recieve an IPN? I have enabled IPN in my paypal account but every time it returns empty IPN. Please help me in this issue. Really liked your class.
PayPal doesn’t POST “nothing” to an IPN listener. If you’re seeing that it’s sending data then there must be something wrong with your listener to make it look empty. You can check the IPN History in your PayPal account to verify. It will show you exactly what it’s sending and whether or not it was successfully received.
i can not use mass pay because paypal not enable for me, but now i want to use parallel and chained paypal. I want to know parallel and chained paypal are enable by default or not ? thank you
No, they are not. You will need to submit your app for approval within your account at http://developer.paypal.com. You’ll do it under the Classic API section. You can test in the sandbox using the global App ID provided in the library, but in order to go live you’ll need to get a live App ID from PayPal.
It’s difficult to get live App ID paypal ?
Nope, you just need to apply for it. As long as there isn’t anything extremely unique about your app it’ll probably get immediate approval.
i access to this page for create app
https://developer.paypal.com/webapps/developer/applications/createapp
, but i not see app id ?
where is my app id ?
thank you.
That is the REST API. Remember I said you need Classic. Here’s the link for that: https://apps.paypal.com/user/my-account/applications
I access to https://apps.paypal.com/user/my-account/applications
And then I create app and i get Sandbox ID And Live App ID
Please See Image link
http://image.ohozaa.com/i/66b/klaDZr.jpg
Now can i use parallel payments and Chained payments ?
Thank you ^^
Yes, it looks like you’re ready to go. Just get the App ID and your API credentials for the sandbox and the live server filled into the config file and everything will work nicely for you.
please see picture
http://image.ohozaa.com/i/240/O3um1P.jpg
1. receiver 1 can delay to send money to receiver 2 ?
2. all fee will charge by receiver 1
3.receiver 1 can not refund to sender, when receiver 2 not refund ?
please suggests code for do that thank you
I’ve really never tested how a refund would work in that scenario, specifically. You should be able to give it a shot on the sandbox, though. Have you tried that?
Thanks for you class, I wish I had found such years ago.
I tested the normal Pay.php for parallel payments to multiple recivers and that works fine…. but when I tried Pay-Chained.php I only see a payment to the primary receiver.
When creating a payment I get…
[Ack] => Success
[Build] => 12595496
[CorrelationID] => 2fc9ac024c396
[Timestamp] => 2014-09-10T06:34:26.014-07:00
[PayKey] => AP-0BL93113BN330561B
[PaymentExecStatus] => CREATED
so that works…
… but when following through with the payment in sandbox I see NO sign of the chain part of the payment to receiver2. Is it delayed? if so how is that controlled as I see no settings in the Pay-Chained.php file that would affect this.
I’m also setting ‘FeesPayer’ => ‘EACHRECEIVER’
receiver 1
‘Primary’ => ‘true’
reciever 2
‘Primary’ => ‘false’
and commented out the 3rd receiver in the sample to simplify
Nothing else changed… what could be the cause of receiver2 not getting a paypment?
Thanks for any insights
On a delayed chained payment the secondary receiver(s) will not receive their payment until you make a follow-up call to ExecutePayment. This is what triggers the secondary payments, so you can attach that API call to a button or some action that triggers that once the product/service is delivered, or whatever makes the secondary payments ready to release.
I think I figured it out…. I would have to call ExecutePayment.php right after with the correct PayKey if I want the secondary receiver in the chain to receive the payment right away. Correct?
Yes, but if you’re doing a delayed chained payment you wouldn’t typically trigger the secondary payment(s) at the same time. If that’s what you’re doing then there’s no need for the delay.
Hello Andrew,
Its great library and i love it, but when i am trying dodirectpayment call in one of my project… it always returns
Array
(
[TIMESTAMP] => 2014-09-10T21:29:37Z
[CORRELATIONID] => 77d021ed37842
[ACK] => Failure
[VERSION] => 112.0
[BUILD] => 12709182
[L_ERRORCODE0] => 10001
[L_SHORTMESSAGE0] => Internal Error
[L_LONGMESSAGE0] => The transaction could not be loaded
[L_SEVERITYCODE0] => Error
[AMT] => 87.99
[CURRENCYCODE] => GBP
[ERRORS] => Array
(
[0] => Array
(
[L_ERRORCODE] => 10001
[L_SHORTMESSAGE] => Internal Error
[L_LONGMESSAGE] => The transaction could not be loaded
[L_SEVERITYCODE] => Error
)
)
I have checked everything but could not fix this. Please help.
Are you working in the sandbox or with a live account? Can you post the entire $PayPalResult so I can see the full request?
Hello Andrew,
Thanks For your library . It will very help full and i have used it many times with codeigniter .
Andrew This time i am not getting any response from api . It only Returns my requeste data no any success/error message.
I tested it for both Sandbox and live.
[ERRORS] => Array
(
)
[REQUESTDATA] => Array
(
[USER] => ****************.com
[PWD] => *************************
[VERSION] => 98.0
[BUTTONSOURCE] => AngellEYE_PHPClass
[SIGNATURE] => ********************************
[METHOD] => DoDirectPayment
[PAYMENTACTION] => Sale
[IPADDRESS] => 171.78.97.199
[RETURNFMFDETAILS] => 1
[CREDITCARDTYPE] => Visa
[ACCT] => 4111111111111111
[EXPDATE] => 062018
[CVV2] => 123
[EMAIL] => abc@gmail.com
[SALUTATION] => Mr.
[FIRSTNAME] => Sanjeev
[LASTNAME] => kumar
[STREET] => JOHN SMITH 300 BOYLSTON AVE E
[CITY] => SEATTLE
[STATE] => 3727
[COUNTRYCODE] => US
[ZIP] => 98102
[PHONENUM] => 1242435543543
[AMT] => 1.99
[CURRENCYCODE] => USD
[ITEMAMT] => 1.99
[SHIPPINGAMT] => 0.00
[DESC] => LifeTimeTribute Memorial Package
[INVNUM] => 123-ABC1
[L_NAME0] => LifeTimeTribute Memorial Package
[L_DESC0] => LifeTimeTribute Memorial Package
[L_AMT0] => 1.99
[L_QTY0] => 1
)
Please Help .
I think it may have to do with your test credit card number you’re using. PayPal’s sandbox server has seen that number so many times that it often craps out and doesn’t work with it. Try using another randomly generated test CC number and that should solve your problem.
Hello Andrew,
I love your library it works great, there is only one thing I have been unable to figure out.
We offer gift cards and coupons to our customers. Is there a way in the library to offer a discount / coupon code for the entire order? i.e. the cart has 3 items and the cart total is $125.00. Is it possible to apply a discount of $25 via a gift card or coupon? Our code already calculates the discount and how much the new total is supposed to be, but when we submit it to PayPal the transaction fails because the item total does not match the cart total.
Any help would be great.
Hi Calvin,
PayPal does not provide a specific parameter to use for a discount, however, what you can do is add an additional line item to the order with a negative amount and call it a discount item. That way the subtotal will take into account this negative (discount) amount so that when you then add ITEMAMT + SHIPPINGAMT + HANDLINGAMT + TAXAMT = AMT and that error will go away.
The only time this may become an issue is when you have a scenario where the ITEMAMT ends up as a negative amount. For example, 2 items at $5.00 would be $10.00, then shipping of $5.00 would be a total of $15, but a discount of $12.00 added as a negative line item would give you an ITEMAMT of -$2.00, which PayPal would not accept. Outside of that type of scenario you won’t have any problems with it.
Hope that helps!
Thanks! That worked perfectly.
Glad to hear it!
Hello Andrew,
Thanks for the library , its great!!.
I am using your library do direct payment pro method with my web application. It was working fine .But after transaction buyer will not get transaction slip email . Don’t know how to enable it.
I also use another paypal recurring payments service with this application. , Both are note send buyer transaction slip email.
Please help me how can i enable this.
Thanks & Regards,
Sanjeev
When running Payments Pro transactions PayPal will not send anything to the buyer by default. They leave it up to you to generate your own email notifications. Part of the reason for this is because when a buyer specifically chooses to use a credit card, not PayPal, it would be odd to receive an email notification from PayPal.
autoloader fails
Parse error: syntax error, unexpected T_FUNCTION, expecting ‘)’ in /home/sunshine/public_html/gw/Library/paypal/autoload.php on line 7
I don’t understand the code, what am I doing wrong?
<?php
if(file_exists('Library/paypal/autoload.php')) {
include_once('Library/paypal/autoload.php');
}
spl_autoload_register(function
($class) {
$file = 'Library/paypal/'.'src'.'/'.implode('/', array_slice(explode('\\', $class ), 0, -1)).'/'.implode('' , array_slice( explode( '\\' , $class ),
-1 , 1)).'.php';
if(file_exists($file)) {
include($file);
}
});
Thanks in advance for you help.
PS I am only using the Button Manager functionality
Hi Raymond,
That definitely doesn’t look right. Where did you pull that from? The autoload.php should be using global PHP params like __DIR__ and other similar things. This looks like the dynamically filled code, but then it’s still mising the /vendor or /src directories, which is probably why it’s failing. Did you install with Composer or manually?
Hi Andrew,
I have been looking at the RequestPermissions sample code and have been abe to use it to grant API permissions from a separate test account.
One of the permissions granted was ACCESS_BASIC_PERSONAL_DATA and I would like to be able to retireve the emailaddres or paypalid of the account to use as the apiSubject in future transactions. On the callback I call GetAccessToken using the returned request_token and verification_code and then call GetBasicPersonalData, but the data returned is that of the API user (my details) not the merchant account that just granted the permissions.
Is there some sample code that would give an idea of how to achieve this? The code in GetBasicPersonalData uses the apiSubject email in the config array, but this email address is ecxactly what I want to get back and I am unsure how to go about this.
Thanks,
Paul.
Hi Paul,
Unfortunately, I do not yet have the Permissions API fully prepared in my library. It’s missing the token generation that is required to work properly. I’ve been planning on getting it added, but I just haven’t had the time to focus on it.
Until then, I’d recommend you go ahead and use the PayPal SDK for Permissions. It’s available on GitHub (https://github.com/paypal/permissions-sdk-php) and works with Composer so it’s very easy to install and utilize just like my library. You could load my library for all the payment processing stuff (because it’s a lot easier with mine) and load their’s for Permissions until I get it done.
Hope that helps!
Hello Andrew,
I’m so glad I have found this helpful class, I looked through and it looks great and easy to use. I’m having this one problem, I wanted to use the chained payment, I used the template, I have adjusted the config file providing the API username, password and signature, however when I try to run the script, I get “Authentication failed. API credentials are incorrect.” response.
Do I need to provide also the other API, such as Payflow Gateway and REST API credentials? After reading through the Paypal guide I understood all I needed were the very first mentioned, username, password and signature.
Thank you very much for your time!
Hi Paolo,
For Adaptive Payments you only need the API username, password, and signature like most calls. You also need to fill out the $developer_paypal_account which would be the email address you use to login to http://developer.paypal.com. That should do it for you.
Of course, double check that your values are good, and also make sure you’re using sandbox account credentials when testing against the sandbox and live account credentials when hitting the live servers. Sometimes people get that backwards or try using the same credentials for both and that won’t work.
If you want to submit a ticket here and send me your config file I can check it out and see if you’ve missed anything.
Hello Andrew,
thank you for your quick reply! I have done further research and in the end I found out what was wrong. I was using the API username, password and signature generated inside of the “sandbox.paypal.com”, while the one that needs to be used – and works for me – is one generated under the accounts within the “developer.paypal.com”. Hopefully it can save some headaches and time to the future users of your amazing class 😉
Hello Andrew,
it’s me again with an additional question. This time it regards Chained payments and their distribution. I use first the Chained Payments template to do the payments, then the Execute Payment teplate do distribute to each of recipients. However I have a question, is it possible to set it up in a way that not all of the recipients would be paid in the very same moment? What I would need is to be able to pay each of participated according to certain conditions, can I set that up with your class?
Thank you in advance!
What you’ve described is the standard delayed chained payment flow. There is not any way to split up the secondary receivers. When “secondary” are triggered it hits them all.
You could go a different route altogether, though, and basically build your own chained payment system. You could do that on the Adaptive Payments platform using the Pay API to disperse funds accordingly, and those could be triggered however/whenever you want. So the payment to your account would be setup with you as the single receiver, and then you’d just use the Pay API to send money to secondary receivers one at a time (or within a loop).
That puts more work in your hands on the development side, but frees you to do what you need.
Hope that helps!
Andrew
Hello Andrew,
I have a couple of questions regarding the Chained payment. One regards the distribution of chained payment, the other is the possibility of using custom values.
1) I use the Pay-Chained.php template, I bring there the required values etc. Then if I understood correctly, to execute the payments to the others – not primary reciever, I need to use the ExecutePayment.php and the PayKey. I would like the money to be sent right at the moment as soon as the payment has happened, could you please tell me how and/or where to call the execute payment file?
2) I would like to be able to pass an additional value, to come back with the payment, once paid. Something like the custom was while using the simple Html payment. Could you please tell me where that could be added?
Thank you very much for your time,
Paolo
1) If you want the money to be sent right away then don’t make it a delayed chained payment. Just make it a regular chained payment. To do that, set the ActionType to PAY instead of PAY_PRIMARY. Then you don’t have to mess with ExecutePayment at all.
2) You could use the Memo parameter in the Pay request, but I’m pretty sure that would be seen in the buyer details, too. Not sure if that’s what you’re after. Another option would be to use the TrackingID to tag the transaction with a unique ID and save any data you need associated with that transaction in the database with that ID. Then you could setup an IPN solution to process transactions, and you could pull data back out of your database using that ID.
Thank you very much for your help Andrew, this indeed does the trick!
I have another question, please bear with me a little bit longer. This time regarding the IPN, once this payment went through. On our website we have no registration system etc, so we would need to get the buyers first name, last name, address etc from the payment information to be able to ship the goods. However my IPN doesn’t seem to get the address. Am I doing something wrong?
I actually just wrote an article about how to test IPN. Maybe it’ll help you. 🙂
I have read the article through, but I think in the end the trouble is not on the side of IPN. It seems like I would need to tell the payment that shipping is required, I tried that with setting RequireShippingAddressSelection as TRUE, however it didn’t work as if I understand well, it’s meant to work only with embeded payments.
Could you tell me how to get out of this situation?
You need to make sure an address is included in the final DoExpressCheckoutPayment request to PayPal. Otherwise, it will not be included with the payment and would not be available in the IPN data.
Thank you for your patience Andrew! I got a bit lost now 🙁 I’m using Pay-Chained.php, so I thought I had to specify there that I required the payer to specify his address during the Paypal payment. What I mean to say, I don’t have the address, I need to obtain it from Paypal. Am I wrong?
Ah, ok, I was thinking you were using Express Checkout. It sounds like what you’re running into is the fact that Adaptive Payments transactions actually have 2 separate IPN’s. One is app specific and the other is transaction specific. It sounds like you’re looking at the app specific IPN, which is what you’d get at the URL you specify in the NotificationURL parameter of the Pay request. That will not include shipping details.
What you need is to make sure IPN is configured in the seller account you’re working with. The IPN that gets sent from that will include transaction specific details including the shipping address.
Hello Andrew, I have tried that, using two different IPNs, one for the application, the other for transaction. However I get the same response from both of them, neither having the address information I need.
What I find a bit unusual is, when I tried to test out the simple html payment, when in the Paypal, it asks me for the address, while in this way, Paypal doesn’t even propone me the option to pick/add an address.
You wouldn’t get the same IPN from both. You must have somehow configured two different IPN URL’s to get hit from the app. The IPN’s would be completely different, and the one from the seller account would have a lot more data included with it. I’ll have to see if I can dig up some samples as I don’t have any readily available, but you will definitely get separate IPN’s.
Thank you very much Andrew!
I have done further tests, now I have my IPNs sending various information exactly as you say. However still no shipping address there. I see that there is log_default_shipping_address_in_transaction=false, do I suspect right that it could have something to do with it?
Andrew, I ran further researches through Google and I found out that several people say that Paypal doesn’t provide the shipping address. Have you encountered this? And could you confirm that from your experience?
I should add when using Adaptive Payments, parallel or chained to my previous statement.
Hello Andrew,
Thanks a lot for your library, it’s fantastic. Going through all the paypal documentation seems like a hell.
I would appreciate if you could help me with something. I’m trying to integrate adaptive parallel payments in my wordpress site, using the Pay.php template. I checked the sandbox credentials countless times, but I still get the same error:
“Authentication failed. API credentials are incorrect.”
I tried making multiple sandbox accounts, tried with all of them, still the same result.
Thank you in advance.
Kind regards,
Alex
My guess would be that the $sandbox parameter in the config file isn’t evaluating the way it should, so while you’ve got the sandbox credentials entered it’s actually getting sent to the live server so it’s not accepting it. Just a hunch. Tough to say without getting a look at your setup.
If you’re working with Parallel payments though, as opposed to Chained payments, I would recommend using the Express Checkout API instead of Adaptive Payments. Express Checkout provides more features and a better buyer experience, and it supports parallel payments as well. It just won’t do chained. Also, with Express Checkout you won’t have to apply for an App ID so you can’t get launched a lot more quickly.
Either way, double check your credentials and also make sure $sandbox is evaluating the way you expect in the config file. If you continue to have troubles you can submit a ticket here and attach your files so I can take a quick look.
i have use adaptive payment for preaproval payment. i am first call preaproval request and after successfull ack sent the preaprovalDetail requst for future payment upto max 10 time and after successfull cal the pay opration but problem is that is macks the twice payment m code is below.
I do not fully understand your question, and reading/responding with code is not easy in these comments. Please submit a ticket here and provide more detail about what your problem is along with the code you originally provided here.
Hi, first of all big thumb for your work.
Now, my query, I have a client and I used your DoDirectPayment method to process a credit card, when i tried with testing credentials, it works like a charm. Then i have changed the credentials to live. But i am getting error 10501 continuously, I checked that this error will come when billing agreement is disabled or inactive. Client is saying that he signed up his account for Website Payments Pro solution.
Is there any other method to process a credit card or code for that, i am not sure how to handle this thing. Can u please give me a hand in that.
Thanks
Hi Akhilesh,
The 10501 error means that DoDirectPayment is simply not active on the live account, or that it is approved but the billing agreement for $30/mo that it costs has not been agreed to.
If the client is signed up for “Website Payments Pro 3.0” then DoDirectPayment would be correct, so if it has been approved then they probably just need to login to the live account and accept the $30/mo agreement.
What often happens, though, is that people end up with “Payments Pro 2.0” which uses the PayFlow API instead of DoDirectPayment. My library does include that as well, but it’s a different template file and works with different credentials and API endpoints.
So the first thing to do is verify exactly which version of Payments Pro they have. One easy way is to check whether or not they have a link at the top of their PayPal.com account that says “Go to PayPal Manager”. If you see this link that means they are most likely on the Payments Pro 2.0 version.
If that is the case, PayPal may be able to switch it to Website Payments Pro 3.0 so you don’t have to re-integrate anything. That all depends on the version of PayPal account they have.
Thanks for your response!,
I have registered for PayPal Payments Pro service and checking my account from this link https://manager.paypal.com/ and it is showing that “Status: Your account is currently in ACTIVE status. You can run both live and test transactions. ” and I used DDP but what i found that this feature is only available with Website Payments Pro (https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/). Does it mean that Website Payments Pro and PayPal Payments Pro both are different and i registered with a wrong service (PayPal Payments Pro), they are charging $30 for this service.
In the other hand when i am checking my developer account (http://developer.paypal.com/) i found that under account eligibility, all features are ticked in Sandbox mode but in Live mode some are still disabled ‘Direct credit cards’ is one of them which ‘Accept payments from customers directly using their credit cards on your web or mobile app.’
and when i am trying to enable this feature using ‘continue’ button it is either redirected to developers home or split a message that they received my application and will revert back soon, but it is about 15 days passed but no luck.
What is wrong with my developer account or can i use that PayPal payments pro to process Credit Cards of a user on my site without redirecting them to PayPal’s site. Is there any way.
Thanks a lot
Sounds like you have Payments Pro 2.0 which requires PayFlow setup in the plugin instead of DoDirectPayment. Please give that a try and if you continue to have troubles you can submit a ticket here.
Hi,
I’m trying use your paywithoptions function to parallel payment.
How could I get back paypal transaction IDs?
If you’re working with Parallel payments (not Chained) I would recommend using the Express Checkout API instead of Adaptive Payments. Either way, though, the best thing to do would be to setup an Instant Payment Notification (IPN) solution to handle post-transaction data processing of any kind.
Array
(
[0] => Array
(
[Receiver] =>
[Category] => Application
[Domain] => PLATFORM
[ErrorID] => 520003
[ExceptionID] =>
[Message] => Authentication failed. API credentials are incorrect.
[Parameter] =>
[Severity] => Error
[Subdomain] => Application
)
)
This error is pretty straight forward. Seems you need to double check your API credentials. Make sure the config file is setup correctly based on the $sandbox flag.
Hi Andrew-
Not sure if this is correct place to post this, but….
I have a few older apps using your class to integrate PayPal processing for some minor payments.
I recently had a new project which required this, and recycled much of the older code.. while testing this I noticed I was getting illegal off-set errors in PHP when trying to access the $PayPalResult object??
Specifically the ACCT value in the array… has something changed?
$PayPalResult[‘RAWREQUEST’][‘ACCT’] = substr($PayPalResult[‘RAWREQUEST’][‘ACCT’], -4);
// which is used to truncate the card# before logging… and has been in use for a long time. (until recently throwing an illegal offset error)
ie: Warning: Illegal string offset ‘ACCT’
but doesnt seem to exist anymore..
Updating to this:
$PayPalResult[‘ACCT’] = substr($PayPalResult[‘ACCT’], -4);
Seems to have worked..
but I’m more concerned about the change, when it happened and what caused it?
I’m not sure if there was a change with the formatting of the returned object/array?
The only other thing I can think of was a few weeks ago, I had this error:
Strict Standards: Declaration of PayPal_PayFlow::CURLRequest() should be compatible with PayPal::CURLRequest($Request = ”, $APIName = ”, $APIOperation = ”) in /usr/home/xxx/lib/php/xxx/paypal_angelleye/includes/paypal.payflow.class.php on line 165
which I had some out of sync files, and updated them all to be compliant/in sync with each other.
Was this update responsible for the array change?
That actually doesn’t look something that would have ever worked. RAWREQUEST is the entire NVP string, so it wouldn’t have ACCT separated within it. Sounds like maybe you didn’t have PHP error reporting enabled previously, so you probably just weren’t seeing the warning. $PayPalResult[‘ACCT’] isn’t going to work either, though. You would need to use $PayPalResult[‘REQUESTDATA’][‘ACCT’].
Is this SDK compliant with all the things Paypal will be requiring in June 2018? This is at: https://www.paypal-notice.com/en/
Looks like most of these are up to the web site itself (such as HTTPS only for IPN).
Yes, the library is good for all of that. As you mentioned, most of it needs to be handled at the server level.
Hello, how would you integrate this library with Laravel 5.8? I have successfully added the package to my project via composer, now I want toss-up the config file and the autoload? Many thanks.
Yes. We’ll be publishing some step by step tutorials for integrating the library into Laravel and other frameworks, but they’re not quite ready yet. For now you can take a look at this old project of mine where I tied these libraries into Laravel. It should all be very similar now.
You will see I have a paypal.php config file and then my controller and model work together.
Take a look at that and let me know if you have any specific questions.