Exemplo n.º 1
0
/**
 * 请求进行付款
 * 
 * @return	失败返回 false,成功返回相关信息
 */
function order_request($orderid)
{
    $orderid = (int) $orderid;
    $sql = "SELECT * FROM `order` WHERE id={$orderid}";
    $res = db_query($sql);
    if ($res == false || db_num_rows($res) == 0) {
        vpn_log('No such order id: ' . $orderid);
        return false;
    }
    $arr = db_fetch_array($res);
    $amount = $arr['amount'] / 100;
    $nvp = paypal_new_payment($orderid, $amount);
    if ($nvp == false) {
        return false;
    }
    /// 生成 PayPal 支付订单
    $token = $nvp['token'];
    $remark = print_r($nvp, true);
    $token = addslashes($token);
    $remark = addslashes($remark);
    $sql = "INSERT INTO payment (orderid, token, remark) VALUES ({$orderid}, '{$token}', '{$remark}')";
    $res = db_query($sql);
    if ($res == false) {
        vpn_log('Error while creating payment record');
        return false;
    }
    $nvp['orderid'] = $orderid;
    return $nvp;
}
Exemplo n.º 2
0
function payment_main()
{
    $user = user_isonline();
    if ($user === false) {
        payment_die(_('Please login before checkout'));
    }
    $sid = @$_GET['serviceid'];
    $sid = (int) $sid;
    $sql = "SELECT * FROM service WHERE id={$sid}";
    $res = db_query($sql);
    if ($res == false || db_num_rows($res) == 0) {
        payment_die(_('We have no this service'));
    }
    $arr = db_fetch_array($res);
    $orderarr = order_new($sid);
    if ($orderarr == false) {
        payment_die(_('Checkout fail, please contact us for help'));
    }
    /// 使用 PayPal 进行支付
    $ret = paypal_new_payment($orderarr['orderid'], $amount);
    if ($ret == false) {
        payment_die(_('Checkout fail, please contact us for help'));
    }
    payment_redirect(PAYPAL_REDIRECTURL . '?token=' . $ret['token']);
}