Changeset 3404386
- Timestamp:
- 11/27/2025 10:21:52 PM (4 months ago)
- Location:
- bulletproof-checkout-lite/trunk
- Files:
-
- 4 edited
-
README.txt (modified) (2 diffs)
-
bulletproof-checkout-lite.php (modified) (3 diffs)
-
includes/class-wc-bulletproof-payment-gateway-lite.php (modified) (27 diffs)
-
includes/class-wc-bulletproof-shop-orders.php (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
bulletproof-checkout-lite/trunk/README.txt
r3370715 r3404386 3 3 Tags: woocommerce, 3DS, payment gateway, bulletproof, chargeback, fraud prevention 4 4 WC requires at least: 5.0 5 WC tested up to: 10. 2.26 Tested up to: 6.8. 27 Stable tag: 1.0.2 15 WC tested up to: 10.3.5 6 Tested up to: 6.8.3 7 Stable tag: 1.0.22 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 235 235 = 1.0.21 = 236 236 Added zip code denial reason at the Checkout 237 = 1.0.22 = 238 Added custom logger to the Wordpress Logs -
bulletproof-checkout-lite/trunk/bulletproof-checkout-lite.php
r3370715 r3404386 1 1 <?php 2 3 2 /** 4 3 * Plugin Name: BulletProof Checkout Lite 5 4 * Plugin URI: https://www.bulletproof-checkout.com/ 6 5 * Description: Protect your credit card payments with 3D Secure (3DS) and say goodbye to chargebacks. 7 * Version: 1.0.2 16 * Version: 1.0.23 8 7 * Author: BulletProof Checkout <support@bulletproof-checkout.com> 9 8 * Author URI: https://www.bulletproof-checkout.com/ … … 12 11 * Text Domain: bulletproof-checkout-lite 13 12 * WC requires at least: 5.0 14 * WC tested up to: 10. 2.215 * Tested up to: 6.8. 213 * WC tested up to: 10.3.5 14 * Tested up to: 6.8.3 16 15 * Requires PHP: 7.4 17 16 * Requires Plugins: woocommerce … … 39 38 // In the Official Mobile App BulletProof does not support Authorize and Capture later 40 39 if (!defined('BULLETPROOF_CHECKOUT_ADDORDERLISTCOLUMNS')) define('BULLETPROOF_CHECKOUT_ADDORDERLISTCOLUMNS', false); 41 // Some hosting providers auto-enabled JetPack SSO whi h is buggy with the Official Mobile App40 // Some hosting providers auto-enabled JetPack SSO which is buggy with the Official Mobile App 42 41 if (!defined('BULLETPROOF_CHECKOUT_DISABLEJETPACKSSO')) define('BULLETPROOF_CHECKOUT_DISABLEJETPACKSSO', false); 43 42 -
bulletproof-checkout-lite/trunk/includes/class-wc-bulletproof-payment-gateway-lite.php
r3370715 r3404386 485 485 $response = wp_remote_post($api_url, $request_args); 486 486 487 // setting log class 488 $logger = wc_get_logger(); 489 $context = array('source' => 'bpcheckout-App'); 487 490 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; 489 497 } else { 490 498 $decoded_response = ""; 491 499 $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 496 517 return $decoded_response; 497 518 } … … 690 711 { 691 712 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); 693 717 // Get the WooCommerce order. 694 718 $order = wc_get_order($order_id); … … 705 729 // Prepare request arguments. 706 730 $request_args = array( 731 'method' => 'POST', 732 'timeout' => 25, 733 'redirection' => 5, 707 734 'headers' => array( 708 735 'accept' => 'application/json', … … 712 739 ); 713 740 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); 715 742 716 743 if ((strtolower($this->get_option('enabled')) == "yes")) { 717 if ( $transaction_id != "") {744 if ((!empty($transaction_id)) && $transaction_id != "") { 718 745 // Locate the API endpoint to be used 719 746 $base_api_url = BULLETPROOF_CHECKOUT_API_BASE_URL; 747 $is_sandbox = false; 720 748 try { 721 749 if ((strtolower($this->get_option('testmode')) == "no") || ($this->get_option('testmode') == "")) { … … 724 752 if (strtolower($this->get_option('testmode')) == "yes") { 725 753 $base_api_url = BULLETPROOF_CHECKOUT_API_BASE_URL_SANDBOX; 754 $is_sandbox = true; 726 755 } 727 756 } … … 735 764 '&security_key=' . urlencode($security_key) . 736 765 '&transactionid=' . urlencode($transaction_id); 766 $api_url_masked = $base_api_url . 'refund.php?user=&pass=&security_key=&transactionid=' . urlencode($transaction_id); 737 767 // adds support for partial refunds 738 768 if ($amount != "") { 739 769 $api_url .= '&amount=' . $amount; 770 $api_url_masked .= '&amount=' . $amount; 740 771 } 741 772 742 773 // 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); 744 775 745 776 $response = $this->bulletproof_refund_payment_api($api_url, $request_args); … … 748 779 if (((isset($response['error'])) && ($response['error'] != "")) || (is_wp_error($response)) || (empty($response))) { 749 780 if (isset($response['error'])) { 750 error_log(print_r($response['error'], true));781 $logger->info(print_r($response['error'], true), $context); 751 782 } else { 752 783 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); 754 785 } else { 755 786 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); 757 792 } else { 758 error_log(print_r('Unknown error occurred.', true));793 $logger->info(print_r('Unknown error occurred.', true), $context); 759 794 } 760 795 } … … 768 803 if (empty($response)) { 769 804 $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 } 770 808 } else { 771 809 $error_message = 'Unknown error occurred.'; … … 775 813 $order->add_order_note($the_msg); 776 814 $order->save(); 815 $logger->info($error_message, $context); 777 816 return new WP_Error('bulletproof_refund_api_error', $error_message); 778 817 } else { … … 780 819 // $order->add_order_note('Refunded via BulletProof Checkout.'); 781 820 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 790 824 try { 791 825 $current_user = wp_get_current_user(); … … 793 827 $current_user = ""; 794 828 } 829 795 830 $the_username = ""; 796 831 if (isset($current_user->user_login)) { … … 807 842 // json array for register refund transactions 808 843 // if (is_string($response)) { 844 $data_to_store = ""; 809 845 $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 } 813 854 } 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 } 825 867 } 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; 829 871 } 830 872 } else { 831 // Nothing was returned (Network error)832 873 $data_to_store = $response; 833 874 } … … 835 876 $data_to_store = $response; 836 877 } 837 } else {838 $data_to_store = $response;839 878 } 879 } catch (Exception $ex) { 880 // in case of error save any updated metadata 881 $logger->info($ex->getMessage(), $context); 882 $order->save(); 840 883 } 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 841 895 if (!empty($data_to_store)) { 842 896 $order->update_meta_data('_bulletproof_refund_response', $data_to_store); … … 846 900 $order->update_meta_data('_bulletproof_refund_response', $error_message); 847 901 $order->update_meta_data('_bulletproof_refund_response_flag', "3"); 902 $order->save(); 903 $logger->info($error_message, $context); 848 904 return new WP_Error('bulletproof_refund_api_error', $error_message); 849 905 } 850 906 // } 851 907 // 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); 858 920 } 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); 861 923 } 862 924 $order->save(); … … 866 928 } else { 867 929 $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); 869 931 return new WP_Error('bulletproof_no_transaction_id', $the_msg); 870 932 } 871 933 } else { 872 934 $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); 874 936 return new WP_Error('bulletproof_disabled', $the_msg); 875 937 } … … 886 948 { 887 949 // Locate the API endpoint to be used 950 // setting log class 951 $logger = wc_get_logger(); 952 $context = array('source' => 'bpcheckout-App'); 888 953 $base_api_url = ""; 889 954 try { … … 927 992 // Log an error message if the API request fails. 928 993 $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); 930 995 } 931 996 … … 1008 1073 } 1009 1074 1075 1076 1010 1077 // check if the plugin is enabled 1011 1078 if ((strtolower($this->get_option('enabled')) == "yes")) { … … 1029 1096 $sale_auth_api_url = $base_api_url . "?rndx=" . time(); 1030 1097 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 1031 1103 // Get sale authorization parameters. 1032 1104 $sale_auth_params = $this->bulletproof_checkout_api_params($order, $order_id); … … 1041 1113 // Build the validation API URL. 1042 1114 $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); 1044 1116 // Return success with redirection URL. 1045 1117 return array( … … 1067 1139 esc_html($sale_auth_response->error) 1068 1140 ); 1069 1141 $logger->info($formatted_message . ". Response from Order ID#" . $order_id, $context); 1070 1142 // Display an error notice and return an empty array. 1071 1143 self::bulletproof_display_notice($formatted_message, 'error'); … … 1083 1155 ); 1084 1156 $order->update_status('wc-failed'); 1085 1157 $logger->info($formatted_message . ". Order ID#" . $order_id, $context); 1158 $logger->info($sale_auth_response, $context); 1086 1159 self::bulletproof_display_notice($formatted_message, 'error'); 1087 1160 } 1088 1161 } else { 1089 1090 1091 1162 // Adding translators comment 1092 1163 /* translators: %s: Error message from the response */ … … 1104 1175 self::bulletproof_display_notice($formatted_message, 'error'); 1105 1176 $order->update_status('wc-failed'); 1177 $logger->info($formatted_message . ". Order ID#" . $order_id, $context); 1106 1178 return array(); 1107 1179 } … … 1376 1448 } 1377 1449 } 1378 1450 1379 1451 // Build an array of sale authorization parameters. 1380 1452 // The parameter fix_iso_codes will ignore states (which are not on ISO format) … … 1473 1545 $api_url, 1474 1546 array( 1547 'timeout' => 25, 1548 'redirection' => 5, 1475 1549 'body' => $params, 1476 1550 'headers' => array( … … 1483 1557 if (is_wp_error($response)) { 1484 1558 // 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); 1486 1565 } else { 1487 1566 … … 1492 1571 $body = wp_remote_retrieve_body($response); 1493 1572 } 1494 if ($body == "" && $response != "" && isset($response['body']) && $response['body'] !="") {1573 if ($body == "" && $response != "" && isset($response['body']) && $response['body'] != "") { 1495 1574 $body = $response['body']; 1496 1575 } -
bulletproof-checkout-lite/trunk/includes/class-wc-bulletproof-shop-orders.php
r3368943 r3404386 30 30 31 31 // 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 34 33 35 34 // Add a meta box inside the Order detail … … 100 99 // Search the transaction at the gateway 101 100 $request_args = array( 101 'timeout' => 25, 102 'redirection' => 5, 102 103 'headers' => array( 103 104 'accept' => 'application/json', … … 219 220 $security_key = $gateway_settings['api_key']; 220 221 } 222 223 $extra_info_for_table = ""; 224 $is_pendingsettlement = false; 221 225 // search related transactions with the same Order Id 222 226 if (($username != "") && ($password != "") && ($security_key != "")) { … … 234 238 235 239 $request_args = array( 240 'timeout' => 25, 241 'redirection' => 5, 236 242 'headers' => array( 237 243 'accept' => 'application/json', … … 245 251 '&security_key=' . urlencode($security_key) . 246 252 '&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 247 258 $response_display = ""; 248 259 $response_search = bulletproof_transaction_information($api_url, $request_args); 260 249 261 $show_error = false; 250 262 $do_not_show_response = false; … … 262 274 if ($response_json["id"] == "823") { // No access to the API endpoint 263 275 $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; 265 277 } else { 266 278 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 … … 274 286 } 275 287 } 288 276 289 if (defined('WP_DEBUG') && true === WP_DEBUG) { 277 290 if ($show_error) { … … 279 292 } 280 293 } 294 /* 281 295 if (!$do_not_show_response) { 282 296 // 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>"; 291 319 } 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; 307 322 } 323 //} 308 324 } 309 325 } 310 326 } 311 */312 327 } 328 */ 313 329 //} 314 330 } … … 397 413 398 414 //if ($paid_date != "") { 399 echo "<td>Transaction Date</td>";415 echo "<td>Transaction Date</td>"; 400 416 //} 401 417 402 418 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 } 418 436 } 419 437 } 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>"; 420 466 } 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 */ 445 468 // any other transaction with the same order id will be here 446 469 447 470 if (isset($response_json["data"])) { 448 if ($active_payment_gateway ==""){449 $active_payment_gateway ="BPCHECKOUT"; // as default in case of the tr5ansaction was initially failed471 if ($active_payment_gateway == "") { 472 $active_payment_gateway = "BPCHECKOUT"; // as default in case of the tr5ansaction was initially failed 450 473 } 451 474 if (is_array($response_json["data"])) { … … 453 476 foreach ($response_json["data"] as $transaction) { 454 477 //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>"; 476 493 } 477 494 } 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; 484 519 } else { 485 echo "<td></td>";520 $url = "https://bulletproofcheckout.net/portal/index.php?tx=" . $display_transaction_id; 486 521 } 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>"; 487 533 } else { 488 534 echo "<td></td>"; 489 535 } 490 echo "</tr>";491 //}536 } else { 537 echo "<td></td>"; 492 538 } 539 echo "</tr>"; 540 //} 541 //} 493 542 } 494 543 } … … 1713 1762 } 1714 1763 $request_args = array( 1764 'timeout' => 25, 1765 'redirection' => 5, 1715 1766 'headers' => array( 1716 1767 'accept' => 'application/json', … … 1771 1822 1772 1823 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) 1774 1825 { 1775 1826 if ($old_status != "") { … … 1781 1832 1782 1833 // 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); 1786 1840 // 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 1788 1842 //|| ! $order->get_transaction_id() 1789 1843 if (! $order || !is_object($order)) { 1790 error_log("Invalid Order " . $order_id . " received.");1844 $logger->info("Invalid Order " . $order_id . " received.", $context); 1791 1845 } else { 1792 1846 $payment_method_used = $order->get_meta('_payment_method', true); 1793 1847 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 } 1795 1857 $date_completed = $order->get_date_completed(); 1796 1858 $datefrom = new DateTime($date_completed); 1797 1859 $dateto = new DateTime(); 1798 1860 $days_diff = $datefrom->diff($dateto)->days; 1799 if ($days_diff < 3 0) {1861 if ($days_diff < 365) { // limited to two years refund period 1800 1862 $lite_gateway = new Bulletproof_Payment_Gateway_Lite(); 1801 1863 $response_refund = $lite_gateway->process_refund($order_id, $order->get_total()); 1802 1864 unset($lite_gateway); // Remove the Object from memory ASAP 1803 1865 if (is_wp_error($response_refund)) { 1804 1866 … … 1813 1875 } 1814 1876 } 1815 error_log($the_msg);1877 $logger->info($the_msg, $context); 1816 1878 if ($error_detail_on_gateway != "") { 1817 1879 $order->add_order_note("This order can not be refunded by BulletProof because " . $error_detail_on_gateway); 1818 1880 $order->save(); 1819 1881 } 1882 $logger->info($the_msg, $context); 1820 1883 return false; 1821 1884 } 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 /* 1826 1888 try { 1827 1889 $current_user = wp_get_current_user(); … … 1839 1901 } 1840 1902 } 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); 1843 1906 // json array for register refund transactions 1844 1907 // 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"); 1847 1910 // } 1848 1911 // json array for register refund transactions 1912 /* 1849 1913 $transaction_id_refunds = $order->get_meta('_payment_gateway_tx_refunds', true); 1850 1914 if ($transaction_id_refunds != "") { … … 1853 1917 $refund_ids_array = array(); 1854 1918 } 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(); 1857 1937 return true; 1858 1938 } 1859 1939 } 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"); 1862 1943 $order->save(); 1944 $logger->info($the_msg, $context); 1863 1945 return false; 1864 1946 } … … 1888 1970 1889 1971 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 1891 1978 return $response->get_error_message(); 1892 1979 } else {
Note: See TracChangeset
for help on using the changeset viewer.