function do_payment($payment_id, $member_id) { global $config; ////////////////////////////////////////////////////////////// global $_IN_PAYMENT; session_register('_IN_PAYMENT'); if ($_IN_PAYMENT == $payment_id) { # fatal_error("Your payment is being processed - To avoid double charges, please DO NOT PRESS THE SUBMIT BUTTON AGAIN"); } $_IN_PAYMENT = $payment_id; session_write_close(); list($err, $errno) = netbilling_payment($payment_id, $member_id); session_register('_IN_PAYMENT'); $_IN_PAYMENT = $payment_id; if ($errno == 2 || $errno == 3) { global $t; $t->assign('error', $err); $t->assign('pay_link', "{$config['root_surl']}/plugins/payment/netbilling/cc.php?payment_id={$payment_id}&member_id={$member_id}&retry=1"); $t->display("cc/cc_declined.html"); } elseif ($err) { fatal_error($err); } else { header("Location: {$config['root_surl']}/thanks.php?payment_id={$payment_id}&member_id={$member_id}"); } exit; }
function netbilling_rebill() { global $config, $db, $t; if (!$config['use_cron']) { fatal_error("NetBilling rebill can be run only with external cron"); } $dat = date('Y-m-d'); $tomorrow = date('Y-m-d', time() + 3600 * 24); $payments = $db->get_expired_payments($dat, $dat, 'netbilling'); $renewed = array(); $log = "NetBilling Rebill\n"; foreach ($payments as $p) { if ($p['data']['CANCELLED']) { continue; } $member_id = $p['member_id']; $member = $db->get_user($member_id); $product_id = $p['product_id']; if ($renewed[$member_id][$product_id]++) { continue; } $product =& get_product($product_id); if (!$product->config['is_recurring']) { continue; } if ($product->config['rebill_times'] && !netbilling_check_rebill_times($product->config['rebill_times'], $p)) { continue; } $vars = array('RENEWAL_ORIG' => "RENEWAL_ORIG: {$p['payment_id']}"); $payment_id = $db->add_waiting_payment($member_id, $product_id, 'netbilling', $product->config['price'], $dat, $product->get_expire($dat), $vars); list($err, $errno) = netbilling_payment($payment_id, $member_id); if ($errno > 1) { mail_rebill_failed_member($member, $payment_id, $product, "{$err} ({$errno})"); } elseif (!$errno) { $db->log_error("no return from NetBilling, payment #{$payment_id}"); } elseif ($errno == 1) { $err = "COMPLETED"; mail_rebill_success_member($member, $payment_id, $product); } $log .= "login: {$p['member_login']} payment#: {$payment_id}: {$err} ({$errno})\n"; } # print $log; }