function done_transaction($oid, $vpnid) { $ret = order_dopayment($oid); if ($ret === false) { pay_error(CANTFINISH); die; } /// 支付成功,开通服务并显示成功信息 $sql = "SELECT * FROM service WHERE id IN (SELECT serviceid FROM `order` WHERE id={$oid})"; $res = db_query($sql); if ($res === false) { pay_error(_("Can not find service correlate to order.id={$oid}, payment token={$token}")); die; } $service = db_fetch_array($res); /// 查找对应的 VPN 帐号 $vpnid = (int) $vpnid; $vpns = db_quick_fetch('vpnaccount', "WHERE id={$vpnid}"); if (count($vpns) <= 0) { vpn_log("No vpnid {$vpnid} found for order {$oid}"); return false; } $vpn = $vpns[0]; /// 下面的代码和 account_new.php 中的代码一致 /// 3. 账户余额足够,开通帐号 vpn_renew($vpn['username'], $service['duration'], $service['radiusgroup']); /// 4. 发货(在 raidus 中设置帐号),并扣款 order_delivery($oid); return true; }
order_setvpnid($order['orderid'], $aid); if ($amt < 0) { /// 余额不足时,显示付款页面,并在付款成功后继续开通帐号操作 //$smarty->assign('amount', abs($amt)); //$smarty->assign('service', $service); $url = "order_preview.php?id={$order['orderid']}"; header("Location: {$url}"); $smarty->assign('redirect_url', $url); $smarty->assign('tip_title', _('Redirect')); $smarty->assign('tip_msg', _('Redirecting...')); $smarty->display('tip.html'); die; } /// 3. 账户余额足够,续费 //print_r($account); //print_r($service); vpn_renew($account['username'], $service['duration'], $service['radiusgroup']); /// 4. 发货(扣款) order_delivery($order['orderid']); $smarty->assign('tip_title', _('Renew Success')); $smarty->assign('tip_msg', _('Thank you for purchase, now you can go to VPN Account page to view you VPN account')); $smarty->assign('redirect_url', 'account.php'); $smarty->display('tip.html'); die; function renew_error($msg) { global $smarty; $smarty->assign('tip_title', _('ERROR')); $smarty->assign('tip_msg', $msg); $smarty->display('tip.html'); }
function account_pay($name, $pass, $serviceid) { global $smarty; $user = user_isonline(); /// 如果账户余额足够,则直接扣款并继续操作;如果余额不足则显示付款页面,并在付款后继续操作 $amt = vpn_afford($serviceid, $user['email']); $services = db_quick_fetch('service', "WHERE id={$serviceid}"); if (count($services) <= 0) { vpn_log("Error: No such service id: {$serviceid}"); } $service = $services[0]; /// 创建订单 $order = null; if ($amt < 0) { $order = order_new($serviceid, abs($amt)); } else { $order = order_new($serviceid); } if ($order === false) { vpn_log("Can not create order({$serviceid}, {$amt})"); $smarty->assign('tip_title', _('An error occur')); $smarty->assign('tip_msg', _('Can not create order, please contact us for help')); $smarty->display('tip.html'); die; } /// 向 order 表中增加 VPN 帐号信息 $qname = addslashes($name); $vpns = db_quick_fetch('vpnaccount', "WHERE username='******'"); if (count($vpns) <= 0) { vpn_log("No VPN username `{$name}' in vpnaccount table"); } db_quick_update('order', "WHERE id={$order['orderid']}", array('vpnid' => $vpns[0]['id'])); if ($amt < 0) { /// 余额不足时,显示付款页面,并在付款成功后继续开通帐号操作 //$smarty->assign('amount', abs($amt)); //$smarty->assign('service', $service); $url = "order_preview.php?id={$order['orderid']}"; header("Location: {$url}"); $smarty->assign('redirect_url', $url); $smarty->assign('tip_title', _('Redirect')); $smarty->assign('tip_msg', _('Redirecting...')); $smarty->display('tip.html'); die; } /// 3. 账户余额足够,开通帐号 //print_r($name); //print_r($service); vpn_renew($name, $service['duration'], $service['radiusgroup']); /// 4. 发货(扣款) order_delivery($order['orderid']); $smarty->assign('tip_title', _('Success')); $smarty->assign('tip_msg', _('Thank you for purchase, now you can go to My Account page to view you VPN account')); $smarty->assign('redirect_url', 'account.php'); $smarty->display('tip.html'); }