0

This is my payment form and success page what I am using for getting paid and store payment data to my database. payment form is working correctly but the success.php page is not getting any data from paypal. I already added the IPN and auto return url in the paypal account, but it is not working. Please somebody help me.

<?php
include 'dbConfig.php';

//Get payment information from PayPal
$item_number = $_GET['item_number']; 
$txn_id = $_GET['tx'];
$payment_gross = $_GET['amt'];
$currency_code = $_GET['cc'];
$payment_status = $_GET['st'];

//Get product price from database
$productResult = $db->query("SELECT price FROM products WHERE id = ".$item_number);
$productRow = $productResult->fetch_assoc();
$productPrice = $productRow['price'];

if(!empty($txn_id) && $payment_gross == $productPrice){
 //Check if payment data exists with the same TXN ID.
    $prevPaymentResult = $db->query("SELECT payment_id FROM payments WHERE txn_id = '".$txn_id."'");

    if($prevPaymentResult->num_rows > 0){
        $paymentRow = $prevPaymentResult->fetch_assoc();
        $last_insert_id = $paymentRow['payment_id'];
    }else{
        //Insert tansaction data into the database
        $insert = $db->query("INSERT INTO payments(item_number,txn_id,payment_gross,currency_code,payment_status) VALUES('".$item_number."','".$txn_id."','".$payment_gross."','".$currency_code."','".$payment_status."')");
        $last_insert_id = $db->insert_id;
    }
?>
  <h1>Your payment has been successful.</h1>
  <h1>Your Payment ID -
    <?php echo $last_insert_id; ?>.</h1>
  <?php }else{ ?>
  <h1>Your payment has failed.</h1>
  <?php } ?>

sing for getting payment and its working fine but I am not getting IPN message to and any data to my database?

<!-- begin snippet: js hide: false console: true babel: false -->
<?php
//Include db configuration file
include 'dbConfig.php';

//Set useful variables for paypal form
$paypalURL = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; //Test PayPal API URL
$paypalID = 'mybusiness@demo.com'; //Business Email

?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PayPal Standard Payment Gateway Integration by CodexWorld</title>
</head>
<body>
<?php
//Fetch products from the database
$results = $db->query("SELECT * FROM products");
while($row = $results->fetch_assoc()){
?>
<img src="images/<?php echo $row['image']; ?>"/>
<br/>Name: <?php echo $row['name']; ?>
<br/>Price: <?php echo $row['price']; ?>
<form action="<?php echo $paypalURL; ?>" method="post">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="<?php echo $paypalID; ?>"> 
<!-- Specify a Buy Now button. -->
<input type="hidden" name="cmd" value="_xclick">
<!-- Specify details about the item that buyers will purchase. -->
<input type="hidden" name="item_name" value="<?php echo $row['name']; ?>">
<input type="hidden" name="item_number" value="<?php echo $row['id']; ?>">
<input type="hidden" name="amount" value="<?php echo $row['price']; ?>">
<input type="hidden" name="currency_code" value="USD">
 <!-- Specify URLs -->
<input type='hidden' name='cancel_return' value='https://example.com/paypal_integration_php/cancel.php'>
<input type='hidden' name='return' value='https://example.com/paypal_integration_php/success.php'>
<input type='hidden' name='notify_url' value='https://example.com/paypal_integration_php/ipn.php'>
<!-- Display the payment button. -->
<input type="image" name="submit" border="0"
src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" alt="PayPal - The safer, easier way to pay online">
<img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form>
<?php } ?>
</body>
</html>
Simon H
  • 2,495
  • 4
  • 30
  • 38
Mmd Mahbub
  • 53
  • 1
  • 10

2 Answers2

0

The code you are using is more likely to be for PDT feature, not for IPN. Please check below page for sample codes of IPN .

https://github.com/paypal/ipn-code-samples

Besides, you may check below page for the comparison of the 2 features, together with their details.

https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNPDTAnAlternativetoIPN/

phillixzk
  • 342
  • 1
  • 3
-2

Brother Use $_REQUEST method instead of $_GET method to get the details of your transactions. Hope it will hep you

Vishal
  • 109
  • 1
  • 4
  • 11
  • The data can come either from `$_GET` or `$_POST`, using `$_REQUEST` shows you're not sure from where it comes. – Matteo Tassinari Jul 11 '17 at 08:19
  • Yes you are right @MatteoTassinari but i tried that same code some days ago and i am faced same problem but when i placed $_request in the place of $_GEt it will working fine. Thats why i give this answer . Hope it will help him to get out from his problem. – Vishal Jul 11 '17 at 08:27
  • If you get the data from `$_REQUEST` and not from `$_GET`, then probably the data is in `$_POST`. – Matteo Tassinari Jul 11 '17 at 08:37
  • Thanks for this useful information @MatteoTassinari . – Vishal Jul 11 '17 at 08:41