diff --git a/BitPayLib/BPC_Invoice.php b/BitPayLib/BPC_Invoice.php
index 2e096f37..96b6283e 100644
--- a/BitPayLib/BPC_Invoice.php
+++ b/BitPayLib/BPC_Invoice.php
@@ -11,13 +11,13 @@ public function __construct($item)
- public function BPC_checkInvoiceStatus($orderID)
+ public function BPC_checkInvoiceStatus($orderID, $token)
{
$post_fields = ($this->item->item_params);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'https://' . $this->item->invoice_endpoint . '/' . $post_fields->invoiceID);
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, 'https://' . $this->item->invoice_endpoint . '/' . $post_fields->invoiceID.'?token='.$token);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
diff --git a/index.php b/index.php
index 81780f10..bf7c29df 100644
--- a/index.php
+++ b/index.php
@@ -3,13 +3,12 @@
* Plugin Name: BitPay Checkout for WooCommerce
* Plugin URI: https://www.bitpay.com
* Description: Create Invoices and process through BitPay. Configure in your WooCommerce->Payments plugin.
- * Version: 3.30.2004
+ * Version: 3.31.2004
* Author: BitPay
* Author URI: mailto:integrations@bitpay.com?subject=BitPay Checkout for WooCommerce
*/
if (!defined('ABSPATH')): exit;endif;
add_action('wp_enqueue_scripts', 'enable_bitpayquickpay_js');
-
global $current_user;
#autoloader
function BPC_autoloader($class)
@@ -82,9 +81,10 @@ function bitpay_checkout_woocommerce_bitpay_failed_requirements()
add_action('plugins_loaded', 'wc_bitpay_checkout_gateway_init', 11);
#create the table if it doesnt exist
+
function bitpay_checkout_plugin_setup()
{
-
+
$failed = bitpay_checkout_woocommerce_bitpay_failed_requirements();
$plugins_url = admin_url('plugins.php');
@@ -96,7 +96,7 @@ function bitpay_checkout_plugin_setup()
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE IF NOT EXISTS $table_name(
`id` int(11) NOT NULL AUTO_INCREMENT,
- `order_id` int(11) NOT NULL,
+ `order_id` varchar(255) NOT NULL,
`transaction_id` varchar(255) NOT NULL,
`transaction_status` varchar(50) NOT NULL DEFAULT 'new',
`date_added` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
@@ -233,7 +233,7 @@ public function email_instructions($order, $sent_to_admin, $plain_text = false)
public function init_form_fields()
{
$wc_statuses_arr = wc_get_order_statuses();
-
+
$this->form_fields = array(
'enabled' => array(
@@ -427,7 +427,37 @@ function process_payment($order_id)
}
-//this is an error message incase a token isnt set
+//update the order_id field in the custom table, try and create the table if this is called before the original
+add_action('admin_notices', 'update_db_1');
+function update_db_1()
+{
+ if ($_GET['section'] == 'bitpay_checkout_gateway' && is_admin()):
+
+ if(get_option('bitpay_wc_checkout_db1') != 1):
+ global $wpdb;
+ require_once ABSPATH . 'wp-admin/includes/upgrade.php';
+ $table_name = '_bitpay_checkout_transactions';
+
+ $charset_collate = $wpdb->get_charset_collate();
+
+ $sql = "CREATE TABLE IF NOT EXISTS $table_name(
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `order_id` varchar(255) NOT NULL,
+ `transaction_id` varchar(255) NOT NULL,
+ `transaction_status` varchar(50) NOT NULL DEFAULT 'new',
+ `date_added` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ PRIMARY KEY (`id`)
+ ) $charset_collate;";
+
+ dbDelta($sql);
+ $sql = "ALTER TABLE `$table_name` CHANGE `order_id` `order_id` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci NOT NULL; ";
+ $wpdb->query($sql);
+ update_option('bitpay_wc_checkout_db1',1);
+ endif;
+
+ endif;
+}
+
add_action('admin_notices', 'bitpay_checkout_check_token');
function bitpay_checkout_check_token()
{
@@ -598,7 +628,7 @@ function bitpay_checkout_ipn(WP_REST_Request $request)
$data = json_decode($data);
$event = $data->event;
$data = $data->data;
-
+
//$orderid = $data->orderId;
$invoiceID = $data->id;
$orderid = bitpay_checkout_get_order_id_bitpay_invoice_id($invoiceID);
@@ -607,7 +637,6 @@ function bitpay_checkout_ipn(WP_REST_Request $request)
$order = new WC_Order($orderid);
if ($order->get_payment_method() != 'bitpay_checkout_gateway'){
-
#ignore the IPN when the order payment method is (no longer) bitpay
BPC_Logger("Order id = ".$orderid.", BitPay invoice id = ".$invoiceID.". Current payment method = " . $order->get_payment_method(), 'Ignore IPN', true);
die();
@@ -617,6 +646,7 @@ function bitpay_checkout_ipn(WP_REST_Request $request)
#verify the ipn matches the status of the actual invoice
if (bitpay_checkout_get_order_transaction($orderid, $invoiceID)):
+
$bitpay_checkout_options = get_option('woocommerce_bitpay_checkout_gateway_settings');
//dev or prod token
$bitpay_checkout_token = BPC_getBitPayToken($bitpay_checkout_options['bitpay_checkout_endpoint']);
@@ -635,8 +665,7 @@ function bitpay_checkout_ipn(WP_REST_Request $request)
$item = new BPC_Item($config, $params);
$invoice = new BPC_Invoice($item); //this creates the invoice with all of the config params
- $orderStatus = json_decode($invoice->BPC_checkInvoiceStatus($invoiceID));
-
+ $orderStatus = json_decode($invoice->BPC_checkInvoiceStatus($invoiceID,$bitpay_checkout_token));
#update the lookup table
$note_set = null;
@@ -659,8 +688,7 @@ function bitpay_checkout_ipn(WP_REST_Request $request)
break;
case 'invoice_completed':
- #if($bitpay_checkout_order_process_status == 1):
-
+
$lbl = $wc_statuses_arr[$bitpay_checkout_order_process_status];
$order->add_order_note('BitPay Invoice ID: ' . $invoiceID . ' has changed to '.$lbl.'.');
@@ -681,11 +709,18 @@ function bitpay_checkout_ipn(WP_REST_Request $request)
break;
case 'invoice_expired':
- $order_status = "wc-cancelled";
- $order->add_order_note('BitPay Invoice ID: ' . $invoiceID . ' has expired.');
- if($bitpay_checkout_order_expired_status == 1):
- $order->update_status($order_status, __('BitPay payment invalid', 'woocommerce'));
+ if(property_exists($orderStatus->data,'underpaidAmount')):
+ $order->add_order_note('BitPay Invoice ID: ' . $invoiceID . ' has been refunded.');
+ $order->update_status('refunded', __('BitPay payment refunded', 'woocommerce'));
+ else:
+ $order_status = "wc-cancelled";
+ $order->add_order_note('BitPay Invoice ID: ' . $invoiceID . ' has expired.');
+ if($bitpay_checkout_order_expired_status == 1):
+ $order->update_status($order_status, __('BitPay payment invalid', 'woocommerce'));
+ endif;
endif;
+
+
break;
diff --git a/readme.txt b/readme.txt
index 2eae1e23..7c46a356 100644
--- a/readme.txt
+++ b/readme.txt
@@ -4,7 +4,7 @@ Tags: bitcoin, bitcoin cash, payments, bitpay, cryptocurrency, payment gateway
Requires at least: 4.9
Tested up to: 5.4.1
Requires PHP: 5.5
-Stable tag: 3.30.2004
+Stable tag: 3.31.2004
License: MIT License (MIT)
License URI: https://github.com/bitpay/bitpay-checkout-for-woocommerce/blob/master/LICENSE
@@ -113,6 +113,10 @@ You can contact our support team via the following form https://bitpay.com/reque
13. Wordpress Woocommerce - order view
== Changelog ==
+
+= 3.31.2004 =
+* IPN Updates
+
= 3.30.2004 =
* Bug fixes and code cleanup