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) {
} 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");
        //check if cancelled
    if($txn_type == "subscr_cancel"){

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

    // process payment
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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.