/** * make payment * * @param mixed $buyerID * @param mixed $sellerID * @param mixed $amount */ public function makePayment($buyerID, $sellerID, $amount) { $sellerBitcoinInfo = BuckysUser::getUserBitcoinInfo($sellerID); if ($amount <= 0 || !$sellerBitcoinInfo) { return false; //no payment } $flag = BuckysBitcoin::sendBitcoin($buyerID, $sellerBitcoinInfo['bitcoin_address'], $amount); buckys_get_messages(); // this will flash the messages return $flag; }
/** * Pay to list products * * @param mixed $userID * @param mixed $paymentType * @return bool|int|null|string|void */ public function payListingFee($userID, $prodID, $paymentType = BuckysShopProduct::LIST_FEE_PAYMENT_TYPE_BTC) { $flag = false; if ($paymentType == BuckysShopProduct::LIST_FEE_PAYMENT_TYPE_CREDIT) { $transactionIns = new BuckysTransaction(); $flag = $transactionIns->useCreditsInShop($userID, SHOP_PRODUCT_LISTING_FEE_IN_CREDIT); } else { if ($paymentType == BuckysShopProduct::LIST_FEE_PAYMENT_TYPE_BTC) { $flag = BuckysBitcoin::sendBitcoin($userID, SHOP_TNB_LISTING_FEE_RECEIVER_BITCOIN_ADDRESS, SHOP_PRODUCT_LISTING_FEE_IN_BTC); buckys_get_messages(); // this will flash the messages if ($flag) { //Create bitcoin transaction BuckysBitcoinTransaction::addTransaction(BuckysBitcoinTransaction::TNB_BITCOIN_RECEIVER_ID, $userID, BuckysBitcoinTransaction::ACTIVITY_TYPE_LISTING_PRODUCT, $prodID, SHOP_PRODUCT_LISTING_FEE_IN_BTC); } } } return $flag; }
$toAddress = $_POST['receiver']; $amount = doubleval($_POST['amount']); $password = $_POST['password']; $user = BuckysUser::getUserData($TNB_GLOBALS['user']['userID']); $is_error = false; if (!$password || !buckys_validate_password($password, $user['password'])) { buckys_redirect("/wallet.php", MSG_CURRENT_PASSWORD_NOT_CORRECT, MSG_TYPE_ERROR); } if (!$toAddress) { buckys_redirect("/wallet.php", MSG_ENTER_BITCOINS_ADDRESS_OF_RECIPIENT, MSG_TYPE_ERROR); } if (!$amount || $amount <= 0) { buckys_redirect("/wallet.php", MSG_INVALID_BITCOIN_AMOUNT, MSG_TYPE_ERROR); } if (!$is_error) { $bitcoinClass->sendBitcoin($userID, $toAddress, $amount); } buckys_redirect("/wallet.php"); } $page = isset($_GET['page']) ? $_GET['page'] : 1; list($totalCount, $bitcoinBalance, $transactions) = $bitcoinClass->getTransactions($userID, $page, $bitcoinClass->COUNT_PER_PAGE); if (!$bitcoinBalance) { $bitcoinBalance = 0; } //Init Pagination Class $pagination = new Pagination($totalCount, $bitcoinClass->COUNT_PER_PAGE, $page); $page = $pagination->getCurrentPage(); //Getting Balance //$bitcoinBalance = $bitcoinClass->getWalletBalance($bitcoinInfo['bitcoin_guid'], buckys_decrypt($bitcoinInfo['bitcoin_password'])); buckys_enqueue_stylesheet('account.css'); buckys_enqueue_stylesheet('credits.css');
/** * @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; }