Plugin Directory

Changeset 3807811


Ignore:
Timestamp:
11/17/2026 04:38:30 PM (8 hours ago)
Author:
ikhokhasupport
Message:

Deploy version v3.0.5 from Git commit 1d9a70f5d81f37f14566a4bd4bdbc116d3d11960

Location:
ikhokha-payment-gateway
Files:
20 added
2 edited

Legend:

Unmodified
Added
Removed
  • ikhokha-payment-gateway/trunk/index.php

    r3756918 r3807811  
    66 * Author: iKhokha
    77 * Author URI: https://www.ikhokha.com/
    8  * Version: 3.0.4
     8 * Version: 3.0.5
    99 * Requires Plugins: woocommerce
    1010 */
    … …  
    485485                public function ikhokha_process_response()
    486486                {
    487                         // Fail closed if gateway is disabled or credentials are not configured
    488                         if ('yes' !== $this->enabled || !$this->is_configured()) {
    489                                 status_header(403);
    490                                 wp_die(__('iKhokha gateway is not enabled or properly configured.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 403));
    491                         }
    492 
    493                         // Extract payload
    494                         $data = null;
    495                         if (isset($_POST['status']) && !empty($_POST['status'])) {
    496                                 $data = array('status' => sanitize_text_field(wp_unslash($_POST['status'])));
    497 
    498                                 if (isset($_POST['transactionId']) && !empty($_POST['transactionId'])) {
    499                                         $data['transactionId'] = sanitize_key(wp_unslash($_POST['transactionId']));
    500                                 }
    501                                 if (isset($_POST['responseCode']) && !empty($_POST['responseCode'])) {
    502                                         $data['responseCode'] = sanitize_text_field(wp_unslash($_POST['responseCode']));
    503                                 }
    504                                 if (isset($_POST['responseMessage']) && !empty($_POST['responseMessage'])) {
    505                                         $data['responseMessage'] = sanitize_text_field(wp_unslash($_POST['responseMessage']));
    506                                 }
    507                         } else {
    508                                 $raw_body = file_get_contents("php://input");
    509                                 if (!empty($raw_body)) {
    510                                         $data = json_decode($raw_body, true);
    511                                 }
    512                         }
    513 
    514                         if (!is_array($data) || empty($data['status'])) {
    515                                 status_header(400);
    516                                 wp_die(__('Invalid or missing callback payload.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 400));
    517                         }
    518 
    519                         // Defensive header retrieval and verification
    520                         $header_sign  = $this->get_request_header('IK-SIGN');
    521                         $header_appid = $this->get_request_header('IK-APPID');
    522 
    523                         // Treat missing or empty headers as immediate hard failure
    524                         if (empty($header_sign) || empty($header_appid)) {
    525                                 status_header(400);
    526                                 wp_die(__('Missing required callback headers.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 400));
    527                         }
    528 
    529                         // Compare Application ID using timing-safe comparison
    530                         if (!hash_equals((string) $this->application_id, (string) $header_appid)) {
    531                                 status_header(401);
    532                                 wp_die(__('Unauthorized: Application ID mismatch.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 401));
    533                         }
    534 
    535                         // Generate and verify callback signature using timing-safe hash_equals
    536                         $expected_signature = self::generate_callback_signature($data);
    537                         if (empty($expected_signature) || !hash_equals((string) $expected_signature, (string) $header_sign)) {
    538                                 status_header(401);
    539                                 wp_die(__('Unauthorized: Invalid callback signature.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 401));
    540                         }
    541 
    542                         // Validate order reference parameter
    543                         if (!isset($_GET['reference'])) {
    544                                 status_header(400);
    545                                 wp_die(__('Missing order reference parameter.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 400));
    546                         }
    547 
    548                         $reference = sanitize_key(wp_unslash($_GET['reference']));
    549                         $order = wc_get_order(is_numeric($reference) ? (int) $reference : $reference);
    550 
    551                         if (!$order || !is_a($order, 'WC_Order')) {
    552                                 status_header(404);
    553                                 wp_die(__('Order not found.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 404));
    554                         }
    555 
    556                         // Bind callback to order by verifying order_key
    557                         $order_key = '';
    558                         if (!empty($_GET['order_key'])) {
    559                                 $order_key = sanitize_text_field(wp_unslash($_GET['order_key']));
    560                         } elseif (!empty($data['order_key'])) {
    561                                 $order_key = sanitize_text_field($data['order_key']);
    562                         } elseif (!empty($_POST['order_key'])) {
    563                                 $order_key = sanitize_text_field(wp_unslash($_POST['order_key']));
    564                         }
    565 
    566                         if (empty($order_key) || !hash_equals((string) $order->get_order_key(), (string) $order_key)) {
    567                                 status_header(401);
    568                                 wp_die(__('Unauthorized: Invalid order key.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 401));
    569                         }
    570 
    571                         // Confirm order was placed using this gateway
    572                         if ($order->get_payment_method() !== $this->id) {
    573                                 status_header(400);
    574                                 wp_die(__('Order payment method does not match iKhokha.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 400));
    575                         }
    576 
    577                         // Verify currency is ZAR
    578                         if ($order->get_currency() !== 'ZAR') {
    579                                 status_header(400);
    580                                 wp_die(__('Invalid order currency.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 400));
    581                         }
    582 
    583                         // Verify reported currency if provided
    584                         $reported_currency = '';
    585                         if (!empty($data['currency'])) {
    586                                 $reported_currency = $data['currency'];
    587                         } elseif (!empty($_POST['currency'])) {
    588                                 $reported_currency = sanitize_text_field(wp_unslash($_POST['currency']));
    589                         }
    590 
    591                         if (!empty($reported_currency) && strtoupper($reported_currency) !== strtoupper($order->get_currency())) {
    592                                 status_header(400);
    593                                 wp_die(__('Reported currency does not match order currency.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 400));
    594                         }
    595 
    596                         // Verify reported amount if provided
    597                         $reported_amount = null;
    598                         if (isset($data['amount'])) {
    599                                 $reported_amount = $data['amount'];
    600                         } elseif (isset($_POST['amount'])) {
    601                                 $reported_amount = sanitize_text_field(wp_unslash($_POST['amount']));
    602                         }
    603 
    604                         if ($reported_amount !== null && $reported_amount !== '') {
    605                                 $reported_float    = (float) $reported_amount;
    606                                 $order_total       = (float) $order->get_total();
    607                                 $order_total_cents = round($order_total * 100);
    608 
    609                                 $matches_cents = abs($reported_float - $order_total_cents) < 0.01;
    610                                 $matches_total = abs($reported_float - $order_total) < 0.01;
    611 
    612                                 if (!$matches_cents && !$matches_total) {
     487                        try {
     488                                // Fail closed if gateway is disabled or credentials are not configured
     489                                if ('yes' !== $this->enabled || !$this->is_configured()) {
     490                                        status_header(403);
     491                                        wp_die(__('iKhokha gateway is not enabled or properly configured.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 403));
     492                                }
     493
     494                                // Extract payload
     495                                $data = null;
     496                                if (isset($_POST['status']) && !empty($_POST['status'])) {
     497                                        $data = array('status' => sanitize_text_field(wp_unslash($_POST['status'])));
     498
     499                                        if (isset($_POST['transactionId']) && !empty($_POST['transactionId'])) {
     500                                                $data['transactionId'] = sanitize_text_field(wp_unslash($_POST['transactionId']));
     501                                        }
     502                                        if (isset($_POST['responseCode']) && !empty($_POST['responseCode'])) {
     503                                                $data['responseCode'] = sanitize_text_field(wp_unslash($_POST['responseCode']));
     504                                        }
     505                                        if (isset($_POST['responseMessage']) && !empty($_POST['responseMessage'])) {
     506                                                $data['responseMessage'] = sanitize_text_field(wp_unslash($_POST['responseMessage']));
     507                                        }
     508                                } else {
     509                                        $raw_body = file_get_contents("php://input");
     510                                        if (!empty($raw_body)) {
     511                                                $data = json_decode($raw_body, true);
     512                                        }
     513                                }
     514
     515                                if (!is_array($data) || empty($data['status'])) {
    613516                                        status_header(400);
    614                                         wp_die(__('Reported payment amount does not match order total.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 400));
    615                                 }
    616                         }
    617 
    618                         // Process order status safely
    619                         $order_is_paid      = $order->has_status(array('processing', 'completed'));
    620                         $transaction_status = strtolower($data['status']);
    621 
    622                         if (!$order_is_paid && 'success' === $transaction_status) {
    623                                 $transaction_id = !empty($data['transactionId']) ? $data['transactionId'] : '';
    624 
    625                                 $order->update_meta_data('ikhokha_data', $data);
    626                                 $order->payment_complete($transaction_id);
    627                                 $order->add_order_note(
    628                                         sprintf(
    629                                                 /* translators: 1: Currency, 2: Amount */
    630                                                 __('%1$s %2$s was successfully processed through iKhokha', 'ikhokha-payment-gateway'),
    631                                                 $order->get_currency(),
    632                                                 $order->get_total()
    633                                         )
    634                                 );
    635                                 $order->save();
    636 
    637                                 global $woocommerce;
    638                                 if (isset($woocommerce->cart) && is_object($woocommerce->cart)) {
    639                                         $woocommerce->cart->empty_cart();
    640                                 }
    641 
    642                                 status_header(200);
    643                                 wp_send_json(array('status' => true));
    644                         } elseif (!$order_is_paid && 'failed' === $transaction_status) {
    645                                 $order->update_meta_data('ikhokha_data', $data);
    646                                 $order->update_status(
    647                                         'failed',
    648                                         sprintf(
    649                                                 /* translators: 1: Currency, 2: Amount */
    650                                                 __('%1$s %2$s payment failed through iKhokha', 'ikhokha-payment-gateway'),
    651                                                 $order->get_currency(),
    652                                                 $order->get_total()
    653                                         )
    654                                 );
    655                                 $order->save();
    656 
    657                                 status_header(200);
    658                                 wp_send_json(array('status' => true));
    659                         } else {
    660                                 status_header(200);
    661                                 wp_send_json(array('status' => true, 'message' => 'Order state already finalized or unchanged.'));
     517                                        wp_die(__('Invalid or missing callback payload.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 400));
     518                                }
     519
     520                                // Defensive header retrieval and verification
     521                                $header_sign  = $this->get_request_header('IK-SIGN');
     522                                $header_appid = $this->get_request_header('IK-APPID');
     523
     524                                // Treat missing or empty headers as immediate hard failure
     525                                if (empty($header_sign) || empty($header_appid)) {
     526                                        status_header(400);
     527                                        wp_die(__('Missing required callback headers.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 400));
     528                                }
     529
     530                                // Compare Application ID using timing-safe comparison
     531                                if (!hash_equals((string) $this->application_id, (string) $header_appid)) {
     532                                        status_header(401);
     533                                        wp_die(__('Unauthorized: Application ID mismatch.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 401));
     534                                }
     535
     536                                // Generate and verify callback signature using timing-safe hash_equals
     537                                $expected_signature = self::generate_callback_signature($data);
     538                                if (empty($expected_signature) || !hash_equals((string) $expected_signature, (string) $header_sign)) {
     539                                        status_header(401);
     540                                        wp_die(__('Unauthorized: Invalid callback signature.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 401));
     541                                }
     542
     543                                // Validate order reference parameter
     544                                if (!isset($_GET['reference'])) {
     545                                        status_header(400);
     546                                        wp_die(__('Missing order reference parameter.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 400));
     547                                }
     548
     549                                $reference = sanitize_key(wp_unslash($_GET['reference']));
     550                                $order = wc_get_order(is_numeric($reference) ? (int) $reference : $reference);
     551
     552                                if (!$order || !is_a($order, 'WC_Order')) {
     553                                        status_header(404);
     554                                        wp_die(__('Order not found.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 404));
     555                                }
     556
     557                                // Bind callback to order by verifying order_key
     558                                $order_key = '';
     559                                if (!empty($_GET['order_key'])) {
     560                                        $order_key = sanitize_text_field(wp_unslash($_GET['order_key']));
     561                                } elseif (!empty($data['order_key'])) {
     562                                        $order_key = sanitize_text_field($data['order_key']);
     563                                } elseif (!empty($_POST['order_key'])) {
     564                                        $order_key = sanitize_text_field(wp_unslash($_POST['order_key']));
     565                                }
     566
     567                                if (empty($order_key) || !hash_equals((string) $order->get_order_key(), (string) $order_key)) {
     568                                        status_header(401);
     569                                        wp_die(__('Unauthorized: Invalid order key.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 401));
     570                                }
     571
     572                                // Confirm order was placed using this gateway
     573                                if ($order->get_payment_method() !== $this->id) {
     574                                        status_header(400);
     575                                        wp_die(__('Order payment method does not match iKhokha.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 400));
     576                                }
     577
     578                                // If payload includes authoritative order reference fields, verify binding
     579                                if (!empty($data['externalEntityRef'])) {
     580                                        $ref_val = (string) $data['externalEntityRef'];
     581                                        $order_prefix = $order->get_id() . '-';
     582                                        if ($ref_val !== (string) $order->get_id() && strpos($ref_val, $order_prefix) !== 0) {
     583                                                status_header(400);
     584                                                wp_die(__('Payload externalEntityRef does not match order.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 400));
     585                                        }
     586                                }
     587
     588                                if (!empty($data['custom1'])) {
     589                                        if (!hash_equals((string) $order->get_order_key(), (string) $data['custom1'])) {
     590                                                status_header(401);
     591                                                wp_die(__('Payload custom reference does not match order key.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 401));
     592                                        }
     593                                }
     594
     595                                if (!empty($data['reference'])) {
     596                                        $data_ref = (string) $data['reference'];
     597                                        if ($data_ref !== (string) $order->get_id() && $data_ref !== (string) $order->get_order_number()) {
     598                                                status_header(400);
     599                                                wp_die(__('Payload reference does not match order.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 400));
     600                                        }
     601                                }
     602
     603                                // Verify currency is ZAR
     604                                if ($order->get_currency() !== 'ZAR') {
     605                                        status_header(400);
     606                                        wp_die(__('Invalid order currency.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 400));
     607                                }
     608
     609                                // Verify reported currency if provided
     610                                $reported_currency = '';
     611                                if (!empty($data['currency'])) {
     612                                        $reported_currency = $data['currency'];
     613                                } elseif (!empty($_POST['currency'])) {
     614                                        $reported_currency = sanitize_text_field(wp_unslash($_POST['currency']));
     615                                }
     616
     617                                if (!empty($reported_currency) && strtoupper($reported_currency) !== strtoupper($order->get_currency())) {
     618                                        status_header(400);
     619                                        wp_die(__('Reported currency does not match order currency.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 400));
     620                                }
     621
     622                                // Verify reported amount if provided
     623                                $reported_amount = null;
     624                                if (isset($data['amount'])) {
     625                                        $reported_amount = $data['amount'];
     626                                } elseif (isset($_POST['amount'])) {
     627                                        $reported_amount = sanitize_text_field(wp_unslash($_POST['amount']));
     628                                }
     629
     630                                if ($reported_amount !== null && $reported_amount !== '') {
     631                                        $reported_float    = (float) $reported_amount;
     632                                        $order_total       = (float) $order->get_total();
     633                                        $order_total_cents = round($order_total * 100);
     634
     635                                        $matches_cents = abs($reported_float - $order_total_cents) < 0.01;
     636                                        $matches_total = abs($reported_float - $order_total) < 0.01;
     637
     638                                        if (!$matches_cents && !$matches_total) {
     639                                                status_header(400);
     640                                                wp_die(__('Reported payment amount does not match order total.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 400));
     641                                        }
     642                                }
     643
     644                                $transaction_status = strtolower($data['status']);
     645                                $transaction_id     = !empty($data['transactionId']) ? sanitize_text_field($data['transactionId']) : '';
     646
     647                                // Finding 1: Strict idempotency and cross-order reuse prevention
     648                                if ('success' === $transaction_status && empty($transaction_id)) {
     649                                        status_header(400);
     650                                        wp_die(__('Missing transaction ID in successful payment callback.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 400));
     651                                }
     652
     653                                if (!empty($transaction_id)) {
     654                                        // Check if this order is already bound to a different transaction ID
     655                                        $existing_order_txn = $order->get_transaction_id();
     656                                        if (!empty($existing_order_txn) && !hash_equals((string) $existing_order_txn, (string) $transaction_id)) {
     657                                                status_header(409);
     658                                                wp_die(__('Conflict: Order is already associated with a different transaction ID.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 409));
     659                                        }
     660
     661                                        // Check if this transaction ID was already recorded on any other order in WooCommerce
     662                                        $existing_orders = wc_get_orders(array(
     663                                                'limit'          => 1,
     664                                                'transaction_id' => $transaction_id,
     665                                                'type'           => 'shop_order',
     666                                        ));
     667
     668                                        if (empty($existing_orders)) {
     669                                                $existing_orders = wc_get_orders(array(
     670                                                        'limit'      => 1,
     671                                                        'meta_key'   => '_ikhokha_transaction_id',
     672                                                        'meta_value' => $transaction_id,
     673                                                        'type'       => 'shop_order',
     674                                                ));
     675                                        }
     676
     677                                        if (!empty($existing_orders)) {
     678                                                $matched_order = reset($existing_orders);
     679
     680                                                // Cross-order signed-callback reuse attempt detected
     681                                                if ($matched_order->get_id() !== $order->get_id()) {
     682                                                        status_header(409);
     683                                                        wp_die(__('Conflict: Transaction ID has already been processed for another order.', 'ikhokha-payment-gateway'), 'iKhokha Payment Error', array('response' => 409));
     684                                                }
     685
     686                                                // Same order: duplicate callback notification - respond idempotently
     687                                                if ($order->has_status(array('processing', 'completed')) || (method_exists($order, 'is_paid') && $order->is_paid())) {
     688                                                        status_header(200);
     689                                                        wp_send_json(array(
     690                                                                'status'  => true,
     691                                                                'message' => 'Duplicate callback acknowledged; order is already finalized.',
     692                                                        ));
     693                                                }
     694                                        }
     695                                }
     696
     697                                // Check current order paid state
     698                                $order_is_paid = $order->has_status(array('processing', 'completed')) || (method_exists($order, 'is_paid') && $order->is_paid());
     699
     700                                if (!$order_is_paid && 'success' === $transaction_status) {
     701                                        // Update metadata and transaction ID
     702                                        $order->update_meta_data('ikhokha_data', $data);
     703                                        $order->update_meta_data('_ikhokha_transaction_id', $transaction_id);
     704
     705                                        // Attempt order completion in WooCommerce
     706                                        $completion_result = $order->payment_complete($transaction_id);
     707
     708                                        // Verify if order actually transitioned to a paid state
     709                                        $order_now_paid = $order->has_status(array('processing', 'completed')) || (method_exists($order, 'is_paid') && $order->is_paid());
     710
     711                                        // Finding 2: Do not acknowledge success or add a success note if WooCommerce rejected completion
     712                                        if (!$completion_result && !$order_now_paid) {
     713                                                $order->add_order_note(
     714                                                        sprintf(
     715                                                                /* translators: 1: Transaction ID, 2: Current order status */
     716                                                                __('iKhokha payment captured (Transaction ID: %1$s), but WooCommerce rejected order completion. Current order status: %2$s. Manual reconciliation required.', 'ikhokha-payment-gateway'),
     717                                                                $transaction_id,
     718                                                                $order->get_status()
     719                                                        )
     720                                                );
     721                                                $order->save();
     722
     723                                                status_header(500);
     724                                                wp_send_json(array(
     725                                                        'status'  => false,
     726                                                        'message' => 'Order payment completion could not be recorded by WooCommerce.',
     727                                                ));
     728                                        }
     729
     730                                        // Successfully completed
     731                                        $order->add_order_note(
     732                                                sprintf(
     733                                                        /* translators: 1: Currency, 2: Amount */
     734                                                        __('%1$s %2$s was successfully processed through iKhokha', 'ikhokha-payment-gateway'),
     735                                                        $order->get_currency(),
     736                                                        $order->get_total()
     737                                                )
     738                                        );
     739                                        $order->save();
     740
     741                                        global $woocommerce;
     742                                        if (isset($woocommerce->cart) && is_object($woocommerce->cart)) {
     743                                                $woocommerce->cart->empty_cart();
     744                                        }
     745
     746                                        status_header(200);
     747                                        wp_send_json(array('status' => true));
     748                                } elseif (!$order_is_paid && 'failed' === $transaction_status) {
     749                                        $order->update_meta_data('ikhokha_data', $data);
     750                                        if (!empty($transaction_id)) {
     751                                                $order->update_meta_data('_ikhokha_transaction_id', $transaction_id);
     752                                        }
     753                                        $order->update_status(
     754                                                'failed',
     755                                                sprintf(
     756                                                        /* translators: 1: Currency, 2: Amount */
     757                                                        __('%1$s %2$s payment failed through iKhokha', 'ikhokha-payment-gateway'),
     758                                                        $order->get_currency(),
     759                                                        $order->get_total()
     760                                                )
     761                                        );
     762                                        $order->save();
     763
     764                                        status_header(200);
     765                                        wp_send_json(array('status' => true));
     766                                } else {
     767                                        status_header(200);
     768                                        wp_send_json(array('status' => true, 'message' => 'Order state already finalized or unchanged.'));
     769                                }
     770                        } catch (\Throwable $e) {
     771                                if (defined('WP_DEBUG') && WP_DEBUG) {
     772                                        error_log('iKhokha callback error: ' . $e->getMessage());
     773                                }
     774                                status_header(500);
     775                                wp_send_json(array(
     776                                        'status'  => false,
     777                                        'message' => 'An error occurred while processing the callback.',
     778                                ));
    662779                        }
    663780                }
    … …  
    674791
    675792                                $transaction_id = null;
    676 
    677                                 $getData = get_post_meta($order_id, 'ikhokha_data', true) ? get_post_meta($order_id, 'ikhokha_data', true) : '';
     793                                $order = wc_get_order($order_id);
     794                                $getData = $order ? $order->get_meta('ikhokha_data', true) : get_post_meta($order_id, 'ikhokha_data', true);
    678795
    679796                                if (isset($getData['transactionId']) && !empty($getData['transactionId'])) {
    … …  
    681798                                }
    682799
     800                                if (empty($transaction_id) && $order && $order->get_transaction_id()) {
     801                                        $transaction_id = $order->get_transaction_id();
     802                                }
     803
    683804                                if (empty($transaction_id)) {
    684                                         $payment_url = get_post_meta($order_id, 'ikhokha_payment_url', true);
     805                                        $payment_url = $order ? $order->get_meta('ikhokha_payment_url', true) : get_post_meta($order_id, 'ikhokha_payment_url', true);
    685806                                        $arr_payment = explode("/", $payment_url);
    686807                                        $arr_payment_reversed = array_reverse($arr_payment);
    … …  
    715836
    716837                                $transaction_id = null;
    717 
    718                                 $getData = get_post_meta($order_id, 'ikhokha_data', true) ? get_post_meta($order_id, 'ikhokha_data', true) : '';
     838                                $order = wc_get_order($order_id);
     839                                $getData = $order ? $order->get_meta('ikhokha_data', true) : get_post_meta($order_id, 'ikhokha_data', true);
    719840
    720841                                if (isset($getData['transactionId']) && !empty($getData['transactionId'])) {
    … …  
    722843                                }
    723844
     845                                if (empty($transaction_id) && $order && $order->get_transaction_id()) {
     846                                        $transaction_id = $order->get_transaction_id();
     847                                }
     848
    724849                                if (empty($transaction_id)) {
    725                                         $payment_url = get_post_meta($order_id, 'ikhokha_payment_url', true);
     850                                        $payment_url = $order ? $order->get_meta('ikhokha_payment_url', true) : get_post_meta($order_id, 'ikhokha_payment_url', true);
    726851                                        $arr_payment = explode("/", $payment_url);
    727852                                        $arr_payment_reversed = array_reverse($arr_payment);
    … …  
    803928
    804929                global $post;
    805                 $getData = get_post_meta($post->ID, 'ikhokha_data', true) ? get_post_meta($post->ID, 'ikhokha_data', true) : '';
     930                $post_id = $post ? $post->ID : 0;
     931                $order = wc_get_order($post_id);
     932                $getData = $order ? $order->get_meta('ikhokha_data', true) : get_post_meta($post_id, 'ikhokha_data', true);
     933                $transaction_id = '';
     934
     935                if (isset($getData['transactionId']) && !empty($getData['transactionId'])) {
     936                        $transaction_id = $getData['transactionId'];
     937                } elseif ($order && $order->get_transaction_id()) {
     938                        $transaction_id = $order->get_transaction_id();
     939                }
    806940
    807941                $html = '';
    808                 if (isset($getData['transactionId']) && !empty($getData['transactionId'])) {
    809                         $html .= '<table width="100%"><tbody><tr><td><strong>Transaction ID:</strong></td><td>' . $getData['transactionId'] . '</td></tr></tbody></table>';
     942                if (!empty($transaction_id)) {
     943                        $html .= '<table width="100%"><tbody><tr><td><strong>Transaction ID:</strong></td><td>' . esc_html($transaction_id) . '</td></tr></tbody></table>';
    810944                }
    811945
  • ikhokha-payment-gateway/trunk/readme.md

    r3756918 r3807811  
    66Tested up to: 7.1.3
    77Requires PHP: 7.4
    8 Stable tag: 3.0.4
    9 Version: 3.0.4
     8Stable tag: 3.0.5
     9Version: 3.0.5
    1010License: GPLv2 or later
    1111License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    159159- Standardized one correct text domain across all PHP and JS files.
    160160
     161= 3.0.4 =
     162
     163- Fixes a critical security vulnerability where payment callbacks could be forged on unconfigured or default installations to manipulate order payment statuses. The callback endpoint now strictly fails closed if the gateway is disabled or credentials are missing, enforces defensive header extraction and timing-safe hash_equals signature verification, binds callbacks directly to orders via order_key validation, and ensures orders belong to iKhokha with matching currencies and totals before updating status.
     164
     165= 3.0.5 =
     166
     167- Security & Payment Safety: Resolves cross-order callback reuse vulnerability by enforcing cryptographic/payload reference binding, store-wide transaction ID uniqueness, and idempotent replay handling. Callbacks attempting to reuse an existing transaction ID for a different order are rejected with HTTP 409 Conflict.
     168- Integrity: Resolves false-positive success acknowledgments when WooCommerce rejects order payment completion. If WooCommerce payment_complete() is rejected, the gateway returns HTTP 500, suppresses the false success note, logs an alert note for manual reconciliation, and enables provider retry mechanisms.
     169
    161170== Upgrade Notice ==
    162171= 1.0.0 =
    … …  
    214223
    215224- Fixes a critical security vulnerability where payment callbacks could be forged on unconfigured or default installations to manipulate order payment statuses. The callback endpoint now strictly fails closed if the gateway is disabled or credentials are missing, enforces defensive header extraction and timing-safe hash_equals signature verification, binds callbacks directly to orders via order_key validation, and ensures orders belong to iKhokha with matching currencies and totals before updating status.
     225
     226= 3.0.5 =
     227
     228- Critical payment safety update: Prevents cross-order callback reuse, enforces transaction idempotency, and prevents false success notes on rejected order completions.
Note: See TracChangeset for help on using the changeset viewer.