Skip to content

Commit 362a39c

Browse files
committed
feat: add extensive debug logging to Apple Pay domain registration
- Add debug logging at each step of registration flow - Log when hook is triggered, nonce verification, enabled check - Log domain value being sent to API - Log API response body on success and failure - Accept both 'yes' and '1' as enabled values (checkbox compatibility) - Add user-facing success/error messages in admin This will help diagnose if automatic registration is working properly. To test: Enable Apple/Google Pay in WooCommerce > Settings > Payments and check debug.log for registration status.
1 parent 354e290 commit 362a39c

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/Services/MoneiApplePayVerificationService.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,49 @@ public function __construct( MoneiPaymentServices $moneiPaymentServices ) {
2727

2828
/**
2929
* Apple API Domain registration.
30+
* Automatically registers domain with Apple Pay when gateway is enabled.
3031
*/
3132
public function apple_domain_register() {
33+
WC_Monei_Logger::log( 'Apple domain registration hook triggered', 'debug' );
34+
3235
if ( ! check_admin_referer( 'woocommerce-settings' ) ) {
36+
WC_Monei_Logger::log( 'Apple domain registration: nonce verification failed', 'debug' );
3337
return;
3438
}
3539

36-
// Check if Apple/Google Pay is being enabled
40+
// Check if Apple/Google Pay is enabled
3741
if ( ! isset( $_POST['woocommerce_monei_apple_google_enabled'] ) ) {
42+
WC_Monei_Logger::log( 'Apple domain registration: enabled field not set', 'debug' );
3843
return;
3944
}
4045
//phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
41-
if ( 'yes' !== wc_clean( wp_unslash( $_POST['woocommerce_monei_apple_google_enabled'] ) ) ) {
46+
$enabled_value = wc_clean( wp_unslash( $_POST['woocommerce_monei_apple_google_enabled'] ) );
47+
WC_Monei_Logger::log( 'Apple domain registration: enabled value = ' . $enabled_value, 'debug' );
48+
49+
if ( 'yes' !== $enabled_value && '1' !== $enabled_value ) {
50+
WC_Monei_Logger::log( 'Apple domain registration: gateway not enabled', 'debug' );
4251
return;
4352
}
4453

4554
try {
4655
$domain = isset( $_SERVER['HTTP_HOST'] ) ? sanitize_text_field( $_SERVER['HTTP_HOST'] ) : str_replace( array( 'https://', 'http://' ), '', get_site_url() ); // @codingStandardsIgnoreLine
47-
$this->moneiPaymentServices->register_apple_domain( $domain );
56+
57+
WC_Monei_Logger::log( 'Attempting to register Apple Pay domain: ' . $domain, 'info' );
58+
59+
$result = $this->moneiPaymentServices->register_apple_domain( $domain );
60+
61+
WC_Monei_Logger::log( 'Apple Pay domain registration successful for: ' . $domain, 'info' );
62+
WC_Monei_Logger::log( 'Registration result: ' . wp_json_encode( $result ), 'debug' );
63+
\WC_Admin_Settings::add_message( __( 'Apple Pay domain registered successfully.', 'monei' ) );
4864
} catch ( ApiException $e ) {
49-
WC_Monei_Logger::log( $e, 'error' );
65+
WC_Monei_Logger::log( 'Apple Pay domain registration failed: ' . $e->getMessage(), 'error' );
66+
WC_Monei_Logger::log( 'Exception response body: ' . $e->getResponseBody(), 'error' );
5067
$response_body = json_decode( $e->getResponseBody() );
51-
WC_Admin_Settings::add_error( __( 'Apple', 'monei' ) . ' ' . $response_body->message );
68+
if ( $response_body && isset( $response_body->message ) ) {
69+
\WC_Admin_Settings::add_error( __( 'Apple Pay', 'monei' ) . ': ' . $response_body->message );
70+
} else {
71+
\WC_Admin_Settings::add_error( __( 'Apple Pay domain registration failed. Please check the logs.', 'monei' ) );
72+
}
5273
}
5374
}
5475

0 commit comments

Comments
 (0)