Created
June 11, 2026 08:58
-
-
Save xlplugins/8ff8ed291b5b9c493de745e00bbea503 to your computer and use it in GitHub Desktop.
mollie mandate find for order
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
| /** | |
| * TEMP DIAGNOSTIC — check Mollie mandates for a given order's customer right now. | |
| * Run on the LIVE site as an admin: /wp-admin/?fk_check_mandate=5644 | |
| * Remove after testing. | |
| */ | |
| add_action( 'admin_init', function () { | |
| if ( ! isset( $_GET['fk_check_mandate'] ) || ! current_user_can( 'manage_woocommerce' ) ) { | |
| return; | |
| } | |
| $order_id = absint( $_GET['fk_check_mandate'] ); | |
| $order = wc_get_order( $order_id ); | |
| if ( ! $order ) { | |
| wp_die( 'Order not found: ' . esc_html( $order_id ) ); | |
| } | |
| if ( ! class_exists( 'WFOCU_Mollie_Helper' ) || ! class_exists( 'WFOCU_Mollie_Helper_Compat' ) ) { | |
| wp_die( 'WFOCU Mollie helper not loaded (is FunnelKit Pro + Mollie active?).' ); | |
| } | |
| // 1) Resolve the Mollie customer id the same way the gateway does. | |
| $customer_id = ''; | |
| if ( $order->get_customer_id() > 0 && ( $user = get_user_by( 'id', $order->get_customer_id() ) ) ) { | |
| $customer_id = $user->mollie_customer_id; | |
| } | |
| if ( empty( $customer_id ) ) { | |
| $customer_id = $order->get_meta( '_mollie_customer_id', true ); | |
| } | |
| if ( empty( $customer_id ) ) { | |
| wp_die( 'No _mollie_customer_id found on order ' . esc_html( $order_id ) ); | |
| } | |
| $container = WFOCU_Mollie_Helper::instance()->container; | |
| $test_mode = WFOCU_Mollie_Helper_Compat::get_settings_helper( $container )->isTestModeEnabled(); | |
| $out = array(); | |
| $out[] = 'Order: ' . $order_id; | |
| $out[] = 'Mollie customer: ' . $customer_id; | |
| $out[] = 'Mode: ' . ( $test_mode ? 'TEST' : 'LIVE' ); | |
| $out[] = 'Checked at (server time): ' . current_time( 'mysql' ); | |
| $out[] = str_repeat( '-', 50 ); | |
| try { | |
| // 2) Same call the upsell flow makes — list this customer's mandates NOW. | |
| $mandates = WFOCU_Mollie_Helper_Compat::get_api_client( $container, $test_mode ) | |
| ->customers->get( $customer_id )->mandates(); | |
| $count = 0; | |
| $has_valid = false; | |
| foreach ( $mandates as $mandate ) { | |
| $count++; | |
| if ( 'valid' === $mandate->status ) { | |
| $has_valid = true; | |
| } | |
| $out[] = sprintf( | |
| "#%d id=%s status=%s method=%s createdAt=%s", | |
| $count, | |
| isset( $mandate->id ) ? $mandate->id : '-', | |
| isset( $mandate->status ) ? $mandate->status : '-', | |
| isset( $mandate->method ) ? $mandate->method : '-', | |
| isset( $mandate->createdAt ) ? $mandate->createdAt : '-' | |
| ); | |
| } | |
| $out[] = str_repeat( '-', 50 ); | |
| $out[] = 'Total mandates: ' . $count; | |
| $out[] = 'Has a VALID mandate now: ' . ( $has_valid ? 'YES ✅ (so it was a timing race — mandate exists now, was missing at upsell-check time)' : 'NO ❌' ); | |
| } catch ( Exception $e ) { | |
| $out[] = 'Mollie API exception: ' . $e->getMessage(); | |
| } | |
| wp_die( '<pre>' . esc_html( implode( "\n", $out ) ) . '</pre>' ); | |
| } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment