Allow payment to be sent in several "chunks"

Addresses issue #31
This commit is contained in:
cryptochangements34 2017-12-05 19:46:45 -06:00 committed by GitHub
parent 79dca7f9b7
commit 20b7b15192
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -394,7 +394,21 @@ class Monero_Gateway extends WC_Payment_Gateway
return $price; return $price;
} }
} }
private function on_verified($payment_id, $amount_atomic_units, $order_id)
{
$message = "Payment has been received and confirmed. Thanks!";
$this->log->add('Monero_gateway', '[SUCCESS] Payment has been recorded. Congratulations!');
$this->confirmed = true;
$order = wc_get_order($order_id);
$order->update_status('completed', __('Payment has been received', 'monero_gateway'));
global $wpdb;
$wpdb->query("DROP TABLE $payment_id"); // Drop the table from database after payment has been confirmed as it is no longer needed
$this->reloadTime = 3000000000000; // Greatly increase the reload time as it is no longer needed
return $message;
}
public function verify_payment($payment_id, $amount, $order_id) public function verify_payment($payment_id, $amount, $order_id)
{ {
/* /*
@ -405,16 +419,25 @@ class Monero_Gateway extends WC_Payment_Gateway
$amount_atomic_units = $amount * 1000000000000; $amount_atomic_units = $amount * 1000000000000;
$get_payments_method = $this->monero_daemon->get_payments($payment_id); $get_payments_method = $this->monero_daemon->get_payments($payment_id);
if (isset($get_payments_method["payments"][0]["amount"])) { if (isset($get_payments_method["payments"][0]["amount"])) {
if ($get_payments_method["payments"][0]["amount"] >= $amount_atomic_units) { if ($get_payments_method["payments"][0]["amount"] >= $amount_atomic_units)
$message = "Payment has been received and confirmed. Thanks!"; {
$this->log->add('Monero_gateway', '[SUCCESS] Payment has been recorded. Congratulations!'); $message = $this->on_verified($payment_id, $amount_atomic_units, $order_id);
$this->confirmed = true; }
$order = wc_get_order($order_id); if ($get_payments_method["payments"][0]["amount"] < $amount_atomic_units)
$order->update_status('completed', __('Payment has been received', 'monero_gateway')); {
global $wpdb; $totalPayed = $get_payments_method["payments"][0]["amount"];
$wpdb->query("DROP TABLE $payment_id"); // Drop the table from database after payment has been confirmed as it is no longer needed $outputs_count = count($get_payments_method["payments"]); // number of outputs recieved with this payment id
$output_counter = 1;
$this->reloadTime = 3000000000000; // Greatly increase the reload time as it is no longer needed while($output_counter < $outputs_count)
{
$totalPayed += $get_payments_method["payments"][$output_counter]["amount"];
$output_counter++;
}
if($totalPayed >= $amount_atomic_units)
{
$message = $this->on_verified($payment_id, $amount_atomic_units, $order_id);
}
} }
} }
return $message; return $message;