Easier way to integrate PayPal express checkout? Easier way to integrate PayPal express checkout? wordpress wordpress

Easier way to integrate PayPal express checkout?


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>


You may want to use the new PayPalSDK. 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-indexGet the SDK for Express checkout. At thistime, 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'sall 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 anythinglike that. The user is redirected to the PayPal websiteand 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 transactionis approved. PayPal then executes the transaction and sends you back a confirmation with a transaction id.You can then call getTransactionDetails and display theconfirmation 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 listenerthat they provide, that will help. You will need toset up your listener URL on the PayPal website. You willalso need to set up an SSL certificate.

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