Skip to content

Commit

Permalink
Merge pull request #11 from mwarzybok-sumoheavy/feature/SP-607
Browse files Browse the repository at this point in the history
SP-607 Fix Order Cancellation Issue
  • Loading branch information
bobbrodie authored Jun 26, 2023
2 parents de4519f + 3950a9f commit 37e0866
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
14 changes: 14 additions & 0 deletions BitPayEddLib/class-bitpaycheckouttransactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ public function create_transaction(
$this->get_wpdb()->query( $query );
}

public function get_order_id_by_invoice_id(mixed $invoice_id): ?int {
$table_name = $this->table_name;
$wp_db = $this->get_wpdb();
$sql = $wp_db->prepare(
"SELECT order_id FROM $table_name WHERE transaction_id = %s LIMIT 1",
$invoice_id
);
$order_id = $wp_db->get_var( $sql );
if ( ! $order_id ) {
return null;
}
return (int) $order_id;
}

private function get_wpdb(): wpdb {
global $wpdb;
return $wpdb;
Expand Down
8 changes: 6 additions & 2 deletions BitPayEddLib/class-bitpayeddabandonorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ public function __construct( BitPayCheckoutTransactions $bitpay_checkout_transac
}

public function execute( WP_REST_Request $request ): void {
$data = $request->get_params();
$order_id = $data['orderid'];
$data = $request->get_params();
$invoice_id = $data['invoiceid'];
$order_id = $this->bitpay_checkout_transactions->get_order_id_by_invoice_id($invoice_id);
if ( ! $order_id ) {
die();
}

$this->bitpay_checkout_transactions->update_last_pending_status( 'invoice_expired', $order_id );
edd_update_order_status( $order_id, 'abandoned' );
Expand Down
3 changes: 1 addition & 2 deletions BitPayEddLib/class-bitpayeddprintenqueuescripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ public function execute(): void {
);

var urlParams = new URLSearchParams(window.location.search);
var $oid = urlParams.get('order_id')
var $iid = urlParams.get('invoiceID')
$cart_url = "<?php echo esc_js( edd_get_checkout_uri() ); ?>"
$fix_url = "<?php echo esc_js( get_home_url() . '/wp-json/bitpay-edd/cartfix/update' ); ?>"

setTimeout(function () {
showBPInvoice('<?php echo esc_js( $mode ); ?>', $iid, $oid, $cart_url, $fix_url)
showBPInvoice('<?php echo esc_js( $mode ); ?>', $iid, $cart_url, $fix_url)
},
250
);
Expand Down
4 changes: 2 additions & 2 deletions js/bitpay_edd.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function showBPInvoice($env, $invoiceID,$orderId,$cart_url,$fix_url) {
function showBPInvoice($env, $invoiceID,$cart_url,$fix_url) {

let payment_status = null;
let is_paid = false
Expand Down Expand Up @@ -26,7 +26,7 @@ function showBPInvoice($env, $invoiceID,$orderId,$cart_url,$fix_url) {
jQuery( '#primary' ).css( 'opacity', '1' );
} else {
let myKeyVals = {
orderid: $orderId
invoiceid: $invoiceID
}

let saveData = jQuery.ajax(
Expand Down

0 comments on commit 37e0866

Please sign in to comment.