/**
  * Check if the user has credits or BTC to list the product
  *
  * @param mixed $userID
  * @param mixed $paymentType
  * @return boolean
  */
 public function hasMoneyToListProduct($userID, $paymentType = BuckysShopProduct::LIST_FEE_PAYMENT_TYPE_BTC)
 {
     if ($paymentType == BuckysShopProduct::LIST_FEE_PAYMENT_TYPE_CREDIT) {
         $tradeUserIns = new BuckysTradeUser();
         return $tradeUserIns->hasCredits($userID, SHOP_PRODUCT_LISTING_FEE_IN_CREDIT);
     } else {
         if ($paymentType == BuckysShopProduct::LIST_FEE_PAYMENT_TYPE_BTC) {
             $balance = BuckysBitcoin::getUserWalletBalance($userID);
             return $balance >= SHOP_PRODUCT_LISTING_FEE_IN_BTC;
         } else {
             return false;
         }
     }
 }
 /**
  * Check if you have money or credits
  *
  * @param mixed $userID
  * @param mixed $paymentType
  * @return bool
  */
 public function hasMoneyToListTradeItem($userID, $paymentType = BuckysTradeItem::LIST_FEE_PAYMENT_TYPE_BTC)
 {
     if ($paymentType == BuckysTradeItem::LIST_FEE_PAYMENT_TYPE_CREDIT) {
         $tradeUserIns = new BuckysTradeUser();
         return $tradeUserIns->hasCredits($userID, TRADE_ITEM_LISTING_FEE_IN_CREDIT);
     } else {
         if ($paymentType == BuckysTradeItem::LIST_FEE_PAYMENT_TYPE_BTC) {
             $balance = BuckysBitcoin::getUserWalletBalance($userID);
             return $balance >= TRADE_ITEM_LISTING_FEE_IN_BTC;
         } else {
             return false;
         }
     }
 }
 /**
  * @param $userID
  * @param $adID
  * @param $amount
  * @return bool
  */
 public function addFunds($userID, $adID, $amount)
 {
     global $db;
     $amount = doubleval($amount);
     //Check User Balance
     $bitcoinClass = new BuckysBitcoin();
     $userBalance = $bitcoinClass->getUserWalletBalance($userID);
     if ($userBalance < $amount) {
         $this->last_message = sprintf(MSG_AD_BITCOIN_BALANCE_NOT_ENOUGH_ERROR, $userBalance . ' BTC');
         return false;
     }
     $sendPayment = $bitcoinClass->sendBitcoin($userID, TNB_BITCOIN_ADDRESS, $amount);
     //they tried to send all the BTC in their wallet and didn't have enough for the fee
     if ($sendPayment === false) {
         $_SESSION['message'] = [];
         $tryPaymentAgain = $bitcoinClass->sendBitcoin($userID, TNB_BITCOIN_ADDRESS, $amount - BLOCKCHAIN_FEE);
         if ($tryPaymentAgain === false) {
             $this->last_message = MSG_INVALID_REQUEST;
             return false;
         }
     }
     $impressions = round($amount / ADS_PRICE_FOR_THOUSAND_IMPRESSIONS * 1000);
     //Update AD
     $query = $db->prepare("UPDATE " . TABLE_ADS . " SET `status`=1, `budget`=`budget` + " . $amount . ", `impressions`=`impressions` + " . $impressions . " WHERE id=%d", $adID);
     $db->query($query);
     $this->last_message = MSG_AD_UPDATED;
     return true;
 }
Пример #4
0
buckys_enqueue_stylesheet('trade.css');
buckys_enqueue_javascript('uploadify/jquery.uploadify.js');
buckys_enqueue_javascript('jquery.Jcrop.js');
buckys_enqueue_javascript('jquery.color.js');
buckys_enqueue_javascript('trade.js');
buckys_enqueue_javascript('trade-edit.js');
buckys_enqueue_javascript('uploadify/flash_install.js');
$TNB_GLOBALS['content'] = 'trade/additem';
$TNB_GLOBALS['headerType'] = 'trade';
$view = [];
$tradeCatIns = new BuckysTradeCategory();
$countryIns = new BuckysCountry();
$tradeUserIns = new BuckysTradeUser();
$view['no_cash'] = false;
$view['no_credits'] = false;
if (!$tradeUserIns->hasCredits($userID)) {
    $view['no_credits'] = true;
}
$userInfo = BuckysUser::getUserBasicInfo($userID);
$view['category_list'] = $tradeCatIns->getCategoryList(0);
$view['country_list'] = $countryIns->getCountryList();
$view['action_name'] = 'addTradeItem';
$view['page_title'] = 'Add an Item';
$view['type'] = 'additem';
$view['my_bitcoin_balance'] = BuckysBitcoin::getUserWalletBalance($userID);
$view['my_credit_balance'] = $userInfo['credits'];
if ($view['my_bitcoin_balance'] < TRADE_ITEM_LISTING_FEE_IN_BTC && $view['my_credit_balance'] < TRADE_ITEM_LISTING_FEE_IN_CREDIT) {
    $view['no_cash'] = true;
}
$TNB_GLOBALS['title'] = 'Add an Item - BuckysRoomTrade';
require DIR_FS_TEMPLATE . $TNB_GLOBALS['template'] . "/" . $TNB_GLOBALS['layout'] . ".php";
Пример #5
0
/**
 * Purchase product function
 * this function is POST
 */
function purchaseProduct()
{
    $productIns = new BuckysShopProduct();
    $orderIns = new BuckysShopOrder();
    $buyerID = get_secure_integer($_REQUEST['buyerID']);
    $productID = get_secure_integer($_REQUEST['productID']);
    $userID = buckys_is_logged_in();
    //Can  you purchase this item?
    if ($buyerID != $userID) {
        buckys_redirect('/shop/view.php?id=' . $productID, MSG_PERMISSION_DENIED, MSG_TYPE_ERROR);
    }
    //Product is active?
    $prodData = $productIns->getProductById($productID, false);
    if (!$prodData || $prodData['status'] == BuckysShopProduct::STATUS_INACTIVE) {
        echo "here";
        exit;
        buckys_redirect('/shop/index.php' . $productID, MSG_INVALID_REQUEST, MSG_TYPE_ERROR);
    }
    //Is this your product?
    if ($prodData['userID'] == $buyerID) {
        buckys_redirect('/shop/view.php?id=' . $productID, MSG_PERMISSION_DENIED, MSG_TYPE_ERROR);
    }
    //Shipping price is set?
    if (!$prodData['isDownloadable']) {
        $shippingPrice = fn_buckys_get_available_shipping_price($buyerID, $productID);
        if ($shippingPrice === null) {
            buckys_redirect('/shop/view.php?id=' . $productID, 'This item can not be shipped to your address. Check your shipping address or contact the owner.', MSG_TYPE_ERROR);
        }
    } else {
        $shippingPrice = 0;
    }
    //Do you have money?
    $balance = BuckysBitcoin::getUserWalletBalance($buyerID);
    $balance = 100;
    $total = $prodData['price'] + $shippingPrice;
    if ($total > $balance) {
        buckys_redirect('/shop/view.php?id=' . $productID, 'You do not have bitcoin enough to purchase this item.', MSG_TYPE_ERROR);
    }
    //Purchase product
    $flag = $orderIns->makePayment($buyerID, $prodData['userID'], $total);
    if ($flag) {
        if (!$prodData['isDownloadable']) {
            $buyerShippingInfoID = $orderIns->createShippingInfo($buyerID);
        } else {
            $buyerShippingInfoID = 0;
        }
        $param = ['sellerID' => $prodData['userID'], 'buyerID' => $buyerID, 'productID' => $productID, 'unitPrice' => $prodData['price'], 'shippingPrice' => $shippingPrice, 'totalPrice' => $total, 'buyerShippingID' => $buyerShippingInfoID, 'trackingNo' => '', 'createdDate' => date('Y-m-d H:i:s'), 'status' => BuckysShopOrder::STATUS_SOLD];
        if ($orderIns->createOrder($param)) {
            buckys_redirect('/shop/purchase.php', 'You have purchased an item successfully!', MSG_TYPE_SUCCESS);
        } else {
            buckys_redirect('/shop/view.php?id=' . $productID, 'Something goes wrong with your purchase. Please contact customer support!', MSG_TYPE_ERROR);
        }
    } else {
        buckys_redirect('/shop/view.php?id=' . $productID, 'Payment problem. Please contact customer support!', MSG_TYPE_ERROR);
    }
}