Jump to content

Paypal IPN & inventory


Guest
 Share

Recommended Posts

Hello, Im having problems with the IPN part of the paypal gateway, for some reason its not bringing me back to the site. and its also not taking what i buy away from the inventory. Can you tell me what i did wrong?

I set up the IPN page in paypal and thats all i have to do right? Help would be most appreciated.

heres the link

http://www.newportcomedy.com/sales/index.p...viewCat&catId=1

Link to comment
Share on other sites

If im correct, this will come back to cubecart and tell it to turn the order from pending to complete automaticly right? also decrease the inventory? THanks for your help.

Link to comment
Share on other sites

I could really use some help with this bug, or even some info? is this a known bug? or is this something new? i really like the script but i need to know so i can complete the project and give it to my customer.

Link to comment
Share on other sites

I think the problem lies in this code, it seems to send payment alright but wont transfer the paypal ipn information with the order. are we sure if this is the exact code that paypal takes for ipn?

if($module['method']=="std"){

$hiddenVars .="<input type='hidden' name='return' value='".$GLOBALS['storeURL']."/confirmed.php?act=conf&amp;oid=".base64_encode($cart_order_id)."' />\r\n

<input type='hidden' name='cancel_return' value='".$GLOBALS['storeURL']."/confirmed.php?act=conf&amp;f=1&amp;oid=".base64_encode($cart_order_id)."' />";

}

<?php

/*

+--------------------------------------------------------------------------

|   CubeCart v3.0.0 Beta

|   ========================================

|   by Alistair Brookbanks

|	CubeCart is a Trade Mark of Devellion Limited

|   (c) 2005 Devellion Limited

|   Devellion Limited,

|   Westfield Lodge,

|   Westland Green,

|   Little Hadham,

|   Nr Ware, HERTS.

|   SG11 2AL

|   UNITED KINGDOM

|   http://www.devellion.com

|	UK Private Limited Company No. 5323904

|   ========================================

|   Web: http://www.cubecart.com

|   Date: Friday, 15 April 2005

|   Email: [email protected]

|	License Type: CubeCart is NOT Open Source Software and Limitations Apply 

|   Licence Info: http://www.cubecart.com/site/faq/license.php

+--------------------------------------------------------------------------

|	transfer.php

|   ========================================

|	Core functions for the PayPal Gateway	

+--------------------------------------------------------------------------

*/



/*

//////////////////////////

// PAYPAL GATEWAY

//////////////////////////

// [email protected]@K AT ALL THE LOVELY 

// VARIABLES WE HAVE TO

// PLAY WITH!!

//////



//////////////////////////

// IN THE REPEATED REGION

//////

$productId        - product id as an integer

$product[0]["name"]      - product name as a varchar

$price        	- price of each product (inc options)

$quantity        - quantity of products as an integer

$product_options      - products attributes as test

$product[0]["productCode"]    - product code as a varchar

$i          - This is the current incremented integer starting at 0



/////////////////////////

// FIXED VARS

///////

$cart_order_id      	- cart order id as a varchar

$ccUserData[0]['email']      - Customers email address

$ccUserData[0]['title']      - Customers title (Mr Miss etc...)

$ccUserData[0]['firstName']    	- Customers first name

$ccUserData[0]['lastName']    	- Customers last name 

$ccUserData[0]['add_1']      - Invoice Address line 1

$ccUserData[0]['add_2']      - Invoice Address line 1

$ccUserData[0]['town']      - Invoice Town or city

$ccUserData[0]['county']    	- Invoice County or state

$ccUserData[0]['postcode']    	- Invoice Post/Zip Code

$ccUserData[0]['country']    	- Invoice country Id we can look up the country name like this

          countryName($ccUserData[0]['country']);

$ccUserData[0]['phone']      - Contact phone no

$ccUserData[0]['mobile']    	- Mobile/Cell phone number



$basket['delInf']['title']    - Delivery title (Mr Miss etc...)

$basket['delInf']['firstName']  	- Delivery customers first name

$basket['delInf']['lastName']  	- Delivery customers last name 

$basket['delInf']['add_1']    - Delivery Address line 1

$basket['delInf']['add_2']    - Delivery Address line 1

$basket['delInf']['town']    - Delivery Town or city

$basket['delInf']['county']    - Delivery County or state

$basket['delInf']['postcode']  	- Delivery Post/Zip Code

$basket['delInf']['country']  	- Delivery  country Id we can look up the country name like this	

        	countryName($basket['delInf']['country']);





$basket['subTotal']      - Order Subtotal (exTax and Shipping)

$basket['grandTotal']    	- Basket total which has to be paid (inc Tax and Shipping).

$basket['tax']      	- Total tax to pay

$basket['shipCost']      - Shipping price

////////////////////////////////////////////////////////

*/



include("config.inc.php");



function repeatVars(){



  return FALSE;

	

}



function fixedVars(){

	

	global $module, $basket, $ccUserData, $cart_order_id, $config, $GLOBALS;

	

	$hiddenVars = "<input type='hidden' name='cmd' value='_xclick' />

    <input type='hidden' name='business' value='".$module['email']."' />

    <input type='hidden' name='item_name' value='Cart Order No: ".$cart_order_id."' />

    <input type='hidden' name='item_number' value='".$cart_order_id."' />

    <input type='hidden' name='amount' value='".$basket['grandTotal']."' />

    <input type='hidden' name='invoice' value='".$cart_order_id."' />

    <input type='hidden' name='first_name' value='".$ccUserData[0]['firstName']."' />

    <input type='hidden' name='last_name' value='".$ccUserData[0]['lastName']."' />

    <input type='hidden' name='currency_code' value='".$config['defaultCurrency']."' />

    <input type='hidden' name='address1' value='".$ccUserData[0]['add_1']."' />

    <input type='hidden' name='address2' value='".$ccUserData[0]['add_2']."' />

    <input type='hidden' name='city' value='".$ccUserData[0]['town']."' />

    <input type='hidden' name='state' value='".$ccUserData[0]['county']."' />

    <input type='hidden' name='zip' value='".$ccUserData[0]['postcode']."' />

    <input type='hidden' name='day_phone_a' value='".$ccUserData[0]['phone']."' />

    <input type='hidden' name='add' value='1' />

    <input type='hidden' name='no_note' value='1' />

    <input type='hidden' name='upload' value='1' />";

    

    if($module['method']=="std"){

    

    $hiddenVars .="<input type='hidden' name='return' value='".$GLOBALS['storeURL']."/confirmed.php?act=conf&amp;oid=".base64_encode($cart_order_id)."' />\r\n

    <input type='hidden' name='cancel_return' value='".$GLOBALS['storeURL']."/confirmed.php?act=conf&amp;f=1&amp;oid=".base64_encode($cart_order_id)."' />";

    

    }

    

  	return $hiddenVars;

	

}



function success(){

	global $db, $config, $module, $basket;

	

	if($module['method']=="std"){

  

  if( (base64_decode($_GET['oid']) == $basket['cart_order_id']) && !isset($_GET['f']) ) {

  

  	return TRUE;

  

  } else{

  

  	return FALSE;

  

  }

	

	} elseif($module['method']=="ipn") {

  // see if order was successful or not

  $result = $db->select("SELECT status  FROM ".$config['dbprefix']."CubeCart_Modules WHERE cart_order_id = ".$db->mySQLSafe($basket['cart_order_id']) );

  

  if($result['status']==2){

  	return TRUE;

  } else {

  	return FALSE;

  }	

  

	}



}



///////////////////////////

// Other Vars

////////

if($module['testMode']==1){

	$formAction = "https://www.sandbox.paypal.com/cgi-bin/webscr";

	$formMethod = "post";

	$formTarget = "_self";

} else {

	$formAction = "https://www.paypal.com/cgi-bin/webscr";

	$formMethod = "post";

	$formTarget = "_self";

}





if($module['method']=="std"){



	$transfer = "auto";

	$stateUpdate = TRUE;

	



} else {



	$transfer = "auto";

	$stateUpdate = FALSE;

}

?>

Link to comment
Share on other sites

Well i got the ipn working and now when it returns it turns the order to complete status. But im still having a problem. When its taking away from the inventory its taking away too much inventory. so if i order 2 items it takes 4 if i order 3 it takes 6. Does anyone know where this is stored? I looked in ipn.php and transfer.inc.php and its not there.

Link to comment
Share on other sites

WOW im talking to myself on this whole thread lol, how come i cant get the interest of some devs?

well heres the modified code

go down to this line

$MicroUpdateComment['stock_level'] = "(".$ProdSQL[0][stock_level]."-".$InvSQL[$i]['quantity'].")";

This is where the problem is, for some reason its doubling my subtracted inventory. 2=4 4=8 8=16 and so on. any suggestions?

<?php

/*

+--------------------------------------------------------------------------

|   CubeCart v3.0.0 Beta

|   ========================================

|   by Alistair Brookbanks

|	CubeCart is a Trade Mark of Devellion Limited

|   (c) 2005 Devellion Limited

|   Devellion Limited,

|   Westfield Lodge,

|   Westland Green,

|   Little Hadham,

|   Nr Ware, HERTS.

|   SG11 2AL

|   UNITED KINGDOM

|   http://www.devellion.com

|	UK Private Limited Company No. 5323904

|   ========================================

|   Web: http://www.cubecart.com

|   Date: Friday, 15 April 2005

|   Email: [email protected]

|	License Type: CubeCart is NOT Open Source Software and Limitations Apply 

|   Licence Info: http://www.cubecart.com/site/faq/license.php

+--------------------------------------------------------------------------

|	ipn.php

|   ========================================

|	IPN for the PayPal Gateway	

+--------------------------------------------------------------------------

*/



// INCLUDE CORE VARIABLES & FUNCTIONS

include_once("../../../includes/global.inc.php");

include_once("../../../includes/functions.inc.php");

include_once("config.inc.php");



// initiate db class

include_once("../../../classes/db.inc.php");

$db = new db();

	

// read the post from PayPal system and add 'cmd'

$req = 'cmd=_notify-validate';



foreach ($_POST as $key => $value) {

	$value = urlencode(stripslashes($value));

	$req .= "&$key=$value";

}



if($module['testMode']==1){ 

	$ipnUrl = "www.sandbox.paypal.com";

} else {

	$ipnUrl = "www.paypal.com";

}



// post back to PayPal system to validate

$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";

$header .= "Content-Type: application/x-www-form-urlencoded\r\n";

$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

$fp = fsockopen ($ipnUrl, 80, $errno, $errstr, 30);



	if (!$fp) {

  // HTTP ERROR

	} else {

  fputs ($fp, $header . $req);

  

  while (!feof($fp)) {

  

  $res = fgets ($fp, 1024);

  

  if (strcmp ($res, "VERIFIED") == 0) {



 	 $cart_order_id = $_POST['invoice'];



 	 $summary = $db->select("SELECT prod_total, comments FROM ".$config['dbprefix']."CubeCart_order_sum WHERE cart_order_id = ".$db->mySQLsafe($_POST['invoice']));

 	 

 	 // check the payment_status is Completed

 	 if($_POST['payment_status']!=="Completed"){



    $fail = TRUE;

    // add auto paypal status to comments of order

    $ppComment = "";

    switch($_POST['payment_status']){

   	 case "Canceled_Reversal":

   	 $ppComment = "Canceled Reversal - This means a reversal has been canceled; for example, you, the merchant, won a dispute with the customer and the funds for the transaction that was reversed have been returned to you.";

   	 $NowStatus = 4;

   	 break;

   	 

   	 case "Denied":

   	 $ppComment = "Denied - You, the merchant, denied the payment. This will only happen if the payment was previously pending due to one of the following pending reasons.";

   	 $NowStatus = 4;

   	 break;

   	 

   	 case "Failed":

   	 $ppComment = "Failed - The payment has failed. This will only happen if the payment was attempted from your customer’s bank account.";

   	 $NowStatus = 4;

   	 break;

   	 

   	 case "Pending":

   	 $ppComment = "Pending - The payment is pending; see the pending_reason variable for more information. Please note, you will receive another Instant Payment Notification when the status of the payment changes to

\"Completed,\" \"Failed,\" or

\"Denied.\"";

   	 $NowStatus = 4; //1

   	 break;

   	 

   	 case "Refunded":

   	 $ppComment = "Refunded - You, the merchant, refunded the payment.";

   	 $NowStatus = 3;

   	 break;

   	 

   	 case "Reversed":

   	 $ppComment = "Reversed - This means that a payment was reversed due to a chargeback or other type of reversal. The funds have been debited from your account balance and returned to the customer. The reason for the reversal is given

by the reason_code variable.";

   	 $NowStatus = 4;

   	 break;

   	 

   	 default:

   	 $ppComment = "Unspecified Error.";

   	 $NowStatus = 4;

   	 break;

   	 

    } 

    /*if(empty($summary[0]['comment'])){

   	 $updateComment['comment'] = "PayPal Comment: ".$ppComment;

    } else {

   	 $updateComment['comment'] = $summary[0]['comment']."\r\n\r\nPayPal Comment: ".$ppComment;

    } */

    //$updateComment['comment'] = "PayPal Comment: ".$ppComment;

    $updateComment['status'] = $db->mySQLsafe($NowStatus);

    $update = $db->update($config['dbprefix']."CubeCart_order_sum", $updateComment,"cart_order_id=".$db->mySQLSafe($_POST['invoice']));

    

 	 } else {

    //$updateComment['comment'] = "PayPal Comment: Completed";

    $updateComment['status'] = $db->mySQLsafe(3);

    $update = $db->update($config['dbprefix']."CubeCart_order_sum", $updateComment,"cart_order_id=".$db->mySQLSafe($_POST['invoice']));

    //$InvSQL = @mysql_query("SELECT * FROM ".$config['dbprefix']."CubeCart_order_inv WHERE cart_order_id=".$db->mySQLSafe($_POST['invoice']));

    $InvSQL = $db->select("SELECT * FROM ".$config['dbprefix']."CubeCart_order_inv WHERE cart_order_id=".$db->mySQLSafe($_POST['invoice']));

    for ($i=0; $i<count($InvSQL); $i++) {

     $ProdSQL = $db->select("SELECT * FROM ".$config['dbprefix']."CubeCart_inventory WHERE productId=".$db->mySQLSafe($InvSQL[$i]['productId']));

     $MicroUpdateComment = Array();

     $MicroUpdateComment['stock_level'] = "(".$ProdSQL[0][stock_level]."-".$InvSQL[$i]['quantity'].")";

     //$MicroUpdateComment['stock_level'] = "(stock_level-".$InvSQL[$i]['quantity'].")";

     //print("AAAAAAAAAAAAA: (stock_level-".$InvSQL[$i]['quantity'].")");

     $updateInv = $db->update($config['dbprefix']."CubeCart_inventory", $MicroUpdateComment,"productId=".$db->mySQLSafe($InvSQL[$i]['productId']));

     /* //@mysql_query("UPDATE ".$config['dbprefix']."CubeCart_inventory SET (stock_level = stock_level-".$InvResult[quantity]." ) WHERE productId=".$db->mySQLSafe($InvResult['productId'])); */

    }

 	 }

 	 

 	 // check that txn_id has not been previously processed

 	 $txn_id = $db->select("SELECT * FROM ".$config['dbprefix']."CubeCart_order_sum WHERE sec_order_id = ".$db->mySQLsafe($_POST['txn_id']));

 	 if($txn_id == TRUE){

    $fail = TRUE;

 	 } /*else {

    $updateOrder['sec_order_id='] = $_POST['txn_id'];

    $update = $db->update($config['dbprefix']."CubeCart_order_sum", $updateOrder,"cart_order_id=".$db->mySQLSafe($_POST['invoice']));

 	 }*/

 	 

 	 // check that receiver_email is your Primary PayPal email

 	 if($_POST['receiver_email']!==$module['email']){

    $fail = TRUE;

 	 }

 	 

 	 // make sure amount paid is same as in database

 	 if($_POST['mc_gross']!==$summary[0]['prod_total']){

    $fail = TRUE;

 	 }

 	 

 	 // process payment

 	 if(!isset($fail)){

    $cart_order_id = $_POST['invoice'];

    include_once("../../../includes/orderSuccess.inc.php");

 	 }

 	 

 	 

  } elseif (strcmp ($res, "INVALID") == 0) {

 	 // log for manual investigation

  }

	

	}



fclose ($fp);



}



header ("Location: http://newportcomedy.com/sales/cart.php?act=viewOrders");



?>

Link to comment
Share on other sites

Well i got the ipn working and now when it returns it turns the order to complete status.

Sorry i cant help with the other problem, havent really even looked at the cc3 code as of yet... but just curious as to how you got the paypal ipn working?

Link to comment
Share on other sites

Heres the zip, but its still having the problem where its doubling what should be subtracted. Im searching through hundreds of lines of code in other files to see where its subtracting. if a dev could reply to this post then it would make it much easier.

paypal.zip

Link to comment
Share on other sites

Guest phonecrazy

hello capetek,

I dont have a problem with the inventory as I dont use that section, but when someone pays it is taking them to their paypal account instead of back to the shop... how did you fix your paypal ipn section?

Cheers in advance

Robert

Link to comment
Share on other sites

Guest phonecrazy

Got the paypal ipn working with your files capetek, although the email that is sent to the customer is blank:

>From: Phone Crazy <[email protected]>

>To: **

>Subject: 050529-082040-4978

>Date: Sun, 29 May 2005 08:22:02 -0500

>

>

>

Thats all, nothing is in the body of the email...

Any suggestions?

Robert

Link to comment
Share on other sites

  • 4 weeks later...
Guest RAlfieri

I cannot get IPN to work correctly either. The return URL displays a blank page, the cart doesn't clear and the stock is not subtracted.

This is with FINAL 3.0.

I changed PayPal to STANDARD and all worked correctly.

Rob

Link to comment
Share on other sites

Ok, I'm really confused about what you guys are describing. I am trying to setup paypal and I can't find it documented anywhere, what the return URL or what the IPN URL should be. So I'm assuming you all have this set correctly, but paypal's return info isn't being processed correctly by not reducing inventory or sending out emails with info.

Can someone start by telling me the correct return URL AND the IPN URL?

Link to comment
Share on other sites

  • 2 weeks later...

I'm having same problem with settings set to standard and NOT using IPN. Payment is going through, but when user selects Return to Merchant on paypal, the store page says the order failed and the item is not deducted from inventory, but the order shows in the buyer's profile as having occurred.

What part of code submitted fixes this? if any?

thanx

M

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...