Hack Forums
[Looking] PHP coder to fix my paypal IPN script 5$ - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Marketplace (https://hackforums.net/forumdisplay.php?fid=105)
+--- Forum: Auxiliary (https://hackforums.net/forumdisplay.php?fid=453)
+---- Forum: Buyers Bay (https://hackforums.net/forumdisplay.php?fid=44)
+---- Thread: [Looking] PHP coder to fix my paypal IPN script 5$ (/showthread.php?tid=4445282)



PHP coder to fix my paypal IPN script 5$ - NoSuchAgency - Sep 13, 2014

I need someone to fix my paypal IPN file so it creates a voucher, and then adds it to your account. Please contact me for details.

5$, via paypal

The code to add it is not flawed, lik I can put it in a test.php file and the script will work, but when I put it in the ipn script it won't work.

Code
<?php
require_once 'includes/db.php';
require_once 'includes/init.php';
require_once 'includes/cCoupon.php';

   // Send an empty HTTP 200 OK response to acknowledge receipt of the notification
   header('HTTP/1.1 200 OK');
     // Assign payment notification values to local variables
  $item_name      = $_POST['item_name'];
  $item_number      = $_POST['item_number'];
  $payment_status   = $_POST['payment_status'];
  $payment_amount   = $_POST['mc_gross'];
  $payment_currency = $_POST['mc_currency'];
  $txn_id      = $_POST['txn_id'];
  $receiver_email   = $_POST['receiver_email'];
  $payer_email      = $_POST['payer_email'];
    // Build the required acknowledgement message out of the notification just received
  $req = 'cmd=_notify-validate';      // Add 'cmd=_notify-validate' to beginning of the acknowledgement

  foreach ($_POST as $key => $value) {      // Loop through the notification NV pairs
    $value = urlencode(stripslashes($value));  // Encode these values
    $req  .= "&$key=$value";      // Add the NV pairs to the acknowledgement
  }
   // Set up the acknowledgement request headers
  $header  = "POST /cgi-bin/webscr HTTP/1.1\r\n";      // HTTP POST request
  $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
  $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

  // Open a socket for the acknowledgement request
  $fp = fsockopen('ssl://www.paypal.com', 443, $errno, $errstr, 30);

  // Send the HTTP POST request back to PayPal for validation
  fputs($fp, $header . $req);
    while (!feof($fp)) {      // While not EOF
    $res = fgets($fp, 1024);      // Get the acknowledgement response

      if (!strcmp ($reply, "VERIFIED"))
      {
    if($payment_status == "Completed"){

                        $code = $_POST['item_name'];
                        $amount = $_POST['quantity'];
                        $uid = $_POST['custom'];;

                        if(strlen($code) > 30 || strlen($code) == 0 || empty($code))
                        {
                        $errors[] = "Code must be between 1-30 chars";
                        }
                        if(!ctype_alnum($code))
                        {
                        $errors[] = "Code must only contain a-z 0-9";
                        }
                        if(!is_numeric($amount) && $amount > 1)
                        {
                        $errors[] = "Amount must be a valid integer above 1";
                        }
                        if (empty($errors))
                        {
                        $cCoupon = new CouponClass($odb);
                        if($cCoupon->addCoupon($code, $amount))
                        {

                        }else{

                        }
                        }
                        else
                        {
                        foreach($errors as $error)
                        {

                        }
                        }

                        require_once('includes/cCoupon.php');
                        $errors = array();

                        if(!ctype_alnum($code))
                        {
                        array_push($errors,"Voucher can only contain 0-9 A-Z");
                        }

                        if (empty($errors))
                        {
                        $cCoupon = new CouponClass($odb);
                        if($cCoupon->useCoupon($code, $uid))
                        {
                        $getCoupon = $odb->prepare("select `Amount` from `coupons` where `Code` = :Code and `UserID` = :UID");
                        $getCoupon->execute(array(
                        ":Code" => $code,
                        ":UID" => $uid,
                        ));

                        $amount = intval($getCoupon->fetchColumn(0));

                        $addCredits = $odb->prepare("insert into `creditpayments`(paid, type, payer, credits, UserID, tid, date) values('0', 'Coupon', 'Coupon', :Credits, :UserID, 0, unix_timestamp())");
                        $addCredits->execute(array(
                        ":Credits" => $amount,
                        ":UserID" => $uid,
                        ));

                        }else{

                        }
                        }
                        else
                        {

                        foreach($errors as $error)
                        {
                        echo ' '.$error.'</p></div>';
                        }
                        }
    }
    else if (strcmp ($res, "INVALID") == 0) { //Response contains INVALID - reject notification

      // Send an email announcing the IPN message is INVALID

    }
  }
  }

  ?>

My button:
Code
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
      <input type="hidden" name="cmd" value="_s-xclick">
      <input type="hidden" name="hosted_button_id" value="N8Z4G73SG49R6">
      <input type="hidden" name="lc" value="US" >
      <input type="hidden" name="item_name" value="<?php echo $code ?>" >
      <input type="hidden" name="amount" value="1" >
      <input type="hidden" name="quantity" value="<?php echo $amount1 ?>" >
      <input type="hidden" name="currency_code" value="USD" >
      <input type="hidden" name="custom" value="<?php $_SESSION['ID']; ?>" >
      <input type="hidden" name="button_subtype" value="services" >
      <input type="hidden" name="no_note" value="0" >
      <input type="hidden" name="notify_url" value="http://fishin.rs/ipn.php" />
      <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
      <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

Spoiler (Click to View)


Fixed it myself. Closing thread. thank you