'checkout_classic', 'stage' => 'final', 'email' => '', 'billing_country' => '', 'first_name' => '', 'last_name' => '', 'address_1' => '', 'postcode' => '', 'order_id' => 0, 'total' => null, 'items' => 0, 'gateway' => '', 'origin_unknown' => false, ), $given ); if ( ! in_array( $c['route'], self::ROUTES, true ) ) { $c['route'] = 'gateway_ajax'; } $c['ip'] = isset( $given['ip'] ) ? Ip::clean( $given['ip'] ) : Client_Ip::get(); $c['prefix'] = Ip::prefix( $c['ip'] ); $c['user_agent'] = isset( $given['user_agent'] ) ? (string) $given['user_agent'] : Client_Ip::server( 'HTTP_USER_AGENT' ); $c['ua_hash'] = Token::ua_hash( $c['user_agent'] ); $has_language = isset( $given['accept_language'] ) ? (bool) $given['accept_language'] : '' !== Client_Ip::server( 'HTTP_ACCEPT_LANGUAGE' ); $c['headless'] = self::is_scripted( $c['user_agent'], $has_language ); $posted = isset( $given['posted'] ) && is_array( $given['posted'] ) ? $given['posted'] : array(); $field = static function ( $name ) use ( $posted ) { return isset( $posted[ $name ] ) && is_string( $posted[ $name ] ) ? $posted[ $name ] : ''; }; $c['token'] = isset( $given['token'] ) ? (string) $given['token'] : self::input( 'HTTP_X_BM_TOKEN', $field( 'bm_token' ), 'bm_t' ); $c['pass'] = isset( $given['pass'] ) ? (string) $given['pass'] : self::input( 'HTTP_X_BM_PASS', $field( 'bm_pass' ), 'bm_p' ); $c['honeypot'] = isset( $given['honeypot'] ) ? (string) $given['honeypot'] : ( 'checkout_classic' === $c['route'] ? substr( $field( 'bm_hp' ), 0, 400 ) : '' ); unset( $c['posted'] ); $c['user_id'] = isset( $given['user_id'] ) ? (int) $given['user_id'] : (int) get_current_user_id(); $c['order_id'] = (int) $c['order_id']; $c['items'] = (int) $c['items']; $c['total'] = null === $c['total'] ? null : (float) $c['total']; $c['gateway'] = substr( sanitize_key( (string) $c['gateway'] ), 0, 40 ); $c['email'] = is_string( $c['email'] ) ? trim( $c['email'] ) : ''; $c['email_norm'] = Email::normalise( $c['email'] ); $c['billing_country'] = strtoupper( substr( sanitize_text_field( (string) $c['billing_country'] ), 0, 2 ) ); $name = strtolower( trim( (string) $c['first_name'] ) . ' ' . trim( (string) $c['last_name'] ) ); $address = strtolower( trim( (string) $c['address_1'] ) . '|' . trim( (string) $c['postcode'] ) ); $c['addr_hash'] = ( ' ' === $name && '|' === $address ) ? '' : md5( $name . '|' . $address ); unset( $c['first_name'], $c['last_name'], $c['address_1'], $c['postcode'] ); return $c; } /** * Reads a value sent with the request: a header first, then a form field, then a cookie. * This class never reads form fields itself. The checkout guard reads them after checking * the form's nonce (see Guard::posted()) and hands them over. * * @param string $header Key in $_SERVER, or ''. * @param string $posted The form field's value as read by the guard, or ''. * @param string $cookie Cookie name, or ''. * @return string */ public static function input( $header, $posted, $cookie ) { $value = ''; if ( '' !== $header ) { $value = Client_Ip::server( $header ); } if ( '' === $value ) { $value = (string) $posted; } if ( '' === $value && '' !== $cookie && isset( $_COOKIE[ $cookie ] ) && is_string( $_COOKIE[ $cookie ] ) ) { $value = sanitize_text_field( wp_unslash( $_COOKIE[ $cookie ] ) ); } return substr( $value, 0, 400 ); } /** * Whether the client looks like a script rather than a browser a person is using: * a known automation tool, no user agent at all, or no Accept-Language header. * * @param string $user_agent User agent. * @param bool $has_language Whether an Accept-Language header was sent. * @return bool */ public static function is_scripted( $user_agent, $has_language ) { $user_agent = trim( (string) $user_agent ); if ( '' === $user_agent || ! $has_language ) { return true; } return 1 === preg_match( '#HeadlessChrome|PhantomJS|Puppeteer|Playwright|Selenium|python-requests|python-urllib|aiohttp|httpx|curl/|Wget/|Go-http-client|node-fetch|undici|axios/|okhttp|Java/|libwww-perl|Scrapy|Apache-HttpClient|PostmanRuntime|insomnia|^node$|^node[ /]#i', $user_agent ); } /** * Whether WooCommerce's order attribution would show an order's origin as "Unknown". * * @param mixed $source_type The source type sent with the checkout. * @return bool */ public static function origin_is_unknown( $source_type ) { return ! is_string( $source_type ) || ! in_array( $source_type, array( 'utm', 'organic', 'referral', 'typein', 'mobile_app', 'admin' ), true ); } /** * Whether the store records where orders come from (WooCommerce 8.5+ order attribution). * * @return bool */ public static function attribution_enabled() { static $enabled = null; if ( null === $enabled ) { $enabled = class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) && \Automattic\WooCommerce\Utilities\FeaturesUtil::feature_is_enabled( 'order_attribution' ); /** * Filters whether Brickmoat uses WooCommerce's order attribution as a signal. * * @param bool $enabled True when the order attribution feature is on. */ $enabled = (bool) apply_filters( 'brickmoat_use_order_attribution', $enabled ); } return $enabled; } }