Created
December 10, 2025 12:19
-
-
Save OneStep21/838891e992649c8d2f91cc07fc2ea6da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Check MAIB transaction status | |
| add_action('admin_enqueue_scripts', function() { | |
| wp_localize_script('jquery', 'ajax_object', [ | |
| 'ajax_url' => admin_url('admin-ajax.php'), | |
| ]); | |
| }); | |
| add_action('woocommerce_order_item_add_action_buttons', function ($order) { | |
| if ($order->get_payment_method() !== 'moldovaagroindbank') { | |
| return; | |
| } | |
| echo '<button type="button" class="button maib-check-status" | |
| data-id="' . esc_attr($order->get_id()) . '" | |
| style="margin-left:8px;background:#159544;color:white;"> | |
| Check MAIB | |
| </button>'; | |
| }); | |
| add_action('admin_footer', function () { | |
| ?> | |
| <script> | |
| jQuery(document).on("click", ".maib-check-status", function () { | |
| if (!confirm("Check transaction status throught MAIB?")) return; | |
| const orderId = jQuery(this).data("id"); | |
| const ajaxUrl = (typeof ajax_object !== "undefined") | |
| ? ajax_object.ajax_url | |
| : "<?php echo admin_url('admin-ajax.php'); ?>"; | |
| console.log("AJAX URL →", ajaxUrl); | |
| jQuery.post(ajaxUrl, { | |
| action: "maib_manual_check", | |
| order_id: orderId | |
| }) | |
| .done(function(response) { | |
| console.log("MAIB RESPONSE →", response); | |
| if (!response) { | |
| alert("Empty response from server"); | |
| return; | |
| } | |
| if (response.success) { | |
| alert(response.data.message); | |
| location.reload(); | |
| } else { | |
| alert("Error MAIB: " + response.data.message); | |
| } | |
| }) | |
| .fail(function(xhr, status, error) { | |
| console.error("AJAX FAILED"); | |
| console.log("STATUS:", status); | |
| console.log("ERROR:", error); | |
| console.log("RESPONSE:", xhr.responseText); | |
| alert("AJAX ERROR — check console"); | |
| }); | |
| }); | |
| </script> | |
| <?php | |
| }); | |
| add_action('wp_ajax_maib_manual_check', 'maib_manual_check_handler'); | |
| function maib_manual_check_handler() { | |
| if (!current_user_can('manage_woocommerce')) { | |
| wp_send_json_error(['message' => 'No enought rules']); | |
| } | |
| $order_id = intval($_POST['order_id'] ?? 0); | |
| if (!$order_id) { | |
| wp_send_json_error(['message' => 'No order_id provided']); | |
| } | |
| $order = wc_get_order($order_id); | |
| if (!$order) { | |
| wp_send_json_error(['message' => 'Order is not found']); | |
| } | |
| if ($order->get_payment_method() !== WC_MoldovaAgroindbank::MOD_ID) { | |
| wp_send_json_error(['message' => 'Its not a MAIB order']); | |
| } | |
| $gateway = new WC_MoldovaAgroindbank(); | |
| // Check status (command=v) | |
| $result = $gateway->verify_transaction($order); | |
| if ($result) { | |
| wp_send_json_success([ | |
| 'message' => 'Check finished. Check order comments.', | |
| ]); | |
| } else { | |
| wp_send_json_error([ | |
| 'message' => 'MAIB: There is no result.', | |
| ]); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment