Solved

Paypal integration instructions

Posted on 2012-03-16
6
272 Views
Last Modified: 2016-03-24
I have a custom shopping cart (coded in php) which lists individual items, quantities, item and total item prices, shipping and total amount.  I want to integrate PayPal but I'm having trouble figuring out the steps required.  I have the PayPal API and a PayPal Sandbox setup with a buyer and seller test account and signature setup and ready to go.

From what I can find out so far, I believe I need the following files:
SetExpressCheckout.php
GetExpressCheckoutDetails.php
DoExpressCheckoutPayment.php


Q1) Do I need a Website Payments Pro account or will the free business accounts work (i.e. website payments standard) or is the API independant of these two as long as the account type is 'business'?

Q2) Could anyone provide clear steps I need to follow once I have a shopping cart ready to checkout

I'm sorry I don't have any more details but if you need anything else, I will do my utmost to provide what I can.  I'm pretty familiar with PHP, but have never worked with APIs before.
0
Comment
Question by:sbickerstaff
  • 3
  • 2
6 Comments
 
LVL 28

Accepted Solution

by:
sammySeltzer earned 500 total points
ID: 37731363
I think it depends on what you want to do.

If you wish to use their "Add to Cart" feature, then you would something exactly like this:


		<form name="_xclick" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
          <input type="hidden" name="cmd" value="_cart">
          <input type="hidden" name="business" value="someemail@somedomain.com">
          <input type="hidden" name="item_name" value="<%=rs("cname")%>">
          <input type="hidden" name="amount" value="<%= formatCurrency(cprice,2) %>">
          <input type="hidden" name="currency_code" value="USD">
   		<table>
	 		<tr>
	 			<td>Quantity: <input maxLength="6" Name="quantity" size=2 value="1" style="height: 2.2em; border: 1px solid Black; background: ButtonFace;">
	 			<input type="hidden" name="fproductid" value="<%=id%>">
          <input type="image" src="images/button_in_cart.jpg" border="0" name="submit" alt="PayPal">
          <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"></td>
	 		</tr>
		</table>
          <input type="hidden" name="add" value="1">

Open in new window


Notice this line below:

          <input type="hidden" name="add" value="1">

It lets paypal's integration bit know you are using their "Add to Cart" feature.

They will handle checkout from there.

To add "Continue Shopping" feature, you would need to be sure to login to your merchant section, perform a series of fillings and they would grab your domain name for redirecting to your website.

If you wish to use your own "Add to Cart" but you want to use Paypal's checkout feature, then use same code except instead of

<input type="hidden" name="add" value="1">

you would have something like

<input type="hidden" name="checkout" value="1">


More information here:

https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_paypal_shopping_cart
0
 
LVL 3

Author Comment

by:sbickerstaff
ID: 37731390
I've used the 'Add to cart' buttons before but these have to be generated manually per item and then the html code placed on the website.

My shopping cart is actually for a photo gallery and there could be thousands of items so I can't use that indicidual 'add to cart' button of paypal.  I will have all the items details, amounts, etc, stored but need some way to pass this information to PayPal to the show a summary and handle the payment.  I was reading something about Name Value Pairs (NVP).

I found the following piece of code, but not sure if it's valid anymore (up-to-date):
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="you@youremail.com" />
<input type="hidden" name="item_name" value="Item Name" />
<input type="hidden" name="currency_code" value="GBP" />


<!-- An internet URL where your customer will be returned after completing payment -->
<input type="hidden" name="return" value="http://www......" />
<!-- An internet URL where your customer will be returned after cancelling payment -->
<input type="hidden" name="cancel_return" value="http://www......" />
<!-- The internet URL of the 150 X 50 pixel image you would like to use as your logo -->
<input type="hidden" name="image_url" value="http://www......" />
<!-- Sets the background color of your payment pages. If set to "1," the background color will be black. This is optional; if omitted or set to "0," the background color will be white -->
<input type="hidden" name="cs" value="0" />

<input type="hidden" name="upload" value="1" />


<!-- (Required for item #x) Name of item #x in the cart. Must be alpha-numeric, with a 127 character limit -->
<input type="hidden" name="item_name_x " value="" />
<!-- Optional pass-through variable associated with item #x in the cart. Must be alpha-numeric, with a 127 character limit -->
<input type="hidden" name="item_number_x " value="" />
<!-- (Required for item #x) Price of the item #x -->
<input type="hidden" name="amount_x" value="" />
<!-- The cost of shipping the first piece (quantity of 1) of item #x 
<input type="hidden" name="shipping_x" value="" />
<!-- The cost of shipping each additional piece (quantity of 2 or above) of item #x 
<input type="hidden" name="shipping2_x" value="" />
<!-- The cost of handling for item #x 
<input type="hidden" name="handling_x" value="" />
<!-- First option field name for item #x. 64 character limit 
<input type="hidden" name="on0_x" value="" />
<!-- First set of option value(s) for item #x. 200 character limit. "on0_x" must be defined in order for "os0_x" to be recognized. 
<input type="hidden" name="os0_x" value="" />
<!-- Second option field name for item #x. 64 character limit
<input type="hidden" name="on1_x" value="" />
<!-- Second set of option value(s) for item #x. 200 character limit. "on1_x" must be defined in order for "os1_x" to be recognized. 
<input type="hidden" name="os1_x" value="" />


<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>

Open in new window

0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 37732543
You have just misread my post.

Bear in mind that you are dealing with hidden forms.

So, you are still going to write your php code and do your loop, etc.

So, depending on how you write your code, thousands of your pictures will be dislayed online with Add to Cart buttons.

At the end of the day, your users will push Add to Cart once item at a time.

THey might order different quantities but it will add one item at a time.

THe code you posted shows that you want to upload your items.

Notice

 <input type="hidden" name="upload" value="1" />

Take a look this website and see how I handled Add to cart.

Click the Add to Cart button and see where it takes you.

If that's what you are trying to do, then original code I posted is what you need.

http://www.millenniumhealthproducts.com

Click on any Category and go from there.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 3

Author Comment

by:sbickerstaff
ID: 37733251
Apologies sammy,  I did miss read it.  When you mentioned the Add to cart button, i assumed it was where you go onto the paypal site and generate a button for each specific item and price and then add that code to my site (this would be unpractical for constantly updating content).

If it was possible, I'd prefer to keep using my own cart and when ready to checkout, then go to PayPal and pass over all the cart contents.  Do you know is this possible?

Otherwise, if this isn't possible, I would use their cart feature (and the code you provided).
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 37733484
I have not done the Checkout bit.

What we did was the add to cart and paypal handles the rest.

However, if you have already signed up for it, then they will send you html checkout code.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37734652
You can use PHP to generate the "add to cart" buttons. The free account will almost certainly meet your basic needs.  You will need the paid account if you want to use paypal in a brick-and-mortar store or if you want to take credit cards over the telephone.

A Google search for "PHP PayPal Integration" will turn up several good resources.  Example:
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/library_download_sdks

Given a choice between SOAP and Name-Value pairs, I would expect the latter to be a RESTful interface, so I would choose that and avoid SOAP.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Often people are aiming at development of perfect Magento websites. Though, it is easier said than done. You know what’s much easier? To ruin everything. It can be done in seconds. Many of us experimented with design, tried to change some values dir…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now