@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @extends WC_Email_Failed_Order |
11 | 11 | */ |
12 | 12 | |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -26,17 +26,17 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function __construct() { |
28 | 28 | $this->id = 'failed_authentication_requested'; |
29 | - $this->title = __( 'Payment Authentication Requested Email', 'woocommerce-gateway-stripe' ); |
|
30 | - $this->description = __( 'Payment authentication requested emails are sent to chosen recipient(s) when an attempt to automatically process a subscription renewal payment fails because the transaction requires an SCA verification, the customer is requested to authenticate the payment, and a retry rule has been applied to notify the customer again within a certain time period.', 'woocommerce-gateway-stripe' ); |
|
29 | + $this->title = __('Payment Authentication Requested Email', 'woocommerce-gateway-stripe'); |
|
30 | + $this->description = __('Payment authentication requested emails are sent to chosen recipient(s) when an attempt to automatically process a subscription renewal payment fails because the transaction requires an SCA verification, the customer is requested to authenticate the payment, and a retry rule has been applied to notify the customer again within a certain time period.', 'woocommerce-gateway-stripe'); |
|
31 | 31 | |
32 | - $this->heading = __( 'Automatic renewal payment failed due to authentication required', 'woocommerce-gateway-stripe' ); |
|
33 | - $this->subject = __( '[{site_title}] Automatic payment failed for {order_number}. Customer asked to authenticate payment and will be notified again {retry_time}', 'woocommerce-gateway-stripe' ); |
|
32 | + $this->heading = __('Automatic renewal payment failed due to authentication required', 'woocommerce-gateway-stripe'); |
|
33 | + $this->subject = __('[{site_title}] Automatic payment failed for {order_number}. Customer asked to authenticate payment and will be notified again {retry_time}', 'woocommerce-gateway-stripe'); |
|
34 | 34 | |
35 | 35 | $this->template_html = 'emails/failed-renewal-authentication-requested.php'; |
36 | 36 | $this->template_plain = 'emails/plain/failed-renewal-authentication-requested.php'; |
37 | - $this->template_base = plugin_dir_path( WC_STRIPE_MAIN_FILE ) . 'templates/'; |
|
37 | + $this->template_base = plugin_dir_path(WC_STRIPE_MAIN_FILE) . 'templates/'; |
|
38 | 38 | |
39 | - $this->recipient = $this->get_option( 'recipient', get_option( 'admin_email' ) ); |
|
39 | + $this->recipient = $this->get_option('recipient', get_option('admin_email')); |
|
40 | 40 | |
41 | 41 | // We want all the parent's methods, with none of its properties, so call its parent's constructor, rather than my parent constructor. |
42 | 42 | WC_Email::__construct(); |
@@ -66,26 +66,26 @@ discard block |
||
66 | 66 | * @param int $order_id The order ID. |
67 | 67 | * @param WC_Order|null $order Order object. |
68 | 68 | */ |
69 | - public function trigger( $order_id, $order = null ) { |
|
69 | + public function trigger($order_id, $order = null) { |
|
70 | 70 | $this->object = $order; |
71 | 71 | |
72 | 72 | $this->find['retry-time'] = '{retry_time}'; |
73 | - if ( class_exists( 'WCS_Retry_Manager' ) && function_exists( 'wcs_get_human_time_diff' ) ) { |
|
74 | - $this->retry = WCS_Retry_Manager::store()->get_last_retry_for_order( wcs_get_objects_property( $order, 'id' ) ); |
|
75 | - $this->replace['retry-time'] = wcs_get_human_time_diff( $this->retry->get_time() ); |
|
73 | + if (class_exists('WCS_Retry_Manager') && function_exists('wcs_get_human_time_diff')) { |
|
74 | + $this->retry = WCS_Retry_Manager::store()->get_last_retry_for_order(wcs_get_objects_property($order, 'id')); |
|
75 | + $this->replace['retry-time'] = wcs_get_human_time_diff($this->retry->get_time()); |
|
76 | 76 | } else { |
77 | - WC_Stripe_Logger::log( 'WCS_Retry_Manager class or does not exist. Not able to send admnin email about customer notification for authentication required for renewal payment.' ); |
|
77 | + WC_Stripe_Logger::log('WCS_Retry_Manager class or does not exist. Not able to send admnin email about customer notification for authentication required for renewal payment.'); |
|
78 | 78 | return; |
79 | 79 | } |
80 | 80 | |
81 | 81 | $this->find['order-number'] = '{order_number}'; |
82 | 82 | $this->replace['order-number'] = $this->object->get_order_number(); |
83 | 83 | |
84 | - if ( ! $this->is_enabled() || ! $this->get_recipient() ) { |
|
84 | + if ( ! $this->is_enabled() || ! $this->get_recipient()) { |
|
85 | 85 | return; |
86 | 86 | } |
87 | 87 | |
88 | - $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() ); |
|
88 | + $this->send($this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments()); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; // Exit if accessed directly. |
4 | 4 | } |
5 | 5 | |
@@ -14,20 +14,20 @@ discard block |
||
14 | 14 | * |
15 | 15 | * @param WC_Email[] $email_classes All existing instances of WooCommerce emails. |
16 | 16 | */ |
17 | - public function __construct( $email_classes = array() ) { |
|
17 | + public function __construct($email_classes = array()) { |
|
18 | 18 | $this->id = 'failed_renewal_authentication'; |
19 | - $this->title = __( 'Failed Subscription Renewal SCA Authentication', 'woocommerce-gateway-stripe' ); |
|
20 | - $this->description = __( 'Sent to a customer when a renewal fails because the transaction requires an SCA verification. The email contains renewal order information and payment links.', 'woocommerce-gateway-stripe' ); |
|
19 | + $this->title = __('Failed Subscription Renewal SCA Authentication', 'woocommerce-gateway-stripe'); |
|
20 | + $this->description = __('Sent to a customer when a renewal fails because the transaction requires an SCA verification. The email contains renewal order information and payment links.', 'woocommerce-gateway-stripe'); |
|
21 | 21 | $this->customer_email = true; |
22 | 22 | |
23 | 23 | $this->template_html = 'emails/failed-renewal-authentication.php'; |
24 | 24 | $this->template_plain = 'emails/plain/failed-renewal-authentication.php'; |
25 | - $this->template_base = plugin_dir_path( WC_STRIPE_MAIN_FILE ) . 'templates/'; |
|
25 | + $this->template_base = plugin_dir_path(WC_STRIPE_MAIN_FILE) . 'templates/'; |
|
26 | 26 | |
27 | 27 | // Triggers the email at the correct hook. |
28 | - add_action( 'wc_gateway_stripe_process_payment_authentication_required', array( $this, 'trigger' ) ); |
|
28 | + add_action('wc_gateway_stripe_process_payment_authentication_required', array($this, 'trigger')); |
|
29 | 29 | |
30 | - if ( isset( $email_classes['WCS_Email_Customer_Renewal_Invoice'] ) ) { |
|
30 | + if (isset($email_classes['WCS_Email_Customer_Renewal_Invoice'])) { |
|
31 | 31 | $this->original_email = $email_classes['WCS_Email_Customer_Renewal_Invoice']; |
32 | 32 | } |
33 | 33 | |
@@ -40,21 +40,21 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @param WC_Order $order The order that is being paid. |
42 | 42 | */ |
43 | - public function trigger( $order ) { |
|
44 | - if ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order->get_id() ) || wcs_is_subscription( $order->get_id() ) || wcs_order_contains_renewal( $order->get_id() ) ) ) { |
|
45 | - parent::trigger( $order ); |
|
43 | + public function trigger($order) { |
|
44 | + if (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order->get_id()) || wcs_is_subscription($order->get_id()) || wcs_order_contains_renewal($order->get_id()))) { |
|
45 | + parent::trigger($order); |
|
46 | 46 | |
47 | 47 | // Prevent the renewal email from WooCommerce Subscriptions from being sent. |
48 | - if ( isset( $this->original_email ) ) { |
|
49 | - remove_action( 'woocommerce_generated_manual_renewal_order_renewal_notification', array( $this->original_email, 'trigger' ) ); |
|
50 | - remove_action( 'woocommerce_order_status_failed_renewal_notification', array( $this->original_email, 'trigger' ) ); |
|
48 | + if (isset($this->original_email)) { |
|
49 | + remove_action('woocommerce_generated_manual_renewal_order_renewal_notification', array($this->original_email, 'trigger')); |
|
50 | + remove_action('woocommerce_order_status_failed_renewal_notification', array($this->original_email, 'trigger')); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | // Prevent the retry email from WooCommerce Subscriptions from being sent. |
54 | - add_filter( 'wcs_get_retry_rule_raw', array( $this, 'prevent_retry_notification_email' ), 100, 3 ); |
|
54 | + add_filter('wcs_get_retry_rule_raw', array($this, 'prevent_retry_notification_email'), 100, 3); |
|
55 | 55 | |
56 | 56 | // Send email to store owner indicating communication is happening with the customer to request authentication. |
57 | - add_filter( 'wcs_get_retry_rule_raw', array( $this, 'set_store_owner_custom_email' ), 100, 3 ); |
|
57 | + add_filter('wcs_get_retry_rule_raw', array($this, 'set_store_owner_custom_email'), 100, 3); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @return string |
65 | 65 | */ |
66 | 66 | public function get_default_subject() { |
67 | - return __( 'Payment authorization needed for renewal of {site_title} order {order_number}', 'woocommerce-gateway-stripe' ); |
|
67 | + return __('Payment authorization needed for renewal of {site_title} order {order_number}', 'woocommerce-gateway-stripe'); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @return string |
74 | 74 | */ |
75 | 75 | public function get_default_heading() { |
76 | - return __( 'Payment authorization needed for renewal of order {order_number}', 'woocommerce-gateway-stripe' ); |
|
76 | + return __('Payment authorization needed for renewal of order {order_number}', 'woocommerce-gateway-stripe'); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | * @param int $order_id The ID of the order that needs payment. |
85 | 85 | * @return array |
86 | 86 | */ |
87 | - public function prevent_retry_notification_email( $rule_array, $retry_number, $order_id ) { |
|
88 | - if ( wcs_get_objects_property( $this->object, 'id' ) === $order_id ) { |
|
87 | + public function prevent_retry_notification_email($rule_array, $retry_number, $order_id) { |
|
88 | + if (wcs_get_objects_property($this->object, 'id') === $order_id) { |
|
89 | 89 | $rule_array['email_template_customer'] = ''; |
90 | 90 | } |
91 | 91 | |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | * @param int $order_id The ID of the order that needs payment. |
101 | 101 | * @return array |
102 | 102 | */ |
103 | - public function set_store_owner_custom_email( $rule_array, $retry_number, $order_id ) { |
|
103 | + public function set_store_owner_custom_email($rule_array, $retry_number, $order_id) { |
|
104 | 104 | if ( |
105 | - wcs_get_objects_property( $this->object, 'id' ) === $order_id && |
|
105 | + wcs_get_objects_property($this->object, 'id') === $order_id && |
|
106 | 106 | '' !== $rule_array['email_template_admin'] // Only send our email if a retry admin email was already going to be sent. |
107 | 107 | ) { |
108 | 108 | $rule_array['email_template_admin'] = 'WC_Stripe_Email_Failed_Authentication_Retry'; |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | * |
16 | 16 | */ |
17 | 17 | |
18 | -if ( ! defined( 'ABSPATH' ) ) { |
|
18 | +if ( ! defined('ABSPATH')) { |
|
19 | 19 | exit; |
20 | 20 | } |
21 | 21 | |
@@ -29,29 +29,29 @@ discard block |
||
29 | 29 | */ |
30 | 30 | function woocommerce_stripe_missing_wc_notice() { |
31 | 31 | /* translators: 1. URL link. */ |
32 | - echo '<div class="error"><p><strong>' . sprintf( esc_html__( 'Stripe requires WooCommerce to be installed and active. You can download %s here.', 'woocommerce-gateway-stripe' ), '<a href="https://woocommerce.com/" target="_blank">WooCommerce</a>' ) . '</strong></p></div>'; |
|
32 | + echo '<div class="error"><p><strong>' . sprintf(esc_html__('Stripe requires WooCommerce to be installed and active. You can download %s here.', 'woocommerce-gateway-stripe'), '<a href="https://woocommerce.com/" target="_blank">WooCommerce</a>') . '</strong></p></div>'; |
|
33 | 33 | } |
34 | 34 | |
35 | -add_action( 'plugins_loaded', 'woocommerce_gateway_stripe_init' ); |
|
35 | +add_action('plugins_loaded', 'woocommerce_gateway_stripe_init'); |
|
36 | 36 | |
37 | 37 | function woocommerce_gateway_stripe_init() { |
38 | - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
|
38 | + load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages'); |
|
39 | 39 | |
40 | - if ( ! class_exists( 'WooCommerce' ) ) { |
|
41 | - add_action( 'admin_notices', 'woocommerce_stripe_missing_wc_notice' ); |
|
40 | + if ( ! class_exists('WooCommerce')) { |
|
41 | + add_action('admin_notices', 'woocommerce_stripe_missing_wc_notice'); |
|
42 | 42 | return; |
43 | 43 | } |
44 | 44 | |
45 | - if ( ! class_exists( 'WC_Stripe' ) ) : |
|
45 | + if ( ! class_exists('WC_Stripe')) : |
|
46 | 46 | /** |
47 | 47 | * Required minimums and constants |
48 | 48 | */ |
49 | - define( 'WC_STRIPE_VERSION', '4.3.0' ); |
|
50 | - define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' ); |
|
51 | - define( 'WC_STRIPE_MIN_WC_VER', '2.6.0' ); |
|
52 | - define( 'WC_STRIPE_MAIN_FILE', __FILE__ ); |
|
53 | - define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); |
|
54 | - define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); |
|
49 | + define('WC_STRIPE_VERSION', '4.3.0'); |
|
50 | + define('WC_STRIPE_MIN_PHP_VER', '5.6.0'); |
|
51 | + define('WC_STRIPE_MIN_WC_VER', '2.6.0'); |
|
52 | + define('WC_STRIPE_MAIN_FILE', __FILE__); |
|
53 | + define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)))); |
|
54 | + define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__))); |
|
55 | 55 | |
56 | 56 | class WC_Stripe { |
57 | 57 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @return Singleton The *Singleton* instance. |
67 | 67 | */ |
68 | 68 | public static function get_instance() { |
69 | - if ( null === self::$instance ) { |
|
69 | + if (null === self::$instance) { |
|
70 | 70 | self::$instance = new self(); |
71 | 71 | } |
72 | 72 | return self::$instance; |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * *Singleton* via the `new` operator from outside of this class. |
94 | 94 | */ |
95 | 95 | private function __construct() { |
96 | - add_action( 'admin_init', array( $this, 'install' ) ); |
|
96 | + add_action('admin_init', array($this, 'install')); |
|
97 | 97 | $this->init(); |
98 | 98 | } |
99 | 99 | |
@@ -104,52 +104,52 @@ discard block |
||
104 | 104 | * @version 4.0.0 |
105 | 105 | */ |
106 | 106 | public function init() { |
107 | - if ( is_admin() ) { |
|
108 | - require_once dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-privacy.php'; |
|
107 | + if (is_admin()) { |
|
108 | + require_once dirname(__FILE__) . '/includes/admin/class-wc-stripe-privacy.php'; |
|
109 | 109 | } |
110 | 110 | |
111 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-exception.php'; |
|
112 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php'; |
|
113 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php'; |
|
114 | - include_once dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php'; |
|
115 | - require_once dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php'; |
|
116 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php'; |
|
117 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-sepa-payment-token.php'; |
|
118 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay-registration.php'; |
|
119 | - require_once dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-pre-orders-compat.php'; |
|
120 | - require_once dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php'; |
|
121 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'; |
|
122 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'; |
|
123 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'; |
|
124 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-eps.php'; |
|
125 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php'; |
|
126 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php'; |
|
127 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php'; |
|
128 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php'; |
|
129 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-multibanco.php'; |
|
130 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php'; |
|
131 | - require_once dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-subs-compat.php'; |
|
132 | - require_once dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-subs-compat.php'; |
|
133 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php'; |
|
134 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php'; |
|
135 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php'; |
|
136 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-intent-controller.php'; |
|
137 | - |
|
138 | - if ( is_admin() ) { |
|
139 | - require_once dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-admin-notices.php'; |
|
111 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-exception.php'; |
|
112 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-logger.php'; |
|
113 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-helper.php'; |
|
114 | + include_once dirname(__FILE__) . '/includes/class-wc-stripe-api.php'; |
|
115 | + require_once dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php'; |
|
116 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php'; |
|
117 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-sepa-payment-token.php'; |
|
118 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay-registration.php'; |
|
119 | + require_once dirname(__FILE__) . '/includes/compat/class-wc-stripe-pre-orders-compat.php'; |
|
120 | + require_once dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php'; |
|
121 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'; |
|
122 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'; |
|
123 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'; |
|
124 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-eps.php'; |
|
125 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php'; |
|
126 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php'; |
|
127 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php'; |
|
128 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php'; |
|
129 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-multibanco.php'; |
|
130 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php'; |
|
131 | + require_once dirname(__FILE__) . '/includes/compat/class-wc-stripe-subs-compat.php'; |
|
132 | + require_once dirname(__FILE__) . '/includes/compat/class-wc-stripe-sepa-subs-compat.php'; |
|
133 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php'; |
|
134 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php'; |
|
135 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-customer.php'; |
|
136 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-intent-controller.php'; |
|
137 | + |
|
138 | + if (is_admin()) { |
|
139 | + require_once dirname(__FILE__) . '/includes/admin/class-wc-stripe-admin-notices.php'; |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | // REMOVE IN THE FUTURE. |
143 | - require_once dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php'; |
|
143 | + require_once dirname(__FILE__) . '/includes/deprecated/class-wc-stripe-apple-pay.php'; |
|
144 | 144 | |
145 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
146 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
|
145 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
146 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); |
|
147 | 147 | |
148 | 148 | // Modify emails emails. |
149 | - add_filter( 'woocommerce_email_classes', array( $this, 'add_emails' ), 20 ); |
|
149 | + add_filter('woocommerce_email_classes', array($this, 'add_emails'), 20); |
|
150 | 150 | |
151 | - if ( version_compare( WC_VERSION, '3.4', '<' ) ) { |
|
152 | - add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) ); |
|
151 | + if (version_compare(WC_VERSION, '3.4', '<')) { |
|
152 | + add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin')); |
|
153 | 153 | } |
154 | 154 | } |
155 | 155 | |
@@ -160,8 +160,8 @@ discard block |
||
160 | 160 | * @version 4.0.0 |
161 | 161 | */ |
162 | 162 | public function update_plugin_version() { |
163 | - delete_option( 'wc_stripe_version' ); |
|
164 | - update_option( 'wc_stripe_version', WC_STRIPE_VERSION ); |
|
163 | + delete_option('wc_stripe_version'); |
|
164 | + update_option('wc_stripe_version', WC_STRIPE_VERSION); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -171,15 +171,15 @@ discard block |
||
171 | 171 | * @version 3.1.0 |
172 | 172 | */ |
173 | 173 | public function install() { |
174 | - if ( ! is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
|
174 | + if ( ! is_plugin_active(plugin_basename(__FILE__))) { |
|
175 | 175 | return; |
176 | 176 | } |
177 | 177 | |
178 | - if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) { |
|
179 | - do_action( 'woocommerce_stripe_updated' ); |
|
178 | + if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) { |
|
179 | + do_action('woocommerce_stripe_updated'); |
|
180 | 180 | |
181 | - if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) { |
|
182 | - define( 'WC_STRIPE_INSTALLING', true ); |
|
181 | + if ( ! defined('WC_STRIPE_INSTALLING')) { |
|
182 | + define('WC_STRIPE_INSTALLING', true); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | $this->update_plugin_version(); |
@@ -192,13 +192,13 @@ discard block |
||
192 | 192 | * @since 1.0.0 |
193 | 193 | * @version 4.0.0 |
194 | 194 | */ |
195 | - public function plugin_action_links( $links ) { |
|
195 | + public function plugin_action_links($links) { |
|
196 | 196 | $plugin_links = array( |
197 | - '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
198 | - '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
199 | - '<a href="https://woocommerce.com/my-account/create-a-ticket?broken=primary&select=18627">' . esc_html__( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
197 | + '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
198 | + '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
199 | + '<a href="https://woocommerce.com/my-account/create-a-ticket?broken=primary&select=18627">' . esc_html__('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
200 | 200 | ); |
201 | - return array_merge( $plugin_links, $links ); |
|
201 | + return array_merge($plugin_links, $links); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -207,8 +207,8 @@ discard block |
||
207 | 207 | * @since 1.0.0 |
208 | 208 | * @version 4.0.0 |
209 | 209 | */ |
210 | - public function add_gateways( $methods ) { |
|
211 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) { |
|
210 | + public function add_gateways($methods) { |
|
211 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) { |
|
212 | 212 | $methods[] = 'WC_Stripe_Subs_Compat'; |
213 | 213 | $methods[] = 'WC_Stripe_Sepa_Subs_Compat'; |
214 | 214 | } else { |
@@ -234,28 +234,28 @@ discard block |
||
234 | 234 | * @since 4.0.0 |
235 | 235 | * @version 4.0.0 |
236 | 236 | */ |
237 | - public function filter_gateway_order_admin( $sections ) { |
|
238 | - unset( $sections['stripe'] ); |
|
239 | - unset( $sections['stripe_bancontact'] ); |
|
240 | - unset( $sections['stripe_sofort'] ); |
|
241 | - unset( $sections['stripe_giropay'] ); |
|
242 | - unset( $sections['stripe_eps'] ); |
|
243 | - unset( $sections['stripe_ideal'] ); |
|
244 | - unset( $sections['stripe_p24'] ); |
|
245 | - unset( $sections['stripe_alipay'] ); |
|
246 | - unset( $sections['stripe_sepa'] ); |
|
247 | - unset( $sections['stripe_multibanco'] ); |
|
237 | + public function filter_gateway_order_admin($sections) { |
|
238 | + unset($sections['stripe']); |
|
239 | + unset($sections['stripe_bancontact']); |
|
240 | + unset($sections['stripe_sofort']); |
|
241 | + unset($sections['stripe_giropay']); |
|
242 | + unset($sections['stripe_eps']); |
|
243 | + unset($sections['stripe_ideal']); |
|
244 | + unset($sections['stripe_p24']); |
|
245 | + unset($sections['stripe_alipay']); |
|
246 | + unset($sections['stripe_sepa']); |
|
247 | + unset($sections['stripe_multibanco']); |
|
248 | 248 | |
249 | 249 | $sections['stripe'] = 'Stripe'; |
250 | - $sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
251 | - $sections['stripe_sofort'] = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
252 | - $sections['stripe_giropay'] = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
253 | - $sections['stripe_eps'] = __( 'Stripe EPS', 'woocommerce-gateway-stripe' ); |
|
254 | - $sections['stripe_ideal'] = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
255 | - $sections['stripe_p24'] = __( 'Stripe P24', 'woocommerce-gateway-stripe' ); |
|
256 | - $sections['stripe_alipay'] = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
257 | - $sections['stripe_sepa'] = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
258 | - $sections['stripe_multibanco'] = __( 'Stripe Multibanco', 'woocommerce-gateway-stripe' ); |
|
250 | + $sections['stripe_bancontact'] = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
251 | + $sections['stripe_sofort'] = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
252 | + $sections['stripe_giropay'] = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
253 | + $sections['stripe_eps'] = __('Stripe EPS', 'woocommerce-gateway-stripe'); |
|
254 | + $sections['stripe_ideal'] = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
255 | + $sections['stripe_p24'] = __('Stripe P24', 'woocommerce-gateway-stripe'); |
|
256 | + $sections['stripe_alipay'] = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
257 | + $sections['stripe_sepa'] = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
258 | + $sections['stripe_multibanco'] = __('Stripe Multibanco', 'woocommerce-gateway-stripe'); |
|
259 | 259 | |
260 | 260 | return $sections; |
261 | 261 | } |
@@ -266,16 +266,16 @@ discard block |
||
266 | 266 | * @param WC_Email[] $email_classes All existing emails. |
267 | 267 | * @return WC_Email[] |
268 | 268 | */ |
269 | - public function add_emails( $email_classes ) { |
|
269 | + public function add_emails($email_classes) { |
|
270 | 270 | require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-authentication.php'; |
271 | 271 | require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-renewal-authentication.php'; |
272 | 272 | require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-preorder-authentication.php'; |
273 | 273 | require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-authentication-retry.php'; |
274 | 274 | |
275 | 275 | // Add all emails, generated by the gateway. |
276 | - $email_classes['WC_Stripe_Email_Failed_Renewal_Authentication'] = new WC_Stripe_Email_Failed_Renewal_Authentication( $email_classes ); |
|
277 | - $email_classes['WC_Stripe_Email_Failed_Preorder_Authentication'] = new WC_Stripe_Email_Failed_Preorder_Authentication( $email_classes ); |
|
278 | - $email_classes['WC_Stripe_Email_Failed_Authentication_Retry'] = new WC_Stripe_Email_Failed_Authentication_Retry( $email_classes ); |
|
276 | + $email_classes['WC_Stripe_Email_Failed_Renewal_Authentication'] = new WC_Stripe_Email_Failed_Renewal_Authentication($email_classes); |
|
277 | + $email_classes['WC_Stripe_Email_Failed_Preorder_Authentication'] = new WC_Stripe_Email_Failed_Preorder_Authentication($email_classes); |
|
278 | + $email_classes['WC_Stripe_Email_Failed_Authentication_Retry'] = new WC_Stripe_Email_Failed_Authentication_Retry($email_classes); |
|
279 | 279 | |
280 | 280 | return $email_classes; |
281 | 281 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -85,9 +85,9 @@ discard block |
||
85 | 85 | public function __construct() { |
86 | 86 | $this->retry_interval = 1; |
87 | 87 | $this->id = 'stripe'; |
88 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
88 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
89 | 89 | /* translators: 1) link to Stripe register page 2) link to Stripe api keys page */ |
90 | - $this->method_description = sprintf( __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys' ); |
|
90 | + $this->method_description = sprintf(__('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys'); |
|
91 | 91 | $this->has_fields = true; |
92 | 92 | $this->supports = array( |
93 | 93 | 'products', |
@@ -114,37 +114,37 @@ discard block |
||
114 | 114 | $this->init_settings(); |
115 | 115 | |
116 | 116 | // Get setting values. |
117 | - $this->title = $this->get_option( 'title' ); |
|
118 | - $this->description = $this->get_option( 'description' ); |
|
119 | - $this->enabled = $this->get_option( 'enabled' ); |
|
120 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
121 | - $this->inline_cc_form = 'yes' === $this->get_option( 'inline_cc_form' ); |
|
122 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
123 | - $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) ); |
|
124 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
125 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
126 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
127 | - $this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
128 | - |
|
129 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
117 | + $this->title = $this->get_option('title'); |
|
118 | + $this->description = $this->get_option('description'); |
|
119 | + $this->enabled = $this->get_option('enabled'); |
|
120 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
121 | + $this->inline_cc_form = 'yes' === $this->get_option('inline_cc_form'); |
|
122 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
123 | + $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor')); |
|
124 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
125 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
126 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
127 | + $this->payment_request = 'yes' === $this->get_option('payment_request', 'yes'); |
|
128 | + |
|
129 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
130 | 130 | |
131 | 131 | // Hooks. |
132 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
133 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
|
134 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
135 | - add_action( 'woocommerce_admin_order_totals_after_total', array( $this, 'display_order_fee' ) ); |
|
136 | - add_action( 'woocommerce_admin_order_totals_after_total', array( $this, 'display_order_payout' ), 20 ); |
|
137 | - add_action( 'woocommerce_customer_save_address', array( $this, 'show_update_card_notice' ), 10, 2 ); |
|
138 | - add_filter( 'woocommerce_available_payment_gateways', array( $this, 'prepare_order_pay_page' ) ); |
|
139 | - add_action( 'woocommerce_account_view-order_endpoint', array( $this, 'check_intent_status_on_order_page' ), 1 ); |
|
140 | - add_filter( 'woocommerce_payment_successful_result', array( $this, 'modify_successful_payment_result' ), 99999, 2 ); |
|
141 | - add_action( 'set_logged_in_cookie', array( $this, 'set_cookie_on_current_request' ) ); |
|
142 | - add_filter( 'woocommerce_get_checkout_payment_url', array( $this, 'get_checkout_payment_url' ), 10, 2 ); |
|
143 | - |
|
144 | - if ( WC_Stripe_Helper::is_pre_orders_exists() ) { |
|
132 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
133 | + add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); |
|
134 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
135 | + add_action('woocommerce_admin_order_totals_after_total', array($this, 'display_order_fee')); |
|
136 | + add_action('woocommerce_admin_order_totals_after_total', array($this, 'display_order_payout'), 20); |
|
137 | + add_action('woocommerce_customer_save_address', array($this, 'show_update_card_notice'), 10, 2); |
|
138 | + add_filter('woocommerce_available_payment_gateways', array($this, 'prepare_order_pay_page')); |
|
139 | + add_action('woocommerce_account_view-order_endpoint', array($this, 'check_intent_status_on_order_page'), 1); |
|
140 | + add_filter('woocommerce_payment_successful_result', array($this, 'modify_successful_payment_result'), 99999, 2); |
|
141 | + add_action('set_logged_in_cookie', array($this, 'set_cookie_on_current_request')); |
|
142 | + add_filter('woocommerce_get_checkout_payment_url', array($this, 'get_checkout_payment_url'), 10, 2); |
|
143 | + |
|
144 | + if (WC_Stripe_Helper::is_pre_orders_exists()) { |
|
145 | 145 | $this->pre_orders = new WC_Stripe_Pre_Orders_Compat(); |
146 | 146 | |
147 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this->pre_orders, 'process_pre_order_release_payment' ) ); |
|
147 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this->pre_orders, 'process_pre_order_release_payment')); |
|
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * @return bool |
156 | 156 | */ |
157 | 157 | public function are_keys_set() { |
158 | - if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) { |
|
158 | + if (empty($this->secret_key) || empty($this->publishable_key)) { |
|
159 | 159 | return false; |
160 | 160 | } |
161 | 161 | |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * @since 4.0.2 |
169 | 169 | */ |
170 | 170 | public function is_available() { |
171 | - if ( is_add_payment_method_page() && ! $this->saved_cards ) { |
|
171 | + if (is_add_payment_method_page() && ! $this->saved_cards) { |
|
172 | 172 | return false; |
173 | 173 | } |
174 | 174 | |
@@ -182,13 +182,13 @@ discard block |
||
182 | 182 | * @param int $user_id The ID of the current user. |
183 | 183 | * @param string $load_address The address to load. |
184 | 184 | */ |
185 | - public function show_update_card_notice( $user_id, $load_address ) { |
|
186 | - if ( ! $this->saved_cards || ! WC_Stripe_Payment_Tokens::customer_has_saved_methods( $user_id ) || 'billing' !== $load_address ) { |
|
185 | + public function show_update_card_notice($user_id, $load_address) { |
|
186 | + if ( ! $this->saved_cards || ! WC_Stripe_Payment_Tokens::customer_has_saved_methods($user_id) || 'billing' !== $load_address) { |
|
187 | 187 | return; |
188 | 188 | } |
189 | 189 | |
190 | 190 | /* translators: 1) Opening anchor tag 2) closing anchor tag */ |
191 | - wc_add_notice( sprintf( __( 'If your billing address has been changed for saved payment methods, be sure to remove any %1$ssaved payment methods%2$s on file and re-add them.', 'woocommerce-gateway-stripe' ), '<a href="' . esc_url( wc_get_endpoint_url( 'payment-methods' ) ) . '" class="wc-stripe-update-card-notice" style="text-decoration:underline;">', '</a>' ), 'notice' ); |
|
191 | + wc_add_notice(sprintf(__('If your billing address has been changed for saved payment methods, be sure to remove any %1$ssaved payment methods%2$s on file and re-add them.', 'woocommerce-gateway-stripe'), '<a href="' . esc_url(wc_get_endpoint_url('payment-methods')) . '" class="wc-stripe-update-card-notice" style="text-decoration:underline;">', '</a>'), 'notice'); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -203,24 +203,24 @@ discard block |
||
203 | 203 | |
204 | 204 | $icons_str = ''; |
205 | 205 | |
206 | - $icons_str .= isset( $icons['visa'] ) ? $icons['visa'] : ''; |
|
207 | - $icons_str .= isset( $icons['amex'] ) ? $icons['amex'] : ''; |
|
208 | - $icons_str .= isset( $icons['mastercard'] ) ? $icons['mastercard'] : ''; |
|
206 | + $icons_str .= isset($icons['visa']) ? $icons['visa'] : ''; |
|
207 | + $icons_str .= isset($icons['amex']) ? $icons['amex'] : ''; |
|
208 | + $icons_str .= isset($icons['mastercard']) ? $icons['mastercard'] : ''; |
|
209 | 209 | |
210 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
211 | - $icons_str .= isset( $icons['discover'] ) ? $icons['discover'] : ''; |
|
212 | - $icons_str .= isset( $icons['jcb'] ) ? $icons['jcb'] : ''; |
|
213 | - $icons_str .= isset( $icons['diners'] ) ? $icons['diners'] : ''; |
|
210 | + if ('USD' === get_woocommerce_currency()) { |
|
211 | + $icons_str .= isset($icons['discover']) ? $icons['discover'] : ''; |
|
212 | + $icons_str .= isset($icons['jcb']) ? $icons['jcb'] : ''; |
|
213 | + $icons_str .= isset($icons['diners']) ? $icons['diners'] : ''; |
|
214 | 214 | } |
215 | 215 | |
216 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
216 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
220 | 220 | * Initialise Gateway Settings Form Fields |
221 | 221 | */ |
222 | 222 | public function init_form_fields() { |
223 | - $this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' ); |
|
223 | + $this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php'); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -228,27 +228,27 @@ discard block |
||
228 | 228 | */ |
229 | 229 | public function payment_fields() { |
230 | 230 | $user = wp_get_current_user(); |
231 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
231 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
232 | 232 | $total = WC()->cart->total; |
233 | 233 | $user_email = ''; |
234 | 234 | $description = $this->get_description(); |
235 | - $description = ! empty( $description ) ? $description : ''; |
|
235 | + $description = ! empty($description) ? $description : ''; |
|
236 | 236 | $firstname = ''; |
237 | 237 | $lastname = ''; |
238 | 238 | |
239 | 239 | // If paying from order, we need to get total from order not cart. |
240 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { // wpcs: csrf ok. |
|
241 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); // wpcs: csrf ok, sanitization ok. |
|
240 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { // wpcs: csrf ok. |
|
241 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); // wpcs: csrf ok, sanitization ok. |
|
242 | 242 | $total = $order->get_total(); |
243 | - $user_email = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_email : $order->get_billing_email(); |
|
243 | + $user_email = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_email : $order->get_billing_email(); |
|
244 | 244 | } else { |
245 | - if ( $user->ID ) { |
|
246 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
245 | + if ($user->ID) { |
|
246 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
247 | 247 | $user_email = $user_email ? $user_email : $user->user_email; |
248 | 248 | } |
249 | 249 | } |
250 | 250 | |
251 | - if ( is_add_payment_method_page() ) { |
|
251 | + if (is_add_payment_method_page()) { |
|
252 | 252 | $firstname = $user->user_firstname; |
253 | 253 | $lastname = $user->user_lastname; |
254 | 254 | } |
@@ -257,33 +257,33 @@ discard block |
||
257 | 257 | |
258 | 258 | echo '<div |
259 | 259 | id="stripe-payment-data" |
260 | - data-email="' . esc_attr( $user_email ) . '" |
|
261 | - data-full-name="' . esc_attr( $firstname . ' ' . $lastname ) . '" |
|
262 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
260 | + data-email="' . esc_attr($user_email) . '" |
|
261 | + data-full-name="' . esc_attr($firstname . ' ' . $lastname) . '" |
|
262 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
263 | 263 | >'; |
264 | 264 | |
265 | - if ( $this->testmode ) { |
|
265 | + if ($this->testmode) { |
|
266 | 266 | /* translators: link to Stripe testing page */ |
267 | - $description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the <a href="%s" target="_blank">Testing Stripe documentation</a> for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' ); |
|
267 | + $description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the <a href="%s" target="_blank">Testing Stripe documentation</a> for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing'); |
|
268 | 268 | } |
269 | 269 | |
270 | - $description = trim( $description ); |
|
270 | + $description = trim($description); |
|
271 | 271 | |
272 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); // wpcs: xss ok. |
|
272 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); // wpcs: xss ok. |
|
273 | 273 | |
274 | - if ( $display_tokenization ) { |
|
274 | + if ($display_tokenization) { |
|
275 | 275 | $this->tokenization_script(); |
276 | 276 | $this->saved_payment_methods(); |
277 | 277 | } |
278 | 278 | |
279 | 279 | $this->elements_form(); |
280 | 280 | |
281 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { // wpcs: csrf ok. |
|
281 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { // wpcs: csrf ok. |
|
282 | 282 | |
283 | 283 | $this->save_payment_method_checkbox(); |
284 | 284 | } |
285 | 285 | |
286 | - do_action( 'wc_stripe_cards_payment_fields', $this->id ); |
|
286 | + do_action('wc_stripe_cards_payment_fields', $this->id); |
|
287 | 287 | |
288 | 288 | echo '</div>'; |
289 | 289 | |
@@ -298,12 +298,12 @@ discard block |
||
298 | 298 | */ |
299 | 299 | public function elements_form() { |
300 | 300 | ?> |
301 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
302 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
301 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
302 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
303 | 303 | |
304 | - <?php if ( $this->inline_cc_form ) { ?> |
|
304 | + <?php if ($this->inline_cc_form) { ?> |
|
305 | 305 | <label for="card-element"> |
306 | - <?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?> |
|
306 | + <?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?> |
|
307 | 307 | </label> |
308 | 308 | |
309 | 309 | <div id="stripe-card-element" class="wc-stripe-elements-field"> |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | </div> |
312 | 312 | <?php } else { ?> |
313 | 313 | <div class="form-row form-row-wide"> |
314 | - <label for="stripe-card-element"><?php esc_html_e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
314 | + <label for="stripe-card-element"><?php esc_html_e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
315 | 315 | <div class="stripe-card-group"> |
316 | 316 | <div id="stripe-card-element" class="wc-stripe-elements-field"> |
317 | 317 | <!-- a Stripe Element will be inserted here. --> |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | </div> |
323 | 323 | |
324 | 324 | <div class="form-row form-row-first"> |
325 | - <label for="stripe-exp-element"><?php esc_html_e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
325 | + <label for="stripe-exp-element"><?php esc_html_e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
326 | 326 | |
327 | 327 | <div id="stripe-exp-element" class="wc-stripe-elements-field"> |
328 | 328 | <!-- a Stripe Element will be inserted here. --> |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | </div> |
331 | 331 | |
332 | 332 | <div class="form-row form-row-last"> |
333 | - <label for="stripe-cvc-element"><?php esc_html_e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
333 | + <label for="stripe-cvc-element"><?php esc_html_e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
334 | 334 | <div id="stripe-cvc-element" class="wc-stripe-elements-field"> |
335 | 335 | <!-- a Stripe Element will be inserted here. --> |
336 | 336 | </div> |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | <!-- Used to display form errors --> |
342 | 342 | <div class="stripe-source-errors" role="alert"></div> |
343 | 343 | <br /> |
344 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
344 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
345 | 345 | <div class="clear"></div> |
346 | 346 | </fieldset> |
347 | 347 | <?php |
@@ -354,13 +354,13 @@ discard block |
||
354 | 354 | * @version 3.1.0 |
355 | 355 | */ |
356 | 356 | public function admin_scripts() { |
357 | - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
357 | + if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
358 | 358 | return; |
359 | 359 | } |
360 | 360 | |
361 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
361 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
362 | 362 | |
363 | - wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
363 | + wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | /** |
@@ -372,97 +372,97 @@ discard block |
||
372 | 372 | * @version 4.0.0 |
373 | 373 | */ |
374 | 374 | public function payment_scripts() { |
375 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) || ( is_order_received_page() ) ) { // wpcs: csrf ok. |
|
375 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method']) || (is_order_received_page())) { // wpcs: csrf ok. |
|
376 | 376 | return; |
377 | 377 | } |
378 | 378 | |
379 | 379 | // If Stripe is not enabled bail. |
380 | - if ( 'no' === $this->enabled ) { |
|
380 | + if ('no' === $this->enabled) { |
|
381 | 381 | return; |
382 | 382 | } |
383 | 383 | |
384 | 384 | // If keys are not set bail. |
385 | - if ( ! $this->are_keys_set() ) { |
|
386 | - WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
385 | + if ( ! $this->are_keys_set()) { |
|
386 | + WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
387 | 387 | return; |
388 | 388 | } |
389 | 389 | |
390 | 390 | // If no SSL bail. |
391 | - if ( ! $this->testmode && ! is_ssl() ) { |
|
392 | - WC_Stripe_Logger::log( 'Stripe live mode requires SSL.' ); |
|
391 | + if ( ! $this->testmode && ! is_ssl()) { |
|
392 | + WC_Stripe_Logger::log('Stripe live mode requires SSL.'); |
|
393 | 393 | return; |
394 | 394 | } |
395 | 395 | |
396 | 396 | $current_theme = wp_get_theme(); |
397 | 397 | |
398 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
398 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
399 | 399 | |
400 | - wp_register_style( 'stripe_styles', plugins_url( 'assets/css/stripe-styles.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
401 | - wp_enqueue_style( 'stripe_styles' ); |
|
400 | + wp_register_style('stripe_styles', plugins_url('assets/css/stripe-styles.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
401 | + wp_enqueue_style('stripe_styles'); |
|
402 | 402 | |
403 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
404 | - wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
403 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
404 | + wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true); |
|
405 | 405 | |
406 | 406 | $stripe_params = array( |
407 | 407 | 'key' => $this->publishable_key, |
408 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
409 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
408 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
409 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
410 | 410 | ); |
411 | 411 | |
412 | 412 | // If we're on the pay page we need to pass stripe.js the address of the order. |
413 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { // wpcs: csrf ok. |
|
414 | - $order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); // wpcs: csrf ok, sanitization ok, xss ok. |
|
415 | - $order = wc_get_order( $order_id ); |
|
416 | - |
|
417 | - if ( is_a( $order, 'WC_Order' ) ) { |
|
418 | - $stripe_params['billing_first_name'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_first_name : $order->get_billing_first_name(); |
|
419 | - $stripe_params['billing_last_name'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_last_name : $order->get_billing_last_name(); |
|
420 | - $stripe_params['billing_address_1'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_address_1 : $order->get_billing_address_1(); |
|
421 | - $stripe_params['billing_address_2'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_address_2 : $order->get_billing_address_2(); |
|
422 | - $stripe_params['billing_state'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_state : $order->get_billing_state(); |
|
423 | - $stripe_params['billing_city'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_city : $order->get_billing_city(); |
|
424 | - $stripe_params['billing_postcode'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_postcode : $order->get_billing_postcode(); |
|
425 | - $stripe_params['billing_country'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_country : $order->get_billing_country(); |
|
413 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { // wpcs: csrf ok. |
|
414 | + $order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); // wpcs: csrf ok, sanitization ok, xss ok. |
|
415 | + $order = wc_get_order($order_id); |
|
416 | + |
|
417 | + if (is_a($order, 'WC_Order')) { |
|
418 | + $stripe_params['billing_first_name'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_first_name : $order->get_billing_first_name(); |
|
419 | + $stripe_params['billing_last_name'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_last_name : $order->get_billing_last_name(); |
|
420 | + $stripe_params['billing_address_1'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_address_1 : $order->get_billing_address_1(); |
|
421 | + $stripe_params['billing_address_2'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_address_2 : $order->get_billing_address_2(); |
|
422 | + $stripe_params['billing_state'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_state : $order->get_billing_state(); |
|
423 | + $stripe_params['billing_city'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_city : $order->get_billing_city(); |
|
424 | + $stripe_params['billing_postcode'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_postcode : $order->get_billing_postcode(); |
|
425 | + $stripe_params['billing_country'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_country : $order->get_billing_country(); |
|
426 | 426 | } |
427 | 427 | } |
428 | 428 | |
429 | 429 | $sepa_elements_options = apply_filters( |
430 | 430 | 'wc_stripe_sepa_elements_options', |
431 | 431 | array( |
432 | - 'supportedCountries' => array( 'SEPA' ), |
|
432 | + 'supportedCountries' => array('SEPA'), |
|
433 | 433 | 'placeholderCountry' => WC()->countries->get_base_country(), |
434 | - 'style' => array( 'base' => array( 'fontSize' => '15px' ) ), |
|
434 | + 'style' => array('base' => array('fontSize' => '15px')), |
|
435 | 435 | ) |
436 | 436 | ); |
437 | 437 | |
438 | - $stripe_params['no_prepaid_card_msg'] = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
439 | - $stripe_params['no_sepa_owner_msg'] = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' ); |
|
440 | - $stripe_params['no_sepa_iban_msg'] = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' ); |
|
441 | - $stripe_params['payment_intent_error'] = __( 'We couldn\'t initiate the payment. Please try again.', 'woocommerce-gateway-stripe' ); |
|
442 | - $stripe_params['sepa_mandate_notification'] = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' ); |
|
443 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
438 | + $stripe_params['no_prepaid_card_msg'] = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
439 | + $stripe_params['no_sepa_owner_msg'] = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe'); |
|
440 | + $stripe_params['no_sepa_iban_msg'] = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe'); |
|
441 | + $stripe_params['payment_intent_error'] = __('We couldn\'t initiate the payment. Please try again.', 'woocommerce-gateway-stripe'); |
|
442 | + $stripe_params['sepa_mandate_notification'] = apply_filters('wc_stripe_sepa_mandate_notification', 'email'); |
|
443 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
444 | 444 | $stripe_params['inline_cc_form'] = $this->inline_cc_form ? 'yes' : 'no'; |
445 | - $stripe_params['is_checkout'] = ( is_checkout() && empty( $_GET['pay_for_order'] ) ) ? 'yes' : 'no'; // wpcs: csrf ok. |
|
445 | + $stripe_params['is_checkout'] = (is_checkout() && empty($_GET['pay_for_order'])) ? 'yes' : 'no'; // wpcs: csrf ok. |
|
446 | 446 | $stripe_params['return_url'] = $this->get_stripe_return_url(); |
447 | - $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint( '%%endpoint%%' ); |
|
448 | - $stripe_params['stripe_nonce'] = wp_create_nonce( '_wc_stripe_nonce' ); |
|
447 | + $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint('%%endpoint%%'); |
|
448 | + $stripe_params['stripe_nonce'] = wp_create_nonce('_wc_stripe_nonce'); |
|
449 | 449 | $stripe_params['statement_descriptor'] = $this->statement_descriptor; |
450 | - $stripe_params['elements_options'] = apply_filters( 'wc_stripe_elements_options', array() ); |
|
450 | + $stripe_params['elements_options'] = apply_filters('wc_stripe_elements_options', array()); |
|
451 | 451 | $stripe_params['sepa_elements_options'] = $sepa_elements_options; |
452 | - $stripe_params['invalid_owner_name'] = __( 'Billing First Name and Last Name are required.', 'woocommerce-gateway-stripe' ); |
|
453 | - $stripe_params['is_change_payment_page'] = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no'; // wpcs: csrf ok. |
|
454 | - $stripe_params['is_add_payment_page'] = is_wc_endpoint_url( 'add-payment-method' ) ? 'yes' : 'no'; |
|
455 | - $stripe_params['is_pay_for_order_page'] = is_wc_endpoint_url( 'order-pay' ) ? 'yes' : 'no'; |
|
456 | - $stripe_params['elements_styling'] = apply_filters( 'wc_stripe_elements_styling', false ); |
|
457 | - $stripe_params['elements_classes'] = apply_filters( 'wc_stripe_elements_classes', false ); |
|
452 | + $stripe_params['invalid_owner_name'] = __('Billing First Name and Last Name are required.', 'woocommerce-gateway-stripe'); |
|
453 | + $stripe_params['is_change_payment_page'] = isset($_GET['change_payment_method']) ? 'yes' : 'no'; // wpcs: csrf ok. |
|
454 | + $stripe_params['is_add_payment_page'] = is_wc_endpoint_url('add-payment-method') ? 'yes' : 'no'; |
|
455 | + $stripe_params['is_pay_for_order_page'] = is_wc_endpoint_url('order-pay') ? 'yes' : 'no'; |
|
456 | + $stripe_params['elements_styling'] = apply_filters('wc_stripe_elements_styling', false); |
|
457 | + $stripe_params['elements_classes'] = apply_filters('wc_stripe_elements_classes', false); |
|
458 | 458 | |
459 | 459 | // Merge localized messages to be use in JS. |
460 | - $stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() ); |
|
460 | + $stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages()); |
|
461 | 461 | |
462 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
462 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
463 | 463 | |
464 | 464 | $this->tokenization_script(); |
465 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
465 | + wp_enqueue_script('woocommerce_stripe'); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | /** |
@@ -473,14 +473,14 @@ discard block |
||
473 | 473 | * @param object $prepared_source The object with source details. |
474 | 474 | * @throws WC_Stripe_Exception An exception if the card is prepaid, but prepaid cards are not allowed. |
475 | 475 | */ |
476 | - public function maybe_disallow_prepaid_card( $prepared_source ) { |
|
476 | + public function maybe_disallow_prepaid_card($prepared_source) { |
|
477 | 477 | // Check if we don't allow prepaid credit cards. |
478 | - if ( apply_filters( 'wc_stripe_allow_prepaid_card', true ) || ! $this->is_prepaid_card( $prepared_source->source_object ) ) { |
|
478 | + if (apply_filters('wc_stripe_allow_prepaid_card', true) || ! $this->is_prepaid_card($prepared_source->source_object)) { |
|
479 | 479 | return; |
480 | 480 | } |
481 | 481 | |
482 | - $localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
483 | - throw new WC_Stripe_Exception( print_r( $prepared_source->source_object, true ), $localized_message ); |
|
482 | + $localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
483 | + throw new WC_Stripe_Exception(print_r($prepared_source->source_object, true), $localized_message); |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | /** |
@@ -490,10 +490,10 @@ discard block |
||
490 | 490 | * @param object $prepared_source The source that should be verified. |
491 | 491 | * @throws WC_Stripe_Exception An exception if the source ID is missing. |
492 | 492 | */ |
493 | - public function check_source( $prepared_source ) { |
|
494 | - if ( empty( $prepared_source->source ) ) { |
|
495 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
496 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
493 | + public function check_source($prepared_source) { |
|
494 | + if (empty($prepared_source->source)) { |
|
495 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
496 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
497 | 497 | } |
498 | 498 | } |
499 | 499 | |
@@ -505,17 +505,17 @@ discard block |
||
505 | 505 | * @param WC_Order $order The order those payment is being processed. |
506 | 506 | * @return bool A flag that indicates that the customer does not exist and should be removed. |
507 | 507 | */ |
508 | - public function maybe_remove_non_existent_customer( $error, $order ) { |
|
509 | - if ( ! $this->is_no_such_customer_error( $error ) ) { |
|
508 | + public function maybe_remove_non_existent_customer($error, $order) { |
|
509 | + if ( ! $this->is_no_such_customer_error($error)) { |
|
510 | 510 | return false; |
511 | 511 | } |
512 | 512 | |
513 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
514 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
515 | - delete_post_meta( $order->get_id(), '_stripe_customer_id' ); |
|
513 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
514 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
515 | + delete_post_meta($order->get_id(), '_stripe_customer_id'); |
|
516 | 516 | } else { |
517 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
518 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
517 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
518 | + $order->delete_meta_data('_stripe_customer_id'); |
|
519 | 519 | $order->save(); |
520 | 520 | } |
521 | 521 | |
@@ -531,16 +531,16 @@ discard block |
||
531 | 531 | * @param boolean $force_save_source Whether the payment source must be saved, like when dealing with a Subscription setup. |
532 | 532 | * @return array Redirection data for `process_payment`. |
533 | 533 | */ |
534 | - public function complete_free_order( $order, $prepared_source, $force_save_source ) { |
|
534 | + public function complete_free_order($order, $prepared_source, $force_save_source) { |
|
535 | 535 | $response = array( |
536 | 536 | 'result' => 'success', |
537 | - 'redirect' => $this->get_return_url( $order ), |
|
537 | + 'redirect' => $this->get_return_url($order), |
|
538 | 538 | ); |
539 | 539 | |
540 | - if ( $force_save_source ) { |
|
541 | - $intent_secret = $this->setup_intent( $order, $prepared_source ); |
|
540 | + if ($force_save_source) { |
|
541 | + $intent_secret = $this->setup_intent($order, $prepared_source); |
|
542 | 542 | |
543 | - if ( ! empty( $intent_secret ) ) { |
|
543 | + if ( ! empty($intent_secret)) { |
|
544 | 544 | $response['setup_intent_secret'] = $intent_secret; |
545 | 545 | return $response; |
546 | 546 | } |
@@ -568,70 +568,70 @@ discard block |
||
568 | 568 | * @throws Exception If payment will not be accepted. |
569 | 569 | * @return array|void |
570 | 570 | */ |
571 | - public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) { |
|
571 | + public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) { |
|
572 | 572 | try { |
573 | - $order = wc_get_order( $order_id ); |
|
573 | + $order = wc_get_order($order_id); |
|
574 | 574 | |
575 | 575 | // ToDo: `process_pre_order` saves the source to the order for a later payment. |
576 | 576 | // This might not work well with PaymentIntents. |
577 | - if ( $this->maybe_process_pre_orders( $order_id ) ) { |
|
578 | - return $this->pre_orders->process_pre_order( $order_id ); |
|
577 | + if ($this->maybe_process_pre_orders($order_id)) { |
|
578 | + return $this->pre_orders->process_pre_order($order_id); |
|
579 | 579 | } |
580 | 580 | |
581 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source ); |
|
581 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source); |
|
582 | 582 | |
583 | - $this->maybe_disallow_prepaid_card( $prepared_source ); |
|
584 | - $this->check_source( $prepared_source ); |
|
585 | - $this->save_source_to_order( $order, $prepared_source ); |
|
583 | + $this->maybe_disallow_prepaid_card($prepared_source); |
|
584 | + $this->check_source($prepared_source); |
|
585 | + $this->save_source_to_order($order, $prepared_source); |
|
586 | 586 | |
587 | - if ( 0 >= $order->get_total() ) { |
|
588 | - return $this->complete_free_order( $order, $prepared_source, $force_save_source ); |
|
587 | + if (0 >= $order->get_total()) { |
|
588 | + return $this->complete_free_order($order, $prepared_source, $force_save_source); |
|
589 | 589 | } |
590 | 590 | |
591 | 591 | // This will throw exception if not valid. |
592 | - $this->validate_minimum_order_amount( $order ); |
|
592 | + $this->validate_minimum_order_amount($order); |
|
593 | 593 | |
594 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
594 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
595 | 595 | |
596 | - $intent = $this->get_intent_from_order( $order ); |
|
597 | - if ( isset( $intent->object ) && 'setup_intent' === $intent->object ) { |
|
596 | + $intent = $this->get_intent_from_order($order); |
|
597 | + if (isset($intent->object) && 'setup_intent' === $intent->object) { |
|
598 | 598 | $intent = false; // This function can only deal with *payment* intents |
599 | 599 | } |
600 | 600 | |
601 | - if ( $intent ) { |
|
602 | - $intent = $this->update_existing_intent( $intent, $order, $prepared_source ); |
|
601 | + if ($intent) { |
|
602 | + $intent = $this->update_existing_intent($intent, $order, $prepared_source); |
|
603 | 603 | } else { |
604 | - $intent = $this->create_intent( $order, $prepared_source ); |
|
604 | + $intent = $this->create_intent($order, $prepared_source); |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | // Confirm the intent after locking the order to make sure webhooks will not interfere. |
608 | - if ( empty( $intent->error ) ) { |
|
609 | - $this->lock_order_payment( $order, $intent ); |
|
610 | - $intent = $this->confirm_intent( $intent, $order, $prepared_source ); |
|
608 | + if (empty($intent->error)) { |
|
609 | + $this->lock_order_payment($order, $intent); |
|
610 | + $intent = $this->confirm_intent($intent, $order, $prepared_source); |
|
611 | 611 | } |
612 | 612 | |
613 | - if ( ! empty( $intent->error ) ) { |
|
614 | - $this->maybe_remove_non_existent_customer( $intent->error, $order ); |
|
613 | + if ( ! empty($intent->error)) { |
|
614 | + $this->maybe_remove_non_existent_customer($intent->error, $order); |
|
615 | 615 | |
616 | 616 | // We want to retry. |
617 | - if ( $this->is_retryable_error( $intent->error ) ) { |
|
618 | - return $this->retry_after_error( $intent, $order, $retry, $force_save_source, $previous_error ); |
|
617 | + if ($this->is_retryable_error($intent->error)) { |
|
618 | + return $this->retry_after_error($intent, $order, $retry, $force_save_source, $previous_error); |
|
619 | 619 | } |
620 | 620 | |
621 | - $this->unlock_order_payment( $order ); |
|
622 | - $this->throw_localized_message( $intent, $order ); |
|
621 | + $this->unlock_order_payment($order); |
|
622 | + $this->throw_localized_message($intent, $order); |
|
623 | 623 | } |
624 | 624 | |
625 | - if ( ! empty( $intent ) ) { |
|
625 | + if ( ! empty($intent)) { |
|
626 | 626 | // Use the last charge within the intent to proceed. |
627 | - $response = end( $intent->charges->data ); |
|
627 | + $response = end($intent->charges->data); |
|
628 | 628 | |
629 | 629 | // If the intent requires a 3DS flow, redirect to it. |
630 | - if ( 'requires_action' === $intent->status ) { |
|
631 | - $this->unlock_order_payment( $order ); |
|
630 | + if ('requires_action' === $intent->status) { |
|
631 | + $this->unlock_order_payment($order); |
|
632 | 632 | |
633 | - if ( is_wc_endpoint_url( 'order-pay' ) ) { |
|
634 | - $redirect_url = add_query_arg( 'wc-stripe-confirmation', 1, $order->get_checkout_payment_url( false ) ); |
|
633 | + if (is_wc_endpoint_url('order-pay')) { |
|
634 | + $redirect_url = add_query_arg('wc-stripe-confirmation', 1, $order->get_checkout_payment_url(false)); |
|
635 | 635 | |
636 | 636 | return array( |
637 | 637 | 'result' => 'success', |
@@ -646,7 +646,7 @@ discard block |
||
646 | 646 | |
647 | 647 | return array( |
648 | 648 | 'result' => 'success', |
649 | - 'redirect' => $this->get_return_url( $order ), |
|
649 | + 'redirect' => $this->get_return_url($order), |
|
650 | 650 | 'payment_intent_secret' => $intent->client_secret, |
651 | 651 | ); |
652 | 652 | } |
@@ -654,30 +654,30 @@ discard block |
||
654 | 654 | } |
655 | 655 | |
656 | 656 | // Process valid response. |
657 | - $this->process_response( $response, $order ); |
|
657 | + $this->process_response($response, $order); |
|
658 | 658 | |
659 | 659 | // Remove cart. |
660 | - if ( isset( WC()->cart ) ) { |
|
660 | + if (isset(WC()->cart)) { |
|
661 | 661 | WC()->cart->empty_cart(); |
662 | 662 | } |
663 | 663 | |
664 | 664 | // Unlock the order. |
665 | - $this->unlock_order_payment( $order ); |
|
665 | + $this->unlock_order_payment($order); |
|
666 | 666 | |
667 | 667 | // Return thank you page redirect. |
668 | 668 | return array( |
669 | 669 | 'result' => 'success', |
670 | - 'redirect' => $this->get_return_url( $order ), |
|
670 | + 'redirect' => $this->get_return_url($order), |
|
671 | 671 | ); |
672 | 672 | |
673 | - } catch ( WC_Stripe_Exception $e ) { |
|
674 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
675 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
673 | + } catch (WC_Stripe_Exception $e) { |
|
674 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
675 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
676 | 676 | |
677 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
677 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
678 | 678 | |
679 | 679 | /* translators: error message */ |
680 | - $order->update_status( 'failed' ); |
|
680 | + $order->update_status('failed'); |
|
681 | 681 | |
682 | 682 | return array( |
683 | 683 | 'result' => 'fail', |
@@ -693,17 +693,17 @@ discard block |
||
693 | 693 | * |
694 | 694 | * @param int $order_id The ID of the order. |
695 | 695 | */ |
696 | - public function display_order_fee( $order_id ) { |
|
697 | - if ( apply_filters( 'wc_stripe_hide_display_order_fee', false, $order_id ) ) { |
|
696 | + public function display_order_fee($order_id) { |
|
697 | + if (apply_filters('wc_stripe_hide_display_order_fee', false, $order_id)) { |
|
698 | 698 | return; |
699 | 699 | } |
700 | 700 | |
701 | - $order = wc_get_order( $order_id ); |
|
701 | + $order = wc_get_order($order_id); |
|
702 | 702 | |
703 | - $fee = WC_Stripe_Helper::get_stripe_fee( $order ); |
|
704 | - $currency = WC_Stripe_Helper::get_stripe_currency( $order ); |
|
703 | + $fee = WC_Stripe_Helper::get_stripe_fee($order); |
|
704 | + $currency = WC_Stripe_Helper::get_stripe_currency($order); |
|
705 | 705 | |
706 | - if ( ! $fee || ! $currency ) { |
|
706 | + if ( ! $fee || ! $currency) { |
|
707 | 707 | return; |
708 | 708 | } |
709 | 709 | |
@@ -711,12 +711,12 @@ discard block |
||
711 | 711 | |
712 | 712 | <tr> |
713 | 713 | <td class="label stripe-fee"> |
714 | - <?php echo wc_help_tip( __( 'This represents the fee Stripe collects for the transaction.', 'woocommerce-gateway-stripe' ) ); // wpcs: xss ok. ?> |
|
715 | - <?php esc_html_e( 'Stripe Fee:', 'woocommerce-gateway-stripe' ); ?> |
|
714 | + <?php echo wc_help_tip(__('This represents the fee Stripe collects for the transaction.', 'woocommerce-gateway-stripe')); // wpcs: xss ok. ?> |
|
715 | + <?php esc_html_e('Stripe Fee:', 'woocommerce-gateway-stripe'); ?> |
|
716 | 716 | </td> |
717 | 717 | <td width="1%"></td> |
718 | 718 | <td class="total"> |
719 | - - <?php echo wc_price( $fee, array( 'currency' => $currency ) ); // wpcs: xss ok. ?> |
|
719 | + - <?php echo wc_price($fee, array('currency' => $currency)); // wpcs: xss ok. ?> |
|
720 | 720 | </td> |
721 | 721 | </tr> |
722 | 722 | |
@@ -730,17 +730,17 @@ discard block |
||
730 | 730 | * |
731 | 731 | * @param int $order_id The ID of the order. |
732 | 732 | */ |
733 | - public function display_order_payout( $order_id ) { |
|
734 | - if ( apply_filters( 'wc_stripe_hide_display_order_payout', false, $order_id ) ) { |
|
733 | + public function display_order_payout($order_id) { |
|
734 | + if (apply_filters('wc_stripe_hide_display_order_payout', false, $order_id)) { |
|
735 | 735 | return; |
736 | 736 | } |
737 | 737 | |
738 | - $order = wc_get_order( $order_id ); |
|
738 | + $order = wc_get_order($order_id); |
|
739 | 739 | |
740 | - $net = WC_Stripe_Helper::get_stripe_net( $order ); |
|
741 | - $currency = WC_Stripe_Helper::get_stripe_currency( $order ); |
|
740 | + $net = WC_Stripe_Helper::get_stripe_net($order); |
|
741 | + $currency = WC_Stripe_Helper::get_stripe_currency($order); |
|
742 | 742 | |
743 | - if ( ! $net || ! $currency ) { |
|
743 | + if ( ! $net || ! $currency) { |
|
744 | 744 | return; |
745 | 745 | } |
746 | 746 | |
@@ -748,12 +748,12 @@ discard block |
||
748 | 748 | |
749 | 749 | <tr> |
750 | 750 | <td class="label stripe-payout"> |
751 | - <?php echo wc_help_tip( __( 'This represents the net total that will be credited to your Stripe bank account. This may be in the currency that is set in your Stripe account.', 'woocommerce-gateway-stripe' ) ); // wpcs: xss ok. ?> |
|
752 | - <?php esc_html_e( 'Stripe Payout:', 'woocommerce-gateway-stripe' ); ?> |
|
751 | + <?php echo wc_help_tip(__('This represents the net total that will be credited to your Stripe bank account. This may be in the currency that is set in your Stripe account.', 'woocommerce-gateway-stripe')); // wpcs: xss ok. ?> |
|
752 | + <?php esc_html_e('Stripe Payout:', 'woocommerce-gateway-stripe'); ?> |
|
753 | 753 | </td> |
754 | 754 | <td width="1%"></td> |
755 | 755 | <td class="total"> |
756 | - <?php echo wc_price( $net, array( 'currency' => $currency ) ); // wpcs: xss ok. ?> |
|
756 | + <?php echo wc_price($net, array('currency' => $currency)); // wpcs: xss ok. ?> |
|
757 | 757 | </td> |
758 | 758 | </tr> |
759 | 759 | |
@@ -768,18 +768,18 @@ discard block |
||
768 | 768 | * @param WC_Order $order The order to add a note to. |
769 | 769 | * @throws WC_Stripe_Exception An exception with the right message. |
770 | 770 | */ |
771 | - public function throw_localized_message( $response, $order ) { |
|
771 | + public function throw_localized_message($response, $order) { |
|
772 | 772 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
773 | 773 | |
774 | - if ( 'card_error' === $response->error->type ) { |
|
775 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
774 | + if ('card_error' === $response->error->type) { |
|
775 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
776 | 776 | } else { |
777 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
777 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
778 | 778 | } |
779 | 779 | |
780 | - $order->add_order_note( $localized_message ); |
|
780 | + $order->add_order_note($localized_message); |
|
781 | 781 | |
782 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
782 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
783 | 783 | } |
784 | 784 | |
785 | 785 | /** |
@@ -794,22 +794,22 @@ discard block |
||
794 | 794 | * @throws WC_Stripe_Exception If the payment is not accepted. |
795 | 795 | * @return array|void |
796 | 796 | */ |
797 | - public function retry_after_error( $response, $order, $retry, $force_save_source, $previous_error ) { |
|
798 | - if ( ! $retry ) { |
|
799 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
800 | - $order->add_order_note( $localized_message ); |
|
801 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions. |
|
797 | + public function retry_after_error($response, $order, $retry, $force_save_source, $previous_error) { |
|
798 | + if ( ! $retry) { |
|
799 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
800 | + $order->add_order_note($localized_message); |
|
801 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); // phpcs:ignore WordPress.PHP.DevelopmentFunctions. |
|
802 | 802 | } |
803 | 803 | |
804 | 804 | // Don't do anymore retries after this. |
805 | - if ( 5 <= $this->retry_interval ) { |
|
806 | - return $this->process_payment( $order->get_id(), false, $force_save_source, $response->error, $previous_error ); |
|
805 | + if (5 <= $this->retry_interval) { |
|
806 | + return $this->process_payment($order->get_id(), false, $force_save_source, $response->error, $previous_error); |
|
807 | 807 | } |
808 | 808 | |
809 | - sleep( $this->retry_interval ); |
|
809 | + sleep($this->retry_interval); |
|
810 | 810 | $this->retry_interval++; |
811 | 811 | |
812 | - return $this->process_payment( $order->get_id(), true, $force_save_source, $response->error, $previous_error ); |
|
812 | + return $this->process_payment($order->get_id(), true, $force_save_source, $response->error, $previous_error); |
|
813 | 813 | } |
814 | 814 | |
815 | 815 | /** |
@@ -820,23 +820,23 @@ discard block |
||
820 | 820 | * @param WC_Payment_Gateway[] $gateways A list of all available gateways. |
821 | 821 | * @return WC_Payment_Gateway[] Either the same list or an empty one in the right conditions. |
822 | 822 | */ |
823 | - public function prepare_order_pay_page( $gateways ) { |
|
824 | - if ( ! is_wc_endpoint_url( 'order-pay' ) || ! isset( $_GET['wc-stripe-confirmation'] ) ) { // wpcs: csrf ok. |
|
823 | + public function prepare_order_pay_page($gateways) { |
|
824 | + if ( ! is_wc_endpoint_url('order-pay') || ! isset($_GET['wc-stripe-confirmation'])) { // wpcs: csrf ok. |
|
825 | 825 | return $gateways; |
826 | 826 | } |
827 | 827 | |
828 | 828 | try { |
829 | 829 | $this->prepare_intent_for_order_pay_page(); |
830 | - } catch ( WC_Stripe_Exception $e ) { |
|
830 | + } catch (WC_Stripe_Exception $e) { |
|
831 | 831 | // Just show the full order pay page if there was a problem preparing the Payment Intent |
832 | 832 | return $gateways; |
833 | 833 | } |
834 | 834 | |
835 | - add_filter( 'woocommerce_checkout_show_terms', '__return_false' ); |
|
836 | - add_filter( 'woocommerce_pay_order_button_html', '__return_false' ); |
|
837 | - add_filter( 'woocommerce_available_payment_gateways', '__return_empty_array' ); |
|
838 | - add_filter( 'woocommerce_no_available_payment_methods_message', array( $this, 'change_no_available_methods_message' ) ); |
|
839 | - add_action( 'woocommerce_pay_order_after_submit', array( $this, 'render_payment_intent_inputs' ) ); |
|
835 | + add_filter('woocommerce_checkout_show_terms', '__return_false'); |
|
836 | + add_filter('woocommerce_pay_order_button_html', '__return_false'); |
|
837 | + add_filter('woocommerce_available_payment_gateways', '__return_empty_array'); |
|
838 | + add_filter('woocommerce_no_available_payment_methods_message', array($this, 'change_no_available_methods_message')); |
|
839 | + add_action('woocommerce_pay_order_after_submit', array($this, 'render_payment_intent_inputs')); |
|
840 | 840 | |
841 | 841 | return array(); |
842 | 842 | } |
@@ -849,7 +849,7 @@ discard block |
||
849 | 849 | * @return string the new message. |
850 | 850 | */ |
851 | 851 | public function change_no_available_methods_message() { |
852 | - return wpautop( __( "Almost there!\n\nYour order has already been created, the only thing that still needs to be done is for you to authorize the payment with your bank.", 'woocommerce-gateway-stripe' ) ); |
|
852 | + return wpautop(__("Almost there!\n\nYour order has already been created, the only thing that still needs to be done is for you to authorize the payment with your bank.", 'woocommerce-gateway-stripe')); |
|
853 | 853 | } |
854 | 854 | |
855 | 855 | /** |
@@ -860,23 +860,23 @@ discard block |
||
860 | 860 | * @throws WC_Stripe_Exception |
861 | 861 | * @since 4.3 |
862 | 862 | */ |
863 | - public function prepare_intent_for_order_pay_page( $order = null ) { |
|
864 | - if ( ! isset( $order ) || empty( $order ) ) { |
|
865 | - $order = wc_get_order( absint( get_query_var( 'order-pay' ) ) ); |
|
863 | + public function prepare_intent_for_order_pay_page($order = null) { |
|
864 | + if ( ! isset($order) || empty($order)) { |
|
865 | + $order = wc_get_order(absint(get_query_var('order-pay'))); |
|
866 | 866 | } |
867 | - $intent = $this->get_intent_from_order( $order ); |
|
867 | + $intent = $this->get_intent_from_order($order); |
|
868 | 868 | |
869 | - if ( ! $intent ) { |
|
870 | - throw new WC_Stripe_Exception( 'Payment Intent not found', __( 'Payment Intent not found for order #' . $order->get_id(), 'woocommerce-gateway-stripe' ) ); |
|
869 | + if ( ! $intent) { |
|
870 | + throw new WC_Stripe_Exception('Payment Intent not found', __('Payment Intent not found for order #' . $order->get_id(), 'woocommerce-gateway-stripe')); |
|
871 | 871 | } |
872 | 872 | |
873 | - if ( 'requires_payment_method' === $intent->status && isset( $intent->last_payment_error ) |
|
874 | - && 'authentication_required' === $intent->last_payment_error->code ) { |
|
875 | - $intent = WC_Stripe_API::request( array( |
|
873 | + if ('requires_payment_method' === $intent->status && isset($intent->last_payment_error) |
|
874 | + && 'authentication_required' === $intent->last_payment_error->code) { |
|
875 | + $intent = WC_Stripe_API::request(array( |
|
876 | 876 | 'payment_method' => $intent->last_payment_error->source->id, |
877 | - ), 'payment_intents/' . $intent->id . '/confirm' ); |
|
878 | - if ( isset( $intent->error ) ) { |
|
879 | - throw new WC_Stripe_Exception( print_r( $intent, true ), $intent->error->message ); |
|
877 | + ), 'payment_intents/' . $intent->id . '/confirm'); |
|
878 | + if (isset($intent->error)) { |
|
879 | + throw new WC_Stripe_Exception(print_r($intent, true), $intent->error->message); |
|
880 | 880 | } |
881 | 881 | } |
882 | 882 | |
@@ -891,26 +891,26 @@ discard block |
||
891 | 891 | * @throws WC_Stripe_Exception |
892 | 892 | * @since 4.2 |
893 | 893 | */ |
894 | - public function render_payment_intent_inputs( $order = null ) { |
|
895 | - if ( ! isset( $order ) || empty( $order ) ) { |
|
896 | - $order = wc_get_order( absint( get_query_var( 'order-pay' ) ) ); |
|
894 | + public function render_payment_intent_inputs($order = null) { |
|
895 | + if ( ! isset($order) || empty($order)) { |
|
896 | + $order = wc_get_order(absint(get_query_var('order-pay'))); |
|
897 | 897 | } |
898 | - if ( ! isset( $this->order_pay_intent ) ) { |
|
899 | - $this->prepare_intent_for_order_pay_page( $order ); |
|
898 | + if ( ! isset($this->order_pay_intent)) { |
|
899 | + $this->prepare_intent_for_order_pay_page($order); |
|
900 | 900 | } |
901 | 901 | |
902 | 902 | $verification_url = add_query_arg( |
903 | 903 | array( |
904 | 904 | 'order' => $order->get_id(), |
905 | - 'nonce' => wp_create_nonce( 'wc_stripe_confirm_pi' ), |
|
906 | - 'redirect_to' => rawurlencode( $this->get_return_url( $order ) ), |
|
905 | + 'nonce' => wp_create_nonce('wc_stripe_confirm_pi'), |
|
906 | + 'redirect_to' => rawurlencode($this->get_return_url($order)), |
|
907 | 907 | 'is_pay_for_order' => true, |
908 | 908 | ), |
909 | - WC_AJAX::get_endpoint( 'wc_stripe_verify_intent' ) |
|
909 | + WC_AJAX::get_endpoint('wc_stripe_verify_intent') |
|
910 | 910 | ); |
911 | 911 | |
912 | - echo '<input type="hidden" id="stripe-intent-id" value="' . esc_attr( $this->order_pay_intent->client_secret ) . '" />'; |
|
913 | - echo '<input type="hidden" id="stripe-intent-return" value="' . esc_attr( $verification_url ) . '" />'; |
|
912 | + echo '<input type="hidden" id="stripe-intent-id" value="' . esc_attr($this->order_pay_intent->client_secret) . '" />'; |
|
913 | + echo '<input type="hidden" id="stripe-intent-return" value="' . esc_attr($verification_url) . '" />'; |
|
914 | 914 | } |
915 | 915 | |
916 | 916 | /** |
@@ -920,11 +920,11 @@ discard block |
||
920 | 920 | * @param WC_Payment_Token $token Payment Token. |
921 | 921 | * @return string Generated payment method HTML |
922 | 922 | */ |
923 | - public function get_saved_payment_method_option_html( $token ) { |
|
924 | - $html = parent::get_saved_payment_method_option_html( $token ); |
|
923 | + public function get_saved_payment_method_option_html($token) { |
|
924 | + $html = parent::get_saved_payment_method_option_html($token); |
|
925 | 925 | $error_wrapper = '<div class="stripe-source-errors" role="alert"></div>'; |
926 | 926 | |
927 | - return preg_replace( '~</(\w+)>\s*$~', "$error_wrapper</$1>", $html ); |
|
927 | + return preg_replace('~</(\w+)>\s*$~', "$error_wrapper</$1>", $html); |
|
928 | 928 | } |
929 | 929 | |
930 | 930 | /** |
@@ -934,18 +934,18 @@ discard block |
||
934 | 934 | * @since 4.2.0 |
935 | 935 | * @param int $order_id The ID that will be used for the thank you page. |
936 | 936 | */ |
937 | - public function check_intent_status_on_order_page( $order_id ) { |
|
938 | - if ( empty( $order_id ) || absint( $order_id ) <= 0 ) { |
|
937 | + public function check_intent_status_on_order_page($order_id) { |
|
938 | + if (empty($order_id) || absint($order_id) <= 0) { |
|
939 | 939 | return; |
940 | 940 | } |
941 | 941 | |
942 | - $order = wc_get_order( absint( $order_id ) ); |
|
942 | + $order = wc_get_order(absint($order_id)); |
|
943 | 943 | |
944 | - if ( ! $order ) { |
|
944 | + if ( ! $order) { |
|
945 | 945 | return; |
946 | 946 | } |
947 | 947 | |
948 | - $this->verify_intent_after_checkout( $order ); |
|
948 | + $this->verify_intent_after_checkout($order); |
|
949 | 949 | } |
950 | 950 | |
951 | 951 | /** |
@@ -959,8 +959,8 @@ discard block |
||
959 | 959 | * @param int $order_id The ID of the order which is being paid for. |
960 | 960 | * @return array |
961 | 961 | */ |
962 | - public function modify_successful_payment_result( $result, $order_id ) { |
|
963 | - if ( ! isset( $result['payment_intent_secret'] ) && ! isset( $result['setup_intent_secret'] ) ) { |
|
962 | + public function modify_successful_payment_result($result, $order_id) { |
|
963 | + if ( ! isset($result['payment_intent_secret']) && ! isset($result['setup_intent_secret'])) { |
|
964 | 964 | // Only redirects with intents need to be modified. |
965 | 965 | return $result; |
966 | 966 | } |
@@ -969,16 +969,16 @@ discard block |
||
969 | 969 | $verification_url = add_query_arg( |
970 | 970 | array( |
971 | 971 | 'order' => $order_id, |
972 | - 'nonce' => wp_create_nonce( 'wc_stripe_confirm_pi' ), |
|
973 | - 'redirect_to' => rawurlencode( $result['redirect'] ), |
|
972 | + 'nonce' => wp_create_nonce('wc_stripe_confirm_pi'), |
|
973 | + 'redirect_to' => rawurlencode($result['redirect']), |
|
974 | 974 | ), |
975 | - WC_AJAX::get_endpoint( 'wc_stripe_verify_intent' ) |
|
975 | + WC_AJAX::get_endpoint('wc_stripe_verify_intent') |
|
976 | 976 | ); |
977 | 977 | |
978 | - if ( isset( $result['payment_intent_secret'] ) ) { |
|
979 | - $redirect = sprintf( '#confirm-pi-%s:%s', $result['payment_intent_secret'], rawurlencode( $verification_url ) ); |
|
980 | - } else if ( isset( $result['setup_intent_secret'] ) ) { |
|
981 | - $redirect = sprintf( '#confirm-si-%s:%s', $result['setup_intent_secret'], rawurlencode( $verification_url ) ); |
|
978 | + if (isset($result['payment_intent_secret'])) { |
|
979 | + $redirect = sprintf('#confirm-pi-%s:%s', $result['payment_intent_secret'], rawurlencode($verification_url)); |
|
980 | + } else if (isset($result['setup_intent_secret'])) { |
|
981 | + $redirect = sprintf('#confirm-si-%s:%s', $result['setup_intent_secret'], rawurlencode($verification_url)); |
|
982 | 982 | } |
983 | 983 | |
984 | 984 | return array( |
@@ -990,8 +990,8 @@ discard block |
||
990 | 990 | /** |
991 | 991 | * Proceed with current request using new login session (to ensure consistent nonce). |
992 | 992 | */ |
993 | - public function set_cookie_on_current_request( $cookie ) { |
|
994 | - $_COOKIE[ LOGGED_IN_COOKIE ] = $cookie; |
|
993 | + public function set_cookie_on_current_request($cookie) { |
|
994 | + $_COOKIE[LOGGED_IN_COOKIE] = $cookie; |
|
995 | 995 | } |
996 | 996 | |
997 | 997 | /** |
@@ -1001,48 +1001,48 @@ discard block |
||
1001 | 1001 | * @since 4.2.0 |
1002 | 1002 | * @param WC_Order $order The order which is in a transitional state. |
1003 | 1003 | */ |
1004 | - public function verify_intent_after_checkout( $order ) { |
|
1005 | - $payment_method = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->payment_method : $order->get_payment_method(); |
|
1006 | - if ( $payment_method !== $this->id ) { |
|
1004 | + public function verify_intent_after_checkout($order) { |
|
1005 | + $payment_method = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->payment_method : $order->get_payment_method(); |
|
1006 | + if ($payment_method !== $this->id) { |
|
1007 | 1007 | // If this is not the payment method, an intent would not be available. |
1008 | 1008 | return; |
1009 | 1009 | } |
1010 | 1010 | |
1011 | - $intent = $this->get_intent_from_order( $order ); |
|
1012 | - if ( ! $intent ) { |
|
1011 | + $intent = $this->get_intent_from_order($order); |
|
1012 | + if ( ! $intent) { |
|
1013 | 1013 | // No intent, redirect to the order received page for further actions. |
1014 | 1014 | return; |
1015 | 1015 | } |
1016 | 1016 | |
1017 | 1017 | // A webhook might have modified or locked the order while the intent was retreived. This ensures we are reading the right status. |
1018 | - clean_post_cache( $order->get_id() ); |
|
1019 | - $order = wc_get_order( $order->get_id() ); |
|
1018 | + clean_post_cache($order->get_id()); |
|
1019 | + $order = wc_get_order($order->get_id()); |
|
1020 | 1020 | |
1021 | - if ( 'pending' !== $order->get_status() && 'failed' !== $order->get_status() ) { |
|
1021 | + if ('pending' !== $order->get_status() && 'failed' !== $order->get_status()) { |
|
1022 | 1022 | // If payment has already been completed, this function is redundant. |
1023 | 1023 | return; |
1024 | 1024 | } |
1025 | 1025 | |
1026 | - if ( $this->lock_order_payment( $order, $intent ) ) { |
|
1026 | + if ($this->lock_order_payment($order, $intent)) { |
|
1027 | 1027 | return; |
1028 | 1028 | } |
1029 | 1029 | |
1030 | - if ( 'setup_intent' === $intent->object && 'succeeded' === $intent->status ) { |
|
1030 | + if ('setup_intent' === $intent->object && 'succeeded' === $intent->status) { |
|
1031 | 1031 | WC()->cart->empty_cart(); |
1032 | - if ( WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order( $order ) ) { |
|
1033 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
1032 | + if (WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order($order)) { |
|
1033 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
1034 | 1034 | } else { |
1035 | 1035 | $order->payment_complete(); |
1036 | 1036 | } |
1037 | - } else if ( 'succeeded' === $intent->status || 'requires_capture' === $intent->status ) { |
|
1037 | + } else if ('succeeded' === $intent->status || 'requires_capture' === $intent->status) { |
|
1038 | 1038 | // Proceed with the payment completion. |
1039 | - $this->process_response( end( $intent->charges->data ), $order ); |
|
1040 | - } else if ( 'requires_payment_method' === $intent->status ) { |
|
1039 | + $this->process_response(end($intent->charges->data), $order); |
|
1040 | + } else if ('requires_payment_method' === $intent->status) { |
|
1041 | 1041 | // `requires_payment_method` means that SCA got denied for the current payment method. |
1042 | - $this->failed_sca_auth( $order, $intent ); |
|
1042 | + $this->failed_sca_auth($order, $intent); |
|
1043 | 1043 | } |
1044 | 1044 | |
1045 | - $this->unlock_order_payment( $order ); |
|
1045 | + $this->unlock_order_payment($order); |
|
1046 | 1046 | } |
1047 | 1047 | |
1048 | 1048 | /** |
@@ -1052,18 +1052,18 @@ discard block |
||
1052 | 1052 | * @param WC_Order $order The order which should be checked. |
1053 | 1053 | * @param object $intent The intent, associated with the order. |
1054 | 1054 | */ |
1055 | - public function failed_sca_auth( $order, $intent ) { |
|
1055 | + public function failed_sca_auth($order, $intent) { |
|
1056 | 1056 | // If the order has already failed, do not repeat the same message. |
1057 | - if ( 'failed' === $order->get_status() ) { |
|
1057 | + if ('failed' === $order->get_status()) { |
|
1058 | 1058 | return; |
1059 | 1059 | } |
1060 | 1060 | |
1061 | 1061 | // Load the right message and update the status. |
1062 | - $status_message = isset( $intent->last_payment_error ) |
|
1062 | + $status_message = isset($intent->last_payment_error) |
|
1063 | 1063 | /* translators: 1) The error message that was received from Stripe. */ |
1064 | - ? sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $intent->last_payment_error->message ) |
|
1065 | - : __( 'Stripe SCA authentication failed.', 'woocommerce-gateway-stripe' ); |
|
1066 | - $order->update_status( 'failed', $status_message ); |
|
1064 | + ? sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $intent->last_payment_error->message) |
|
1065 | + : __('Stripe SCA authentication failed.', 'woocommerce-gateway-stripe'); |
|
1066 | + $order->update_status('failed', $status_message); |
|
1067 | 1067 | } |
1068 | 1068 | |
1069 | 1069 | /** |
@@ -1074,10 +1074,10 @@ discard block |
||
1074 | 1074 | * |
1075 | 1075 | * @return string Checkout URL for the given order. |
1076 | 1076 | */ |
1077 | - public function get_checkout_payment_url( $pay_url, $order ) { |
|
1077 | + public function get_checkout_payment_url($pay_url, $order) { |
|
1078 | 1078 | global $wp; |
1079 | - if ( isset( $_GET['wc-stripe-confirmation'] ) && isset( $wp->query_vars['order-pay'] ) && $wp->query_vars['order-pay'] == $order->get_id() ) { |
|
1080 | - $pay_url = add_query_arg( 'wc-stripe-confirmation', 1, $pay_url ); |
|
1079 | + if (isset($_GET['wc-stripe-confirmation']) && isset($wp->query_vars['order-pay']) && $wp->query_vars['order-pay'] == $order->get_id()) { |
|
1080 | + $pay_url = add_query_arg('wc-stripe-confirmation', 1, $pay_url); |
|
1081 | 1081 | } |
1082 | 1082 | return $pay_url; |
1083 | 1083 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @since 4.0.6 |
6 | 6 | */ |
7 | 7 | |
8 | -if ( ! defined( 'ABSPATH' ) ) { |
|
8 | +if ( ! defined('ABSPATH')) { |
|
9 | 9 | exit; |
10 | 10 | } |
11 | 11 | |
@@ -60,23 +60,23 @@ discard block |
||
60 | 60 | public $apple_pay_verify_notice; |
61 | 61 | |
62 | 62 | public function __construct() { |
63 | - add_action( 'woocommerce_stripe_updated', array( $this, 'update_verification_file' ) ); |
|
63 | + add_action('woocommerce_stripe_updated', array($this, 'update_verification_file')); |
|
64 | 64 | |
65 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
66 | - $this->stripe_enabled = $this->get_option( 'enabled' ); |
|
67 | - $this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
68 | - $this->apple_pay_domain_set = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' ); |
|
65 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
66 | + $this->stripe_enabled = $this->get_option('enabled'); |
|
67 | + $this->payment_request = 'yes' === $this->get_option('payment_request', 'yes'); |
|
68 | + $this->apple_pay_domain_set = 'yes' === $this->get_option('apple_pay_domain_set', 'no'); |
|
69 | 69 | $this->apple_pay_verify_notice = ''; |
70 | - $this->testmode = 'yes' === $this->get_option( 'testmode', 'no' ); |
|
71 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
70 | + $this->testmode = 'yes' === $this->get_option('testmode', 'no'); |
|
71 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
72 | 72 | |
73 | - if ( empty( $this->stripe_settings ) ) { |
|
73 | + if (empty($this->stripe_settings)) { |
|
74 | 74 | return; |
75 | 75 | } |
76 | 76 | |
77 | 77 | $this->init_apple_pay(); |
78 | 78 | |
79 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
79 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -87,13 +87,13 @@ discard block |
||
87 | 87 | * @param string default |
88 | 88 | * @return string $setting_value |
89 | 89 | */ |
90 | - public function get_option( $setting = '', $default = '' ) { |
|
91 | - if ( empty( $this->stripe_settings ) ) { |
|
90 | + public function get_option($setting = '', $default = '') { |
|
91 | + if (empty($this->stripe_settings)) { |
|
92 | 92 | return $default; |
93 | 93 | } |
94 | 94 | |
95 | - if ( ! empty( $this->stripe_settings[ $setting ] ) ) { |
|
96 | - return $this->stripe_settings[ $setting ]; |
|
95 | + if ( ! empty($this->stripe_settings[$setting])) { |
|
96 | + return $this->stripe_settings[$setting]; |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | return $default; |
@@ -108,9 +108,9 @@ discard block |
||
108 | 108 | public function init_apple_pay() { |
109 | 109 | if ( |
110 | 110 | is_admin() && |
111 | - isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && |
|
112 | - isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] && |
|
113 | - isset( $_GET['section'] ) && 'stripe' === $_GET['section'] && |
|
111 | + isset($_GET['page']) && 'wc-settings' === $_GET['page'] && |
|
112 | + isset($_GET['tab']) && 'checkout' === $_GET['tab'] && |
|
113 | + isset($_GET['section']) && 'stripe' === $_GET['section'] && |
|
114 | 114 | $this->payment_request |
115 | 115 | ) { |
116 | 116 | $this->process_apple_pay_verification(); |
@@ -124,9 +124,9 @@ discard block |
||
124 | 124 | * @version 3.1.0 |
125 | 125 | * @param string $secret_key |
126 | 126 | */ |
127 | - private function register_apple_pay_domain( $secret_key = '' ) { |
|
128 | - if ( empty( $secret_key ) ) { |
|
129 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
127 | + private function register_apple_pay_domain($secret_key = '') { |
|
128 | + if (empty($secret_key)) { |
|
129 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -144,22 +144,22 @@ discard block |
||
144 | 144 | $endpoint, |
145 | 145 | array( |
146 | 146 | 'headers' => $headers, |
147 | - 'body' => http_build_query( $data ), |
|
147 | + 'body' => http_build_query($data), |
|
148 | 148 | ) |
149 | 149 | ); |
150 | 150 | |
151 | - if ( is_wp_error( $response ) ) { |
|
151 | + if (is_wp_error($response)) { |
|
152 | 152 | /* translators: error message */ |
153 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
153 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
154 | 154 | } |
155 | 155 | |
156 | - if ( 200 !== $response['response']['code'] ) { |
|
157 | - $parsed_response = json_decode( $response['body'] ); |
|
156 | + if (200 !== $response['response']['code']) { |
|
157 | + $parsed_response = json_decode($response['body']); |
|
158 | 158 | |
159 | 159 | $this->apple_pay_verify_notice = $parsed_response->error->message; |
160 | 160 | |
161 | 161 | /* translators: error message */ |
162 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) ); |
|
162 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message)); |
|
163 | 163 | } |
164 | 164 | } |
165 | 165 | |
@@ -172,31 +172,31 @@ discard block |
||
172 | 172 | * @since 4.3.0 |
173 | 173 | * @return bool True on success, false on failure. |
174 | 174 | */ |
175 | - public function update_verification_file( $force = false ) { |
|
176 | - $path = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] ); |
|
175 | + public function update_verification_file($force = false) { |
|
176 | + $path = untrailingslashit($_SERVER['DOCUMENT_ROOT']); |
|
177 | 177 | $dir = '.well-known'; |
178 | 178 | $file = 'apple-developer-merchantid-domain-association'; |
179 | 179 | $fullpath = $path . '/' . $dir . '/' . $file; |
180 | 180 | |
181 | - $existing_contents = @file_get_contents( $fullpath ); |
|
182 | - $new_contents = @file_get_contents( WC_STRIPE_PLUGIN_PATH . '/' . $file ); |
|
183 | - if ( ( ! $existing_contents && ! $force ) || $existing_contents === $new_contents ) { |
|
181 | + $existing_contents = @file_get_contents($fullpath); |
|
182 | + $new_contents = @file_get_contents(WC_STRIPE_PLUGIN_PATH . '/' . $file); |
|
183 | + if (( ! $existing_contents && ! $force) || $existing_contents === $new_contents) { |
|
184 | 184 | return true; |
185 | 185 | } |
186 | 186 | |
187 | - if ( ! file_exists( $path . '/' . $dir ) ) { |
|
188 | - if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) { // @codingStandardsIgnoreLine |
|
189 | - WC_Stripe_Logger::log( 'Error: ' . __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
187 | + if ( ! file_exists($path . '/' . $dir)) { |
|
188 | + if ( ! @mkdir($path . '/' . $dir, 0755)) { // @codingStandardsIgnoreLine |
|
189 | + WC_Stripe_Logger::log('Error: ' . __('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe')); |
|
190 | 190 | return false; |
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
194 | - if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { // @codingStandardsIgnoreLine |
|
195 | - WC_Stripe_Logger::log( 'Error: ' . __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
194 | + if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { // @codingStandardsIgnoreLine |
|
195 | + WC_Stripe_Logger::log('Error: ' . __('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe')); |
|
196 | 196 | return false; |
197 | 197 | } |
198 | 198 | |
199 | - WC_Stripe_Logger::log( 'Domain association file updated.' ); |
|
199 | + WC_Stripe_Logger::log('Domain association file updated.'); |
|
200 | 200 | return true; |
201 | 201 | } |
202 | 202 | |
@@ -207,31 +207,31 @@ discard block |
||
207 | 207 | * @version 3.1.0 |
208 | 208 | */ |
209 | 209 | public function process_apple_pay_verification() { |
210 | - if ( ! $this->update_verification_file( true ) ) { |
|
210 | + if ( ! $this->update_verification_file(true)) { |
|
211 | 211 | $this->stripe_settings['apple_pay_domain_set'] = 'no'; |
212 | - update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); |
|
212 | + update_option('woocommerce_stripe_settings', $this->stripe_settings); |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | |
216 | 216 | try { |
217 | 217 | // At this point then the domain association folder and file should be available. |
218 | 218 | // Proceed to verify/and or verify again. |
219 | - $this->register_apple_pay_domain( $this->secret_key ); |
|
219 | + $this->register_apple_pay_domain($this->secret_key); |
|
220 | 220 | |
221 | 221 | // No errors to this point, verification success! |
222 | 222 | $this->stripe_settings['apple_pay_domain_set'] = 'yes'; |
223 | 223 | $this->apple_pay_domain_set = true; |
224 | 224 | |
225 | - update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); |
|
225 | + update_option('woocommerce_stripe_settings', $this->stripe_settings); |
|
226 | 226 | |
227 | - WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' ); |
|
227 | + WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!'); |
|
228 | 228 | |
229 | - } catch ( Exception $e ) { |
|
229 | + } catch (Exception $e) { |
|
230 | 230 | $this->stripe_settings['apple_pay_domain_set'] = 'no'; |
231 | 231 | |
232 | - update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); |
|
232 | + update_option('woocommerce_stripe_settings', $this->stripe_settings); |
|
233 | 233 | |
234 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
234 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
235 | 235 | } |
236 | 236 | } |
237 | 237 | |
@@ -241,15 +241,15 @@ discard block |
||
241 | 241 | * @since 4.0.6 |
242 | 242 | */ |
243 | 243 | public function admin_notices() { |
244 | - if ( ! $this->stripe_enabled ) { |
|
244 | + if ( ! $this->stripe_enabled) { |
|
245 | 245 | return; |
246 | 246 | } |
247 | 247 | |
248 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
248 | + if ( ! current_user_can('manage_woocommerce')) { |
|
249 | 249 | return; |
250 | 250 | } |
251 | 251 | |
252 | - if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) { |
|
252 | + if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) { |
|
253 | 253 | $allowed_html = array( |
254 | 254 | 'a' => array( |
255 | 255 | 'href' => array(), |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | ), |
258 | 258 | ); |
259 | 259 | |
260 | - echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>'; |
|
260 | + echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>'; |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | /** |
@@ -265,9 +265,9 @@ discard block |
||
265 | 265 | * when setting screen is displayed. So if domain verification is not set, |
266 | 266 | * something went wrong so lets notify user. |
267 | 267 | */ |
268 | - if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) { |
|
268 | + if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) { |
|
269 | 269 | /* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */ |
270 | - echo '<div class="error stripe-apple-pay-message"><p>' . sprintf( __( 'Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>'; |
|
270 | + echo '<div class="error stripe-apple-pay-message"><p>' . sprintf(__('Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', '</a>') . '</p></div>'; |
|
271 | 271 | } |
272 | 272 | } |
273 | 273 | } |