// When transaction has a minimum confirmations if ($bitcoin->getreceivedbyaccount($address_id, BITCOIN_MIN_TRANSACTION_CONFIRMATIONS)) { // New approved statuses $approved_count++; // Set order as APPROVED $statement = $db->prepare('UPDATE `order` SET `order_status_id` = ? WHERE `order_id` = ? LIMIT 1'); $statement->execute(array(ORDER_APPROVED_STATUS_ID, $order->order_id)); // Add file quota bonus $statement = $db->prepare('UPDATE `user` SET `file_quota` = `file_quota` + ? WHERE `user_id` = ? LIMIT 1'); $statement->execute(array(QUOTA_BONUS_SIZE_PER_ORDER, $order->seller_user_id)); // Generating a billing report if ($statement->rowCount()) { $fund_profit = (double) $order->amount * FEE_PER_ORDER / 100; $seller_profit = (double) $order->amount - $fund_profit; // Withdraw seller profit if ($transaction_id = $bitcoin->sendtoaddress($order->withdraw_address, $seller_profit, sprintf("%s Payout - Order ID %s", PROJECT_NAME, $order->order_id))) { $transaction_count++; } else { $error[] = sprintf("Seller Withdraw %s", $bitcoin->error); } // Withdraw profit if (!$error && $fund_profit > 0) { if ($transaction_id = $bitcoin->sendtoaddress(BITCOIN_FUND_ADDRESS, $fund_profit, sprintf("%s Profit - Order ID %s", PROJECT_NAME, $order->order_id))) { $transaction_count++; } else { $error[] = sprintf("[Fund Withdraw] %s", $bitcoin->error); } } // Add seller notification $notification = $db->prepare('INSERT INTO `user_notification` SET `user_id` = :user_id, `language_id` = :language_id,
if ($statement->rowCount()) { foreach ($statement->fetchAll() as $request) { $total_count++; $address_id = BITCOIN_USER_VERIFICATION_PREFIX . $request->user_id; // When order has been purchased if ((double) $bitcoin->getreceivedbyaccount($address_id) >= (double) $request->amount && $bitcoin->getreceivedbyaccount($address_id, BITCOIN_MIN_TRANSACTION_CONFIRMATIONS)) { // Transaction has minimum confirmations // Increase counter $processed_count++; // Set order as PROCESSED $statement = $db->prepare('UPDATE `user_verification_request` SET `status` = ? WHERE `user_verification_id` = ? LIMIT 1'); $statement->execute(array('processed', $request->user_verification_id)); $affiliate_profit = round($request->amount - $request->amount * FEE_USER_VERIFICATION_AFFILIATE / 100, 8); $fund_profit = round($request->amount - $affiliate_profit, 8); // Withdraw affiliate profit if ($transaction_id = $bitcoin->sendtoaddress($request->affiliate_address, $affiliate_profit, sprintf("%s Payout to Affiliate ID %s - User Verification ID %s", PROJECT_NAME, $request->affiliate_user_id, $request->user_verification_id))) { $transaction_count++; } else { $error[] = sprintf("[Affiliate Withdraw] %s", $bitcoin->error); } // Withdraw fund profit if (!$error && $fund_profit > 0) { if ($transaction_id = $bitcoin->sendtoaddress(BITCOIN_FUND_ADDRESS, $fund_profit, sprintf("%s Profit - User Verification ID %s", PROJECT_NAME, $request->user_verification_id))) { $transaction_count++; } else { $error[] = sprintf("[Fund Withdraw] %s", $bitcoin->error); } } // Add affiliate notification $notification = $db->prepare('INSERT INTO `user_notification` SET `user_id` = :user_id, `language_id` = :language_id,
if ($approved_order_data) { $text .= "\n\nAPPROVED ORDERS\n\n"; foreach ($approved_order_data as $order_id => $approved_order) { $text .= sprintf("Order #%s\n\n", $order_id); $text .= sprintf("\tBuyer #%s\n", $approved_order['buyer_id']); $text .= sprintf("\tSeller #%s\n", $approved_order['seller_id']); $text .= sprintf("\tProduct #%s\n", $approved_order['product_id']); $text .= sprintf("\tAmount: %s / Currency #%s\n", $approved_order['amount'], $approved_order['currency_id']); $text .= sprintf("\tWithdraw address: %s\n", $approved_order['withdraw_address']); $text .= sprintf("\tApproved time: %s\n\n", $approved_order['date']); } } // Withdraw to the Bank Storage if Current Balance more than 0 $total_balance = $bitcoin->getbalance(); if (BITCOIN_STORAGE_WITHDRAW_ENABLED && 0 < $total_balance && $total_balance > BITCOIN_STORAGE_WITHDRAW_MINIMUM_AMOUNT) { if ($bitcoin->sendtoaddress(BITCOIN_STORAGE_WITHDRAW_ADDRESS, $total_balance, 'BITSYBAY BACKUP')) { $text .= "\n\nFund " . $total_balance . ' BTC has been send to the reserve address ' . BITCOIN_STORAGE_WITHDRAW_ADDRESS . ' at ' . date('d.m.y H:i:s'); } else { $text .= "\n\nFund " . $total_balance . ' BTC has not been send to the reserve address ' . BITCOIN_STORAGE_WITHDRAW_ADDRESS . ' at ' . date('d.m.y H:i:s'); $text .= sprintf("\nReason: %s", $bitcoin->error); } } // Send billing report if (!empty($text)) { $mail = new Mail(); $mail->setTo(MAIL_BILLING); $mail->setFrom(MAIL_FROM); $mail->setReplyTo(MAIL_INFO); $mail->setSender(MAIL_SENDER); $mail->setSubject('BitsyBay - ORDER PROCESSOR REPORT'); $mail->setText($text);