public static function BTC_transaction_o_complete() { $id = Core::validate($_GET['id']); $hash = Core::validate($_GET['hash']); $at = new AtBtc(); if (!$at->findById($id)) { header('Location: ' . URL_WRONG_DATA_INPUT); exit; } if ($hash != self::hash_for_money_output_link($at->getId(), $at->getUID())) { header('Location: ' . URL_WRONG_DATA_INPUT); exit; } $amount = $at->getValue(); $wallets = self::BTC_MinAndMaxWallets(); if ($wallets['max'] == null || $wallets['max']['current_balance'] < $amount) { header('Location: ' . URL_SERVER_ERROR); exit; } $wallet = new WalletsBtc(); $wallet->findById($wallets['max']['id']); $rpcClient = new jsonRPCClient('http://' . BTC_RPC_USER . ':' . BTC_RPC_PASSWORD . '@' . BTC_RPC_HOST . ':' . BTC_RPC_PORT . '/'); try { $transaction_hash = $rpcClient->sendfrom($wallet->getAccount(), $amount, BTC_CONFIRMATIONS); } catch (Exception $e) { header('Location: ' . URL_SERVER_ERROR); return; } $currency = new Currency(); $currency->findBy(array('Name' => 'BTC')); $limits = self::transactionLimits($currency->getId(), 'BTC', 1); $feeVolume = $amount * $limits['fee']; $feeVolume = Core::round_up($feeVolume, 8); $purses = Purse::findBy(array('UID' => $at->getUID(), 'CurId' => $currency->getId())); $purse = new Purse(); $purse->findById($purses[0]['id']); $purse->addValue(-($amount + $feeVolume)); $purse->save(); $systemFeeVolume = $amount * $limits['system_fee']; $systemFeeVolume = Core::round_up($systemFeeVolume, 8); $profit = ($feeVolume - $systemFeeVolume) * $wallet->getShare(); $wallet->setProfit($wallet->getProfit() + $profit); $wallet->save(); $at->setDone(1); $at->setTransactionHash($transaction_hash); $at->setTimestamp(Core::timestamp_gmp()); $at->save(); header('Location: ' . URL_SUCCESS_PAYMENT); }