Paypal Express Checkout

Does anyone have working sample code using Paypal Express Checkout in PHP
Since a majority of my customers use PayPal I thought I may as well add in the express checkout.
So what I need is the code to do the login, grab the billing/shipping address and then finalize the transaction.
I already have the normal checkout procedure in place.

No links!
LVL 58
GaryAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
No Links means no answer.  Paypal Express Checkout is too complicated to explain here.  I got it working but it took 6 PHP files and a declaration of Congress to do it.  Now they won't talk to me anymore.  They didn't want to in the first place.
0
GaryAuthor Commented:
Dave
That's why I said no links, I'm looking it over and why is there no simple use this code to do the login and this code to do the payment posting.
0
GaryAuthor Commented:
Just found this
https://developer.paypal.com/docs/classic/express-checkout/overview-ec/#express-checkout-sample-code

Not sure how current it is since the code is over a year old.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Andrew AngellCo-Owner / DeveloperCommented:
Kinda hard to provide an answer without links, but my PHP Class Library for PayPal makes Express Checkout integration very simple.  It does include working samples for each of the calls, too.

Basically, you'll be working with SetExpressCheckout, GetExpressCheckoutDetails, and DoExpressCheckoutPayment.  As you can see, the library provides everything all setup for you so all you have to do is fill in the blanks with your own data and everything else takes care of itself.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GaryAuthor Commented:
When I say "no links" I mean blind links - here's some random blog I found on Google that I've never used ;o)

Will look at that tomorrow Andrew, looks good at first glance
0
Dave BaldwinFixer of ProblemsCommented:
I used the old code for 'Set', 'Get' and 'Do' and it took a long time to get it working.  PayPal support was not good.  You will probably be better off working with Andrew since he has specialized in this for quite a while.  The code I am using dates from 2012 or earlier.  Andrew and PayPal combined a lot of things into one large library and I didn't like doing it that way.
0
Andrew AngellCo-Owner / DeveloperCommented:
To elaborate, here's the general flow for Express Checkout.

1. Call SetExpressCheckout to obtain a token for the checkout.  This token will get appended to the end of the URL that you send the user to at PayPal.  My library will return $PayPalResult['REDIRECTURL'] with this already put together for you, so you'd simply redirect to that URL.

2.  The user gets to PayPal and either logs in or fills out credit card details (guest checkout).  They agree to the order and they are then sent back to the ReturnURL that you provided in the SetExpressCheckout request.  

3.  Within your ReturnURL (which is often nothing but a processing script) you can make a call to GetExpressCheckoutDetails to obtain the payer's shipping information from PayPal.  This way you can use those details to calculate shipping and tax (if applicable) and then display a final review page that includes everything totaled up.  This call will also return the PayerID, which is required in the final API request.

4.  When the user accepts this final review (or you could skip the review and just go straight here) you will make a call to DoExpressCheckoutPayment to finalize everything.  DECP is very similar to the first SEC call except that it's the call that finalizes the payment.  Until DECP is called, no money is moved.  Here you'll pass in the same token as before along with the PayerID obtained from the previous step.

So it sounds like a lot, but it's really just gathering data and making 3 API calls, which again, my library makes very simple for you.
0
GaryAuthor Commented:
Yeah, and just seen his address verification, been thinking I need to do that for a long time instead of manually checking - bonus!

Looks good Andrew, will review tomorrow, off to the bar now!
0
Andrew AngellCo-Owner / DeveloperCommented:
The library includes pretty much every API PayPal offers.  You'll probably find lots of useful things in there.  :)
0
GaryAuthor Commented:
Obviously I'm totally stupid, as I don't even know where to begin with this library and something is just not clicking with me
I have this in a blank page

<?php
include_once('/paypal/templates/SetExpressCheckout.php');


and I get this
Notice: Undefined index: REDIRECTURL in E:\htdocs\paypal\templates\SetExpressCheckout.php on line 172

I cannot see where  $PayPal->SetExpressCheckout is coming from/going to?
0
Andrew AngellCo-Owner / DeveloperCommented:
You don't include the template file.  All you include is the class file.  Then the template files are already setup to include the class so it just runs.  

Did you read the guide?  It gives you all the steps to use the library and is very straight forward.
0
GaryAuthor Commented:
I'm trying opening your sample files and I get the same error.
What class file are you on about?
Sorry but the guide is not really clear at all
0
GaryAuthor Commented:
I get the dump of all the array data but also this
    [ACK] => Failure
    [VERSION] => 97.0
    [BUILD] => 12658619
    [L_ERRORCODE0] => 10002
    [L_SHORTMESSAGE0] => Security error
    [L_LONGMESSAGE0] => Security header is not valid
    [L_SEVERITYCODE0] => Error
0
GaryAuthor Commented:
OK, so the instructions are a bit off, there is no includes folder. But still I cannot find where REDIRECTURL is being set - am I supposed to set this session myself?
0
Andrew AngellCo-Owner / DeveloperCommented:
Ah, your'e right.  I moved the config into samples not long ago since that's really what it is...a sample config file.  I'll get the docs updated.  Thanks for pointing that out.  

Seurity header not valid means your API credentials are incorrect, so that's where getting the config file setup correctly comes into play.

REDIRECTURL is returned by the library when you call SetExpressCheckout, so it would be in $PayPalResult['REDIRECTURL'], but of course that won't be valid until you get a successful response back from PayPal.
0
GaryAuthor Commented:
OK Andrew will look at it again tomorrow, I did enter my API credentials originally so I don't know why it is coming back as invalid but I cannot see where that session is being set?
0
Andrew AngellCo-Owner / DeveloperCommented:
The credentials get set in the config file and you need to make sure $sandbox is evaluating to true/false depending on what you're doing.
0
GaryAuthor Commented:
Ah ha success, I was using the wrong API credentials - had to rebuild it.
Confused by this warning

Merchant not enabled for reference transactions

How do I set it for a single payment? Tried changing it to
MerchantInitiatedBillingSingleSource

But that fails

Edit
So I commented out that whole section and it seems to work ok.
0
GaryAuthor Commented:
Haven't implemented it yet but seems to be working fine in local testing.

Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.