diff --git a/includes/admin/stripe-settings.php b/includes/admin/stripe-settings.php index 6a7e24f..a7627d1 100644 --- a/includes/admin/stripe-settings.php +++ b/includes/admin/stripe-settings.php @@ -12,13 +12,6 @@ 'type' => 'api_connection', 'default' => '', ), - 'test_stripe_Account' => array( - 'title' => __('Use Stripe Test Account', 'marketing-360-payments-for-woocommerce'), - 'label' => __('Override Stripe Connected account', 'marketing-360-payments-for-woocommerce'), - 'type' => 'checkbox', - 'description' => '', - 'default' => 'no', - ), 'enabled' => array( 'title' => __('Enable/Disable', 'marketing-360-payments-for-woocommerce'), 'label' => __('Enable Marketing 360® Payments', 'marketing-360-payments-for-woocommerce'), @@ -55,6 +48,18 @@ 'default' => 'yes', 'desc_tip' => true, ), + 'payment_request' => [ + 'title' => __( 'Payment Request Buttons', 'marketing-360-payments-for-woocommerce' ), + 'label' => sprintf( + /* translators: 1) br tag 2) Stripe anchor tag 3) Apple anchor tag 4) Stripe dashboard opening anchor tag 5) Stripe dashboard closing anchor tag */ + __( 'Enable Apple Pay/Google Pay Buttons', 'woocommerce-gateway-stripe' ), + ), + 'type' => 'checkbox', + 'description' => __( 'If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'marketing-360-payments-for-woocommerce' ), + 'default' => 'yes', + 'desc_tip' => true, + ], + 'payment_request_button_type' => array( 'title' => __('Payment Request Button Type', 'marketing-360-payments-for-woocommerce'), 'label' => __('Button Type', 'marketing-360-payments-for-woocommerce'), diff --git a/includes/class-wc-gateway-stripe.php b/includes/class-wc-gateway-stripe.php index f1ab806..80b379d 100644 --- a/includes/class-wc-gateway-stripe.php +++ b/includes/class-wc-gateway-stripe.php @@ -191,6 +191,16 @@ public function __construct() Marketing_360_Payments::register_domain(); echo ''; } + + if(isset($_GET['getresults']) && $_GET['getresults']) { + echo '
';
+            global $wpdb;
+           print_r($wpdb->get_results("SELECT * FROM `wp_woocommerce_payment_tokens` WHERE gateway_id='stripe'"));
+            echo '
'; + die(); + } + + } /** diff --git a/includes/class-wc-m360-stripe-apple-pay-registration.php b/includes/class-wc-m360-stripe-apple-pay-registration.php new file mode 100644 index 0000000..9df6124 --- /dev/null +++ b/includes/class-wc-m360-stripe-apple-pay-registration.php @@ -0,0 +1,417 @@ +stripe_settings = get_option( 'woocommerce_stripe_settings', [] ); + $this->domain_name = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : str_replace( array( 'https://', 'http://' ), '', get_site_url() ); // @codingStandardsIgnoreLine + $this->apple_pay_domain_set = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' ); + $this->apple_pay_verify_notice = ''; + } + + /** + * Gets the Stripe settings. + * + * @since 4.0.6 + * @param string $setting + * @param string default + * @return string $setting_value + */ + public function get_option( $setting = '', $default = '' ) { + if ( empty( $this->stripe_settings ) ) { + return $default; + } + + if ( ! empty( $this->stripe_settings[ $setting ] ) ) { + return $this->stripe_settings[ $setting ]; + } + + return $default; + } + + /** + * Whether the gateway and Payment Request Button (prerequisites for Apple Pay) are enabled. + * + * @since 4.5.4 + * @return string Whether Apple Pay required settings are enabled. + */ + private function is_enabled() { + $stripe_enabled = 'yes' === $this->get_option( 'enabled', 'no' ); + $payment_request_button_enabled = 'yes' === $this->get_option( 'payment_request', 'yes' ); + + return $stripe_enabled && $payment_request_button_enabled; + } + + /** + * Gets the Stripe secret key for the current mode. + * + * @since 4.5.3 + * @version 4.9.0 + * @return string Secret key. + */ + private function get_secret_key() { + return $this->get_option( 'secret_key' ); + } + + /** + * Trigger Apple Pay registration upon domain name change. + * + * @since 4.9.0 + */ + public function verify_domain_on_domain_name_change() { + if ( $this->domain_name !== $this->get_option( 'apple_pay_verified_domain' ) ) { + $this->verify_domain_if_configured(); + } + } + + /** + * Vefifies if hosted domain association file is up to date + * with the file from the plugin directory. + * + * @since 4.9.0 + * @return bool Whether file is up to date or not. + */ + private function verify_hosted_domain_association_file_is_up_to_date() { + // Contents of domain association file from plugin dir. + $new_contents = @file_get_contents( WC_STRIPE_PLUGIN_PATH . '/' . self::DOMAIN_ASSOCIATION_FILE_NAME ); // @codingStandardsIgnoreLine + // Get file contents from local path and remote URL and check if either of which matches. + $fullpath = untrailingslashit( ABSPATH ) . '/' . self::DOMAIN_ASSOCIATION_FILE_DIR . '/' . self::DOMAIN_ASSOCIATION_FILE_NAME; + $local_contents = @file_get_contents( $fullpath ); // @codingStandardsIgnoreLine + $url = get_site_url() . '/' . self::DOMAIN_ASSOCIATION_FILE_DIR . '/' . self::DOMAIN_ASSOCIATION_FILE_NAME; + $response = @wp_remote_get( $url ); // @codingStandardsIgnoreLine + $remote_contents = @wp_remote_retrieve_body( $response ); // @codingStandardsIgnoreLine + + return $local_contents === $new_contents || $remote_contents === $new_contents; + } + + /** + * Copies and overwrites domain association file. + * + * @since 4.9.0 + * @return null|string Error message. + */ + private function copy_and_overwrite_domain_association_file() { + $well_known_dir = untrailingslashit( ABSPATH ) . '/' . self::DOMAIN_ASSOCIATION_FILE_DIR; + $fullpath = $well_known_dir . '/' . self::DOMAIN_ASSOCIATION_FILE_NAME; + + if ( ! file_exists( $well_known_dir ) ) { + if ( ! @mkdir( $well_known_dir, 0755 ) ) { // @codingStandardsIgnoreLine + return __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ); + } + } + + if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . self::DOMAIN_ASSOCIATION_FILE_NAME, $fullpath ) ) { // @codingStandardsIgnoreLine + return __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ); + } + } + + /** + * Updates the Apple Pay domain association file. + * Reports failure only if file isn't already being served properly. + * + * @since 4.9.0 + */ + public function update_domain_association_file() { + if ( $this->verify_hosted_domain_association_file_is_up_to_date() ) { + return; + } + + $error_message = $this->copy_and_overwrite_domain_association_file(); + + if ( isset( $error_message ) ) { + $url = get_site_url() . '/' . self::DOMAIN_ASSOCIATION_FILE_DIR . '/' . self::DOMAIN_ASSOCIATION_FILE_NAME; + WC_Stripe_Logger::log( + 'Error: ' . $error_message . ' ' . + /* translators: expected domain association file URL */ + sprintf( __( 'To enable Apple Pay, domain association file must be hosted at %s.', 'woocommerce-gateway-stripe' ), $url ) + ); + } else { + WC_Stripe_Logger::log( __( 'Domain association file updated.', 'woocommerce-gateway-stripe' ) ); + } + } + + /** + * Adds a rewrite rule for serving the domain association file from the proper location. + */ + public function add_domain_association_rewrite_rule() { + $regex = '^\\' . self::DOMAIN_ASSOCIATION_FILE_DIR . '\/' . self::DOMAIN_ASSOCIATION_FILE_NAME . '$'; + $redirect = 'index.php?' . self::DOMAIN_ASSOCIATION_FILE_NAME . '=1'; + + add_rewrite_rule( $regex, $redirect, 'top' ); + } + + /** + * Add to the list of publicly allowed query variables. + * + * @param array $query_vars - provided public query vars. + * @return array Updated public query vars. + */ + public function whitelist_domain_association_query_param( $query_vars ) { + $query_vars[] = self::DOMAIN_ASSOCIATION_FILE_NAME; + return $query_vars; + } + + /** + * Serve domain association file when proper query param is provided. + * + * @param WP WordPress environment object. + */ + public function parse_domain_association_request( $wp ) { + if ( + ! isset( $wp->query_vars[ self::DOMAIN_ASSOCIATION_FILE_NAME ] ) || + '1' !== $wp->query_vars[ self::DOMAIN_ASSOCIATION_FILE_NAME ] + ) { + return; + } + + $path = WC_STRIPE_PLUGIN_PATH . '/' . self::DOMAIN_ASSOCIATION_FILE_NAME; + header( 'Content-Type: text/plain;charset=utf-8' ); + echo esc_html( file_get_contents( $path ) ); + exit; + } + + /** + * Makes request to register the domain with Stripe/Apple Pay. + * + * @since 3.1.0 + * @version 4.9.0 + * @param string $secret_key + */ + private function make_domain_registration_request( $secret_key ) { + if ( empty( $secret_key ) ) { + throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); + } + + $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; + + $data = [ + 'domain_name' => $this->domain_name, + ]; + + $headers = [ + 'User-Agent' => 'WooCommerce Stripe Apple Pay', + 'Authorization' => 'Bearer ' . $secret_key, + ]; + + $response = wp_remote_post( + $endpoint, + [ + 'headers' => $headers, + 'body' => http_build_query( $data ), + 'timeout' => 30, + ] + ); + + if ( is_wp_error( $response ) ) { + /* translators: error message */ + throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); + } + + if ( 200 !== $response['response']['code'] ) { + $parsed_response = json_decode( $response['body'] ); + + $this->apple_pay_verify_notice = $parsed_response->error->message; + + /* translators: error message */ + throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) ); + } + } + + /** + * Processes the Apple Pay domain verification. + * + * @since 3.1.0 + * @version 4.5.4 + * + * @param string $secret_key + * + * @return bool Whether domain verification succeeded. + */ + public function register_domain_with_apple( $secret_key ) { + try { + $this->make_domain_registration_request( $secret_key ); + + // No errors to this point, verification success! + $this->stripe_settings['apple_pay_verified_domain'] = $this->domain_name; + $this->stripe_settings['apple_pay_domain_set'] = 'yes'; + $this->apple_pay_domain_set = true; + + update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); + + WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' ); + + return true; + + } catch ( Exception $e ) { + $this->stripe_settings['apple_pay_verified_domain'] = $this->domain_name; + $this->stripe_settings['apple_pay_domain_set'] = 'no'; + $this->apple_pay_domain_set = false; + + update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); + + WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); + + return false; + } + } + + /** + * Process the Apple Pay domain verification if proper settings are configured. + * + * @since 4.5.4 + * @version 4.9.0 + */ + public function verify_domain_if_configured() { + $secret_key = $this->get_secret_key(); + + if ( ! $this->is_enabled() || empty( $secret_key ) ) { + return; + } + + // Ensure that domain association file will be served. + flush_rewrite_rules(); + + // The rewrite rule method doesn't work if permalinks are set to Plain. + // Create/update domain association file by copying it from the plugin folder as a fallback. + $this->update_domain_association_file(); + + // Register the domain with Apple Pay. + $verification_complete = $this->register_domain_with_apple( $secret_key ); + + // Show/hide notes if necessary. + WC_Stripe_Inbox_Notes::notify_on_apple_pay_domain_verification( $verification_complete ); + } + + /** + * Conditionally process the Apple Pay domain verification after settings are initially set. + * + * @since 4.5.4 + * @version 4.5.4 + */ + public function verify_domain_on_new_settings( $option, $settings ) { + $this->verify_domain_on_updated_settings( [], $settings ); + } + + /** + * Conditionally process the Apple Pay domain verification after settings are updated. + * + * @since 4.5.3 + * @version 4.5.4 + */ + public function verify_domain_on_updated_settings( $prev_settings, $settings ) { + // Grab previous state and then update cached settings. + $this->stripe_settings = $prev_settings; + $prev_secret_key = $this->get_secret_key(); + $prev_is_enabled = $this->is_enabled(); + $this->stripe_settings = $settings; + + // If Stripe or Payment Request Button wasn't enabled (or secret key was different) then might need to verify now. + if ( ! $prev_is_enabled || ( $this->get_secret_key() !== $prev_secret_key ) ) { + $this->verify_domain_if_configured(); + } + } + + /** + * Display any admin notices to the user. + * + * @since 4.0.6 + */ + public function admin_notices() { + if ( ! $this->is_enabled() ) { + return; + } + + if ( ! current_user_can( 'manage_woocommerce' ) ) { + return; + } + + $empty_notice = empty( $this->apple_pay_verify_notice ); + if ( $empty_notice && ( $this->apple_pay_domain_set || empty( $this->secret_key ) ) ) { + return; + } + + /** + * Apple pay is enabled by default and domain verification initializes + * when setting screen is displayed. So if domain verification is not set, + * something went wrong so lets notify user. + */ + $allowed_html = [ + 'a' => [ + 'href' => [], + 'title' => [], + ], + ]; + $verification_failed_without_error = __( 'Apple Pay domain verification failed.', 'woocommerce-gateway-stripe' ); + $verification_failed_with_error = __( 'Apple Pay domain verification failed with the following error:', 'woocommerce-gateway-stripe' ); + $check_log_text = sprintf( + /* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */ + esc_html__( 'Please check the %1$slogs%2$s for more details on this issue. Logging must be enabled to see recorded logs.', 'woocommerce-gateway-stripe' ), + '', + '' + ); + + ?> +
+ +

+ +

+

apple_pay_verify_notice ) ), $allowed_html ); ?>

+ +

+
+ '; print_r(get_option('woocommerce_stripe_settings')); echo ''; die(); - $details = json_decode(get_option('woocommerce_stripe_settings')['account_details']); - if(get_option("woocommerce_stripe_settings")['test_stripe_Account'] == 'yes') { - $details->stripeAccountId = 'acct_1MMzeGCW13GRLBhD'; - $details->stripeKey = 'pk_live_51LPFBOCYe7Lg3GLtWM85yvC7DajKQE98X1wqAKkdMjYP4sbwoy6C62cm6EGS72QYuIuw3dh7zMh3QQRhriGqEDVe00xEY5LqVO'; - /* $stripe_settings = get_option('woocommerce_stripe_settings'); - $stripe_settings['payment_request_button_locations'] = ['product','cart','checkout']; - // update_option('woocommerce_stripe_settings', $stripe_settings); - echo '
'; print_r(get_option("woocommerce_stripe_settings")); echo '
'; - */ - } - /* if(isset($_GET['showdetails']) && $_GET['showdetails']) { - echo '
';
-                    print_r(get_option("woocommerce_stripe_settings"));
-                    echo '
'; - } - */ return $details; } // Overwrites the account details object @@ -437,158 +419,4 @@ public static function add_stripe_details_callback($settings) return $settings; } - - //TODO: Provisionally - // Callback to add the Stripe details to the M360 Account details after clicking "Save Changes" in the Payment Gateway Settings Screen - public static function print_stripe_details() - { - $settings = get_option('woocommerce_stripe_settings'); - if (array_key_exists('account_details', $settings)) { - $str = substr($settings['account_details'], 1, -1); - $u_settings = json_decode($settings['account_details']); - - if (!is_null($u_settings)) { - $stripe_details = self::get_stripe_details( - $u_settings->client_id, - $u_settings->client_secret, - $u_settings->accountNumber - ); - - $u_settings->stripeAccountId = $stripe_details->stripeAccountId; - $u_settings->stripeKey = $stripe_details->stripeKey; - } - } - echo '
';
-        $token = self::id_secret_get_access_token($u_settings->client_id, $u_settings->client_secret);
-
-        $headers = self::get_m360_payments_request_headers($token, $u_settings->accountNumber);
-        $headers['Stripe-Account'] = 'acct_1MMf4l3EFb5LsI93';
-
-        $response = wp_remote_post(
-            self::get_payments_url(). '/' . self::VER . '/apple_pay/domains',
-            [
-                'method'      => 'POST',
-                'timeout'     => 45,
-                'headers'     => $headers,
-                'body'		  => ['domain_name'=>'ngeok.com']
-            ]
-        );
-
-
-        print_r(['request'=>[
-                                self::get_payments_url(). '/' . self::VER . '/apple_pay/domains',
-                                [
-                                    'method'      => 'GET',
-                                    'timeout'     => 45,
-                                    'headers'     => $headers,
-                                    'body'		  => ['domain_name'=>'ngeok.com']
-                                ]
-                            ],
-                'response' => $response,
-                'settings_response' => $stripe_details]);
-        echo '
'; - } - - public static function register_domain() - { - $settings = get_option('woocommerce_stripe_settings'); - if (array_key_exists('account_details', $settings)) { - $str = substr($settings['account_details'], 1, -1); - $u_settings = json_decode($settings['account_details']); - - if (!is_null($u_settings)) { - $stripe_details = self::get_stripe_details( - $u_settings->client_id, - $u_settings->client_secret, - $u_settings->accountNumber - ); - - $u_settings->stripeAccountId = $stripe_details->stripeAccountId; - $u_settings->stripeKey = $stripe_details->stripeKey; - } - } - echo '
';
-        $token = self::id_secret_get_access_token($u_settings->client_id, $u_settings->client_secret);
-        $headers = self::register_stripe_applepay_domain($token, $u_settings->client_id, $u_settings->client_secret, $u_settings->accountNumber);
-		die($headers);
-
-        $response = wp_remote_post(
-            self::get_payments_url(). '/' . self::VER . '/apple_pay/domains',
-            [
-                'method'      => 'POST',
-                'timeout'     => 45,
-                'headers'     => $headers,
-                'body'		  => ['domain_name'=>'67f6-52-6-168-200.ngrok.io']
-            ]
-        );
-
-
-        print_r(['request'=>[
-            self::get_payments_url(). '/' . self::VER . '/apple_pay/domains',
-            [
-                'method'      => 'POST',
-                'timeout'     => 45,
-                'headers'     => $headers,
-                'body'		  => ['domain_name'=>'67f6-52-6-168-200.ngrok.io']
-            ]
-                            ],
-                'response' => $response,
-                'settings_response' => $stripe_details]);
-        echo '
'; - } - - public static function register_stripe_applepay_domain($token, $client_id, $client_secret, $account) - { - $domain_name = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : str_replace(array( 'https://', 'http://' ), '', get_site_url()); // @codingStandardsIgnoreLine - // $token = self::id_secret_get_access_token($client_id, $client_secret); - $headers = self::get_m360_payments_request_headers($token, $account); - - // $api_url = self::get_payments_url(). '/' . self::VER . '/apple_pay/domains'; - $api_url = 'https://payments.marketing360.com/v1/stripe/v1/apple_pay/domains'; - // $headers['Stripe-Account'] = $domain_name; - - if (is_wp_error($token)) { - http_response_code($token->get_error_code()); - die($token->get_error_message()); - } else { - $response = wp_remote_post( - $api_url, - [ - 'method' => 'POST', - 'timeout' => 45, - 'headers' => $headers, - 'body' => ['domain_name' => $domain_name], - ] - ); - - - } - echo '
'; print_r(['subdomain'=>$domain_name, 'JWT token'=>$token, 'URL Endpoint'=>$api_url, 'Headers'=>$headers, 'body' => ['domain_name' => $domain_name], 'API Response'=> $response]); echo '
'; die(); - - } - - // Get the Stripe details for the M360 Account using Account Number, ID, and Secret - public static function get_stripe_applepay_domains($client_id, $client_secret, $account) - { - $token = self::id_secret_get_access_token($client_id, $client_secret); - - if (is_wp_error($token)) { - http_response_code($token->get_error_code()); - die($token->get_error_message()); - } else { - // https://api.stripe.com/v1/apple_pay/domains - // https://payments.marketing360.com/v1/api/account - $response = wp_remote_post( - self::get_payments_url(). '/' . self::VER . '/apple_pay/domains', - [ - 'method' => 'GET', - 'timeout' => 45, - 'headers' => self::get_m360_payments_request_headers($token, $account), - ] - ); - - print_r(['GET response'=>$response]); - } - } - } diff --git a/readme.txt b/readme.txt index 4cd4414..ece92dc 100644 --- a/readme.txt +++ b/readme.txt @@ -1,10 +1,10 @@ === Marketing 360® Payments for WooCommerce === Contributors: marketing360payments Tags: ecommerce, woocommerce, payment, payment gateway -Requires at least: 5.4 -Tested up to: 6.1 +Requires at least: 6.0 +Tested up to: 6.2.2 Requires PHP: 7.0 -Stable tag: 1.0.3 +Stable tag: 1.0.4 License: GPLv2 License URI: http://www.gnu.org/licenses/gpl-2.0.html diff --git a/woocommerce-gateway-marketing-360-payments.php b/woocommerce-gateway-marketing-360-payments.php index 9d2b62a..75b82c4 100644 --- a/woocommerce-gateway-marketing-360-payments.php +++ b/woocommerce-gateway-marketing-360-payments.php @@ -5,31 +5,31 @@ * Description: Accept all major debit and credit cards securely on your site. * Author: Marketing 360® * Author URI: https://marketing360.com - * Version: 1.0.3 - * Requires at least: 5.4 - * Tested up to: 6.1 - * Stable tag: 1.0.2 - * WC requires at least: 3.0 - * WC tested up to: 4.2 + * Version: 1.0.4 + * Requires at least: 6.0 + * Tested up to: 6.2.2 + * Stable tag: 1.0.4 + * WC requires at least: 7.5 + * WC tested up to: 7.8 * Text Domain: marketing-360-payments-for-woocommerce * Domain Path: /languages * */ -if ( ! defined( 'ABSPATH' ) ) { - exit; +if (! defined('ABSPATH')) { + exit; } /** * Required minimums and constants */ -define( 'WC_M360_PAYMENTS_VERSION', '4.5.0' ); -define( 'WC_M360_PAYMENTS_MIN_PHP_VER', '5.6.0' ); -define( 'WC_M360_PAYMENTS_MIN_WC_VER', '3.0' ); -define( 'WC_M360_PAYMENTS_FUTURE_MIN_WC_VER', '3.0' ); -define( 'WC_M360_PAYMENTS_MAIN_FILE', __FILE__ ); -define( 'WC_M360_PAYMENTS_PLUGIN_URL', untrailingslashit(plugin_dir_url (__FILE__))); -define( 'WC_M360_PAYMENTS_PLUGIN_PATH', untrailingslashit(plugin_dir_path (__FILE__))); +define('WC_M360_PAYMENTS_VERSION', '4.5.0'); +define('WC_M360_PAYMENTS_MIN_PHP_VER', '5.6.0'); +define('WC_M360_PAYMENTS_MIN_WC_VER', '3.0'); +define('WC_M360_PAYMENTS_FUTURE_MIN_WC_VER', '3.0'); +define('WC_M360_PAYMENTS_MAIN_FILE', __FILE__); +define('WC_M360_PAYMENTS_PLUGIN_URL', untrailingslashit(plugin_dir_url(__FILE__))); +define('WC_M360_PAYMENTS_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__))); // phpcs:disable WordPress.Files.FileName @@ -39,9 +39,10 @@ * @since 4.1.2 * @return string */ -function woocommerce_m360_payments_missing_wc_notice() { - /* translators: 1. URL link. */ - echo '

' . sprintf( esc_html__( 'Marketing 360® Payments requires WooCommerce to be installed and active. You can download %s here.', 'marketing-360-payments-for-woocommerce' ), 'WooCommerce' ) . '

'; +function woocommerce_m360_payments_missing_wc_notice() +{ + /* translators: 1. URL link. */ + echo '

' . sprintf(esc_html__('Marketing 360® Payments requires WooCommerce to be installed and active. You can download %s here.', 'marketing-360-payments-for-woocommerce'), 'WooCommerce') . '

'; } /** @@ -50,256 +51,299 @@ function woocommerce_m360_payments_missing_wc_notice() { * @since 4.4.0 * @return string */ -function woocommerce_m360_payments_wc_not_supported() { - /* translators: $1. Minimum WooCommerce version. $2. Current WooCommerce version. */ - echo '

' . sprintf( esc_html__( 'Marketing 360® Payments requires WooCommerce %1$s or greater to be installed and active. WooCommerce %2$s is no longer supported.', 'marketing-360-payments-for-woocommerce' ), WC_M360_PAYMENTS_MIN_WC_VER, WC_VERSION ) . '

'; +function woocommerce_m360_payments_wc_not_supported() +{ + /* translators: $1. Minimum WooCommerce version. $2. Current WooCommerce version. */ + echo '

' . sprintf(esc_html__('Marketing 360® Payments requires WooCommerce %1$s or greater to be installed and active. WooCommerce %2$s is no longer supported.', 'marketing-360-payments-for-woocommerce'), WC_M360_PAYMENTS_MIN_WC_VER, WC_VERSION) . '

'; } -function woocommerce_gateway_m360_payments_stripe_installed_notice() { - ob_start(); ?> +function woocommerce_gateway_m360_payments_stripe_installed_notice() +{ + ob_start(); ?>

init(); - } - - /** - * Init the plugin after plugins_loaded so environment variables are set. - * - * @since 1.0.0 - * @version 4.0.0 - */ - public function init() { - if ( is_admin() ) { - require_once dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-privacy.php'; - } - - require_once dirname( __FILE__ ) . '/marketing-360-payments.php'; - - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-exception.php'; - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php'; - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php'; - include_once dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php'; - require_once dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php'; - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php'; - require_once dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-pre-orders-compat.php'; - require_once dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php'; - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php'; - require_once dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-subs-compat.php'; - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php'; - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php'; - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php'; - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-intent-controller.php'; - - if ( is_admin() ) { - require_once dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-admin-notices.php'; - } - - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); - add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 ); - - // Modify emails emails. - add_filter( 'woocommerce_email_classes', array( $this, 'add_emails' ), 20 ); - - if ( version_compare( WC_VERSION, '3.4', '<' ) ) { - add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) ); - } - - // Register the REST endpoint for testing the authorization credentials and returning a list of M360 Accounts. - add_action('rest_api_init', function() { - - require_once('marketing-360-payments.php'); - - register_rest_route('wc_marketing_360_payments/' . Marketing_360_Payments::VER, '/sign_in', array( - 'methods' => 'POST', - 'callback' => 'Marketing_360_Payments::rest_list_m360_accounts', - 'permission_callback' => function() { - return current_user_can('manage_options'); - } - )); - }, 10); - } - - /** - * Updates the plugin version in db - * - * @since 3.1.0 - * @version 4.0.0 - */ - public function update_plugin_version() { - delete_option( 'wc_m360_payments_version' ); - update_option( 'wc_m360_payments_version', WC_M360_PAYMENTS_VERSION ); - } - - /** - * Handles upgrade routines. - * - * @since 3.1.0 - * @version 3.1.0 - */ - public function install() { - if ( ! is_plugin_active( plugin_basename( __FILE__ ) ) ) { - return; - } - - if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_M360_PAYMENTS_VERSION !== get_option( 'wc_m360_payments_version' ) ) ) { - do_action( 'woocommerce_stripe_updated' ); - - if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) { - define( 'WC_STRIPE_INSTALLING', true ); - } - - $this->update_plugin_version(); - } - } - - /** - * Add plugin action links. - * - * @since 1.0.0 - * @version 4.0.0 - */ - public function plugin_action_links( $links ) { - $plugin_links = array( - '' . esc_html__( 'Settings', 'marketing-360-payments-for-woocommerce' ) . '', - ); - return array_merge( $plugin_links, $links ); - } - - /** - * Add plugin action links. - * - * @since 4.3.4 - * @param array $links Original list of plugin links. - * @param string $file Name of current file. - * @return array $links Update list of plugin links. - */ - public function plugin_row_meta( $links, $file ) { - if ( plugin_basename( __FILE__ ) === $file ) { - $row_meta = array( - //'docs' => '' . __( 'Docs', 'marketing-360-payments-for-woocommerce' ) . '', - //'support' => '' . __( 'Support', 'marketing-360-payments-for-woocommerce' ) . '', - ); - return array_merge( $links, $row_meta ); - } - return (array) $links; - } - - /** - * Add the gateways to WooCommerce. - * - * @since 1.0.0 - * @version 4.0.0 - */ - public function add_gateways( $methods ) { - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) { - $methods[] = 'WC_Stripe_Subs_Compat'; - } else { - $methods[] = 'WC_Gateway_Stripe'; - } - - return $methods; - } - - /** - * Modifies the order of the gateways displayed in admin. - * - * @since 4.0.0 - * @version 4.0.0 - */ - public function filter_gateway_order_admin( $sections ) { - unset( $sections['stripe'] ); - $sections['stripe'] = 'Stripe'; - - return $sections; - } - - /** - * Adds the failed SCA auth email to WooCommerce. - * - * @param WC_Email[] $email_classes All existing emails. - * @return WC_Email[] - */ - public function add_emails( $email_classes ) { - require_once WC_M360_PAYMENTS_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-authentication.php'; - require_once WC_M360_PAYMENTS_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-renewal-authentication.php'; - require_once WC_M360_PAYMENTS_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-preorder-authentication.php'; - require_once WC_M360_PAYMENTS_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-authentication-retry.php'; - - // Add all emails, generated by the gateway. - $email_classes['WC_Stripe_Email_Failed_Renewal_Authentication'] = new WC_Stripe_Email_Failed_Renewal_Authentication( $email_classes ); - $email_classes['WC_Stripe_Email_Failed_Preorder_Authentication'] = new WC_Stripe_Email_Failed_Preorder_Authentication( $email_classes ); - $email_classes['WC_Stripe_Email_Failed_Authentication_Retry'] = new WC_Stripe_Email_Failed_Authentication_Retry( $email_classes ); - - return $email_classes; - } - } - - WC_Stripe::get_instance(); - endif; -} \ No newline at end of file +add_action('plugins_loaded', 'woocommerce_gateway_m360_payments_init', 9999); + +function woocommerce_gateway_m360_payments_init() +{ + if (! class_exists('WooCommerce')) { + add_action('admin_notices', 'woocommerce_m360_payments_missing_wc_notice'); + return; + } + + if (version_compare(WC_VERSION, WC_M360_PAYMENTS_MIN_WC_VER, '<')) { + add_action('admin_notices', 'woocommerce_m360_payments_wc_not_supported'); + return; + } + + if (class_exists('WC_Stripe')): + + add_action('admin_notices', 'woocommerce_gateway_m360_payments_stripe_installed_notice'); + + else: + + class WC_Stripe + { + /** + * @var Singleton The reference the *Singleton* instance of this class + */ + private static $instance; + + /** + * Returns the *Singleton* instance of this class. + * + * @return Singleton The *Singleton* instance. + */ + public static function get_instance() + { + if (null === self::$instance) { + self::$instance = new self(); + } + return self::$instance; + } + + /** + * Private clone method to prevent cloning of the instance of the + * *Singleton* instance. + * + * @return void + */ + public function __clone() + { + } + + /** + * Private unserialize method to prevent unserializing of the *Singleton* + * instance. + * + * @return void + */ + public function __wakeup() + { + } + + /** + * Protected constructor to prevent creating a new instance of the + * *Singleton* via the `new` operator from outside of this class. + */ + public function __construct() + { + if(isset($_GET['show_woocommerce_stripe_settings'])) + { + echo '
'; 
+                   add_filter( 'option_woocommerce_stripe_settings', array( $this, 'temp_woocommerce_stripe_settings') );
+                    print_r(get_option('woocommerce_stripe_settings')); 
+                    echo '
'; + } + + add_action('admin_init', array( $this, 'install' )); + $this->init(); + } + + /** + * Init the plugin after plugins_loaded so environment variables are set. + * + * @since 1.0.0 + * @version 4.0.0 + */ + public function init() + { + if (is_admin()) { + require_once dirname(__FILE__) . '/includes/admin/class-wc-stripe-privacy.php'; + } + + require_once dirname(__FILE__) . '/marketing-360-payments.php'; + + require_once dirname(__FILE__) . '/includes/class-wc-stripe-exception.php'; + require_once dirname(__FILE__) . '/includes/class-wc-stripe-logger.php'; + require_once dirname(__FILE__) . '/includes/class-wc-stripe-helper.php'; + include_once dirname(__FILE__) . '/includes/class-wc-stripe-api.php'; + require_once dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php'; + require_once dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php'; + require_once dirname(__FILE__) . '/includes/compat/class-wc-stripe-pre-orders-compat.php'; + require_once dirname(__FILE__) . '/includes/class-wc-m360-stripe-apple-pay-registration.php'; + require_once dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php'; + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php'; + require_once dirname(__FILE__) . '/includes/compat/class-wc-stripe-subs-compat.php'; + require_once dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php'; + require_once dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php'; + require_once dirname(__FILE__) . '/includes/class-wc-stripe-customer.php'; + require_once dirname(__FILE__) . '/includes/class-wc-stripe-intent-controller.php'; + + if (is_admin()) { + require_once dirname(__FILE__) . '/includes/admin/class-wc-stripe-admin-notices.php'; + } + + add_filter('woocommerce_payment_gateways', array( $this, 'add_gateways' )); + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array( $this, 'plugin_action_links' )); + add_filter('plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2); + + // Modify emails emails. + add_filter('woocommerce_email_classes', array( $this, 'add_emails' ), 20); + + if (version_compare(WC_VERSION, '3.4', '<')) { + add_filter('woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' )); + } + + // Register the REST endpoint for testing the authorization credentials and returning a list of M360 Accounts. + add_action('rest_api_init', function () { + require_once('marketing-360-payments.php'); + + register_rest_route('wc_marketing_360_payments/' . Marketing_360_Payments::VER, '/sign_in', array( + 'methods' => 'POST', + 'callback' => 'Marketing_360_Payments::rest_list_m360_accounts', + 'permission_callback' => function () { + return current_user_can('manage_options'); + } + )); + }, 10); + + } + function temp_woocommerce_stripe_settings( $value ) { + $value['payment_request'] = 'yes'; + /* $value['publishable_key'] = 'pk_live_51MOZw8Fj0Vn6rFSLpYmEexsuvSdkNlk3ILJizEMC1NlHEaeVtO19sHAaTwZ2E0yRZ5gUGBBgD09kPYcUBkAbWJlJ001gNVGjju'; + $value['secret_key'] = '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'; + $value['webhook_secret'] = 'we_1MP6TKFj0Vn6rFSL77YPigSA'; + $value['testmode'] = 'no'; + $value['apple_pay_verified_domain'] = 'fd9a-52-6-168-200.ngrok.io'; + $value['apple_pay_domain_set'] = 'yes'; + // [statement_descriptor] => + $value['title_upe'] = ''; + $value['payment_request_button_size'] = 'default'; + $value['payment_request_button_locations'] = Array('product','cart','checkout'); + + $value['is_short_statement_descriptor_enabled'] = 'no'; + $value['upe_checkout_experience_enabled'] = 'disabled'; + $value['upe_checkout_experience_accepted_payments'] = Array(); + */ + return $value; + } + /** + * Updates the plugin version in db + * + * @since 3.1.0 + * @version 4.0.0 + */ + public function update_plugin_version() + { + delete_option('wc_m360_payments_version'); + update_option('wc_m360_payments_version', WC_M360_PAYMENTS_VERSION); + } + + /** + * Handles upgrade routines. + * + * @since 3.1.0 + * @version 3.1.0 + */ + public function install() + { + if (! is_plugin_active(plugin_basename(__FILE__))) { + return; + } + + if (! defined('IFRAME_REQUEST') && (WC_M360_PAYMENTS_VERSION !== get_option('wc_m360_payments_version'))) { + do_action('woocommerce_stripe_updated'); + + if (! defined('WC_STRIPE_INSTALLING')) { + define('WC_STRIPE_INSTALLING', true); + } + + $this->update_plugin_version(); + } + } + + /** + * Add plugin action links. + * + * @since 1.0.0 + * @version 4.0.0 + */ + public function plugin_action_links($links) + { + $plugin_links = array( + '' . esc_html__('Settings', 'marketing-360-payments-for-woocommerce') . '', + ); + return array_merge($plugin_links, $links); + } + + /** + * Add plugin action links. + * + * @since 4.3.4 + * @param array $links Original list of plugin links. + * @param string $file Name of current file. + * @return array $links Update list of plugin links. + */ + public function plugin_row_meta($links, $file) + { + if (plugin_basename(__FILE__) === $file) { + $row_meta = array( + //'docs' => '' . __( 'Docs', 'marketing-360-payments-for-woocommerce' ) . '', + //'support' => '' . __( 'Support', 'marketing-360-payments-for-woocommerce' ) . '', + ); + return array_merge($links, $row_meta); + } + return (array) $links; + } + + /** + * Add the gateways to WooCommerce. + * + * @since 1.0.0 + * @version 4.0.0 + */ + public function add_gateways($methods) + { + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) { + $methods[] = 'WC_Stripe_Subs_Compat'; + } else { + $methods[] = 'WC_Gateway_Stripe'; + } + + return $methods; + } + + /** + * Modifies the order of the gateways displayed in admin. + * + * @since 4.0.0 + * @version 4.0.0 + */ + public function filter_gateway_order_admin($sections) + { + unset($sections['stripe']); + $sections['stripe'] = 'Stripe'; + + return $sections; + } + + /** + * Adds the failed SCA auth email to WooCommerce. + * + * @param WC_Email[] $email_classes All existing emails. + * @return WC_Email[] + */ + public function add_emails($email_classes) + { + require_once WC_M360_PAYMENTS_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-authentication.php'; + require_once WC_M360_PAYMENTS_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-renewal-authentication.php'; + require_once WC_M360_PAYMENTS_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-preorder-authentication.php'; + require_once WC_M360_PAYMENTS_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-authentication-retry.php'; + + // Add all emails, generated by the gateway. + $email_classes['WC_Stripe_Email_Failed_Renewal_Authentication'] = new WC_Stripe_Email_Failed_Renewal_Authentication($email_classes); + $email_classes['WC_Stripe_Email_Failed_Preorder_Authentication'] = new WC_Stripe_Email_Failed_Preorder_Authentication($email_classes); + $email_classes['WC_Stripe_Email_Failed_Authentication_Retry'] = new WC_Stripe_Email_Failed_Authentication_Retry($email_classes); + + return $email_classes; + } + } + + WC_Stripe::get_instance(); + endif; +}