Beispiel #1
0
        fclose($fp);
        // if VERIFIED=1 process payment
        if ($VERIFIED) {
            JBPLUG_do_callback('pay_trn_verification_passed', $invoice_id, $product_type);
            switch ($payment_status) {
                case "Completed":
                    // Funds successfully transferred
                    if ($product_type == 'P') {
                        JB_complete_package_invoice($invoice_id, 'NOCHEX');
                    } elseif ($product_type == 'S') {
                        JB_complete_subscription_invoice($invoice_id, 'NOCHEX');
                    } elseif ($product_type == 'M') {
                        JB_complete_membership_invoice($invoice_id, 'NOCHEX');
                    }
                    JBPLUG_do_callback('pay_trn_completed', $invoice_id, $product_type);
                    pp_log_entry("Completed NOCHEX: {$product_type} " . $invoice_id);
                    JB_debit_transaction($invoice_id, $amount, 'GBP', $txn_id, $reason, 'NOCHEX', $product_type);
                    break;
                default:
                    JBPLUG_do_callback('pay_trn_failed', $invoice_id, $product_type);
                    break;
            }
        }
    }
}
###########################################################################
# Payment Object
class NOCHEX
{
    var $name = "NOCHEX";
    var $description = "NOCHEX - Credit Card Payments. Accepts British Pounds.";
         }
         // we only accept web payments.
         // txn_type: 'cart', 'send_money', 'web_accept'
         // 'subscr_signup', 'subscr_cancel', 'subscr_failed', 'subscr_payment', 'subscr_eot', 'subscr_modify'
         /*
         if ($txn_type != 'web_accept' ) { 
         	pp_mail_error ("Transaction has incorrect type. txn_type = $txn_type \n");
         	$VERIFIED = false;
         
         }
         */
         $entry_line = "verified: {$res}";
         pp_log_entry($entry_line);
     } else {
         if (strcmp($res, "INVALID") == 0) {
             pp_log_entry($entry_line);
             // log for manual investigation
             $VERIFIED = false;
         }
     }
 }
 fclose($fp);
 // if VERIFIED=1 process payment
 if ($VERIFIED) {
     if ($txn_type == 'subscr_signup') {
     }
     if ($txn_type == 'subscr_cancel') {
     }
     if ($txn_type == 'subscr_modify') {
     }
     if ($txn_type == 'subscr_payment') {
Beispiel #3
0
    function process_payment_return()
    {
        global $label;
        if (PAYPAL_USE_CURL == 'YES') {
            // cannot use cURL for PTD, use for IPN only
            //return false;
        }
        ////////////
        // Paypal
        ###########################
        // read the post from PayPal system and add 'cmd'
        $req = 'cmd=_notify-synch';
        $tx_token = $_GET['tx'];
        $auth_token = PAYPAL_AUTH_TOKEN;
        $req .= "&tx={$tx_token}&at={$auth_token}";
        $result = '';
        if (PAYPAL_USE_CURL == 'YES') {
            // Use curl to post back to PayPAl
            // and put the result in a file.
            // open the file using $fp
            pp_log_entry('PDD - Using cURL to POST to PayPal');
            $URL = "https://" . PAYPAL_SERVER . "/cgi-bin/webscr";
            $ch = curl_init();
            if (PAYPAL_CURL_PROXY != '') {
                curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
                curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
                curl_setopt($ch, CURLOPT_PROXY, PAYPAL_CURL_PROXY);
            }
            //$req = "username=test&password=test";
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($ch, CURLOPT_URL, $URL);
            curl_setopt($ch, CURLOPT_TIMEOUT, 20);
            curl_setopt($ch, CURLOPT_POST, TRUE);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            pp_log_entry('PDT posting to PayPal and using cURL: ' . $result);
            $result = curl_exec($ch);
            pp_log_entry(curl_error($ch));
            curl_close($ch);
            pp_log_entry('PDD -Got this from result from cURL: ' . $result);
            $filename = JB_get_cache_dir() . md5(time() . PAYPAL_AUTH_TOKEN) . 'PDT.paypal';
            $fp = fopen($filename, 'w');
            fwrite($fp, $result, strlen($result));
            $fp = fclose($fp);
            // open for reading
            $fp = fopen($filename, 'r');
        } else {
            // 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(PAYPAL_SERVER, 80, $errno, $errstr, 30);
            // If possible, securely post back to paypal using HTTPS
            // Your PHP server will need to be SSL enabled
            // $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
        }
        if (!$fp) {
            // HTTP ERROR
            //echo  "fp error";
            pp_log_entry('PDD -Could not open socket / file');
        } else {
            if (PAYPAL_USE_CURL != 'YES') {
                fputs($fp, $header . $req);
                // post to paypal
            }
            // read the body data
            $res = '';
            $headerdone = false;
            while (!feof($fp)) {
                $line = fgets($fp, 1024);
                if (strcmp($line, "\r\n") == 0) {
                    // read the header
                    $headerdone = true;
                } else {
                    if ($headerdone) {
                        // header has been read. now read the contents
                        $res .= $line;
                    }
                }
            }
        }
        fclose($fp);
        if (PAYPAL_USE_CURL == 'YES') {
            unlink($filename);
        }
        // parse the data
        $lines = explode("\n", $res);
        $keyarray = array();
        if (strcmp($lines[0], "SUCCESS") == 0 || strpos($result, 'SUCCESS') !== false) {
            pp_log_entry('PDD - Notification verfified');
            for ($i = 1; $i < count($lines); $i++) {
                list($key, $val) = explode("=", $lines[$i]);
                $keyarray[urldecode($key)] = urldecode($val);
            }
            //print_r($_REQUEST);
            // check the payment_status is Completed
            // check that txn_id has not been previously processed
            // check that receiver_email is your Primary PayPal email
            // check that payment_amount/payment_currency are correct
            // process payment
            $firstname = $keyarray['first_name'];
            $lastname = $keyarray['last_name'];
            $itemname = $keyarray['item_name'];
            $amount = $keyarray['payment_gross'];
            $txn_id = $keyarray['txn_id'];
            $mc_gross = $keyarray['mc_gross'];
            $mc_currency = $keyarray['mc_currency'];
            $payer_email = $keyarray['payer_email'];
            $payment_status = $keyarray['payment_status'];
            $invoice_id = jb_strip_order_id($keyarray['invoice']);
            $product_type = substr($invoice_id, 0, 1);
            // 'P' or 'S'
            $invoice_id = substr($invoice_id, 1);
            JBPLUG_do_callback('pay_trn_verification_passed', $invoice_id, $product_type);
            if ($payment_status == 'Completed') {
                if ($product_type == 'P') {
                    ?>
					<center>

					<img src="<?php 
                    echo JB_SITE_LOGO_URL;
                    ?>
">
					<?php 
                    $label['payment_posts_completed2'] = str_replace("%URL%", JB_BASE_HTTP_PATH . JB_EMPLOYER_FOLDER . 'manager.php', $label['payment_posts_completed2']);
                    ?>
					<p><?php 
                    echo $label['payment_posts_completed2'];
                    ?>
</p>
					</center>
					<?php 
                } elseif ($product_type == 'S') {
                    ?>
					<center>
					<img src="<?php 
                    echo JB_SITE_LOGO_URL;
                    ?>
">
					<?php 
                    $label['payment_subscription_completed2'] = str_replace("%URL%", JB_BASE_HTTP_PATH . JB_EMPLOYER_FOLDER . 'search.php', $label['payment_subscription_completed2']);
                    ?>
					<p><?php 
                    echo $label['payment_subscription_completed2'];
                    ?>
</p>
					</center>
					<?php 
                } elseif ($product_type == 'M') {
                    // membership completed
                    ?>
					<center>
					<img src="<?php 
                    echo JB_SITE_LOGO_URL;
                    ?>
">
					<?php 
                    //$label['payment_membership_completed'] = str_replace("%URL%", JB_BASE_HTTP_PATH.JB_EMPLOYER_FOLDER, $label['payment_membership_completed']);
                    ?>
					<p><?php 
                    echo $label['payment_membership_completed'];
                    ?>
</p>
					</center>
					<?php 
                }
                $sql = "SELECT * FROM jb_txn WHERE txn_id='" . jb_escape_sql($txn_id) . "' and origin='PayPal' ";
                $result = JB_mysql_query($sql) or die(mysql_error());
                if (mysql_num_rows($result) > 0) {
                    // already in the database, possibly entered in by the IPN System
                } else {
                    if ($product_type == 'P') {
                        JB_complete_package_invoice($invoice_id, 'PayPal');
                    } elseif ($product_type == 'S') {
                        if (PAYPAL_MANUAL_APPROVE == 'Y') {
                            pp_subscr_manual_approve($invoice_id);
                        } else {
                            JB_complete_subscription_invoice($invoice_id, 'PayPal');
                        }
                    } elseif ($product_type == 'M') {
                        JB_complete_membership_invoice($invoice_id, 'PayPal');
                    }
                    JB_debit_transaction($invoice_id, $mc_gross, $mc_currency, $txn_id, $reason_code, 'PayPal', $product_type, $_REQUEST['subscr_id']);
                }
                JBPLUG_do_callback('pay_trn_completed', $invoice_id, $product_type);
            } elseif ($payment_status == 'Pending') {
                if ($product_type == 'P') {
                    JB_pend_package_invoice($invoice_id, 'PayPal', $reason_code);
                } elseif ($product_type == 'S') {
                    JB_pend_subscription_invoice($invoice_id, 'PayPal', $reason_code);
                } elseif ($product_type == 'M') {
                    JB_pend_membership_invoice($invoice_id, 'PayPal', $reason_code);
                }
                JBPLUG_do_callback('pay_trn_pending', $invoice_id, $product_type);
                $label['payment_return_pending'] = str_replace("%PAYMENT_GW%", $this->name, $label['payment_return_pending']);
                ?>
					<center>
					<img src="<?php 
                echo JB_SITE_LOGO_URL;
                ?>
">
					<p><?php 
                echo $label['payment_return_pending'];
                ?>
</p>
					</center>
					<?php 
            } else {
                echo "Payment status: {$payment_status}";
            }
        } else {
            if (strcmp($lines[0], "FAIL") == 0) {
                // log for manual investigation
                pp_log_entry('PDD - verification failed');
                JBPLUG_do_callback('pay_trn_verification_failed', $invoice_id, $product_type);
                echo $label['paypal_ipn_fail'];
                ?>

			

			<?php 
            }
        }
        ?>

		
		<p>&nbsp;</p>
		<p>&nbsp;</p>
		<p>&nbsp;</p>
		<p>&nbsp;</p>

		<?php 
    }