Skip to content

Commit

Permalink
Merge pull request #317 from ankit61d/pre-3.5.9-refactor
Browse files Browse the repository at this point in the history
Pre 3.5.9 release refactor
  • Loading branch information
shivaenigma committed Mar 24, 2023
2 parents 0dee6af + 3ef08dd commit 6acd0a6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
8 changes: 2 additions & 6 deletions blockonomics-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,11 +523,6 @@ function blockonomics_update_db_check() {
function blockonomics_run_db_updates($installed_ver){
global $wpdb;
global $blockonomics_db_version;
if (version_compare($installed_ver, '1.1', '<')){
$table_name = $wpdb->prefix . 'blockonomics_orders';
maybe_drop_column($table_name, "time_remaining", "ALTER TABLE $table_name DROP COLUMN time_remaining");
maybe_drop_column($table_name, "timestamp", "ALTER TABLE $table_name DROP COLUMN timestamp");
}
if (version_compare($installed_ver, '1.2', '<')){
blockonomics_create_table();
}
Expand Down Expand Up @@ -579,7 +574,8 @@ function blockonomics_uninstall_hook() {
delete_option('blockonomics_network_confirmation');

global $wpdb;
// if module is uninstalled, drop both tables blockonomics_orders & blockonomics_payments
// drop blockonomics_orders & blockonomics_payments on uninstallation
// blockonomics_orders was the payments table before db version 1.2
$wpdb->query($wpdb->prepare("DROP TABLE IF EXISTS ".$wpdb->prefix."blockonomics_orders , ".$wpdb->prefix."blockonomics_payments"));
delete_option("blockonomics_db_version");
}
Expand Down
18 changes: 4 additions & 14 deletions php/Blockonomics.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,8 @@ public function calculate_order_params($order){
if ( $order['payment_status'] == 0) {
return $this->calculate_new_order_params($order);
}
// Check if order has confirmed payment
if ($order['payment_status'] == 2){
//check if order is underpaid
if ($this->is_order_underpaid($order)){
// Create and add new row for underpaid order to the database
return $this->create_and_insert_new_order_on_underpayment($order);
}
}
Expand Down Expand Up @@ -524,10 +521,7 @@ public function create_and_insert_new_order_on_underpayment($order){
// Some error in Address Generation from API, return the same array.
return $order;
}
if (!$this->insert_order($order)) {
// insert_order fails if duplicate address found. Ensures no duplicate orders in the database
return array("error"=>__("Duplicate Address Error. This is a Temporary error, please try again", 'blockonomics-bitcoin-payments'));
}
$this->insert_order($order);
$this->record_address($order['order_id'], $order['crypto'], $order['address']);
return $order;
}
Expand Down Expand Up @@ -705,7 +699,7 @@ public function get_order_by_id_and_crypto($order_id, $crypto){
}


// Inserts a new order in blockonomics_payments table
// Inserts a new row in blockonomics_payments table
public function insert_order($order){
global $wpdb;
$wpdb->hide_errors();
Expand Down Expand Up @@ -740,10 +734,7 @@ public function process_order($order_id, $crypto){
// Some error in Address Generation from API, return the same array.
return $order;
}
if (!$this->insert_order($order)) {
// insert_order fails if duplicate address found. Ensures no duplicate orders in the database
return array("error"=>__("Duplicate Address Error. This is a Temporary error, please try again", 'blockonomics-bitcoin-payments'));
}
$this->insert_order($order);
$this->record_address($order_id, $crypto, $order['address']);
}
return $order;
Expand Down Expand Up @@ -888,8 +879,7 @@ public function add_coupon_on_underpayment($paid_satoshi, $order, $wc_order){
$coupon->set_usage_limit(1);// limit coupon to one time use
$coupon->save();
$wc_order->apply_coupon($coupon_code);

$coupon_note = "Partial payment received for " .get_woocommerce_currency()." ".sprintf('%0.2f', round($coupon->get_amount(), 2)). " and applied as a coupon.";
$coupon_note = "Partial payment of " .get_woocommerce_currency()." ".sprintf('%0.2f', round($coupon->get_amount(), 2)). " received via Blockonomics and applied as a coupon. Customer has been mailed invoice to pay remaining amount";
$wc_order->add_order_note(__( $coupon_note, 'blockonomics-bitcoin-payments' ));
}

Expand Down

0 comments on commit 6acd0a6

Please sign in to comment.