Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easier way to integrate PayPal express checkout?

I have built a product generation and display plugin for the Wordpress CMS and I am now trying to integrate some form of PayPal integration for the checkout process.

I have the cart, the products, the shipping, totals, all that figured out on my end and I was hoping someone could point me in the simplest direction of sending this information to PayPal. I understand some methods of doing this are not that secure and others make you jump through hoops like some sort of show dog. I've been trying to learn how to use cURL and then how to get it to work with PHP - it really seems like a bit of a mess. I do now have cURL working on my WAMP server ... but..

Is there a better way or should I continue to learn cURL?

I can format the data however it needs to be to send off to PayPal and would not mind doing this with JavaScript - this is not a pay-wall and every order is checked for accuracy by a human - so someone messing with the client-side script will not bother me. I also definitely want to send them to PayPal, I want no part of storing/processing their credit card information. It would, however, be nice to have IPN. Can someone point me in the right direction or assure me that I already am headed that way?

Thanks alot.

like image 542
Jon Avatar asked Mar 25 '13 23:03

Jon


People also ask

How do I integrate PayPal checkout on my website?

PayPal HTML buttons — Simply log in to the PayPal website to create, and optionally customize, a payment button. Then copy and paste the payment button's HTML code snippet to your website. Use this option if your HTML or web programming skills are limited and you sell only a few products on your site.

Does PayPal do express checkout?

While Express Checkout uses PayPal APIs, it is also closely integrated with many leading third-party shopping carts and merchant platforms. If your business uses one of our shopping cart or payment gateway partners then staff in your business may be able to add Express Checkout.

Is PayPal Express Checkout the same as PayPal?

PayPal Express is very similar to PayPal Standard with one major difference: the checkout flow. PayPal Express avoids the IPN issues that arise with PayPal Standard. Customers will be directed to PayPal from your site, but they don't complete checkout at PayPal.


2 Answers

This is how i automatically redirect to PayPal with all the form details;

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="paypal">

 <input type="hidden" name="cmd" value="_xclick" />
  <input type="hidden" name="cbt" value="Return to example" />
 <input type="hidden" name="business" value="email" />
 <input type="hidden" name="item_name" value="example Purchase" />
 <input type="hidden" name="amount" value="9.99">
 <input type="hidden" name="button_subtype" value="services" />
 <input type="hidden" name="no_shipping" value="1">
 <input type="hidden" name="return" value="URL" />
 <input type="hidden" name="notify_url" value="URL"/>
 <input type="hidden" name="cancel_return" value="URL" />
<input type="hidden" name="currency_code" value="USD"/>
<input type="hidden" name="image_url" value="" />
<input type="hidden" id="custom" name="custom" value="invoice_id to track"/>
 <input type="hidden" class="btn btn-primary" style="width:100%" alt="PayPal - The safer, easier way to pay online!"/>

</form>

For multiple products, you can simply add more products to the form, example;

<input type="hidden" name="item_name_1" value="Item #1">
<input type="hidden" name="amount_1" value="1.00">
<input type="hidden" name="item_name_2" value="Item #2">
<input type="hidden" name="amount_2" value="2.00">

However, using this method is not all great

All the data would need to be generated with PHP and input into the page, you would also need to check the transaction when the IPN calls back to ensure its been paid.

<script type="text/javascript">
  function myfunc () {
     var frm = document.getElementById("paypal");
     frm.submit();
  }
  window.onload = myfunc;
</script>
like image 94
Harry Beasant Avatar answered Sep 22 '22 13:09

Harry Beasant


You may want to use the new PayPal SDK. They have a good set of sample code, including code for express checkout and IPN. Try here https://www.x.com/developers/paypal/documentation-tools/paypal-sdk-index Get the SDK for Express checkout. At this time, they should be at SDK 98 for PHP.

You won't have to worry about the Curl, the SDK takes care of all that for you. A typical call might be something like this.

$setECResponse = $paypalService->SetExpressCheckout($setECReq);

This line of code is modeled after the samples. It's all object oriented. They provide you with classes. In this case there is a request object you fill out, the examples show exactly how to do it; just use the samples as your template.

It sounds like you want to do PayPal Express checkout, this way you won't have to handle credit cards or anything like that. The user is redirected to the PayPal website and all the financial transactions happen there. The user is redirected back to your site. Then you have a page where the user can review the order and click submit if they approve. When the user clicks submit, you call a PayPal API telling PayPal that the transaction is approved. PayPal then executes the transaction and sends you back a confirmation with a transaction id. You can then call getTransactionDetails and display the confirmation to the customer. You can additionally put those transaction details into a database.

Here are the APIs you can call for this. These are modeled closely to the sample code they provide

$paypalService->SetExpressCheckout($setECReq);

control goes to PayPal URL, and the user goes through a few pages there. control returns to you.

your order review page $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq);

your order confirmation page

$paypalService->GetExpressCheckoutDetails($getECReq);

$paypalService->DoExpressCheckoutPayment($DoECReq);

Tells PayPal to do the transaction.

$paypalService->GetTransactionDetails($request);

Here you can put transaction details into a database. You can also send yourself a mail with all the details, that way you will know whenever a transaction occurs.

IPN can be a bit tricky. There is a sample IPN listener that they provide, that will help. You will need to set up your listener URL on the PayPal website. You will also need to set up an SSL certificate.

The SDKs are fairly new, but PayPal is working on an even newer way to do things, developer.paypal.com. It just came out within the last month or so. You may want to look into that too.

like image 40
Ken Johnson Avatar answered Sep 20 '22 13:09

Ken Johnson