[WORKAROUND] Fully debit user before RPC call
* First debit the user fully for this transaction * Try the payout RPC call * Fail this so admins can first confirm it worked, then force payouts * Added comment what line to remove if this happens a lot This will further address #1586
This commit is contained in:
parent
e3219cf5da
commit
72d923737f
@ -63,16 +63,19 @@ if ($setting->getValue('disable_manual_payouts') != 1) {
|
|||||||
$monitoring->endCronjob($cron_name, 'E0010', 1, true);
|
$monitoring->endCronjob($cron_name, 'E0010', 1, true);
|
||||||
}
|
}
|
||||||
$log->logInfo("\t" . $aData['account_id'] . "\t\t" . $aData['username'] . "\t" . $dBalance . "\t\t" . $aData['coin_address']);
|
$log->logInfo("\t" . $aData['account_id'] . "\t\t" . $aData['username'] . "\t" . $dBalance . "\t\t" . $aData['coin_address']);
|
||||||
try {
|
|
||||||
$txid = $bitcoin->sendtoaddress($aData['coin_address'], $dBalance - $config['txfee_manual']);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
$log->logError('E0078: RPC method did not return 200 OK: Address: ' . $aData['coin_address'] . ' ERROR: ' . $e->getMessage());
|
|
||||||
$monitoring->endCronjob($cron_name, 'E0078', 1, true);
|
|
||||||
}
|
|
||||||
if ($transaction->addTransaction($aData['account_id'], $dBalance - $config['txfee_manual'], 'Debit_MP', NULL, $aData['coin_address'], $txid) && $transaction->addTransaction($aData['account_id'], $config['txfee_manual'], 'TXFee', NULL, $aData['coin_address'])) {
|
if ($transaction->addTransaction($aData['account_id'], $dBalance - $config['txfee_manual'], 'Debit_MP', NULL, $aData['coin_address'], $txid) && $transaction->addTransaction($aData['account_id'], $config['txfee_manual'], 'TXFee', NULL, $aData['coin_address'])) {
|
||||||
// Mark all older transactions as archived
|
// Mark all older transactions as archived
|
||||||
if (!$transaction->setArchived($aData['account_id'], $transaction->insert_id))
|
if (!$transaction->setArchived($aData['account_id'], $transaction->insert_id))
|
||||||
$log->logError('Failed to mark transactions for #' . $aData['account_id'] . ' prior to #' . $transaction->insert_id . ' as archived. ERROR: ' . $transaction->getCronError());
|
$log->logError('Failed to mark transactions for #' . $aData['account_id'] . ' prior to #' . $transaction->insert_id . ' as archived. ERROR: ' . $transaction->getCronError());
|
||||||
|
// Run the payouts from RPC now that the user is fully debited
|
||||||
|
try {
|
||||||
|
$txid = $bitcoin->sendtoaddress($aData['coin_address'], $dBalance - $config['txfee_manual']);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$log->logError('E0078: RPC method did not return 200 OK: Address: ' . $aData['coin_address'] . ' ERROR: ' . $e->getMessage());
|
||||||
|
// Remove this line below if RPC calls are failing but transactions are still added to it
|
||||||
|
// Don't blame MPOS if you run into issues after commenting this out!
|
||||||
|
$monitoring->endCronjob($cron_name, 'E0078', 1, true);
|
||||||
|
}
|
||||||
// Notify user via mail
|
// Notify user via mail
|
||||||
$aMailData['email'] = $user->getUserEmail($user->getUserName($aData['account_id']));
|
$aMailData['email'] = $user->getUserEmail($user->getUserName($aData['account_id']));
|
||||||
$aMailData['subject'] = 'Manual Payout Completed';
|
$aMailData['subject'] = 'Manual Payout Completed';
|
||||||
@ -131,18 +134,20 @@ if ($setting->getValue('disable_auto_payouts') != 1) {
|
|||||||
$log->logInfo("\t" . $aUserData['id'] . "\t" . $aUserData['username'] . "\t" . $dBalance . "\t" . $aUserData['ap_threshold'] . "\t\t" . $aUserData['coin_address']);
|
$log->logInfo("\t" . $aUserData['id'] . "\t" . $aUserData['username'] . "\t" . $dBalance . "\t" . $aUserData['ap_threshold'] . "\t\t" . $aUserData['coin_address']);
|
||||||
// Only run if balance meets threshold and can pay the potential transaction fee
|
// Only run if balance meets threshold and can pay the potential transaction fee
|
||||||
if ($dBalance > $aUserData['ap_threshold'] && $dBalance > $config['txfee_auto']) {
|
if ($dBalance > $aUserData['ap_threshold'] && $dBalance > $config['txfee_auto']) {
|
||||||
// Send balance, fees are reduced later by RPC Server
|
|
||||||
try {
|
|
||||||
$txid = $bitcoin->sendtoaddress($aUserData['coin_address'], $dBalance - $config['txfee_auto']);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
$log->logError('E0078: RPC method did not return 200 OK: Address: ' . $aUserData['coin_address'] . ' ERROR: ' . $e->getMessage());
|
|
||||||
$monitoring->endCronjob($cron_name, 'E0078', 1, true);
|
|
||||||
}
|
|
||||||
// Create transaction record
|
// Create transaction record
|
||||||
if ($transaction->addTransaction($aUserData['id'], $dBalance - $config['txfee_auto'], 'Debit_AP', NULL, $aUserData['coin_address'], $txid) && $transaction->addTransaction($aUserData['id'], $config['txfee_auto'], 'TXFee', NULL, $aUserData['coin_address'])) {
|
if ($transaction->addTransaction($aUserData['id'], $dBalance - $config['txfee_auto'], 'Debit_AP', NULL, $aUserData['coin_address'], $txid) && $transaction->addTransaction($aUserData['id'], $config['txfee_auto'], 'TXFee', NULL, $aUserData['coin_address'])) {
|
||||||
// Mark all older transactions as archived
|
// Mark all older transactions as archived
|
||||||
if (!$transaction->setArchived($aUserData['id'], $transaction->insert_id))
|
if (!$transaction->setArchived($aUserData['id'], $transaction->insert_id))
|
||||||
$log->logError('Failed to mark transactions for user #' . $aUserData['id'] . ' prior to #' . $transaction->insert_id . ' as archived. ERROR: ' . $transaction->getCronError());
|
$log->logError('Failed to mark transactions for user #' . $aUserData['id'] . ' prior to #' . $transaction->insert_id . ' as archived. ERROR: ' . $transaction->getCronError());
|
||||||
|
// Run the payouts from RPC now that the user is fully debited
|
||||||
|
try {
|
||||||
|
$txid = $bitcoin->sendtoaddress($aUserData['coin_address'], $dBalance - $config['txfee_auto']);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$log->logError('E0078: RPC method did not return 200 OK: Address: ' . $aUserData['coin_address'] . ' ERROR: ' . $e->getMessage());
|
||||||
|
// Remove this line below if RPC calls are failing but transactions are still added to it
|
||||||
|
// Don't blame MPOS if you run into issues after commenting this out!
|
||||||
|
$monitoring->endCronjob($cron_name, 'E0078', 1, true);
|
||||||
|
}
|
||||||
// Notify user via mail
|
// Notify user via mail
|
||||||
$aMailData['email'] = $user->getUserEmail($user->getUserName($aUserData['id']));
|
$aMailData['email'] = $user->getUserEmail($user->getUserName($aUserData['id']));
|
||||||
$aMailData['subject'] = 'Auto Payout Completed';
|
$aMailData['subject'] = 'Auto Payout Completed';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user