- Community Pick
So I decided to write a simple, little article to share this little piece of knowledge. Before to start, I have to say that this is not an exhaustive tutorial about implementing PayPal functions and options in a Web site. I only describe a step-by-step procedure to:
1. use in a web page a PayPal Buy Now button (from here BNB) in order to send our customer to PayPal site (other payment options will not be considered);
2. let our customer use PayPal site to pay our product even if he has not a PayPal account;
3. make our customer to return to our site automatically;
4. receive from PayPal the confirmation that transaction has been succsfully completed using PDT and a PHP script included in our site (IPN will not be treated);
5. test all procedure using PayPal Sandbox.
Of course, I'll assume you have a PayPal account: if you don't have it, I suggest you to create a new one before to proceed.
1. Creating a PayPal Buy Now button.
Make Login your PayPal. In the horizontal tabbed menu click 'PayPal Merchant Services', then click 'Sell single items' and then follow these steps:
Step1:
- Fill in Item name box and provide (optionally) an unique ID for it
- Choose price and currency values
- Set the postage cost, if needed
- choose the email address to receive payement notifications
Step2:
- Check 'Save button at Paypal'
- Leave unchecked other options (only because I've not tested yet: feel free to
use them if you need them)
Step3:
Set following options accordingly to your needs
- Do you want to let your customer change order quantities?
- Can your customer add special instructions in a message to you?
- Need your customer's postal address?
- Take customers to this URL when they cancel their checkout
Set following option with the exact url of the page of your Web site wich contains the script that will process the order and will update database, will allow a download and so on... For our examples we'll call this page 'http://yourDomain.com/ppr
- Take customers to this URL when they finish checkout
Well, all done. Now you have to click 'Create button' and you'll get the code to insert in your page: select the code copy it and paste it where you wish your button will appear.
Now, you have to set up all preferences for Website Payment Preferences. Go back to the PayPal home page, the one that appears after you logged in. There, under the horizontal tabbed menu, with My Account tab selected, you'll see the menu item 'Profile'. Moving your mouse over it, a second v ertical menu will appear but this is not interesting for us: click 'Profile'.
In this way you'll be redirected to My Profile page. Here there are three columns: 'Account Information', 'Financial Information', 'Selling Preferences'. In the last one column look for 'Website Payment Preferences' and click it. In the new page you'll see there are several options to set. First af all, to answer to your question, scroll the page and look for 'Payment Data Transfer (optional)' section (is near the top of the page): be sure to turn On this option and get your Identity Token.
About the other options, be sure its are set as following instructions:
- Auto Return for Website Payments:
- On
- Return URL: the page you wish your customer will be redirected to. we call this page http://yourDomain.com/ppre
- Encrypted Website Payments
- I don't use it so I have set it to Off
- PayPal Account Optional
- On
- Contact Telephone Number
- I don't use it so I have set it to Off (reccomended by Paypal)
- PayPal Express Checkout Settings
- Set to No
Well, that's all. Remember that the page you use in Return URL option must be the same set in BNB configuration.
2. The script
BNB has to be placed in the page where is your product description. The script you find in the box code below has to be placed in the page your customer will be redirected to by PayPal system when he will complete transaction (or when he will decide not to buy, sigh!). In our example, this page is 'http://yourDomain.com/ppr
Obviously, this script has to be included or inserted in a web page in the exact point where you wish messages appear.
3. PayPal Sandbox
Now, all is ready to make us reach and happy but... it will work fine? PayPal give us a chance to test our code quite easily, the PayPal Sandbox. Direct your browser to http://www.sandbox.paypal.
When you are creating these two test user, be sure to take note of usernames and passwords: you'll need them soon. The ghost-seller will simulate your real seller account. How? Go in the test user page, select the ghost-seller account and click the 'Test this account' button below. A popup window will appear and you'll be prompted to login: use username and password of your ghost-seller account. Once you are logged in, repeat all steps you have done in the real world of PayPal site. Click 'PayPal Merchant Services', then click on 'Sell single items' and so on.
During this process copy the code to insert the button in your site and take note of your sandbox token.
Now you can close the ghost-seller account window.
Once you have created your sandbox BNB and you have setup Website Payment Preferences, you have to make some changes in your site. First, you have to replace the original BNB code with the one you have taken in Sandbox. Second, in the script in ppreturn.php go to line where you found your token:
$auth_token = "your_paypal_token";
and add this line immediately below:
$auth_token = "your_sandbox_token";
Then comment the line with the PayPal token and leave uncommented the line with sandbox token. When you'll have tested your selling system you'll have to invert comment (commenting sandbox token and uncommenting PayPal token).
Finally, open in your browser the page of your website where is the (sandbox) Buy Now button and click it. You'll be redirected to the sandbox site and you'll have to login using your ghost-buyer account username and password. Complete this simulated transaction and if it's all right you'll be redirected to your ppreturn.php page where you'll see transaction data and your own-written message.
Well, as Warners said, that's all, folks! Good coding.