Plugin Directory

Changeset 3404386


Ignore:
Timestamp:
11/27/2025 10:21:52 PM (4 months ago)
Author:
bulletproofcheckout
Message:

higher priority than default for the webhook woocommerce_order_status_changed, added loggin capabilities

Location:
bulletproof-checkout-lite/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • bulletproof-checkout-lite/trunk/README.txt

    r3370715 r3404386  
    33Tags: woocommerce, 3DS, payment gateway, bulletproof, chargeback, fraud prevention
    44WC requires at least: 5.0
    5 WC tested up to: 10.2.2
    6 Tested up to: 6.8.2
    7 Stable tag: 1.0.21
     5WC tested up to: 10.3.5
     6Tested up to: 6.8.3
     7Stable tag: 1.0.22
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    235235= 1.0.21 =
    236236Added zip code denial reason at the Checkout
     237= 1.0.22 =
     238Added custom logger to the Wordpress Logs
  • bulletproof-checkout-lite/trunk/bulletproof-checkout-lite.php

    r3370715 r3404386  
    11<?php
    2 
    32/**
    43 * Plugin Name: BulletProof Checkout Lite
    54 * Plugin URI: https://www.bulletproof-checkout.com/
    65 * Description: Protect your credit card payments with 3D Secure (3DS) and say goodbye to chargebacks.
    7  * Version: 1.0.21
     6 * Version: 1.0.23
    87 * Author: BulletProof Checkout <support@bulletproof-checkout.com>
    98 * Author URI: https://www.bulletproof-checkout.com/
     
    1211 * Text Domain: bulletproof-checkout-lite
    1312 * WC requires at least: 5.0
    14  * WC tested up to: 10.2.2
    15  * Tested up to: 6.8.2
     13 * WC tested up to: 10.3.5
     14 * Tested up to: 6.8.3
    1615 * Requires PHP: 7.4
    1716 * Requires Plugins: woocommerce
     
    3938// In the Official Mobile App BulletProof does not support Authorize and Capture later
    4039if (!defined('BULLETPROOF_CHECKOUT_ADDORDERLISTCOLUMNS')) define('BULLETPROOF_CHECKOUT_ADDORDERLISTCOLUMNS', false);
    41 // Some hosting providers auto-enabled JetPack SSO whih is buggy with the Official Mobile App
     40// Some hosting providers auto-enabled JetPack SSO which is buggy with the Official Mobile App
    4241if (!defined('BULLETPROOF_CHECKOUT_DISABLEJETPACKSSO')) define('BULLETPROOF_CHECKOUT_DISABLEJETPACKSSO', false);
    4342
  • bulletproof-checkout-lite/trunk/includes/class-wc-bulletproof-payment-gateway-lite.php

    r3370715 r3404386  
    485485        $response = wp_remote_post($api_url, $request_args);
    486486
     487        // setting log class
     488        $logger = wc_get_logger();
     489        $context = array('source' => 'bpcheckout-App');
    487490        if (is_wp_error($response)) {
    488             error_log('Refund API request failed: ' . $response->get_error_message());
     491            $response_detail = "Refund API request failed";
     492            if ($response->get_error_message() != "") {
     493                $response_detail .= ': ' . $response->get_error_message();
     494            }
     495            $logger->info($response_detail, $context);
     496            return $response;
    489497        } else {
    490 
     498            $decoded_response = "";
    491499            $body = wp_remote_retrieve_body($response);
    492             $decoded_response = json_decode($body, true);
    493 
    494             if (isset($decoded_response['error']) && $decoded_response['error'] != "" && isset($decoded_response['response_code']) && $decoded_response['response_code'] != "" && isset($decoded_response['responsetext']) && $decoded_response['responsetext'] != "") {
    495             }
     500            if (empty($body)) {
     501                $logger->info('Refund API request returned an empty body.', $context);
     502            } else {
     503
     504                $decoded_response = json_decode($body, true);
     505                if ($body != "" && ($decoded_response === null || $decoded_response == "")) {
     506                    $logger->info('Refund API request returned invalid JSON: ' . $body, $context);
     507                    //return new WP_Error('invalid_json', 'The BulletProof API response is not valid JSON. Please contact the gateway support team');
     508
     509                } else {
     510                    $logger->info('Refund API request response: ' . print_r($decoded_response, true), $context);
     511                }
     512            }
     513            //if (isset($decoded_response['error']) && $decoded_response['error'] != "" && isset($decoded_response['response_code']) && $decoded_response['response_code'] != "" && isset($decoded_response['responsetext']) && $decoded_response['responsetext'] != "") {
     514            //return new WP_Error('invalid_order', 'Invalid order.');
     515            //}
     516
    496517            return $decoded_response;
    497518        }
     
    690711    {
    691712
    692 
     713        // setting log class
     714        $logger = wc_get_logger();
     715        $context = array('source' => 'bpcheckout-App');
     716        $logger->info('Starting refund Order id#: ' . $order_id . ' . Amount to be refunded:' . $amount, $context);
    693717        // Get the WooCommerce order.
    694718        $order = wc_get_order($order_id);
     
    705729        // Prepare request arguments.
    706730        $request_args = array(
     731            'method'      => 'POST',
     732            'timeout'     => 25,
     733            'redirection' => 5,
    707734            'headers' => array(
    708735                'accept' => 'application/json',
     
    712739        );
    713740
    714         error_log('Executing refund Order id#: ' . $order_id . ' . Amount to be refunded:' . $amount);
     741        $logger->info('Executing refund Order id#: ' . $order_id . ' . Amount to be refunded:' . $amount, $context);
    715742
    716743        if ((strtolower($this->get_option('enabled')) == "yes")) {
    717             if ($transaction_id != "") {
     744            if ((!empty($transaction_id)) && $transaction_id != "") {
    718745                // Locate the API endpoint to be used
    719746                $base_api_url = BULLETPROOF_CHECKOUT_API_BASE_URL;
     747                $is_sandbox = false;
    720748                try {
    721749                    if ((strtolower($this->get_option('testmode')) == "no") || ($this->get_option('testmode') == "")) {
     
    724752                        if (strtolower($this->get_option('testmode')) == "yes") {
    725753                            $base_api_url = BULLETPROOF_CHECKOUT_API_BASE_URL_SANDBOX;
     754                            $is_sandbox = true;
    726755                        }
    727756                    }
     
    735764                    '&security_key=' . urlencode($security_key) .
    736765                    '&transactionid=' . urlencode($transaction_id);
     766                $api_url_masked = $base_api_url . 'refund.php?user=&pass=&security_key=&transactionid=' . urlencode($transaction_id);
    737767                // adds support for partial refunds
    738768                if ($amount != "") {
    739769                    $api_url .= '&amount=' . $amount;
     770                    $api_url_masked .= '&amount=' . $amount;
    740771                }
    741772
    742773                // Make the refund API call.
    743                 error_log("Starting refund at the BulletProof Gateway for the Order ID#:" . $order_id);
     774                $logger->info("Starting refund at the BulletProof Gateway for the Order ID#:" . $order_id . " API ENDPOINT:" . $api_url_masked, $context);
    744775
    745776                $response = $this->bulletproof_refund_payment_api($api_url, $request_args);
     
    748779                if (((isset($response['error'])) && ($response['error'] != "")) || (is_wp_error($response)) || (empty($response))) {
    749780                    if (isset($response['error'])) {
    750                         error_log(print_r($response['error'], true));
     781                        $logger->info(print_r($response['error'], true), $context);
    751782                    } else {
    752783                        if (is_wp_error($response)) {
    753                             error_log(print_r($response->get_error_message(), true));
     784                            $logger->info(print_r($response->get_error_message(), true), $context);
    754785                        } else {
    755786                            if (empty($response)) {
    756                                 error_log(print_r('No response from the gateway (Network error). The refund status must be checked manually on the BulletProof portal.', true));
     787                                $the_msg = 'No response from the gateway (Network error). The refund status must be checked manually on the BulletProof portal.';
     788                                if ($is_sandbox) {
     789                                    $the_msg .= ' (Sandbox mode)';
     790                                }
     791                                $logger->info(print_r($the_msg, true), $context);
    757792                            } else {
    758                                 error_log(print_r('Unknown error occurred.', true));
     793                                $logger->info(print_r('Unknown error occurred.', true), $context);
    759794                            }
    760795                        }
     
    768803                        if (empty($response)) {
    769804                            $error_message = 'No response from the gateway ( Network error ). The refund status must be checked manually on the BulletProof portal.';
     805                            if ($is_sandbox) {
     806                                $error_message .= ' (Sandbox mode)';
     807                            }
    770808                        } else {
    771809                            $error_message = 'Unknown error occurred.';
     
    775813                    $order->add_order_note($the_msg);
    776814                    $order->save();
     815                    $logger->info($error_message, $context);
    777816                    return new WP_Error('bulletproof_refund_api_error', $error_message);
    778817                } else {
     
    780819                    // $order->add_order_note('Refunded via BulletProof Checkout.');
    781820
    782                     $the_msg = "Order " . $order_id . " was refunded succesfully";
    783                     if ($amount != '' && $amount > 0) {
    784                         $the_msg .= " for the amount of " . wc_price($amount);
    785                     }
    786                     // add a note with the refund success message
    787                     $order->add_order_note($the_msg);
    788                     error_log($the_msg);
    789                     //error_log($response_refund);
     821
     822
     823
    790824                    try {
    791825                        $current_user = wp_get_current_user();
     
    793827                        $current_user = "";
    794828                    }
     829
    795830                    $the_username = "";
    796831                    if (isset($current_user->user_login)) {
     
    807842                    // json array for register refund transactions
    808843                    //  if (is_string($response)) {
     844                    $data_to_store = "";
    809845                    $refund_transactionid = "";
    810                     if ((isset($response->action)) && ($response->action == "refund")) {
    811                         if ((isset($response->data))) {
    812                             $data_to_store = $response->data;
     846                    try {
     847
     848                        if ((isset($response->action)) && (($response->action == "refund") || ($response->action == "void"))) {
     849                            if ((isset($response->data))) {
     850                                $data_to_store = $response->data;
     851                            } else {
     852                                $data_to_store = $response;
     853                            }
    813854                        } else {
    814                             $data_to_store = $response;
    815                         }
    816                     } else {
    817                         if ((isset($response['action'])) && ($response['action'] == "refund")) {
    818                             if ((isset($response['data']))) {
    819                                 $data_to_store = $response['data'];
    820                                 if (strpos($data_to_store, "&") > 0) {
    821                                     parse_str($data_to_store, $result_array);
    822                                     if ((isset($result_array['transactionid'])) && ($result_array['transactionid'] != "")) {
    823                                         if ($transaction_id != $result_array['transactionid']) {
    824                                             $refund_transactionid = $result_array['transactionid'];
     855                            if ((isset($response['action'])) && ($response['action'] == "refund")) {
     856                                if ((isset($response['data']))) {
     857                                    $data_to_store = $response['data'];
     858                                    if (strpos($data_to_store, "&") > 0) {
     859                                        parse_str($data_to_store, $result_array);
     860                                        if ((isset($result_array['transactionid'])) && ($result_array['transactionid'] != "")) {
     861                                            if ($transaction_id != $result_array['transactionid']) {
     862                                                $refund_transactionid = $result_array['transactionid'];
     863                                            }
     864                                            if ((isset($result_array['type'])) && ($result_array['type'] == "void")) {
     865                                                $order->update_meta_data('_bulletproof_voided', true);
     866                                            }
    825867                                        }
    826                                         if ((isset($result_array['type'])) && ($result_array['type'] == "void")) {
    827                                             $order->update_meta_data('_bulletproof_voided', true);
    828                                         }
     868                                    } else {
     869                                        // Nothing was returned (Network error)
     870                                        $data_to_store = $response;
    829871                                    }
    830872                                } else {
    831                                     // Nothing was returned (Network error)
    832873                                    $data_to_store = $response;
    833874                                }
     
    835876                                $data_to_store = $response;
    836877                            }
    837                         } else {
    838                             $data_to_store = $response;
    839878                        }
     879                    } catch (Exception $ex) {
     880                        // in case of error save any updated metadata
     881                        $logger->info($ex->getMessage(), $context);
     882                        $order->save();
    840883                    }
     884                    // add a note with the refund success message
     885                    $the_msg = "Order " . $order_id . " was refunded succesfully";
     886                    if ($amount != '' && $amount > 0) {
     887                        $the_msg .= " for the amount of " . wc_price($amount);
     888                    }
     889                    if ($refund_transactionid != "") {
     890                        $the_msg .= ". Refund Transaction ID: " . $refund_transactionid;
     891                    }
     892                    $order->add_order_note($the_msg);
     893                    $logger->info($the_msg, $context);
     894
    841895                    if (!empty($data_to_store)) {
    842896                        $order->update_meta_data('_bulletproof_refund_response', $data_to_store);
     
    846900                        $order->update_meta_data('_bulletproof_refund_response', $error_message);
    847901                        $order->update_meta_data('_bulletproof_refund_response_flag', "3");
     902                        $order->save();
     903                        $logger->info($error_message, $context);
    848904                        return new WP_Error('bulletproof_refund_api_error', $error_message);
    849905                    }
    850906                    //  }
    851907                    // json array for register refund transactions
    852                     if (($refund_transactionid != $transaction_id) && ($refund_transactionid != "")) {
    853                         $transaction_id_refunds = $order->get_meta('_payment_gateway_tx_refunds', true);
    854                         if ($transaction_id_refunds != "") {
    855                             $refund_ids_array = json_decode($transaction_id_refunds, true);
    856                         } else {
    857                             $refund_ids_array = array();
     908                    try {
     909                        if (($refund_transactionid != $transaction_id) && ($refund_transactionid != "")) {
     910                            $transaction_id_refunds = $order->get_meta('_payment_gateway_tx_refunds', true);
     911                            if ($transaction_id_refunds != "") {
     912                                $refund_ids_array = json_decode($transaction_id_refunds, true);
     913                            } else {
     914                                $refund_ids_array = array();
     915                            }
     916                            array_push($refund_ids_array, $refund_transactionid);
     917                            $order->update_meta_data('_payment_gateway_tx_refunds', json_encode($refund_ids_array));
     918                            $the_msg = "Order " . $order_id . " refund transaction id received: " . $refund_transactionid;
     919                            $logger->info($the_msg, $context);
    858920                        }
    859                         array_push($refund_ids_array, $refund_transactionid);
    860                         $order->update_meta_data('_payment_gateway_tx_refunds', json_encode($refund_ids_array));
     921                    } catch (Exception $ex) {
     922                        $logger->info($ex->getMessage(), $context);
    861923                    }
    862924                    $order->save();
     
    866928            } else {
    867929                $the_msg = "The refund was not processed because of a missing transaction ID. The WooCommerce order doesn't have an attached gateway transaction. Please contact the gateway support team.";
    868                 error_log(print_r($the_msg, true));
     930                $logger->info($the_msg, $context);
    869931                return new WP_Error('bulletproof_no_transaction_id', $the_msg);
    870932            }
    871933        } else {
    872934            $the_msg = "Refund endpoint not available due to the Payment Gateway is disabled";
    873             error_log(print_r($the_msg, true));
     935            $logger->info($the_msg, $context);
    874936            return new WP_Error('bulletproof_disabled', $the_msg);
    875937        }
     
    886948    {
    887949        // Locate the API endpoint to be used
     950        // setting log class
     951        $logger = wc_get_logger();
     952        $context = array('source' => 'bpcheckout-App');
    888953        $base_api_url = "";
    889954        try {
     
    927992            // Log an error message if the API request fails.
    928993            $error_message = is_wp_error($response) ? $response->get_error_message() : 'Unknown error occurred';
    929             error_log('Processors API request failed: ' . $response->get_error_message());
     994            $logger->info('Processors API request failed: ' . $response->get_error_message(), $context);
    930995        }
    931996
     
    10081073        }
    10091074
     1075
     1076
    10101077        // check if the plugin is enabled
    10111078        if ((strtolower($this->get_option('enabled')) == "yes")) {
     
    10291096            $sale_auth_api_url = $base_api_url . "?rndx=" . time();
    10301097
     1098            // setting log class
     1099            $logger = wc_get_logger();
     1100            $context = array('source' => 'bpcheckout-App');
     1101            $logger->info("Starting payment Order ID#" . $order_id, $context);
     1102
    10311103            // Get sale authorization parameters.
    10321104            $sale_auth_params = $this->bulletproof_checkout_api_params($order, $order_id);
     
    10411113                    // Build the validation API URL.
    10421114                    $validate_api_url = $base_api_url . 'validate.php?token=' . $sale_auth_response->token;
    1043 
     1115                    $logger->info("Payment Step 1 completed - Order ID#" . $order_id, $context);
    10441116                    // Return success with redirection URL.
    10451117                    return array(
     
    10671139                        esc_html($sale_auth_response->error)
    10681140                    );
    1069 
     1141                    $logger->info($formatted_message . ". Response from Order ID#" . $order_id, $context);
    10701142                    // Display an error notice and return an empty array.
    10711143                    self::bulletproof_display_notice($formatted_message, 'error');
     
    10831155                    );
    10841156                    $order->update_status('wc-failed');
    1085 
     1157                    $logger->info($formatted_message . ". Order ID#" . $order_id, $context);
     1158                    $logger->info($sale_auth_response, $context);
    10861159                    self::bulletproof_display_notice($formatted_message, 'error');
    10871160                }
    10881161            } else {
    1089 
    1090 
    10911162                // Adding translators comment
    10921163                /* translators: %s: Error message from the response */
     
    11041175                self::bulletproof_display_notice($formatted_message, 'error');
    11051176                $order->update_status('wc-failed');
     1177                $logger->info($formatted_message . ". Order ID#" . $order_id, $context);
    11061178                return array();
    11071179            }
     
    13761448            }
    13771449        }
    1378        
     1450
    13791451        // Build an array of sale authorization parameters.
    13801452        // The parameter fix_iso_codes will ignore states (which are not on ISO format)
     
    14731545            $api_url,
    14741546            array(
     1547                'timeout'     => 25,
     1548                'redirection' => 5,
    14751549                'body'    => $params,
    14761550                'headers' => array(
     
    14831557        if (is_wp_error($response)) {
    14841558            // Log an error message if the API request fails.
    1485             error_log('API request failed: ' . $response->get_error_message());
     1559            // setting log class
     1560            $the_msg = 'API request failed: ' . $response->get_error_message();
     1561            error_log($the_msg);
     1562            $logger = wc_get_logger();
     1563            $context = array('source' => 'bpcheckout-App');
     1564            $logger->info($the_msg, $context);
    14861565        } else {
    14871566
     
    14921571                $body = wp_remote_retrieve_body($response);
    14931572            }
    1494             if ($body == "" && $response != "" && isset($response['body']) && $response['body']!="") {
     1573            if ($body == "" && $response != "" && isset($response['body']) && $response['body'] != "") {
    14951574                $body = $response['body'];
    14961575            }
  • bulletproof-checkout-lite/trunk/includes/class-wc-bulletproof-shop-orders.php

    r3368943 r3404386  
    3030
    3131        // Handle order status changes
    32         add_action('woocommerce_order_status_changed', array($this, 'woo_order_status_change_bpcheckout_lite'), 10, 3);
    33 
     32        add_action('woocommerce_order_status_changed', array($this, 'woo_order_status_change_bpcheckout_lite'), 9, 4);  // moved from priority 10 to 9, as some plugins are breaking the execution of this action
    3433
    3534        // Add a meta box inside the Order detail
     
    10099                    // Search the transaction at the gateway
    101100                    $request_args = array(
     101                        'timeout'     => 25,
     102                        'redirection' => 5,
    102103                        'headers' => array(
    103104                            'accept' => 'application/json',
     
    219220                    $security_key = $gateway_settings['api_key'];
    220221                }
     222
     223                $extra_info_for_table = "";
     224                $is_pendingsettlement = false;
    221225                // search related transactions with the same Order Id
    222226                if (($username != "") && ($password != "") && ($security_key != "")) {
     
    234238
    235239                    $request_args = array(
     240                        'timeout'     => 25,
     241                        'redirection' => 5,
    236242                        'headers' => array(
    237243                            'accept' => 'application/json',
     
    245251                        '&security_key=' . urlencode($security_key) .
    246252                        '&orderId=' . urlencode($post->ID);
     253                    $api_url_masked = $base_api_url . '?user=' . urlencode($username) .
     254                        '&pass=XXXXXXXXX' .
     255                        '&security_key=XXXXXXXXXX' .
     256                        '&orderId=' . urlencode($post->ID);
     257
    247258                    $response_display = "";
    248259                    $response_search = bulletproof_transaction_information($api_url, $request_args);
     260
    249261                    $show_error = false;
    250262                    $do_not_show_response = false;
     
    262274                                if ($response_json["id"] == "823") { // No access to the API endpoint
    263275                                    $response_display = $response_json["error"] . " Your current Bulletproof Payment Gateway Lite user is:" . $username . ", please provide this information to support.";
    264                                     $response_display .= " with the url:" . $api_url;
     276                                    $response_display .= " with the url:" . $api_url_masked;
    265277                                } else {
    266278                                    if (($response_json["id"] == "839") || ($response_json["id"] == "820")) { // No access, maybe is an older transaction and currently the user does not have enabled the bulletproof service
     
    274286                                }
    275287                            }
     288
    276289                            if (defined('WP_DEBUG') && true === WP_DEBUG) {
    277290                                if ($show_error) {
     
    279292                                }
    280293                            }
     294                            /*
    281295                            if (!$do_not_show_response) {
    282296                                // receive the transaction information live from the gateway
    283                                 /*
    284                                 if (defined('WP_DEBUG') && true === WP_DEBUG) {
    285                                     // arrar response_json will be like:
    286                                     //var_dump($response_json);
    287                                     if (isset($response_json["data"])) {
    288                                         if (is_array($response_json["data"])) {
    289                                             if (count($response_json["data"]) > 0) {
    290                                                 echo "<p style='color:blue;font-weight:bolder;'>" . count($response_json["data"]) . " transaction(s) found for this Order ID " . $post->ID . "</p>";
     297
     298                                if (isset($response_json["data"])) {
     299
     300                                    if (is_array($response_json["data"])) {
     301
     302                                        foreach ($response_json["data"] as $transaction) {
     303                                            //if ($display_transaction_id != $transaction['transactionid']) {
     304                                            if (($transaction['status'] != "pendingsettlement") && ($transaction['status'] != "complete") && ($transaction['status'] != "completed")) {
     305                                                $extra_info_for_table .= "<tr>";
     306                                                $extra_info_for_table .= "<td colspan='3'></td>";
     307                                                $extra_info_for_table .= "<td>" . $transaction['status'] . "</td>";
     308
     309                                                $extra_info_for_table .= "<td>" . $transaction['transactionid'];
     310                                                if (isset($transaction['batchId'])) {
     311                                                    if ($transaction['batchId'] != "") {
     312                                                        $extra_info_for_table .= "<br>Batch ID:" . $transaction['batchId'];
     313                                                    }
     314                                                }
     315                                                $extra_info_for_table .= "</td>";
     316                                                $extra_info_for_table .= "<td>" . get_woocommerce_currency_symbol() . $transaction['amount'] . "</td>";
     317                                                $extra_info_for_table .= "<td>" . $transaction['Transaction Date'] . "</td>";
     318                                                $extra_info_for_table .= "</tr>";
    291319                                            }
    292                                             // array(4) { ["data"]=> array(1) { [0]=> array(5) { ["transactionid"]=> string(11) "11180612726" ["Transaction Date"]=> string(19) "2025-09-24 19:59:38" ["status"]=> string(17) "pendingsettlement" ["amount"]=> string(5) "25.57" ["batchId"]=> string(0) "" } } ["records"]=> string(1) "1" ["page"]=> string(0) "" ["total_pages"]=> int(1) }
    293                                             foreach ($response_json["data"] as $transaction) {
    294                                                 if ($display_transaction_id != $transaction['transactionid']) {
    295                                                     echo "<div style='border:1px solid gray;margin-top:5px;padding:5px;'>";
    296                                                     echo "<strong>Transaction ID:</strong> " . $transaction['transactionid'] . "<br>";
    297                                                     echo "<strong>Transaction Date:</strong> " . $transaction['Transaction Date'] . "<br>";
    298                                                     echo "<strong>Status:</strong> " . $transaction['status'] . "<br>";
    299                                                     echo "<strong>Amount:</strong> " . get_woocommerce_currency_symbol() . $transaction['amount'] . "<br>";
    300                                                     if (isset($transaction['batchId'])) {
    301                                                         if ($transaction['batchId'] != "") {
    302                                                             echo "<strong>Batch ID:</strong> " . $transaction['batchId'] . "<br>";
    303                                                         }
    304                                                     }
    305                                                     echo "</div>";
    306                                                 }
     320                                            if ($transaction['status'] == "pendingsettlement") {
     321                                                $is_pendingsettlement = true;
    307322                                            }
     323                                            //}
    308324                                        }
    309325                                    }
    310326                                }
    311                                     */
    312327                            }
     328                                */
    313329                            //}
    314330                        }
     
    397413
    398414                //if ($paid_date != "") {
    399                     echo "<td>Transaction Date</td>";
     415                echo "<td>Transaction Date</td>";
    400416                //}
    401417
    402418                echo "</tr>";
    403                 if ($display_transaction_id!=""){
    404                 // for main order
    405                 echo "<tr>";
    406                 echo "<td>Order</td>";
    407                 echo "<td>" . $active_payment_gateway . "</td>";
    408 
    409                 $billing_line = "";
    410                 // Billing info line
    411                 if ($card_type != '') {
    412                     $billing_line = "Billing Name: " . $billing_first_name . " " . $billing_last_name . "<br>Credit Card Type: " . $card_type . "<br>Credit Card Number:" . $card_first6 . "******" . $card_last4 . "<br>";
    413                 } else {
    414                     if ($billing_first_name != "") {
    415                         $billing_line = "Billing Name: " . $billing_first_name . " " . $billing_last_name . "<br>";
    416                         if ($card_first6 != "") {
    417                             $billing_line .= "Credit Card Number:" . $card_first6 . "******" . $card_last4 . "<br>";
     419                /*
     420                if ($display_transaction_id != "") {
     421                    // for main order
     422                    echo "<tr>";
     423                    echo "<td>Order</td>";
     424                    echo "<td>" . $active_payment_gateway . "</td>";
     425
     426                    $billing_line = "";
     427                    // Billing info line
     428                    if ($card_type != '') {
     429                        $billing_line = "Billing Name: " . $billing_first_name . " " . $billing_last_name . "<br>Credit Card Type: " . $card_type . "<br>Credit Card Number:" . $card_first6 . "******" . $card_last4 . "<br>";
     430                    } else {
     431                        if ($billing_first_name != "") {
     432                            $billing_line = "Billing Name: " . $billing_first_name . " " . $billing_last_name . "<br>";
     433                            if ($card_first6 != "") {
     434                                $billing_line .= "Credit Card Number:" . $card_first6 . "******" . $card_last4 . "<br>";
     435                            }
    418436                        }
    419437                    }
     438                    echo "<td>" . $billing_line . "</td>";
     439                    echo "<td>" . $transaction_type;
     440                    if ($is_pendingsettlement) {
     441                        echo "<br>(Pending Settlement)";
     442                    }
     443                    echo "</td>";
     444                    echo "<td>";
     445
     446                    // Link to the transaction detail in the BulletProof portal
     447                    if ($display_transaction_id != "") {
     448                        if ($_SERVER['HTTP_HOST'] == "localhost") { // Used for development environments
     449                            $url = "https://localhost/portal/index.php?tx=" . $display_transaction_id;
     450                        } else {
     451                            $url = "https://bulletproofcheckout.net/portal/index.php?tx=" . $display_transaction_id;
     452                        }
     453                        echo "<a onclick=\"window.open('" . $url . "', '_blank', 'location=no,height=800,width=1024,scrollbars=yes,status=yes');\" style='cursor:pointer;'>";
     454                        echo $display_transaction_id;
     455                        echo "</a>";
     456                    }
     457                    echo "</td>";
     458
     459                    echo "<td>" .  get_woocommerce_currency_symbol() . get_post_meta($post->ID, '_order_total', true) . "</td>";
     460                    //if ($paid_date != "") {
     461
     462                    echo "<td>" . $paid_date . "</td>";
     463                    //}
     464
     465                    echo "</tr>";
    420466                }
    421                 echo "<td>" . $billing_line . "</td>";
    422                 echo "<td>" . $transaction_type . "</td>";
    423                 echo "<td>";
    424 
    425                 // Link to the transaction detail in the BulletProof portal
    426                 if ($display_transaction_id != "") {
    427                     if ($_SERVER['HTTP_HOST'] == "localhost") { // Used for development environments
    428                         $url = "https://localhost/portal/index.php?tx=" . $display_transaction_id;
    429                     } else {
    430                         $url = "https://bulletproofcheckout.net/portal/index.php?tx=" . $display_transaction_id;
    431                     }
    432                     echo "<a onclick=\"window.open('" . $url . "', '_blank', 'location=no,height=800,width=1024,scrollbars=yes,status=yes');\" style='cursor:pointer;'>";
    433                     echo $display_transaction_id;
    434                     echo "</a>";
    435                 }
    436                 echo "</td>";
    437 
    438                 echo "<td>" .  get_woocommerce_currency_symbol() . get_post_meta($post->ID, '_order_total', true) . "</td>";
    439                 //if ($paid_date != "") {
    440                     echo "<td>" . $paid_date . "</td>";
    441                 //}
    442 
    443                 echo "</tr>";
    444             }
     467                */
    445468                // any other transaction with the same order id will be here
    446469
    447470                if (isset($response_json["data"])) {
    448                     if ($active_payment_gateway==""){
    449                         $active_payment_gateway="BPCHECKOUT"; // as default in case of the tr5ansaction was initially failed
     471                    if ($active_payment_gateway == "") {
     472                        $active_payment_gateway = "BPCHECKOUT"; // as default in case of the tr5ansaction was initially failed
    450473                    }
    451474                    if (is_array($response_json["data"])) {
     
    453476                        foreach ($response_json["data"] as $transaction) {
    454477                            //if ($display_transaction_id != $transaction['transactionid']) {
    455                             if (($transaction['status'] != "completed") && ($transaction['status'] != "pendingsettlement")) {
    456                                 echo "<tr>";
    457                                 echo "<td>Order</td>";
    458                                 echo "<td>" . $active_payment_gateway . "</td>";
    459                                 echo "<td></td>";
    460                                 echo "<td>" . strtoupper($transaction['status']) . "</td>";
    461                                 echo "<td>";
    462 
    463                                 if ($transaction['transactionid'] != "") {
    464                                     if ($display_transaction_id != $transaction['transactionid']) {
    465                                         // only show if is different from the main transaction id
    466                                         if ($_SERVER['HTTP_HOST'] == "localhost") { // Used for development environments
    467                                             $url = "https://localhost/portal/index.php?tx=" .  $transaction['transactionid'];
    468                                         } else {
    469                                             $url = "https://bulletproofcheckout.net/portal/index.php?tx=" .  $transaction['transactionid'];
    470                                         }
    471                                         echo "<a onclick=\"window.open('" . $url . "', '_blank', 'location=no,height=800,width=1024,scrollbars=yes,status=yes');\" style='cursor:pointer;'>";
    472                                         echo $transaction['transactionid'];
    473                                         echo "</a>";
    474                                     } else {
    475                                         echo $transaction['transactionid'];
     478                            //  if (($transaction['status'] != "completed") && ($transaction['status'] != "pendingsettlement")) {
     479                            echo "<tr>";
     480                            echo "<td>Order</td>";
     481                            echo "<td>" . $active_payment_gateway . "</td>";
     482                            echo "<td>";
     483                            //if (($transaction['status'] == "completed") && ($transaction['status'] == "pendingsettlement")) {
     484                            $billing_line = "";
     485                            // Billing info line
     486                            if ($card_type != '') {
     487                                $billing_line = "Billing Name: " . $billing_first_name . " " . $billing_last_name . "<br>Credit Card Type: " . $card_type . "<br>Credit Card Number:" . $card_first6 . "******" . $card_last4 . "<br>";
     488                            } else {
     489                                if ($billing_first_name != "") {
     490                                    $billing_line = "Billing Name: " . $billing_first_name . " " . $billing_last_name . "<br>";
     491                                    if ($card_first6 != "") {
     492                                        $billing_line .= "Credit Card Number:" . $card_first6 . "******" . $card_last4 . "<br>";
    476493                                    }
    477494                                }
    478                                 echo  "</td>";
    479                                 echo "<td>" . get_woocommerce_currency_symbol() . $transaction['amount'] . "</td>";
    480                                 echo "<td>" . $transaction['Transaction Date'] . "</td>";
    481                                 if (isset($transaction['batchId'])) {
    482                                     if ($transaction['batchId'] != "") {
    483                                         echo "<td>" . $transaction['batchId'] . "</td>";
     495                            }
     496                            echo $billing_line;
     497                            //}
     498                            echo "</td>";
     499                            echo "<td>";
     500                            if ($transaction['status'] == "completed") {
     501                                echo "SALE";
     502                            } else {
     503                                if ($transaction['status'] == "pendingsettlement") {
     504                                    echo "SALE<br>(Pending Settlement)";
     505                                } else {
     506                                    echo strtoupper($transaction['status']);
     507                                }
     508                            }
     509
     510                            echo  "</td>";
     511                            echo "<td>";
     512
     513                            if ($transaction['transactionid'] != "") {
     514
     515                                // Link to the transaction detail in the BulletProof portal
     516                                if ($display_transaction_id != "") {
     517                                    if ($_SERVER['HTTP_HOST'] == "localhost") { // Used for development environments
     518                                        $url = "https://localhost/portal/index.php?tx=" . $display_transaction_id;
    484519                                    } else {
    485                                         echo "<td></td>";
     520                                        $url = "https://bulletproofcheckout.net/portal/index.php?tx=" . $display_transaction_id;
    486521                                    }
     522                                    echo "<a onclick=\"window.open('" . $url . "', '_blank', 'location=no,height=800,width=1024,scrollbars=yes,status=yes');\" style='cursor:pointer;'>";
     523                                    echo $display_transaction_id;
     524                                    echo "</a>";
     525                                }
     526                            }
     527                            echo  "</td>";
     528                            echo "<td>" . get_woocommerce_currency_symbol() . $transaction['amount'] . "</td>";
     529                            echo "<td>" . $transaction['Transaction Date'] . "</td>";
     530                            if (isset($transaction['batchId'])) {
     531                                if ($transaction['batchId'] != "") {
     532                                    echo "<td>" . $transaction['batchId'] . "</td>";
    487533                                } else {
    488534                                    echo "<td></td>";
    489535                                }
    490                                 echo "</tr>";
    491                                 //}
     536                            } else {
     537                                echo "<td></td>";
    492538                            }
     539                            echo "</tr>";
     540                            //}
     541                            //}
    493542                        }
    494543                    }
     
    17131762            }
    17141763            $request_args = array(
     1764                'timeout'     => 25,
     1765                'redirection' => 5,
    17151766                'headers' => array(
    17161767                    'accept' => 'application/json',
     
    17711822
    17721823
    1773     public function woo_order_status_change_bpcheckout_lite($order_id, $old_status, $new_status)
     1824    public function woo_order_status_change_bpcheckout_lite($order_id, $old_status, $new_status, $order)
    17741825    {
    17751826        if ($old_status != "") {
     
    17811832
    17821833        // If the order changes from completed to cancelled or refunded , then will trigger a refund on the gateway
    1783 
    1784         if (($order_id != "") && ($old_status == "completed") && (($new_status == "cancelled") || ($new_status == "refunded"))) {
    1785             error_log("Starting refund from the BulletProof Lite Plugin for the Order ID#:" . $order_id);
     1834        $logger = wc_get_logger();
     1835        $context = array('source' => 'bpcheckout-App');
     1836        $logger->info("Status update of the order ID#:" . $order_id . " was detected, the old status was:" . $old_status . ", the new status is:" . $new_status, $context);
     1837        if (($order_id != "") && ($old_status == "completed" || $old_status == "processing") && (($new_status == "cancelled") || ($new_status == "refunded"))) {
     1838
     1839            $logger->info("Starting refund from the BulletProof Lite Plugin for the Order ID#:" . $order_id, $context);
    17861840            // Check if the order was paid using the BulletProof Lite plugin (or the BulletProof plus plugin)
    1787             $order = wc_get_order($order_id);
     1841            // $order = wc_get_order($order_id); // not needed as the action has a extra new parameter which includes the $order
    17881842            //|| ! $order->get_transaction_id()
    17891843            if (! $order ||  !is_object($order)) {
    1790                 error_log("Invalid Order " . $order_id . " received.");
     1844                $logger->info("Invalid Order " . $order_id . " received.", $context);
    17911845            } else {
    17921846                $payment_method_used = $order->get_meta('_payment_method', true);
    17931847
    1794                 if (($payment_method_used == "bulletproof_bpcheckout_lite") || ($payment_method_used == "bulletproof_bpcheckout")) {
     1848                if ((!empty($payment_method_used)) && (($payment_method_used == "bulletproof_bpcheckout_lite") || ($payment_method_used == "bulletproof_bpcheckout"))) {
     1849                    // check if was previously refunded
     1850                    $earlier_refund = $order->get_meta('_bulletproof_refunded', true);
     1851                    if (empty($earlier_refund)) {
     1852                        $logger->info("Order " . $order_id . " was not previously refunded, continue with refund process.", $context);
     1853                    } else {
     1854                        $logger->info("Order " . $order_id . " was already refunded earlier, no further action taken.", $context);
     1855                        return false;
     1856                    }
    17951857                    $date_completed = $order->get_date_completed();
    17961858                    $datefrom = new DateTime($date_completed);
    17971859                    $dateto = new DateTime();
    17981860                    $days_diff = $datefrom->diff($dateto)->days;
    1799                     if ($days_diff < 30) {
     1861                    if ($days_diff < 365) {  // limited to two years refund period
    18001862                        $lite_gateway = new Bulletproof_Payment_Gateway_Lite();
    18011863                        $response_refund = $lite_gateway->process_refund($order_id, $order->get_total());
    1802 
     1864                        unset($lite_gateway); // Remove the Object from memory ASAP
    18031865                        if (is_wp_error($response_refund)) {
    18041866
     
    18131875                                }
    18141876                            }
    1815                             error_log($the_msg);
     1877                            $logger->info($the_msg, $context);
    18161878                            if ($error_detail_on_gateway != "") {
    18171879                                $order->add_order_note("This order can not be refunded by BulletProof because " . $error_detail_on_gateway);
    18181880                                $order->save();
    18191881                            }
     1882                            $logger->info($the_msg, $context);
    18201883                            return false;
    18211884                        } else {
    1822                             $the_msg = "Order " . $order_id . " was refunded succesfully";
    1823 
    1824                             error_log($the_msg);
    1825                             //error_log($response_refund);
     1885                            $the_msg = "Order " . $order_id . " was refunded succesfully after status update from ".$old_status." to ".$new_status.".";
     1886                            $logger->info($the_msg, $context);
     1887                                /*
    18261888                            try {
    18271889                                $current_user = wp_get_current_user();
     
    18391901                                }
    18401902                            }
    1841                             $order->update_meta_data('_cancel_by', $the_username);
    1842                             $order->update_meta_data('_bulletproof_refunded', true);
     1903                                */
     1904                            //$order->update_meta_data('_cancel_by', $the_username);
     1905                            //$order->update_meta_data('_bulletproof_refunded', true);
    18431906                            // json array for register refund transactions
    18441907                            //  if (is_string($response_refund)) {
    1845                             $order->update_meta_data('_bulletproof_refund_response', $response_refund);
    1846                             $order->update_meta_data('_bulletproof_refund_response_flag', "1");
     1908                            //$order->update_meta_data('_bulletproof_refund_response_status', $response_refund);
     1909                            //$order->update_meta_data('_bulletproof_refund_response_status_flag', "1");
    18471910                            //  }
    18481911                            // json array for register refund transactions
     1912                            /*
    18491913                            $transaction_id_refunds = $order->get_meta('_payment_gateway_tx_refunds', true);
    18501914                            if ($transaction_id_refunds != "") {
     
    18531917                                $refund_ids_array = array();
    18541918                            }
    1855                             // TODO : adds the transaction ID of the received refund
    1856                             $order->save();
     1919
     1920                            if (($response_refund != "") && (isset($response_refund)) && (isset($response_refund['transactionid'])) && ($response['transactionid'] != "")) {
     1921                                if (is_numeric($response_refund['transactionid'])) {
     1922                                    $refund_transactionid = $response_refund['transactionid'];
     1923                                } else {
     1924                                    $refund_transactionid = "";
     1925                                }
     1926                                if ($refund_transactionid != "") {
     1927                                    $the_msg = "Order " . $order_id . " refund transaction id from status update received: " . $refund_transactionid;
     1928                                    $logger->info($the_msg, $context);
     1929                                    if ((is_string($refund_transactionid)) || (is_numeric($refund_transactionid))) {
     1930                                        array_push($refund_ids_array, $refund_transactionid);
     1931                                        $order->update_meta_data('_payment_gateway_tx_refunds', json_encode($refund_ids_array));
     1932                                    }
     1933                                }
     1934                            }
     1935                                */
     1936                            //$order->save();
    18571937                            return true;
    18581938                        }
    18591939                    } else {
    1860                         error_log("Order " . $order_id . " is older than 30 days and can not be refunded in the Payment Gateway");
    1861                         $order->add_order_note("This order is older than 30 days and can not be refunded from the BulletProof Checkout Plugin, but the status in WooCommerce was changed to Cancelled");
     1940                        $the_msg = "Order " . $order_id . " is older than one year and can not be refunded in the Payment Gateway";
     1941                        error_log($the_msg);
     1942                        $order->add_order_note("This order is older than one year and can not be refunded from the BulletProof Checkout Plugin, but the status in WooCommerce was changed to Cancelled");
    18621943                        $order->save();
     1944                        $logger->info($the_msg, $context);
    18631945                        return false;
    18641946                    }
     
    18881970
    18891971        if (is_wp_error($response)) {
    1890             error_log('Capture payment API request failed: ' . $response->get_error_message());
     1972            $the_msg = 'Capture payment API request failed: ' . $response->get_error_message();
     1973            error_log($the_msg);
     1974            $logger = wc_get_logger();
     1975            $context = array('source' => 'bpcheckout-App');
     1976            $logger->info($the_msg, $context);
     1977
    18911978            return $response->get_error_message();
    18921979        } else {
Note: See TracChangeset for help on using the changeset viewer.