Code Monkey home page Code Monkey logo

paypal's Introduction

How to implement PayPal Express checkout for simple (and single) payment on your web site?

PayPal allows their users to implement checkout functions using their API. But implementing the full API is not a piece of cake. There are some libraries on the web, but the most of them are paid, closed or too complex.

If you wanna implement simple and single-item payments (i.e. "pay for service" or "pay for source code"), you can use this library under BSD license.

How to implement, step-by-step:

   1. Download the library
   2. Get your API Name, Password and Signature, as described here: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_NVPAPIBasics. In a short way:
          * Log into PayPal and click Profile.
          * Click API Access from the Profile menu.
          * Click Request API Credentials.
          * Check Request API signature and click Agree and Submit.
          * Write down your credentials (Name, Password and Signature)
          * Click on Done
   3. Modify the class/paypal.php file:
          * Write your PayPal credentials in the appropriate place
          * Change the PP_RETURN and PP_CANCEL URLs

There are demo files in the root folder. Buy script is simple and straightforward: You have to create an instantion of the PayPal class and call its doExpressCheckout method. This method has these parameters:

$amount
    A desired amount of money
$desc
    Item description
$invoice (default: empty)
    Invoice internal ID. Use if you want to assign the payment to the right invoice.
$currency (default: USD)
    Three-letter currency code (List of the currency codes is here: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_currency_codes)

If everything is OK, the user is redirected to PayPal page to log in and confirm the payment, so the script execution ends. If something was wrong, method returns an array with an error information (see Response codes: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_NVPAPIOverview#id08696I00GBL__id08696I070PM).

After all, the buyer come to PP_RETURN url, or to PP_CANCEL.

At the "cancel" page you haven't to do anything special, just say something like "Your payment was cancelled".

At the "return" page (check ppreturn.php) you have to do one simple operation - call the doPayment() method of the PayPal object. This method confirms the money transfer and executes it. The doPayment() method returns the response code you can use to decide if the payment is OK (and display serial number or unlock the access or something else).

You can call the getCheckoutDetails() method to obtain the detail information about the transaction too, e.g. mail or invoice number

If you want to play with this library at PayPal Sandbox, you have to generate PayPal object as new PayPal();  - to prevent unwanted side effect, such as money loose... ;) 
On the production server you have use new PayPal(true); which indicated you're connected to "live" PayPal, not sandbox.

paypal's People

Contributors

maly avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.