13

I have completely functional cart solution. All I want is the code where I actually pass the name of the products, the total, the return address and my paypal address so that it can direct me to a shopping cart. Can anyone steer me in the right direction?

PayPal has a million different versions. What I've come to learn is that the one I need is called "paypal website payments". Can someone confirm this?

rockstardev
  • 13,479
  • 39
  • 164
  • 296

2 Answers2

15

Yes, the Website Payments Standard is the way to go.

Basically, you create a form that has a few hidden fields ready to go (such as amount and what not) and then submit it. You could even submit this with JavaScript, so it takes your customer right to PayPal to complete the transaction.

As an example:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
  <input type="hidden" name="cmd" value="_xclick" />
  <input type="hidden" name="business" value="your_paypal_email_account" />
  <input type="hidden" name="undefined_quantity" value="1" />
  <input type="hidden" name="item_name" value="Order #1111111 for So-and-So" />
  <input type="hidden" name="item_number" value="order_1111111" />
  <input type="hidden" name="amount" value="5.00" />
  <input type="hidden" name="shipping" value="0.00" />
  <input type="hidden" name="no_shipping" value="1" />
  <input type="hidden" name="cn" value="Comments" />
  <input type="hidden" name="currency_code" value="USD" />
  <input type="hidden" name="lc" value="US" />
  <input type="hidden" name="bn" value="PP-BuyNowBF" />
  <input type="hidden" name="return" value="http://www.example.com/some-page-to-return-to" />
  <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynow_SM.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!" />
  <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />
</form>

You can find documentation on the additional parameters available here: https://www.x.com/sites/default/files/pp_websitepaymentsstandard_integrationguide.pdf

Brad
  • 159,648
  • 54
  • 349
  • 530
  • 1
    But i already have many cart items stored in sessions. Are you saying I must post with those inputs in my form? what address do I post to? What happens with more than one product? – rockstardev Sep 30 '11 at 21:11
  • 1
    @RD., I would use the entire "cart" as the "item". PayPal does have its own shopping card you could integrate with, but you already have that, so there is no need. Just pretend you have an item called "Order #12345" or whatever. The top of the `
    ` tag didn't get pasted. I will edit my answer with that address.
    – Brad Sep 30 '11 at 21:17
  • Sick! It works! Do you know how to set this so it goes via sandbox instead? Or is it not possible? – rockstardev Oct 01 '11 at 01:51
  • And how do you set the return url? – rockstardev Oct 01 '11 at 01:51
  • @RD., I believe the parameter for the return URL is simply, `return`, but I don't remember for certain. For that option, as well as sandbox info, check that documentation I pointed you to. – Brad Oct 01 '11 at 02:17
  • 3
    Yes, the return url is `return`, additionally, using sandbox simply means swapping https://www.paypal.com/cgi-bin/webscr for https://www.sandbox.paypal.com/cgi-bin/webscr in the `action`. Note: You'll need to have a working Sandbox seller account for this and be logged in on https://developer.paypal.com/ – Robert Oct 01 '11 at 18:33
  • btw, you can add `` to set a return url for when the user cancels the payment. – Maurice Aug 28 '13 at 12:19
1

You can use as a reference the following source code: https://github.com/osCommerce/oscommerce2/blob/master/catalog/ext/modules/payment/paypal/express.php

Check out this comparison of PayPal merchant solutions: https://www.paypal.com/gr/cgi-bin/webscr?cmd=_profile-comparison

prekageo
  • 358
  • 3
  • 15