`u`.`email`, `a`.`user_id` AS `affiliate_user_id`, `a`.`email` AS `affiliate_email`, `a`.`affiliate_address` FROM `user_verification_request` AS `uvr` LEFT JOIN `user` AS `u` ON (`u`.`user_id` = `uvr`.`user_id`) LEFT JOIN `user` AS `a` ON (`a`.`user_id` = `u`.`referrer_user_id`) WHERE `status` <> ?'); $statement->execute(array('approved')); 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
exit; } // Init BitCoin try { $bitcoin = new BitCoin(BITCOIN_RPC_USERNAME, BITCOIN_RPC_PASSWORD, BITCOIN_RPC_HOST, BITCOIN_RPC_PORT); } catch (Exception $e) { trigger_error($bitcoin->error . '/' . $e->getMessage()); exit; } // Get pending orders $statement = $db->prepare('SELECT `order_id`, `user_id`, `amount` FROM `order` WHERE `order_status_id` <> ?'); $statement->execute(array(ORDER_APPROVED_STATUS_ID)); if ($statement->rowCount()) { foreach ($statement->fetchAll() as $order) { // Order has ben purchased if ($bitcoin->getreceivedbyaccount($order->order_id) > 0) { // If order amount is correct & already has minimum confirmations if ((double) $order->amount == (double) $bitcoin->getreceivedbyaccount($order->order_id)) { // Set order as PROCESSED $statement = $db->prepare('UPDATE `order` SET `order_status_id` = ? WHERE `order_status_id` <> ? AND `order_id` = ? LIMIT 1'); $statement->execute(array(ORDER_PROCESSED_STATUS_ID, ORDER_PROCESSED_STATUS_ID, $order->order_id)); // todo: Send notices to the customer & merchant // Set order as APPROVED if ($bitcoin->getreceivedbyaccount($order->order_id, ORDER_PROCESSOR_MIN_BTC_TRANSACTION_CONF_TO_ORDER_APPROVE)) { $statement = $db->prepare('UPDATE `order` SET `order_status_id` = ? WHERE `order_id` = ? LIMIT 1'); $statement->execute(array(ORDER_APPROVED_STATUS_ID, $order->order_id)); // Collect the billing report if ($statement->rowCount()) { $ordered_product = $db->prepare('SELECT `p`.`product_id`, `p`.`currency_id`, `o`.`amount`, `p`.`user_id`, `p`.`withdraw_address` FROM `product` AS `p` JOIN `order` AS `o` ON (`o`.`product_id` = `p`.`product_id`) WHERE `o`.`order_id` = ? LIMIT 1'); $ordered_product->execute(array($order->order_id)); if ($ordered_product->rowCount()) {