Search code examples
phppaypalpaymentphp-5.3

paypal payment url not working usin php 5.3


I have problem with paypal payments. All codes is working well but when the page go to payment link/url it will be convert to paypal account homepage.

I am using this:

if (!isset($_POST["txn_id"]) && !isset($_POST["txn_type"])){
    $querystring = '';

    // Firstly Append paypal account to querystring
    $querystring .= "?business=".urlencode($paypal_email)."&";

    // Append amount& currency (£) to quersytring so it cannot be edited in html

    //The item name and amount can be brought in dynamically by querying the $_POST['item_number'] variable.
    $querystring .= "item_name=".urlencode($item_name)."&";
    $querystring .= "amount=".urlencode($item_amount)."&";

    //loop for posted values and append to querystring
    foreach($_POST as $key => $value){
        $value = urlencode(stripslashes($value));
        $querystring .= "$key=$value&";
    }

    // Append paypal return addresses
    $querystring .= "return=".urlencode(stripslashes($return_url))."&";
    $querystring .= "cancel_return=".urlencode(stripslashes($cancel_url))."&";
    $querystring .= "notify_url=".urlencode($notify_url);

    // Append querystring with custom field
    //$querystring .= "&custom=".USERID;

    // Redirect to paypal IPN
    header('location:https://www.paypal.com/cgi-bin/webscr'.$querystring);
    exit();
}

Solution

  • This looks like (your description is missing a bit, I think, but I believe this is a good guess...) your code is for a PayPal IPN Listener.

    There's lots of example code out there (including - and the best IMHO - from PayPal directly https://developer.paypal.com/docs/classic/ipn/ht_ipn/#do-it) that shows how to do this.

    Where did you get code that says to "Redirect to paypal IPN"? Surely that would not work as it would be highly non-secure (anyone could just hack those points...)

    You should be doing a cURL (or perhaps other method, cURL is more common, I think) which will give you the verification and allow your code to process further.

    See the documentation for sample code and post what you are trying to do if you have more issues.

    I don't believe this has anything to do with the PHP version - it has everything to do with following the documentation and flow of secure information.