SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: PayPal payment

  1. #1
    SitePoint Zealot
    Join Date
    May 2006
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PayPal payment

    Hey,

    I am trying to make a simple script that the user clicks buy on my site, they enter their name and email address and anyother details I may need then sends them to PayPal to pay.

    Then I need PayPal to send all the info back and then I need to run my script (It makes an account).

    BUT.. I don't have a clue on how to do this. I am very good at understanding code (Normally) and as I don't really have time to go crawling in the documentation at PayPal (I would prefer to work on the thing I am trying to sell ) could someone please provide me with what I need to get started and a sample script with comments (I have signed up at the developer center at PayPal but that gives me jack all ^^).

    Thanks,

    Tom

  2. #2
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    What you really need is to read documentation. There is no other way, except that someone provides you with complete code.

    Paypal documentation is very comprehensive and shouldn't take much of your time. It consists of examples which are basically exactly what you need.
    -- Jelena --

  3. #3
    SitePoint Zealot
    Join Date
    May 2006
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, I suppose ill have to take a break from my normal PHP coding and check out the PayPal API Documentation.

    Update:

    I am reading this: https://www.paypal.com/IntegrationCe...scheckout.html

    But its not helping one bit..

    First off how am I suppost to access the API? How do I even use the API (All its telling me is what it does really)?

    Prehaps I am looking at the wrong thing?

    Quote Originally Posted by Jelena View Post
    What you really need is to read documentation. There is no other way, except that someone provides you with complete code.

    Paypal documentation is very comprehensive and shouldn't take much of your time. It consists of examples which are basically exactly what you need.

  4. #4
    SitePoint Zealot
    Join Date
    May 2006
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok the documentation is not helping one little bit its just telling me how things Work..

    Could someone just provide me with a sample script please?

    Ok, I found some phpDocumentor generated documents but its just a massive list of classes.

    Now it wont even run install.php in the SDK!!!!

    Microsoft Windows [Version 5.2.3790]
    (C) Copyright 1985-2003 Microsoft Corp.

    C:\Documents and Settings\Administrator>cd "C:\ppsdk\php-sdk"

    C:\ppsdk\php-sdk>php install.php
    PHP Notice: Use of undefined constant STDIN - assumed 'STDIN' in C:\ppsdk\php-s
    dk\install.php on line 44
    PHP Warning: fgets(): supplied argument is not a valid stream resource in C:\pp
    sdk\php-sdk\install.php on line 44
    X-Powered-By: PHP/4.4.6
    Content-type: text/html

    This installer will overwrite any existing files in the target directory.
    Continue (y or n)?
    C:\ppsdk\php-sdk>

    Update:

    I made my own edits to install.php to get it to work

    Update:

    Got the samples installed.. But I don't understand any of it and there is no PayPal directory or PayPal.php!!!
    PHP Code:
    <?php
    include 'ppsdk_include_path.inc';

    require_once 
    'PayPal.php';
    require_once 
    'PayPal/Profile/Handler/Array.php';
    require_once 
    'PayPal/Profile/API.php';
    require_once 
    'PayPal/Type/BasicAmountType.php';
    require_once 
    'PayPal/Type/SetExpressCheckoutRequestType.php';
    require_once 
    'PayPal/Type/SetExpressCheckoutRequestDetailsType.php';
    require_once 
    'PayPal/Type/SetExpressCheckoutResponseType.php';

    require_once 
    'PayPal/Type/GetExpressCheckoutDetailsRequestType.php';
    require_once 
    'PayPal/Type/GetExpressCheckoutDetailsResponseDetailsType.php';
    require_once 
    'PayPal/Type/GetExpressCheckoutDetailsResponseType.php';

    require_once 
    'lib/constants.inc.php';
    require_once 
    'SampleLogger.php';

    define('PAYPAL_URL''https://www.' ENVIRONMENT '.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=');

    session_start();

    $profile $_SESSION['APIProfile'];

    $logger = new SampleLogger('ReviewOrder.php'PEAR_LOG_DEBUG);

    // Verify that user is logged in
    if(! isset($profile)) {
       
    // Not logged in -- Back to the login page
       
       
    $logger->_log('You are not logged in;  return to index.php'); 
       
    $location 'index.php';
       
    header("Location: $location"); 
    } else {
       
    $logger->_log('caller: 'print_r($callertrue));   
    }

    $token $_REQUEST['token'];
    if(! isset(
    $token)) {

       
    // SetExpressCheckout handling
       
    $serverName $_SERVER['SERVER_NAME'];
       
    // Use this to test with NAT
       // $serverName = '192.168.1.10';
       
    $serverPort $_SERVER['SERVER_PORT'];
       
       
    // $pathInfo = '/php-sdk/samples/php';
       
    $path_parts pathinfo($_SERVER['SCRIPT_NAME']);
       
    $path_info $path_parts['dirname'];
       
    $url='http://'.$serverName.':'.$serverPort.$path_info;
       
       
    $paymentAmount=$_REQUEST['paymentAmount'];
       
    $currencyCodeType=$_REQUEST['currencyCodeType'];
       
    // paymentType is ActionCodeType in ASP SDK
       
    $paymentType=$_REQUEST['paymentType'];
       
       
    $returnURL $url.'/ReviewOrder.php?paymentAmount='.$paymentAmount.'&currencyCodeType='.$currencyCodeType.'&paymentType='.$paymentType;
       
    $cancelURL str_replace('ReviewOrder''ExpressCheckout'$returnURL);
       
       
    $ec_request =& PayPal::getType('SetExpressCheckoutRequestType');
       
       
    $ec_details =& PayPal::getType('SetExpressCheckoutRequestDetailsType');
       
    $ec_details->setReturnURL($returnURL);
       
    $ec_details->setCancelURL($cancelURL);
       
    $ec_details->setPaymentAction($paymentType);
        
       
    $amt_type =& PayPal::getType('BasicAmountType');
       
    $amt_type->setattr('currencyID'$currencyCodeType);
       
    $amt_type->setval($paymentAmount'iso-8859-1');  
       
    $ec_details->setOrderTotal($amt_type);
       
       
    $ec_request->setSetExpressCheckoutRequestDetails($ec_details);
       
       
       
    $caller =& PayPal::getCallerServices($profile);

       
    // Execute SOAP request
       
    $response $caller->SetExpressCheckout($ec_request);
       
    // $display = print_r($response, true);
       
    $logger->_log('SetExpressCheckout response: 'print_r($response,true));
       
       
    $ack $response->getAck();
       
       
    $logger->_log('Ack='.$ack);
       
       switch(
    $ack) {
          case 
    ACK_SUCCESS:
          case 
    ACK_SUCCESS_WITH_WARNING:
             
    // Good to break out;
             
             // Redirect to paypal.com here
             
    $token $response->getToken();
             
    $payPalURL PAYPAL_URL.$token;
             
    // $display=$payPalURL;
             
    $logger->_log('Redirect to PayPal for payment: '$payPalURL);
             
    header("Location: ".$payPalURL);
             exit;
          
          default:
             
    $_SESSION['response'] =& $response;   
             
    $logger->_log('SetExpressCheckout failed: ' print_r($responsetrue));
             
    $location "ApiError.php";
             
    header("Location: $location");  
       }
       
    } else {
       
       
    // We have a TOKEN from paypal
       // GetExpressCheckoutDetails handling here
       
    $paymentType=$_REQUEST['paymentType'];
       
    $token $_REQUEST['token'];
       
    $paymentAmount=$_REQUEST['paymentAmount'];
       
    $currencyCodeType=$_REQUEST['currencyCodeType'];
       
       
    $ec_request =& PayPal::getType('GetExpressCheckoutDetailsRequestType');
       
    $ec_request->setToken($token);
       
       
    $caller =& PayPal::getCallerServices($profile);

       
    // Execute SOAP request
       
    $response $caller->GetExpressCheckoutDetails($ec_request);
       
    // $display = print_r($response, true);
       
    $logger->_log('GetExpressCheckoutDetails response: 'print_r($response,true));
       
       
    $ack $response->getAck();
       
       
    $logger->_log('Ack='.$ack);
       
       switch(
    $ack) {
          case 
    ACK_SUCCESS:
          case 
    ACK_SUCCESS_WITH_WARNING:
             
    // Continue on based on the require below...
             
    break;
          
          default:
             
    $_SESSION['response'] =& $response;   
             
    $logger->_log('SetExpressCheckout failed: ' print_r($responsetrue));
             
    $location "ApiError.php";
             
    header("Location: $location");  
       }
       
       require_once 
    'pages/GetExpressCheckoutDetails.html.php'
    }

    ?>

  5. #5
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Before you begin anywhere you need an account with PayPal; This account is to use their development sandbox, so the account you create is for that - development - and is not live, so it doesn't take real payments.

    If it's something simple such as a Buy Now button you are looking for their standard payment scheme; You don't need their SDK for that though, but you have a choice as to use their API - web services - or use their NVP, which is named pair values that are sent via POST instead.

    There are different sandbox urls you use dependent on wether you choose their API or NVP approach as well; The documentation is good, but it's not excellent, but it's not easy to grasp what you need, and what option is best suited to you, from their web site.

    Their site as far as for developers go, is ill thought out in my view, but there you go...

  6. #6
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perhaps take a look at open source shopping carts with PayPal integration. Theres some large scripts already pre made, but i have also found alot of cut down versions that should only do what your after.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •