1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Problem in Paypal Inegration

Discussion in 'PHP' started by vivekmoyal, Dec 25, 2012.

  1. #1
    Let me tell you what i was doing. - I am try to make a page in which there is only one single textfield is there and you have to enter the amount in it and just click over the send button it now it will take you to the paypal page if he pays than it will show the success page other wise it will show the error page.

    Here is the online example of this code and this code is showing me the error that is " Invalid Token".
    link for online check simplyitsols [dot] com /demo/ assignment / test [dot] php

    one more problem i am having that when you open the page it will show the error. Without submitting it means it calls the function as we open the page.
    code i am using is
    
    <form method=post action=<?php echo $_SERVER['PHP_SELF'] ?>>    <input type="text" name="amount" id="amount"><input type=submit name=submit value=checkout></form>
    HTML:
    
    if(isset ($_POST["submit"])){    $amount=$_POST["amount"];    $method="DoExpressCheckoutPayment";
        print_r(PPHttpPost($method, $nvpStr_,$amount));}function PPHttpPost($methodName_, $nvpStr_,$amount) {        $environment = 'live';    // Set up your API credentials, PayPal end point, and API version.    $API_UserName = urlencode('#######');    $API_Password = urlencode('#######');    $API_Signature = urlencode('#######');    $API_Endpoint = "https://api-3t.paypal.com/nvp";    $version = urlencode('72.0');
        // setting the curl parameters.    $ch = curl_init();    curl_setopt($ch, CURLOPT_URL, $API_Endpoint);    curl_setopt($ch, CURLOPT_VERBOSE, 1);
        // Set the curl parameters.    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    curl_setopt($ch, CURLOPT_POST, 1);
        // Set the API operation, version, and API signature in the request.    $nvpreq = "METHOD=$methodName_&VERSION=$version&PAYMENTACTION=Authorization&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";
        // Set the request as a POST FIELD for curl.    curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
        // Get response from the server.    $httpResponse = curl_exec($ch);
        if(!$httpResponse) {        exit('$methodName_ failed: '.curl_error($ch).'('.curl_errno($ch).')');    }    // Extract the response details.    $httpResponseAr = explode("&", $httpResponse);
        $httpParsedResponseAr = array();    foreach ($httpResponseAr as $i => $value) {        $tmpAr = explode("=", $value);        if(sizeof($tmpAr) > 1) {            $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];        }    }
        if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {        exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");    }
        return $httpParsedResponseAr;}
    PHP:
     
    vivekmoyal, Dec 25, 2012 IP
  2. No User Name

    No User Name Member

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    26
    #2
    can you tell us what the error says?
     
    No User Name, Dec 28, 2012 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #3
    Well, for starters you have to define a function BEFORE you try to call it. Your if statement to run PPHttpPost has to come AFTER the function is defined.

    Though it would be a lot easier to diagnose if the code wasn't a poorly formatted illegible mess. If it's actually formatted in the file as one giant long line most of the code is ignored as a comment. (...though I'm HOPING you just cut and paste from a crappy editor that mangled it).
     
    deathshadow, Dec 30, 2012 IP