<commit_before><?php
/**
 * Apple Pay method class.
 *
 * @package wc_checkout_com
 */

defined( 'ABSPATH' ) || exit;

include_once( 'settings/class-wc-checkoutcom-cards-settings.php' );

/**
 * Class WC_Gateway_Checkout_Com_Apple_Pay for Apple Pay method.
 */
class WC_Gateway_Checkout_Com_Apple_Pay extends WC_Payment_Gateway {

	/**
	 * WC_Gateway_Checkout_Com_Apple_Pay constructor.
	 */
	public function __construct() {
		$this->id                 = 'wc_checkout_com_apple_pay';
		$this->method_title       = __( 'Checkout.com', 'checkout-com-unified-payments-api' );
		$this->method_description = __( 'The Checkout.com extension allows shop owners to process online payments through the <a href="https://www.checkout.com">Checkout.com Payment Gateway.</a>', 'checkout-com-unified-payments-api' );
		$this->title              = __( 'Apple Pay', 'checkout-com-unified-payments-api' );
		$this->has_fields         = true;
		$this->supports           = [
			'products',
			'refunds',
			'subscriptions',
			'subscription_cancellation',
			'subscription_suspension',
			'subscription_reactivation',
			'subscription_date_changes',
		];

		$this->init_form_fields();
		$this->init_settings();

		// Turn these settings into variables we can use.
		foreach ( $this->settings as $setting_key => $value ) {
			$this->$setting_key = $value;
		}

		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, [ $this, 'process_admin_options' ] );

		// Redirection hook.
		add_action( 'woocommerce_api_wc_checkoutcom_session', [ $this, 'applepay_sesion' ] );

		add_action( 'woocommerce_api_wc_checkoutcom_generate_token', [ $this, 'applepay_token' ] );

	}

	/**
	 * Show module configuration in backend.
	 *
	 * @return string|void
	 */
	public function init_form_fields() {
		$this->form_fields = WC_Checkoutcom_Cards_Settings::apple_settings();
		$this->form_fields = array_merge(
			$this->form_fields,
			[
				'screen_button' => [
					'id'    => 'screen_button',
					'type'  => 'screen_button',
					'title' => __( 'Other Settings', 'checkout-com-unified-payments-api' ),
				],
			]
		);
	}

	/**
	 * Generate links for the admin page.
	 *
	 * @param string $key The key.
	 * @param array  $value The value.
	 */
	public function generate_screen_button_html( $key, $value ) {
		WC_Checkoutcom_Admin::generate_links( $key, $value );
	}

	/**
	 * Show frames js on checkout page.
	 */
	public function payment_fields() {
		global $woocommerce;

		$chosen_methods     = wc_get_chosen_shipping_method_ids();
		$chosen_shipping    = $chosen_methods[0];
		$shipping_amount    = WC()->cart->get_shipping_total();
		$checkout_fields    = json_encode( $woocommerce->checkout->checkout_fields, JSON_HEX_APOS );
		$session_url        = str_replace( 'https:', 'https:', add_query_arg( 'wc-api', 'wc_checkoutcom_session', home_url( '/' ) ) );
		$generate_token_url = str_replace( 'https:', 'https:', add_query_arg( 'wc-api', 'wc_checkoutcom_generate_token', home_url( '/' ) ) );
		$apple_settings     = get_option( 'woocommerce_wc_checkout_com_apple_pay_settings' );
		$mada_enabled       = isset( $apple_settings['enable_mada_apple_pay'] ) && ( 'yes' === $apple_settings['enable_mada_apple_pay'] );

		if ( ! empty( $this->get_option( 'description' ) ) ) {
			echo  $this->get_option( 'description' );
		}

		// get country of current user.
		$country_code       = WC()->customer->get_billing_country();
		$supported_networks = [ 'amex', 'masterCard', 'visa' ];

		if ( $mada_enabled ) {
			array_push( $supported_networks, 'mada' );
			$country_code = 'SA';
		}

		?>
		<!-- Input needed to sent the card token --><commit_msg>Fix mada Apple Pay MADA enable settings key<commit_after><?php
/**
 * Apple Pay method class.
 *
 * @package wc_checkout_com
 */

defined( 'ABSPATH' ) || exit;

include_once( 'settings/class-wc-checkoutcom-cards-settings.php' );

/**
 * Class WC_Gateway_Checkout_Com_Apple_Pay for Apple Pay method.
 */
class WC_Gateway_Checkout_Com_Apple_Pay extends WC_Payment_Gateway {

	/**
	 * WC_Gateway_Checkout_Com_Apple_Pay constructor.
	 */
	public function __construct() {
		$this->id                 = 'wc_checkout_com_apple_pay';
		$this->method_title       = __( 'Checkout.com', 'checkout-com-unified-payments-api' );
		$this->method_description = __( 'The Checkout.com extension allows shop owners to process online payments through the <a href="https://www.checkout.com">Checkout.com Payment Gateway.</a>', 'checkout-com-unified-payments-api' );
		$this->title              = __( 'Apple Pay', 'checkout-com-unified-payments-api' );
		$this->has_fields         = true;
		$this->supports           = [
			'products',
			'refunds',
			'subscriptions',
			'subscription_cancellation',
			'subscription_suspension',
			'subscription_reactivation',
			'subscription_date_changes',
		];

		$this->init_form_fields();
		$this->init_settings();

		// Turn these settings into variables we can use.
		foreach ( $this->settings as $setting_key => $value ) {
			$this->$setting_key = $value;
		}

		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, [ $this, 'process_admin_options' ] );

		// Redirection hook.
		add_action( 'woocommerce_api_wc_checkoutcom_session', [ $this, 'applepay_sesion' ] );

		add_action( 'woocommerce_api_wc_checkoutcom_generate_token', [ $this, 'applepay_token' ] );

	}

	/**
	 * Show module configuration in backend.
	 *
	 * @return string|void
	 */
	public function init_form_fields() {
		$this->form_fields = WC_Checkoutcom_Cards_Settings::apple_settings();
		$this->form_fields = array_merge(
			$this->form_fields,
			[
				'screen_button' => [
					'id'    => 'screen_button',
					'type'  => 'screen_button',
					'title' => __( 'Other Settings', 'checkout-com-unified-payments-api' ),
				],
			]
		);
	}

	/**
	 * Generate links for the admin page.
	 *
	 * @param string $key The key.
	 * @param array  $value The value.
	 */
	public function generate_screen_button_html( $key, $value ) {
		WC_Checkoutcom_Admin::generate_links( $key, $value );
	}

	/**
	 * Show frames js on checkout page.
	 */
	public function payment_fields() {
		global $woocommerce;

		$chosen_methods     = wc_get_chosen_shipping_method_ids();
		$chosen_shipping    = $chosen_methods[0];
		$shipping_amount    = WC()->cart->get_shipping_total();
		$checkout_fields    = json_encode( $woocommerce->checkout->checkout_fields, JSON_HEX_APOS );
		$session_url        = str_replace( 'https:', 'https:', add_query_arg( 'wc-api', 'wc_checkoutcom_session', home_url( '/' ) ) );
		$generate_token_url = str_replace( 'https:', 'https:', add_query_arg( 'wc-api', 'wc_checkoutcom_generate_token', home_url( '/' ) ) );
		$apple_settings     = get_option( 'woocommerce_wc_checkout_com_apple_pay_settings' );
		$mada_enabled       = isset( $apple_settings['enable_mada'] ) && ( 'yes' === $apple_settings['enable_mada'] );

		if ( ! empty( $this->get_option( 'description' ) ) ) {
			echo  $this->get_option( 'description' );
		}

		// get country of current user.
		$country_code       = WC()->customer->get_billing_country();
		$supported_networks = [ 'amex', 'masterCard', 'visa' ];

		if ( $mada_enabled ) {
			array_push( $supported_networks, 'mada' );
			$country_code = 'SA';
		}

		?>
		<!-- Input needed to sent the card token -->
{'fraction_non_alphanumeric': 0.14929887269727798, 'fraction_numerical': 0.00027495188342040145, 'mean_word_length': 3.9155405405405403, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 65, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2363436', 'n_tokens_mistral': 2709, 'n_tokens_neox': 2493, 'n_words': 449}