Solved

Paypal Express Checkout

Posted on 2014-09-02
19
612 Views
Last Modified: 2016-03-24
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!
0
Comment
Question by:Gary
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 6
  • 2
19 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40299951
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
 
LVL 58

Author Comment

by:Gary
ID: 40299957
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
 
LVL 58

Author Comment

by:Gary
ID: 40299964
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Accepted Solution

by:
Andrew Angell earned 500 total points
ID: 40299974
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
 
LVL 58

Author Comment

by:Gary
ID: 40299982
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
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40299988
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
 
LVL 11

Expert Comment

by:Andrew Angell
ID: 40299990
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
 
LVL 58

Author Comment

by:Gary
ID: 40299992
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
 
LVL 11

Expert Comment

by:Andrew Angell
ID: 40299995
The library includes pretty much every API PayPal offers.  You'll probably find lots of useful things in there.  :)
0
 
LVL 58

Author Comment

by:Gary
ID: 40302494
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
 
LVL 11

Expert Comment

by:Andrew Angell
ID: 40302497
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
 
LVL 58

Author Comment

by:Gary
ID: 40302509
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
 
LVL 58

Author Comment

by:Gary
ID: 40302512
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
 
LVL 58

Author Comment

by:Gary
ID: 40302537
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
 
LVL 11

Expert Comment

by:Andrew Angell
ID: 40302560
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
 
LVL 58

Author Comment

by:Gary
ID: 40302652
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
 
LVL 11

Expert Comment

by:Andrew Angell
ID: 40302656
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
 
LVL 58

Author Comment

by:Gary
ID: 40303668
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
 
LVL 58

Author Closing Comment

by:Gary
ID: 40308668
Haven't implemented it yet but seems to be working fine in local testing.

Thanks
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
Original post  on Monitis Blog. Web performance monitoring is broken into two camps: passive and active. Passive monitoring is defined as looking at real-world historical performance by monitoring actual log-ins, site hits, clicks, requests for …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question