Skip to content

Commit 354e290

Browse files
committed
fix: Apple Pay domain verification automatic registration
- Fix hook to use correct gateway (monei_apple_google instead of monei) - Fix POST field check to use woocommerce_monei_apple_google_enabled - Replace wp_remote_get() with direct readfile() for better performance - Remove esc_html() from file output to preserve raw binary content - Add proper Content-Type and Content-Disposition headers The automatic domain registration now works when enabling Apple/Google Pay in WooCommerce settings, and the verification file is served correctly.
1 parent 8aa2787 commit 354e290

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/Services/MoneiApplePayVerificationService.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class MoneiApplePayVerificationService {
2222
public function __construct( MoneiPaymentServices $moneiPaymentServices ) {
2323
$this->moneiPaymentServices = $moneiPaymentServices;
2424
add_action( 'parse_request', array( $this, 'expose_on_domain_association_request' ), 1 );
25-
add_filter( 'woocommerce_update_options_payment_gateways_monei', array( $this, 'apple_domain_register' ) );
25+
add_filter( 'woocommerce_update_options_payment_gateways_monei_apple_google', array( $this, 'apple_domain_register' ) );
2626
}
2727

2828
/**
@@ -33,11 +33,12 @@ public function apple_domain_register() {
3333
return;
3434
}
3535

36-
if ( ! isset( $_POST['woocommerce_monei_apple_google_pay'] ) ) {
36+
// Check if Apple/Google Pay is being enabled
37+
if ( ! isset( $_POST['woocommerce_monei_apple_google_enabled'] ) ) {
3738
return;
3839
}
3940
//phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
40-
if ( ! wc_clean( wp_unslash( $_POST['woocommerce_monei_apple_google_pay'] ) ) ) {
41+
if ( 'yes' !== wc_clean( wp_unslash( $_POST['woocommerce_monei_apple_google_enabled'] ) ) ) {
4142
return;
4243
}
4344

@@ -58,12 +59,15 @@ public function apple_domain_register() {
5859
*/
5960
public function expose_on_domain_association_request( $wp ) {
6061
if ( isset( $wp->request ) && ( self::DOMAIN_ASSOCIATION_DIR . '/' . self::DOMAIN_ASSOCIATION_FILE_NAME ) === $wp->request ) {
61-
$path = WC_Monei()->plugin_url() . '/' . self::DOMAIN_ASSOCIATION_FILE_NAME;
62-
$args = array( 'headers' => array( 'Content-Type' => 'text/plain;charset=utf-8' ) );
63-
$response = wp_remote_get( $path, $args );
64-
if ( ! is_wp_error( $response ) && is_array( $response ) ) {
65-
$body = $response['body'];
66-
echo esc_html( $response['body'] );
62+
$file_path = WC_Monei()->plugin_path() . '/' . self::DOMAIN_ASSOCIATION_FILE_NAME;
63+
64+
if ( file_exists( $file_path ) ) {
65+
header( 'Content-Type: text/plain' );
66+
header( 'Content-Disposition: inline; filename="' . self::DOMAIN_ASSOCIATION_FILE_NAME . '"' );
67+
readfile( $file_path );
68+
} else {
69+
status_header( 404 );
70+
echo 'Apple Pay domain verification file not found';
6771
}
6872
exit;
6973
}

0 commit comments

Comments
 (0)