954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Trouble with subscr_cancel in Paypal IPN

Hello,

I am using a script to process subscriptions on our sites - I can sucessfully get the subscription payment to process, I am having issues processing a cancel IPN request.

// assign posted variables to local variables
$item_name = make_safe($_POST['item_name']);
$item_number = make_safe($_POST['item_number']);
$payment_status = make_safe($_POST['payment_status']);
$payment_amount = make_safe($_POST['mc_gross']);
$payment_currency = make_safe($_POST['mc_currency']);
$txn_id = make_safe($_POST['txn_id']);
$txn_type = make_safe($_POST['txn_type']);
$subscr_id = make_safe($_POST['subscr_id']);
$receiver_email = $_POST['receiver_email'];
$payer_email = make_safe($_POST['payer_email']);
$custom = numOnly($_POST['custom']);
$date = time();

mail("lblah"," Payment","ID $custom.  $payment_status, $receiver_email TXN TYPE = $txn_type","From:NB");


if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
}

    //check the payment_status is Completed
    if($payment_status != "Completed"){
        $error .= "This Transaction has not been completed";
    //mail("lcah","$sitename Payment2","ID $custom.  $payment_status, $receiver_email $error FAIL","From: $sitename");
    }else{
        //check if cancelled
    if($txn_type == "subscr_cancel"){
  
    }

    if($txn_type == "recurring_payment_outstanding_payment_failed"){
      //cancel & remove
    }
    }

    // process payment
    if(!$error){
           //works
    }else{
            //works
    }
}
elseif (strcmp ($res, "INVALID") == 0) {
// log for manual investigation

}
}
fclose ($fp);
}

I have tried the if $txn_type == "subscr_cancel" in several places but the easiest understanding I have is that $payment_status is not passed when a the IPN sends a cancel request.

Does anyone have some hints or had similar difficulty with something like this before.

Any help would be appreciated.

liamfriel
Junior Poster
103 posts since Oct 2009
Reputation Points: 13
Solved Threads: 13
 

Realised the logical error of putting the code in the else of the section where payment_status was not sent.

liamfriel
Junior Poster
103 posts since Oct 2009
Reputation Points: 13
Solved Threads: 13
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: