@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
3 | +if ( ! defined('ABSPATH')) { |
|
4 | 4 | exit; |
5 | 5 | } |
6 | 6 | |
7 | -if ( ! class_exists( 'WC_Stripe_Connect_REST_Oauth_Connect_Controller' ) ) { |
|
7 | +if ( ! class_exists('WC_Stripe_Connect_REST_Oauth_Connect_Controller')) { |
|
8 | 8 | /** |
9 | 9 | * Stripe Connect Oauth Connect controller class. |
10 | 10 | */ |
@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | * @param WC_Stripe_Connect $connect stripe connect. |
31 | 31 | * @param WC_Stripe_Connect_API $api stripe connect api. |
32 | 32 | */ |
33 | - public function __construct( WC_Stripe_Connect $connect, WC_Stripe_Connect_API $api ) { |
|
33 | + public function __construct(WC_Stripe_Connect $connect, WC_Stripe_Connect_API $api) { |
|
34 | 34 | |
35 | - parent::__construct( $api ); |
|
35 | + parent::__construct($api); |
|
36 | 36 | |
37 | 37 | $this->connect = $connect; |
38 | 38 | } |
@@ -44,19 +44,19 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @return array|WP_Error |
46 | 46 | */ |
47 | - public function post( $request ) { |
|
47 | + public function post($request) { |
|
48 | 48 | |
49 | 49 | $data = $request->get_json_params(); |
50 | - $response = $this->connect->connect_oauth( $data['state'], $data['code'] ); |
|
50 | + $response = $this->connect->connect_oauth($data['state'], $data['code']); |
|
51 | 51 | |
52 | - if ( is_wp_error( $response ) ) { |
|
52 | + if (is_wp_error($response)) { |
|
53 | 53 | |
54 | - WC_Stripe_Logger::log( $response, __CLASS__ ); |
|
54 | + WC_Stripe_Logger::log($response, __CLASS__); |
|
55 | 55 | |
56 | 56 | return new WP_Error( |
57 | 57 | $response->get_error_code(), |
58 | 58 | $response->get_error_message(), |
59 | - array( 'status' => 400 ) |
|
59 | + array('status' => 400) |
|
60 | 60 | ); |
61 | 61 | } |
62 | 62 |
@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
3 | +if ( ! defined('ABSPATH')) { |
|
4 | 4 | exit; |
5 | 5 | } |
6 | 6 | |
7 | -if ( ! class_exists( 'WC_Stripe_Connect_REST_Controller' ) ) { |
|
7 | +if ( ! class_exists('WC_Stripe_Connect_REST_Controller')) { |
|
8 | 8 | /** |
9 | 9 | * Stripe Connect base REST controller class. |
10 | 10 | */ |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @param WC_Stripe_Connect_API $api stripe connect api. |
31 | 31 | */ |
32 | - public function __construct( WC_Stripe_Connect_API $api ) { |
|
32 | + public function __construct(WC_Stripe_Connect_API $api) { |
|
33 | 33 | |
34 | 34 | $this->api = $api; |
35 | 35 | } |
@@ -39,43 +39,43 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function register_routes() { |
41 | 41 | |
42 | - if ( method_exists( $this, 'get' ) ) { |
|
42 | + if (method_exists($this, 'get')) { |
|
43 | 43 | register_rest_route( |
44 | 44 | $this->namespace, |
45 | 45 | '/' . $this->rest_base, |
46 | 46 | array( |
47 | 47 | array( |
48 | 48 | 'methods' => 'GET', |
49 | - 'callback' => array( $this, 'get_internal' ), |
|
50 | - 'permission_callback' => array( $this, 'check_permission' ), |
|
49 | + 'callback' => array($this, 'get_internal'), |
|
50 | + 'permission_callback' => array($this, 'check_permission'), |
|
51 | 51 | ), |
52 | 52 | ) |
53 | 53 | ); |
54 | 54 | } |
55 | 55 | |
56 | - if ( method_exists( $this, 'post' ) ) { |
|
56 | + if (method_exists($this, 'post')) { |
|
57 | 57 | register_rest_route( |
58 | 58 | $this->namespace, |
59 | 59 | '/' . $this->rest_base, |
60 | 60 | array( |
61 | 61 | array( |
62 | 62 | 'methods' => 'POST', |
63 | - 'callback' => array( $this, 'post_internal' ), |
|
64 | - 'permission_callback' => array( $this, 'check_permission' ), |
|
63 | + 'callback' => array($this, 'post_internal'), |
|
64 | + 'permission_callback' => array($this, 'check_permission'), |
|
65 | 65 | ), |
66 | 66 | ) |
67 | 67 | ); |
68 | 68 | } |
69 | 69 | |
70 | - if ( method_exists( $this, 'delete' ) ) { |
|
70 | + if (method_exists($this, 'delete')) { |
|
71 | 71 | register_rest_route( |
72 | 72 | $this->namespace, |
73 | 73 | '/' . $this->rest_base, |
74 | 74 | array( |
75 | 75 | array( |
76 | 76 | 'methods' => 'DELETE', |
77 | - 'callback' => array( $this, 'delete_internal' ), |
|
78 | - 'permission_callback' => array( $this, 'check_permission' ), |
|
77 | + 'callback' => array($this, 'delete_internal'), |
|
78 | + 'permission_callback' => array($this, 'check_permission'), |
|
79 | 79 | ), |
80 | 80 | ) |
81 | 81 | ); |
@@ -89,11 +89,11 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @return array |
91 | 91 | */ |
92 | - public function get_internal( $request ) { |
|
92 | + public function get_internal($request) { |
|
93 | 93 | |
94 | 94 | $this->prevent_route_caching(); |
95 | 95 | |
96 | - return $this->get( $request ); |
|
96 | + return $this->get($request); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @return array |
105 | 105 | */ |
106 | - public function post_internal( $request ) { |
|
106 | + public function post_internal($request) { |
|
107 | 107 | |
108 | 108 | $this->prevent_route_caching(); |
109 | 109 | |
110 | - return $this->post( $request ); |
|
110 | + return $this->post($request); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -117,11 +117,11 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @return array |
119 | 119 | */ |
120 | - public function delete_internal( $request ) { |
|
120 | + public function delete_internal($request) { |
|
121 | 121 | |
122 | 122 | $this->prevent_route_caching(); |
123 | 123 | |
124 | - return $this->delete( $request ); |
|
124 | + return $this->delete($request); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @return bool |
133 | 133 | */ |
134 | - public function check_permission( $request ) { |
|
134 | + public function check_permission($request) { |
|
135 | 135 | |
136 | - return current_user_can( 'manage_woocommerce' ); |
|
136 | + return current_user_can('manage_woocommerce'); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -141,12 +141,12 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public function prevent_route_caching() { |
143 | 143 | |
144 | - if ( ! defined( 'DONOTCACHEPAGE' ) ) { |
|
145 | - define( 'DONOTCACHEPAGE', true ); // Play nice with WP-Super-Cache. |
|
144 | + if ( ! defined('DONOTCACHEPAGE')) { |
|
145 | + define('DONOTCACHEPAGE', true); // Play nice with WP-Super-Cache. |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | // Prevent our REST API endpoint responses from being added to browser cache. |
149 | - add_filter( 'rest_post_dispatch', array( $this, 'send_nocache_header' ), PHP_INT_MAX, 2 ); |
|
149 | + add_filter('rest_post_dispatch', array($this, 'send_nocache_header'), PHP_INT_MAX, 2); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
@@ -160,9 +160,9 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @return WP_REST_Response passthrough $response parameter |
162 | 162 | */ |
163 | - public function send_nocache_header( $response, $server ) { |
|
163 | + public function send_nocache_header($response, $server) { |
|
164 | 164 | |
165 | - $server->send_header( 'Cache-Control', 'no-cache, must-revalidate, max-age=0' ); |
|
165 | + $server->send_header('Cache-Control', 'no-cache, must-revalidate, max-age=0'); |
|
166 | 166 | |
167 | 167 | return $response; |
168 | 168 | } |
@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
3 | +if ( ! defined('ABSPATH')) { |
|
4 | 4 | exit; |
5 | 5 | } |
6 | 6 | |
7 | -if ( ! class_exists( 'WC_Stripe_Connect_REST_Oauth_Init_Controller' ) ) { |
|
7 | +if ( ! class_exists('WC_Stripe_Connect_REST_Oauth_Init_Controller')) { |
|
8 | 8 | /** |
9 | 9 | * Stripe Connect Oauth Init controller class. |
10 | 10 | */ |
@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | * @param WC_Stripe_Connect $connect stripe connect. |
31 | 31 | * @param WC_Stripe_Connect_API $api stripe connect api. |
32 | 32 | */ |
33 | - public function __construct( WC_Stripe_Connect $connect, WC_Stripe_Connect_API $api ) { |
|
33 | + public function __construct(WC_Stripe_Connect $connect, WC_Stripe_Connect_API $api) { |
|
34 | 34 | |
35 | - parent::__construct( $api ); |
|
35 | + parent::__construct($api); |
|
36 | 36 | |
37 | 37 | $this->connect = $connect; |
38 | 38 | } |
@@ -44,19 +44,19 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @return array|WP_Error |
46 | 46 | */ |
47 | - public function post( $request ) { |
|
47 | + public function post($request) { |
|
48 | 48 | |
49 | 49 | $data = $request->get_json_params(); |
50 | - $response = $this->connect->get_oauth_url( isset( $data['returnUrl'] ) ? $data['returnUrl'] : '' ); |
|
50 | + $response = $this->connect->get_oauth_url(isset($data['returnUrl']) ? $data['returnUrl'] : ''); |
|
51 | 51 | |
52 | - if ( is_wp_error( $response ) ) { |
|
52 | + if (is_wp_error($response)) { |
|
53 | 53 | |
54 | - WC_Stripe_Logger::log( $response, __CLASS__ ); |
|
54 | + WC_Stripe_Logger::log($response, __CLASS__); |
|
55 | 55 | |
56 | 56 | return new WP_Error( |
57 | 57 | $response->get_error_code(), |
58 | 58 | $response->get_error_message(), |
59 | - array( 'status' => 400 ) |
|
59 | + array('status' => 400) |
|
60 | 60 | ); |
61 | 61 | } |
62 | 62 |
@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | -if ( ! defined( 'WOOCOMMERCE_CONNECT_SERVER_URL' ) ) { |
|
7 | - define( 'WOOCOMMERCE_CONNECT_SERVER_URL', 'https://api.woocommerce.com/' ); |
|
6 | +if ( ! defined('WOOCOMMERCE_CONNECT_SERVER_URL')) { |
|
7 | + define('WOOCOMMERCE_CONNECT_SERVER_URL', 'https://api.woocommerce.com/'); |
|
8 | 8 | } |
9 | 9 | |
10 | -if ( ! class_exists( 'WC_Stripe_Connect_API' ) ) { |
|
10 | +if ( ! class_exists('WC_Stripe_Connect_API')) { |
|
11 | 11 | /** |
12 | 12 | * Stripe Connect API class. |
13 | 13 | */ |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @return array |
22 | 22 | */ |
23 | 23 | public function get_stripe_account_details() { |
24 | - return $this->request( 'GET', '/stripe/account' ); |
|
24 | + return $this->request('GET', '/stripe/account'); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -31,12 +31,12 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @return array |
33 | 33 | */ |
34 | - public function get_stripe_oauth_init( $return_url ) { |
|
34 | + public function get_stripe_oauth_init($return_url) { |
|
35 | 35 | |
36 | 36 | $current_user = wp_get_current_user(); |
37 | 37 | $business_data = array(); |
38 | 38 | $business_data['url'] = get_site_url(); |
39 | - $business_data['business_name'] = html_entity_decode( get_bloginfo( 'name' ), ENT_QUOTES ); |
|
39 | + $business_data['business_name'] = html_entity_decode(get_bloginfo('name'), ENT_QUOTES); |
|
40 | 40 | $business_data['first_name'] = $current_user->user_firstname; |
41 | 41 | $business_data['last_name'] = $current_user->user_lastname; |
42 | 42 | $business_data['phone'] = ''; |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | |
45 | 45 | $wc_countries = WC()->countries; |
46 | 46 | |
47 | - if ( method_exists( $wc_countries, 'get_base_address' ) ) { |
|
47 | + if (method_exists($wc_countries, 'get_base_address')) { |
|
48 | 48 | $business_data['country'] = $wc_countries->get_base_country(); |
49 | 49 | $business_data['street_address'] = $wc_countries->get_base_address(); |
50 | 50 | $business_data['city'] = $wc_countries->get_base_city(); |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | 'businessData' => $business_data, |
65 | 65 | ); |
66 | 66 | |
67 | - return $this->request( 'POST', '/stripe/oauth-init', $request ); |
|
67 | + return $this->request('POST', '/stripe/oauth-init', $request); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -74,11 +74,11 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @return array |
76 | 76 | */ |
77 | - public function get_stripe_oauth_keys( $code ) { |
|
77 | + public function get_stripe_oauth_keys($code) { |
|
78 | 78 | |
79 | - $request = array( 'code' => $code ); |
|
79 | + $request = array('code' => $code); |
|
80 | 80 | |
81 | - return $this->request( 'POST', '/stripe/oauth-keys', $request ); |
|
81 | + return $this->request('POST', '/stripe/oauth-keys', $request); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function deauthorize_stripe_account() { |
90 | 90 | |
91 | - return $this->request( 'POST', '/stripe/account/deauthorize' ); |
|
91 | + return $this->request('POST', '/stripe/account/deauthorize'); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -100,54 +100,54 @@ discard block |
||
100 | 100 | * |
101 | 101 | * @return array|WP_Error |
102 | 102 | */ |
103 | - protected function request( $method, $path, $body = array() ) { |
|
103 | + protected function request($method, $path, $body = array()) { |
|
104 | 104 | |
105 | - if ( ! class_exists( 'Jetpack_Data' ) ) { |
|
105 | + if ( ! class_exists('Jetpack_Data')) { |
|
106 | 106 | return new WP_Error( |
107 | 107 | 'jetpack_data_class_not_found', |
108 | - __( 'Unable to send request to WooCommerce Connect server. Jetpack_Data was not found.', 'woocommerce-gateway-stripe' ) |
|
108 | + __('Unable to send request to WooCommerce Connect server. Jetpack_Data was not found.', 'woocommerce-gateway-stripe') |
|
109 | 109 | ); |
110 | 110 | } |
111 | 111 | |
112 | - if ( ! method_exists( 'Jetpack_Data', 'get_access_token' ) ) { |
|
112 | + if ( ! method_exists('Jetpack_Data', 'get_access_token')) { |
|
113 | 113 | return new WP_Error( |
114 | 114 | 'jetpack_data_get_access_token_not_found', |
115 | - __( 'Unable to send request to WooCommerce Connect server. Jetpack_Data does not implement get_access_token.', 'woocommerce-gateway-stripe' ) |
|
115 | + __('Unable to send request to WooCommerce Connect server. Jetpack_Data does not implement get_access_token.', 'woocommerce-gateway-stripe') |
|
116 | 116 | ); |
117 | 117 | } |
118 | 118 | |
119 | - if ( ! is_array( $body ) ) { |
|
119 | + if ( ! is_array($body)) { |
|
120 | 120 | return new WP_Error( |
121 | 121 | 'request_body_should_be_array', |
122 | - __( 'Unable to send request to WooCommerce Connect server. Body must be an array.', 'woocommerce-gateway-stripe' ) |
|
122 | + __('Unable to send request to WooCommerce Connect server. Body must be an array.', 'woocommerce-gateway-stripe') |
|
123 | 123 | ); |
124 | 124 | } |
125 | 125 | |
126 | - $url = trailingslashit( WOOCOMMERCE_CONNECT_SERVER_URL ); |
|
127 | - $url = apply_filters( 'wc_connect_server_url', $url ); |
|
128 | - $url = trailingslashit( $url ) . ltrim( $path, '/' ); |
|
126 | + $url = trailingslashit(WOOCOMMERCE_CONNECT_SERVER_URL); |
|
127 | + $url = apply_filters('wc_connect_server_url', $url); |
|
128 | + $url = trailingslashit($url) . ltrim($path, '/'); |
|
129 | 129 | |
130 | 130 | // Add useful system information to requests that contain bodies. |
131 | - if ( in_array( $method, array( 'POST', 'PUT' ), true ) ) { |
|
132 | - $body = $this->request_body( $body ); |
|
133 | - $body = wp_json_encode( apply_filters( 'wc_connect_api_client_body', $body ) ); |
|
131 | + if (in_array($method, array('POST', 'PUT'), true)) { |
|
132 | + $body = $this->request_body($body); |
|
133 | + $body = wp_json_encode(apply_filters('wc_connect_api_client_body', $body)); |
|
134 | 134 | |
135 | - if ( ! $body ) { |
|
135 | + if ( ! $body) { |
|
136 | 136 | return new WP_Error( |
137 | 137 | 'unable_to_json_encode_body', |
138 | - __( 'Unable to encode body for request to WooCommerce Connect server.', 'woocommerce-gateway-stripe' ) |
|
138 | + __('Unable to encode body for request to WooCommerce Connect server.', 'woocommerce-gateway-stripe') |
|
139 | 139 | ); |
140 | 140 | } |
141 | 141 | } |
142 | 142 | |
143 | 143 | $headers = $this->request_headers(); |
144 | - if ( is_wp_error( $headers ) ) { |
|
144 | + if (is_wp_error($headers)) { |
|
145 | 145 | return $headers; |
146 | 146 | } |
147 | 147 | |
148 | 148 | $http_timeout = 60; // 1 minute |
149 | - if ( function_exists( 'wc_set_time_limit' ) ) { |
|
150 | - wc_set_time_limit( $http_timeout + 10 ); |
|
149 | + if (function_exists('wc_set_time_limit')) { |
|
150 | + wc_set_time_limit($http_timeout + 10); |
|
151 | 151 | } |
152 | 152 | $args = array( |
153 | 153 | 'headers' => $headers, |
@@ -158,18 +158,18 @@ discard block |
||
158 | 158 | 'timeout' => $http_timeout, |
159 | 159 | ); |
160 | 160 | |
161 | - $args = apply_filters( 'wc_connect_request_args', $args ); |
|
162 | - $response = wp_remote_request( $url, $args ); |
|
163 | - $response_code = wp_remote_retrieve_response_code( $response ); |
|
164 | - $content_type = wp_remote_retrieve_header( $response, 'content-type' ); |
|
161 | + $args = apply_filters('wc_connect_request_args', $args); |
|
162 | + $response = wp_remote_request($url, $args); |
|
163 | + $response_code = wp_remote_retrieve_response_code($response); |
|
164 | + $content_type = wp_remote_retrieve_header($response, 'content-type'); |
|
165 | 165 | |
166 | - if ( false === strpos( $content_type, 'application/json' ) ) { |
|
167 | - if ( 200 !== $response_code ) { |
|
166 | + if (false === strpos($content_type, 'application/json')) { |
|
167 | + if (200 !== $response_code) { |
|
168 | 168 | return new WP_Error( |
169 | 169 | 'wcc_server_error', |
170 | 170 | sprintf( |
171 | 171 | // Translators: HTTP error code. |
172 | - __( 'Error: The WooCommerce Connect server returned HTTP code: %d', 'woocommerce-gateway-stripe' ), |
|
172 | + __('Error: The WooCommerce Connect server returned HTTP code: %d', 'woocommerce-gateway-stripe'), |
|
173 | 173 | $response_code |
174 | 174 | ) |
175 | 175 | ); |
@@ -177,32 +177,32 @@ discard block |
||
177 | 177 | return $response; |
178 | 178 | } |
179 | 179 | |
180 | - $response_body = wp_remote_retrieve_body( $response ); |
|
181 | - if ( ! empty( $response_body ) ) { |
|
182 | - $response_body = json_decode( $response_body ); |
|
180 | + $response_body = wp_remote_retrieve_body($response); |
|
181 | + if ( ! empty($response_body)) { |
|
182 | + $response_body = json_decode($response_body); |
|
183 | 183 | } |
184 | 184 | |
185 | - if ( 200 !== $response_code ) { |
|
186 | - if ( empty( $response_body ) ) { |
|
185 | + if (200 !== $response_code) { |
|
186 | + if (empty($response_body)) { |
|
187 | 187 | return new WP_Error( |
188 | 188 | 'wcc_server_empty_response', |
189 | 189 | sprintf( |
190 | 190 | // Translators: HTTP error code. |
191 | - __( 'Error: The WooCommerce Connect server returned ( %d ) and an empty response body.', 'woocommerce-gateway-stripe' ), |
|
191 | + __('Error: The WooCommerce Connect server returned ( %d ) and an empty response body.', 'woocommerce-gateway-stripe'), |
|
192 | 192 | $response_code |
193 | 193 | ) |
194 | 194 | ); |
195 | 195 | } |
196 | 196 | |
197 | - $error = property_exists( $response_body, 'error' ) ? $response_body->error : ''; |
|
198 | - $message = property_exists( $response_body, 'message' ) ? $response_body->message : ''; |
|
199 | - $data = property_exists( $response_body, 'data' ) ? $response_body->data : ''; |
|
197 | + $error = property_exists($response_body, 'error') ? $response_body->error : ''; |
|
198 | + $message = property_exists($response_body, 'message') ? $response_body->message : ''; |
|
199 | + $data = property_exists($response_body, 'data') ? $response_body->data : ''; |
|
200 | 200 | |
201 | 201 | return new WP_Error( |
202 | 202 | 'wcc_server_error_response', |
203 | 203 | sprintf( |
204 | 204 | /* translators: %1$s: error code, %2$s: error message, %3$d: HTTP response code */ |
205 | - __( 'Error: The WooCommerce Connect server returned: %1$s %2$s ( %3$d )', 'woocommerce-gateway-stripe' ), |
|
205 | + __('Error: The WooCommerce Connect server returned: %1$s %2$s ( %3$d )', 'woocommerce-gateway-stripe'), |
|
206 | 206 | $error, |
207 | 207 | $message, |
208 | 208 | $response_code |
@@ -221,13 +221,13 @@ discard block |
||
221 | 221 | * |
222 | 222 | * @return array |
223 | 223 | */ |
224 | - protected function request_body( $initial_body = array() ) { |
|
224 | + protected function request_body($initial_body = array()) { |
|
225 | 225 | |
226 | 226 | $default_body = array( |
227 | 227 | 'settings' => array(), |
228 | 228 | ); |
229 | 229 | |
230 | - $body = array_merge( $default_body, $initial_body ); |
|
230 | + $body = array_merge($default_body, $initial_body); |
|
231 | 231 | |
232 | 232 | // Add interesting fields to the body of each request. |
233 | 233 | $body['settings'] = wp_parse_args( |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | 'stripe_version' => WC_STRIPE_VERSION, |
242 | 242 | 'jetpack_version' => JETPACK__VERSION, |
243 | 243 | 'wc_version' => WC()->version, |
244 | - 'wp_version' => get_bloginfo( 'version' ), |
|
244 | + 'wp_version' => get_bloginfo('version'), |
|
245 | 245 | ) |
246 | 246 | ); |
247 | 247 | |
@@ -257,13 +257,13 @@ discard block |
||
257 | 257 | |
258 | 258 | $authorization = $this->authorization_header(); |
259 | 259 | |
260 | - if ( is_wp_error( $authorization ) ) { |
|
260 | + if (is_wp_error($authorization)) { |
|
261 | 261 | return $authorization; |
262 | 262 | } |
263 | 263 | |
264 | 264 | $headers = array(); |
265 | - $locale = strtolower( str_replace( '_', '-', get_locale() ) ); |
|
266 | - $locale_elements = explode( '-', $locale ); |
|
265 | + $locale = strtolower(str_replace('_', '-', get_locale())); |
|
266 | + $locale_elements = explode('-', $locale); |
|
267 | 267 | $lang = $locale_elements[0]; |
268 | 268 | $headers['Accept-Language'] = $locale . ',' . $lang; |
269 | 269 | $headers['Content-Type'] = 'application/json; charset=utf-8'; |
@@ -280,32 +280,32 @@ discard block |
||
280 | 280 | */ |
281 | 281 | protected function authorization_header() { |
282 | 282 | |
283 | - $token = Jetpack_Data::get_access_token( 0 ); |
|
284 | - $token = apply_filters( 'wc_connect_jetpack_access_token', $token ); |
|
283 | + $token = Jetpack_Data::get_access_token(0); |
|
284 | + $token = apply_filters('wc_connect_jetpack_access_token', $token); |
|
285 | 285 | |
286 | - if ( ! $token || empty( $token->secret ) ) { |
|
286 | + if ( ! $token || empty($token->secret)) { |
|
287 | 287 | return new WP_Error( |
288 | 288 | 'missing_token', |
289 | - __( 'Unable to send request to WooCommerce Connect server. Jetpack Token is missing', 'woocommerce-gateway-stripe' ) |
|
289 | + __('Unable to send request to WooCommerce Connect server. Jetpack Token is missing', 'woocommerce-gateway-stripe') |
|
290 | 290 | ); |
291 | 291 | } |
292 | 292 | |
293 | - if ( false === strpos( $token->secret, '.' ) ) { |
|
293 | + if (false === strpos($token->secret, '.')) { |
|
294 | 294 | return new WP_Error( |
295 | 295 | 'invalid_token', |
296 | - __( 'Unable to send request to WooCommerce Connect server. Jetpack Token is malformed.', 'woocommerce-gateway-stripe' ) |
|
296 | + __('Unable to send request to WooCommerce Connect server. Jetpack Token is malformed.', 'woocommerce-gateway-stripe') |
|
297 | 297 | ); |
298 | 298 | } |
299 | 299 | |
300 | - list( $token_key, $token_secret ) = explode( '.', $token->secret ); |
|
300 | + list($token_key, $token_secret) = explode('.', $token->secret); |
|
301 | 301 | |
302 | - $token_key = sprintf( '%s:%d:%d', $token_key, JETPACK__API_VERSION, $token->external_user_id ); |
|
303 | - $time_diff = (int) Jetpack_Options::get_option( 'time_diff' ); |
|
302 | + $token_key = sprintf('%s:%d:%d', $token_key, JETPACK__API_VERSION, $token->external_user_id); |
|
303 | + $time_diff = (int) Jetpack_Options::get_option('time_diff'); |
|
304 | 304 | $timestamp = time() + $time_diff; |
305 | - $nonce = wp_generate_password( 10, false ); |
|
306 | - $signature = $this->request_signature( $token_key, $token_secret, $timestamp, $nonce, $time_diff ); |
|
305 | + $nonce = wp_generate_password(10, false); |
|
306 | + $signature = $this->request_signature($token_key, $token_secret, $timestamp, $nonce, $time_diff); |
|
307 | 307 | |
308 | - if ( is_wp_error( $signature ) ) { |
|
308 | + if (is_wp_error($signature)) { |
|
309 | 309 | return $signature; |
310 | 310 | } |
311 | 311 | |
@@ -318,11 +318,11 @@ discard block |
||
318 | 318 | |
319 | 319 | $header_pieces = array(); |
320 | 320 | |
321 | - foreach ( $auth as $key => $value ) { |
|
322 | - $header_pieces[] = sprintf( '%s="%s"', $key, $value ); |
|
321 | + foreach ($auth as $key => $value) { |
|
322 | + $header_pieces[] = sprintf('%s="%s"', $key, $value); |
|
323 | 323 | } |
324 | 324 | |
325 | - $authorization = 'X_JP_Auth ' . join( ' ', $header_pieces ); |
|
325 | + $authorization = 'X_JP_Auth ' . join(' ', $header_pieces); |
|
326 | 326 | |
327 | 327 | return $authorization; |
328 | 328 | } |
@@ -338,14 +338,14 @@ discard block |
||
338 | 338 | * |
339 | 339 | * @return string|WP_Error |
340 | 340 | */ |
341 | - protected function request_signature( $token_key, $token_secret, $timestamp, $nonce, $time_diff ) { |
|
341 | + protected function request_signature($token_key, $token_secret, $timestamp, $nonce, $time_diff) { |
|
342 | 342 | |
343 | 343 | $local_time = $timestamp - $time_diff; |
344 | 344 | |
345 | - if ( $local_time < time() - 600 || $local_time > time() + 300 ) { |
|
345 | + if ($local_time < time() - 600 || $local_time > time() + 300) { |
|
346 | 346 | return new WP_Error( |
347 | 347 | 'invalid_signature', |
348 | - __( 'Unable to send request to WooCommerce Connect server. The timestamp generated for the signature is too old.', 'woocommerce-gateway-stripe' ) |
|
348 | + __('Unable to send request to WooCommerce Connect server. The timestamp generated for the signature is too old.', 'woocommerce-gateway-stripe') |
|
349 | 349 | ); |
350 | 350 | } |
351 | 351 | |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | ) |
359 | 359 | ) . "\n"; |
360 | 360 | |
361 | - return base64_encode( hash_hmac( 'sha1', $normalized_request_string, $token_secret, true ) ); //phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode |
|
361 | + return base64_encode(hash_hmac('sha1', $normalized_request_string, $token_secret, true)); //phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | } |
@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
3 | +if ( ! defined('ABSPATH')) { |
|
4 | 4 | exit; |
5 | 5 | } |
6 | 6 | |
7 | -if ( ! class_exists( 'WC_Stripe_Connect_REST_Deauthorize_Controller' ) ) { |
|
7 | +if ( ! class_exists('WC_Stripe_Connect_REST_Deauthorize_Controller')) { |
|
8 | 8 | /** |
9 | 9 | * Stripe Connect deauthorize controller class. |
10 | 10 | */ |
@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | * @param WC_Stripe_Connect $connect stripe connect. |
31 | 31 | * @param WC_Stripe_Connect_API $api stripe connect api. |
32 | 32 | */ |
33 | - public function __construct( WC_Stripe_Connect $connect, WC_Stripe_Connect_API $api ) { |
|
33 | + public function __construct(WC_Stripe_Connect $connect, WC_Stripe_Connect_API $api) { |
|
34 | 34 | |
35 | - parent::__construct( $api ); |
|
35 | + parent::__construct($api); |
|
36 | 36 | |
37 | 37 | $this->connect = $connect; |
38 | 38 | } |
@@ -44,18 +44,18 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @return array|WP_Error |
46 | 46 | */ |
47 | - public function post( $request ) { |
|
47 | + public function post($request) { |
|
48 | 48 | |
49 | 49 | $response = $connect->deauthorize_account(); |
50 | 50 | |
51 | - if ( is_wp_error( $response ) ) { |
|
51 | + if (is_wp_error($response)) { |
|
52 | 52 | |
53 | - WC_Stripe_Logger::log( $response, __CLASS__ ); |
|
53 | + WC_Stripe_Logger::log($response, __CLASS__); |
|
54 | 54 | |
55 | 55 | return new WP_Error( |
56 | 56 | $response->get_error_code(), |
57 | 57 | $response->get_error_message(), |
58 | - array( 'status' => 400 ) |
|
58 | + array('status' => 400) |
|
59 | 59 | ); |
60 | 60 | } |
61 | 61 |
@@ -15,20 +15,20 @@ discard block |
||
15 | 15 | * |
16 | 16 | */ |
17 | 17 | |
18 | -if ( ! defined( 'ABSPATH' ) ) { |
|
18 | +if ( ! defined('ABSPATH')) { |
|
19 | 19 | exit; |
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
23 | 23 | * Required minimums and constants |
24 | 24 | */ |
25 | -define( 'WC_STRIPE_VERSION', '4.5.0' ); |
|
26 | -define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' ); |
|
27 | -define( 'WC_STRIPE_MIN_WC_VER', '3.0' ); |
|
28 | -define( 'WC_STRIPE_FUTURE_MIN_WC_VER', '3.0' ); |
|
29 | -define( 'WC_STRIPE_MAIN_FILE', __FILE__ ); |
|
30 | -define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); |
|
31 | -define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); |
|
25 | +define('WC_STRIPE_VERSION', '4.5.0'); |
|
26 | +define('WC_STRIPE_MIN_PHP_VER', '5.6.0'); |
|
27 | +define('WC_STRIPE_MIN_WC_VER', '3.0'); |
|
28 | +define('WC_STRIPE_FUTURE_MIN_WC_VER', '3.0'); |
|
29 | +define('WC_STRIPE_MAIN_FILE', __FILE__); |
|
30 | +define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)))); |
|
31 | +define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__))); |
|
32 | 32 | |
33 | 33 | // phpcs:disable WordPress.Files.FileName |
34 | 34 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | */ |
41 | 41 | function woocommerce_stripe_missing_wc_notice() { |
42 | 42 | /* translators: 1. URL link. */ |
43 | - 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>'; |
|
43 | + 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>'; |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | function woocommerce_stripe_wc_not_supported() { |
53 | 53 | /* translators: $1. Minimum WooCommerce version. $2. Current WooCommerce version. */ |
54 | - echo '<div class="error"><p><strong>' . sprintf( esc_html__( 'Stripe requires WooCommerce %1$s or greater to be installed and active. WooCommerce %2$s is no longer supported.', 'woocommerce-gateway-stripe' ), WC_STRIPE_MIN_WC_VER, WC_VERSION ) . '</strong></p></div>'; |
|
54 | + echo '<div class="error"><p><strong>' . sprintf(esc_html__('Stripe requires WooCommerce %1$s or greater to be installed and active. WooCommerce %2$s is no longer supported.', 'woocommerce-gateway-stripe'), WC_STRIPE_MIN_WC_VER, WC_VERSION) . '</strong></p></div>'; |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @return string |
62 | 62 | */ |
63 | 63 | function woocommerce_stripe_wc_country_not_supported() { |
64 | - echo '<div class="error"><p><strong>' . __( 'Stripe is not available in your store\'s country and will not be available for buyers to choose during checkout.', 'woocommerce-gateway-stripe' ) . '</strong></p></div>'; |
|
64 | + echo '<div class="error"><p><strong>' . __('Stripe is not available in your store\'s country and will not be available for buyers to choose during checkout.', 'woocommerce-gateway-stripe') . '</strong></p></div>'; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | * @return bool |
73 | 73 | */ |
74 | 74 | function woocommerce_stripe_wc_country_is_supported_country() { |
75 | - $wc_default_country = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
75 | + $wc_default_country = substr(get_option('woocommerce_default_country'), 0, 2); |
|
76 | 76 | |
77 | 77 | $supported_countries = apply_filters( |
78 | 78 | 'wc_stripe_supported_countries', |
@@ -118,30 +118,30 @@ discard block |
||
118 | 118 | ) |
119 | 119 | ); |
120 | 120 | |
121 | - return in_array( $wc_default_country, $supported_countries ); |
|
121 | + return in_array($wc_default_country, $supported_countries); |
|
122 | 122 | } |
123 | 123 | |
124 | -add_action( 'plugins_loaded', 'woocommerce_gateway_stripe_init' ); |
|
124 | +add_action('plugins_loaded', 'woocommerce_gateway_stripe_init'); |
|
125 | 125 | |
126 | 126 | function woocommerce_gateway_stripe_init() { |
127 | - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
|
127 | + load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages'); |
|
128 | 128 | |
129 | - if ( ! class_exists( 'WooCommerce' ) ) { |
|
130 | - add_action( 'admin_notices', 'woocommerce_stripe_missing_wc_notice' ); |
|
129 | + if ( ! class_exists('WooCommerce')) { |
|
130 | + add_action('admin_notices', 'woocommerce_stripe_missing_wc_notice'); |
|
131 | 131 | return; |
132 | 132 | } |
133 | 133 | |
134 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
135 | - add_action( 'admin_notices', 'woocommerce_stripe_wc_not_supported' ); |
|
134 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
135 | + add_action('admin_notices', 'woocommerce_stripe_wc_not_supported'); |
|
136 | 136 | return; |
137 | 137 | } |
138 | 138 | |
139 | - if ( ! woocommerce_stripe_wc_country_is_supported_country() ) { |
|
140 | - add_action( 'admin_notices', 'woocommerce_stripe_wc_country_not_supported' ); |
|
139 | + if ( ! woocommerce_stripe_wc_country_is_supported_country()) { |
|
140 | + add_action('admin_notices', 'woocommerce_stripe_wc_country_not_supported'); |
|
141 | 141 | return; |
142 | 142 | } |
143 | 143 | |
144 | - if ( ! class_exists( 'WC_Stripe' ) ) : |
|
144 | + if ( ! class_exists('WC_Stripe')) : |
|
145 | 145 | |
146 | 146 | class WC_Stripe { |
147 | 147 | |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * @return Singleton The *Singleton* instance. |
157 | 157 | */ |
158 | 158 | public static function get_instance() { |
159 | - if ( null === self::$instance ) { |
|
159 | + if (null === self::$instance) { |
|
160 | 160 | self::$instance = new self(); |
161 | 161 | } |
162 | 162 | return self::$instance; |
@@ -197,17 +197,17 @@ discard block |
||
197 | 197 | * *Singleton* via the `new` operator from outside of this class. |
198 | 198 | */ |
199 | 199 | private function __construct() { |
200 | - add_action( 'admin_init', array( $this, 'install' ) ); |
|
200 | + add_action('admin_init', array($this, 'install')); |
|
201 | 201 | |
202 | 202 | $this->init(); |
203 | 203 | |
204 | 204 | $this->api = new WC_Stripe_Connect_API(); |
205 | - $this->connect = new WC_Stripe_Connect( $this->api ); |
|
205 | + $this->connect = new WC_Stripe_Connect($this->api); |
|
206 | 206 | |
207 | - add_action( 'rest_api_init', array( $this, 'register_connect_routes' ) ); |
|
207 | + add_action('rest_api_init', array($this, 'register_connect_routes')); |
|
208 | 208 | |
209 | - if ( get_option( 'stripe_state', false ) ) { |
|
210 | - add_action( 'admin_enqueue_scripts', array( $this->connect, 'maybe_connect_oauth' ) ); |
|
209 | + if (get_option('stripe_state', false)) { |
|
210 | + add_action('admin_enqueue_scripts', array($this->connect, 'maybe_connect_oauth')); |
|
211 | 211 | } |
212 | 212 | } |
213 | 213 | |
@@ -218,55 +218,55 @@ discard block |
||
218 | 218 | * @version 4.0.0 |
219 | 219 | */ |
220 | 220 | public function init() { |
221 | - if ( is_admin() ) { |
|
222 | - require_once dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-privacy.php'; |
|
221 | + if (is_admin()) { |
|
222 | + require_once dirname(__FILE__) . '/includes/admin/class-wc-stripe-privacy.php'; |
|
223 | 223 | } |
224 | 224 | |
225 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-exception.php'; |
|
226 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php'; |
|
227 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php'; |
|
228 | - include_once dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php'; |
|
229 | - require_once dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php'; |
|
230 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php'; |
|
231 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-sepa-payment-token.php'; |
|
232 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay-registration.php'; |
|
233 | - require_once dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-pre-orders-compat.php'; |
|
234 | - require_once dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php'; |
|
235 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'; |
|
236 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'; |
|
237 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'; |
|
238 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-eps.php'; |
|
239 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php'; |
|
240 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php'; |
|
241 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php'; |
|
242 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php'; |
|
243 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-multibanco.php'; |
|
244 | - require_once dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php'; |
|
245 | - require_once dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-subs-compat.php'; |
|
246 | - require_once dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-subs-compat.php'; |
|
247 | - require_once dirname( __FILE__ ) . '/includes/connect/class-wc-stripe-connect.php'; |
|
248 | - require_once dirname( __FILE__ ) . '/includes/connect/class-wc-stripe-connect-api.php'; |
|
249 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php'; |
|
250 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php'; |
|
251 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php'; |
|
252 | - require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-intent-controller.php'; |
|
253 | - |
|
254 | - if ( is_admin() ) { |
|
255 | - require_once dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-admin-notices.php'; |
|
225 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-exception.php'; |
|
226 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-logger.php'; |
|
227 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-helper.php'; |
|
228 | + include_once dirname(__FILE__) . '/includes/class-wc-stripe-api.php'; |
|
229 | + require_once dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php'; |
|
230 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php'; |
|
231 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-sepa-payment-token.php'; |
|
232 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay-registration.php'; |
|
233 | + require_once dirname(__FILE__) . '/includes/compat/class-wc-stripe-pre-orders-compat.php'; |
|
234 | + require_once dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php'; |
|
235 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'; |
|
236 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'; |
|
237 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'; |
|
238 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-eps.php'; |
|
239 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php'; |
|
240 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php'; |
|
241 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php'; |
|
242 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php'; |
|
243 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-multibanco.php'; |
|
244 | + require_once dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php'; |
|
245 | + require_once dirname(__FILE__) . '/includes/compat/class-wc-stripe-subs-compat.php'; |
|
246 | + require_once dirname(__FILE__) . '/includes/compat/class-wc-stripe-sepa-subs-compat.php'; |
|
247 | + require_once dirname(__FILE__) . '/includes/connect/class-wc-stripe-connect.php'; |
|
248 | + require_once dirname(__FILE__) . '/includes/connect/class-wc-stripe-connect-api.php'; |
|
249 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php'; |
|
250 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php'; |
|
251 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-customer.php'; |
|
252 | + require_once dirname(__FILE__) . '/includes/class-wc-stripe-intent-controller.php'; |
|
253 | + |
|
254 | + if (is_admin()) { |
|
255 | + require_once dirname(__FILE__) . '/includes/admin/class-wc-stripe-admin-notices.php'; |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | // REMOVE IN THE FUTURE. |
259 | - require_once dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php'; |
|
259 | + require_once dirname(__FILE__) . '/includes/deprecated/class-wc-stripe-apple-pay.php'; |
|
260 | 260 | |
261 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
262 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
|
263 | - add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 ); |
|
261 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
262 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); |
|
263 | + add_filter('plugin_row_meta', array($this, 'plugin_row_meta'), 10, 2); |
|
264 | 264 | |
265 | 265 | // Modify emails emails. |
266 | - add_filter( 'woocommerce_email_classes', array( $this, 'add_emails' ), 20 ); |
|
266 | + add_filter('woocommerce_email_classes', array($this, 'add_emails'), 20); |
|
267 | 267 | |
268 | - if ( version_compare( WC_VERSION, '3.4', '<' ) ) { |
|
269 | - add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) ); |
|
268 | + if (version_compare(WC_VERSION, '3.4', '<')) { |
|
269 | + add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin')); |
|
270 | 270 | } |
271 | 271 | } |
272 | 272 | |
@@ -277,8 +277,8 @@ discard block |
||
277 | 277 | * @version 4.0.0 |
278 | 278 | */ |
279 | 279 | public function update_plugin_version() { |
280 | - delete_option( 'wc_stripe_version' ); |
|
281 | - update_option( 'wc_stripe_version', WC_STRIPE_VERSION ); |
|
280 | + delete_option('wc_stripe_version'); |
|
281 | + update_option('wc_stripe_version', WC_STRIPE_VERSION); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
@@ -288,15 +288,15 @@ discard block |
||
288 | 288 | * @version 3.1.0 |
289 | 289 | */ |
290 | 290 | public function install() { |
291 | - if ( ! is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
|
291 | + if ( ! is_plugin_active(plugin_basename(__FILE__))) { |
|
292 | 292 | return; |
293 | 293 | } |
294 | 294 | |
295 | - if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) { |
|
296 | - do_action( 'woocommerce_stripe_updated' ); |
|
295 | + if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) { |
|
296 | + do_action('woocommerce_stripe_updated'); |
|
297 | 297 | |
298 | - if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) { |
|
299 | - define( 'WC_STRIPE_INSTALLING', true ); |
|
298 | + if ( ! defined('WC_STRIPE_INSTALLING')) { |
|
299 | + define('WC_STRIPE_INSTALLING', true); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | $this->update_plugin_version(); |
@@ -309,11 +309,11 @@ discard block |
||
309 | 309 | * @since 1.0.0 |
310 | 310 | * @version 4.0.0 |
311 | 311 | */ |
312 | - public function plugin_action_links( $links ) { |
|
312 | + public function plugin_action_links($links) { |
|
313 | 313 | $plugin_links = array( |
314 | - '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
314 | + '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
315 | 315 | ); |
316 | - return array_merge( $plugin_links, $links ); |
|
316 | + return array_merge($plugin_links, $links); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -324,13 +324,13 @@ discard block |
||
324 | 324 | * @param string $file Name of current file. |
325 | 325 | * @return array $links Update list of plugin links. |
326 | 326 | */ |
327 | - public function plugin_row_meta( $links, $file ) { |
|
328 | - if ( plugin_basename( __FILE__ ) === $file ) { |
|
327 | + public function plugin_row_meta($links, $file) { |
|
328 | + if (plugin_basename(__FILE__) === $file) { |
|
329 | 329 | $row_meta = array( |
330 | - 'docs' => '<a href="' . esc_url( apply_filters( 'woocommerce_gateway_stripe_docs_url', 'https://docs.woocommerce.com/document/stripe/' ) ) . '" title="' . esc_attr( __( 'View Documentation', 'woocommerce-gateway-stripe' ) ) . '">' . __( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
331 | - 'support' => '<a href="' . esc_url( apply_filters( 'woocommerce_gateway_stripe_support_url', 'https://woocommerce.com/my-account/create-a-ticket?select=18627' ) ) . '" title="' . esc_attr( __( 'Open a support request at WooCommerce.com', 'woocommerce-gateway-stripe' ) ) . '">' . __( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
330 | + 'docs' => '<a href="' . esc_url(apply_filters('woocommerce_gateway_stripe_docs_url', 'https://docs.woocommerce.com/document/stripe/')) . '" title="' . esc_attr(__('View Documentation', 'woocommerce-gateway-stripe')) . '">' . __('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
331 | + 'support' => '<a href="' . esc_url(apply_filters('woocommerce_gateway_stripe_support_url', 'https://woocommerce.com/my-account/create-a-ticket?select=18627')) . '" title="' . esc_attr(__('Open a support request at WooCommerce.com', 'woocommerce-gateway-stripe')) . '">' . __('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
332 | 332 | ); |
333 | - return array_merge( $links, $row_meta ); |
|
333 | + return array_merge($links, $row_meta); |
|
334 | 334 | } |
335 | 335 | return (array) $links; |
336 | 336 | } |
@@ -341,8 +341,8 @@ discard block |
||
341 | 341 | * @since 1.0.0 |
342 | 342 | * @version 4.0.0 |
343 | 343 | */ |
344 | - public function add_gateways( $methods ) { |
|
345 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) { |
|
344 | + public function add_gateways($methods) { |
|
345 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) { |
|
346 | 346 | $methods[] = 'WC_Stripe_Subs_Compat'; |
347 | 347 | $methods[] = 'WC_Stripe_Sepa_Subs_Compat'; |
348 | 348 | } else { |
@@ -368,28 +368,28 @@ discard block |
||
368 | 368 | * @since 4.0.0 |
369 | 369 | * @version 4.0.0 |
370 | 370 | */ |
371 | - public function filter_gateway_order_admin( $sections ) { |
|
372 | - unset( $sections['stripe'] ); |
|
373 | - unset( $sections['stripe_bancontact'] ); |
|
374 | - unset( $sections['stripe_sofort'] ); |
|
375 | - unset( $sections['stripe_giropay'] ); |
|
376 | - unset( $sections['stripe_eps'] ); |
|
377 | - unset( $sections['stripe_ideal'] ); |
|
378 | - unset( $sections['stripe_p24'] ); |
|
379 | - unset( $sections['stripe_alipay'] ); |
|
380 | - unset( $sections['stripe_sepa'] ); |
|
381 | - unset( $sections['stripe_multibanco'] ); |
|
371 | + public function filter_gateway_order_admin($sections) { |
|
372 | + unset($sections['stripe']); |
|
373 | + unset($sections['stripe_bancontact']); |
|
374 | + unset($sections['stripe_sofort']); |
|
375 | + unset($sections['stripe_giropay']); |
|
376 | + unset($sections['stripe_eps']); |
|
377 | + unset($sections['stripe_ideal']); |
|
378 | + unset($sections['stripe_p24']); |
|
379 | + unset($sections['stripe_alipay']); |
|
380 | + unset($sections['stripe_sepa']); |
|
381 | + unset($sections['stripe_multibanco']); |
|
382 | 382 | |
383 | 383 | $sections['stripe'] = 'Stripe'; |
384 | - $sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
385 | - $sections['stripe_sofort'] = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
386 | - $sections['stripe_giropay'] = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
387 | - $sections['stripe_eps'] = __( 'Stripe EPS', 'woocommerce-gateway-stripe' ); |
|
388 | - $sections['stripe_ideal'] = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
389 | - $sections['stripe_p24'] = __( 'Stripe P24', 'woocommerce-gateway-stripe' ); |
|
390 | - $sections['stripe_alipay'] = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
391 | - $sections['stripe_sepa'] = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
392 | - $sections['stripe_multibanco'] = __( 'Stripe Multibanco', 'woocommerce-gateway-stripe' ); |
|
384 | + $sections['stripe_bancontact'] = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
385 | + $sections['stripe_sofort'] = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
386 | + $sections['stripe_giropay'] = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
387 | + $sections['stripe_eps'] = __('Stripe EPS', 'woocommerce-gateway-stripe'); |
|
388 | + $sections['stripe_ideal'] = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
389 | + $sections['stripe_p24'] = __('Stripe P24', 'woocommerce-gateway-stripe'); |
|
390 | + $sections['stripe_alipay'] = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
391 | + $sections['stripe_sepa'] = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
392 | + $sections['stripe_multibanco'] = __('Stripe Multibanco', 'woocommerce-gateway-stripe'); |
|
393 | 393 | |
394 | 394 | return $sections; |
395 | 395 | } |
@@ -400,16 +400,16 @@ discard block |
||
400 | 400 | * @param WC_Email[] $email_classes All existing emails. |
401 | 401 | * @return WC_Email[] |
402 | 402 | */ |
403 | - public function add_emails( $email_classes ) { |
|
403 | + public function add_emails($email_classes) { |
|
404 | 404 | require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-authentication.php'; |
405 | 405 | require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-renewal-authentication.php'; |
406 | 406 | require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-preorder-authentication.php'; |
407 | 407 | require_once WC_STRIPE_PLUGIN_PATH . '/includes/compat/class-wc-stripe-email-failed-authentication-retry.php'; |
408 | 408 | |
409 | 409 | // Add all emails, generated by the gateway. |
410 | - $email_classes['WC_Stripe_Email_Failed_Renewal_Authentication'] = new WC_Stripe_Email_Failed_Renewal_Authentication( $email_classes ); |
|
411 | - $email_classes['WC_Stripe_Email_Failed_Preorder_Authentication'] = new WC_Stripe_Email_Failed_Preorder_Authentication( $email_classes ); |
|
412 | - $email_classes['WC_Stripe_Email_Failed_Authentication_Retry'] = new WC_Stripe_Email_Failed_Authentication_Retry( $email_classes ); |
|
410 | + $email_classes['WC_Stripe_Email_Failed_Renewal_Authentication'] = new WC_Stripe_Email_Failed_Renewal_Authentication($email_classes); |
|
411 | + $email_classes['WC_Stripe_Email_Failed_Preorder_Authentication'] = new WC_Stripe_Email_Failed_Preorder_Authentication($email_classes); |
|
412 | + $email_classes['WC_Stripe_Email_Failed_Authentication_Retry'] = new WC_Stripe_Email_Failed_Authentication_Retry($email_classes); |
|
413 | 413 | |
414 | 414 | return $email_classes; |
415 | 415 | } |
@@ -424,9 +424,9 @@ discard block |
||
424 | 424 | require_once WC_STRIPE_PLUGIN_PATH . '/includes/connect/class-wc-stripe-connect-rest-oauth-connect-controller.php'; |
425 | 425 | require_once WC_STRIPE_PLUGIN_PATH . '/includes/connect/class-wc-stripe-connect-rest-deauthorize-controller.php'; |
426 | 426 | |
427 | - $oauth_init = new WC_Stripe_Connect_REST_Oauth_Init_Controller( $this->connect, $this->api ); |
|
428 | - $oauth_connect = new WC_Stripe_Connect_REST_Oauth_Connect_Controller( $this->connect, $this->api ); |
|
429 | - $deauthorize = new WC_Stripe_Connect_REST_Deauthorize_Controller( $this->connect, $this->api ); |
|
427 | + $oauth_init = new WC_Stripe_Connect_REST_Oauth_Init_Controller($this->connect, $this->api); |
|
428 | + $oauth_connect = new WC_Stripe_Connect_REST_Oauth_Connect_Controller($this->connect, $this->api); |
|
429 | + $deauthorize = new WC_Stripe_Connect_REST_Deauthorize_Controller($this->connect, $this->api); |
|
430 | 430 | |
431 | 431 | $oauth_init->register_routes(); |
432 | 432 | $oauth_connect->register_routes(); |
@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
3 | +if ( ! defined('ABSPATH')) { |
|
4 | 4 | exit; |
5 | 5 | } |
6 | 6 | |
7 | -if ( ! class_exists( 'WC_Stripe_Connect' ) ) { |
|
7 | +if ( ! class_exists('WC_Stripe_Connect')) { |
|
8 | 8 | /** |
9 | 9 | * Stripe Connect class. |
10 | 10 | */ |
@@ -24,11 +24,11 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @param WC_Stripe_Connect_API $api stripe connect api. |
26 | 26 | */ |
27 | - public function __construct( WC_Stripe_Connect_API $api ) { |
|
27 | + public function __construct(WC_Stripe_Connect_API $api) { |
|
28 | 28 | |
29 | 29 | $this->api = $api; |
30 | 30 | |
31 | - add_action( 'wc_ajax_wc_stripe_connect_oauth', array( $this, 'wc_ajax_connect_oauth' ) ); |
|
31 | + add_action('wc_ajax_wc_stripe_connect_oauth', array($this, 'wc_ajax_connect_oauth')); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -38,23 +38,23 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @return string|WP_Error |
40 | 40 | */ |
41 | - public function get_oauth_url( $return_url = '' ) { |
|
41 | + public function get_oauth_url($return_url = '') { |
|
42 | 42 | |
43 | - if ( empty( $return_url ) ) { |
|
44 | - $return_url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ); |
|
43 | + if (empty($return_url)) { |
|
44 | + $return_url = admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe'); |
|
45 | 45 | } |
46 | 46 | |
47 | - if ( substr( $return_url, 0, 8 ) !== 'https://' ) { |
|
48 | - return new WP_Error( 'invalid_url_protocol', __( 'Your site must be served over HTTPS in order to connect your Stripe account automatically.', 'woocommerce-gateway-stripe' ) ); |
|
47 | + if (substr($return_url, 0, 8) !== 'https://') { |
|
48 | + return new WP_Error('invalid_url_protocol', __('Your site must be served over HTTPS in order to connect your Stripe account automatically.', 'woocommerce-gateway-stripe')); |
|
49 | 49 | } |
50 | 50 | |
51 | - $result = $this->api->get_stripe_oauth_init( $return_url ); |
|
51 | + $result = $this->api->get_stripe_oauth_init($return_url); |
|
52 | 52 | |
53 | - if ( is_wp_error( $result ) ) { |
|
53 | + if (is_wp_error($result)) { |
|
54 | 54 | return $result; |
55 | 55 | } |
56 | 56 | |
57 | - update_option( 'stripe_state', $result->state ); |
|
57 | + update_option('stripe_state', $result->state); |
|
58 | 58 | |
59 | 59 | return $result->oauthUrl; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
60 | 60 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | |
69 | 69 | $response = $this->api->deauthorize_stripe_account(); |
70 | 70 | |
71 | - if ( is_wp_error( $response ) ) { |
|
71 | + if (is_wp_error($response)) { |
|
72 | 72 | return $response; |
73 | 73 | } |
74 | 74 | |
@@ -85,21 +85,21 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @return string|WP_Error |
87 | 87 | */ |
88 | - public function connect_oauth( $state, $code ) { |
|
88 | + public function connect_oauth($state, $code) { |
|
89 | 89 | |
90 | - if ( get_option( 'stripe_state', false ) !== $state ) { |
|
91 | - return new WP_Error( 'Invalid stripe state' ); |
|
90 | + if (get_option('stripe_state', false) !== $state) { |
|
91 | + return new WP_Error('Invalid stripe state'); |
|
92 | 92 | } |
93 | 93 | |
94 | - $response = $this->api->get_stripe_oauth_keys( $code ); |
|
94 | + $response = $this->api->get_stripe_oauth_keys($code); |
|
95 | 95 | |
96 | - if ( is_wp_error( $response ) ) { |
|
96 | + if (is_wp_error($response)) { |
|
97 | 97 | return $response; |
98 | 98 | } |
99 | 99 | |
100 | - delete_option( 'stripe_state' ); |
|
100 | + delete_option('stripe_state'); |
|
101 | 101 | |
102 | - return $this->save_stripe_keys( $response ); |
|
102 | + return $this->save_stripe_keys($response); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -107,10 +107,10 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public function maybe_connect_oauth() { |
109 | 109 | |
110 | - if ( isset( $_GET['wcs_stripe_code'], $_GET['wcs_stripe_state'] ) ) { |
|
111 | - $response = $this->connect_oauth( $_GET['wcs_stripe_state'], $_GET['wcs_stripe_code'] ); |
|
110 | + if (isset($_GET['wcs_stripe_code'], $_GET['wcs_stripe_state'])) { |
|
111 | + $response = $this->connect_oauth($_GET['wcs_stripe_state'], $_GET['wcs_stripe_code']); |
|
112 | 112 | |
113 | - wp_safe_redirect( remove_query_arg( array( 'wcs_stripe_state', 'wcs_stripe_code' ) ) ); |
|
113 | + wp_safe_redirect(remove_query_arg(array('wcs_stripe_state', 'wcs_stripe_code'))); |
|
114 | 114 | exit; |
115 | 115 | } |
116 | 116 | } |
@@ -123,28 +123,28 @@ discard block |
||
123 | 123 | * |
124 | 124 | * @return array|WP_Error |
125 | 125 | */ |
126 | - private function save_stripe_keys( $result ) { |
|
126 | + private function save_stripe_keys($result) { |
|
127 | 127 | |
128 | - if ( ! isset( $result->publishableKey, $result->secretKey ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
129 | - return new WP_Error( 'Invalid credentials received from WooCommerce Connect server' ); |
|
128 | + if ( ! isset($result->publishableKey, $result->secretKey)) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
129 | + return new WP_Error('Invalid credentials received from WooCommerce Connect server'); |
|
130 | 130 | } |
131 | 131 | |
132 | - $is_test = false !== strpos( $result->publishableKey, '_test_' ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
132 | + $is_test = false !== strpos($result->publishableKey, '_test_'); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
133 | 133 | $prefix = $is_test ? 'test_' : ''; |
134 | 134 | $default_options = array(); |
135 | 135 | |
136 | - $options = array_merge( $default_options, get_option( self::SETTINGS_OPTION, array() ) ); |
|
136 | + $options = array_merge($default_options, get_option(self::SETTINGS_OPTION, array())); |
|
137 | 137 | $options['enabled'] = 'yes'; |
138 | 138 | $options['testmode'] = $is_test ? 'yes' : 'no'; |
139 | - $options[ $prefix . 'publishable_key' ] = $result->publishableKey; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
140 | - $options[ $prefix . 'secret_key' ] = $result->secretKey; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
139 | + $options[$prefix . 'publishable_key'] = $result->publishableKey; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
140 | + $options[$prefix . 'secret_key'] = $result->secretKey; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
141 | 141 | |
142 | 142 | // While we are at it, let's also clear the account_id and |
143 | 143 | // test_account_id if present. |
144 | - unset( $options['account_id'] ); |
|
145 | - unset( $options['test_account_id'] ); |
|
144 | + unset($options['account_id']); |
|
145 | + unset($options['test_account_id']); |
|
146 | 146 | |
147 | - update_option( self::SETTINGS_OPTION, $options ); |
|
147 | + update_option(self::SETTINGS_OPTION, $options); |
|
148 | 148 | |
149 | 149 | return $result; |
150 | 150 | } |
@@ -155,9 +155,9 @@ discard block |
||
155 | 155 | private function clear_stripe_keys() { |
156 | 156 | |
157 | 157 | $default_options = $this->get_default_config(); |
158 | - $options = array_merge( $default_options, get_option( self::SETTINGS_OPTION, array() ) ); |
|
158 | + $options = array_merge($default_options, get_option(self::SETTINGS_OPTION, array())); |
|
159 | 159 | |
160 | - if ( 'yes' === $options['testmode'] ) { |
|
160 | + if ('yes' === $options['testmode']) { |
|
161 | 161 | $options['test_publishable_key'] = ''; |
162 | 162 | $options['test_secret_key'] = ''; |
163 | 163 | } else { |
@@ -167,10 +167,10 @@ discard block |
||
167 | 167 | |
168 | 168 | // While we are at it, let's also clear the account_id and |
169 | 169 | // test_account_id if present. |
170 | - unset( $options['account_id'] ); |
|
171 | - unset( $options['test_account_id'] ); |
|
170 | + unset($options['account_id']); |
|
171 | + unset($options['test_account_id']); |
|
172 | 172 | |
173 | - update_option( self::SETTINGS_OPTION, $options ); |
|
173 | + update_option(self::SETTINGS_OPTION, $options); |
|
174 | 174 | |
175 | 175 | } |
176 | 176 | |
@@ -179,17 +179,17 @@ discard block |
||
179 | 179 | */ |
180 | 180 | public function wc_ajax_connect_oauth() { |
181 | 181 | |
182 | - if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_connect_nonce' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash |
|
183 | - wp_die( __( 'You are not authorized to automatically copy Stripe keys', 'woocommerce-gateway-stripe' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
182 | + if (empty($_POST['nonce']) || ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_connect_nonce')) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash |
|
183 | + wp_die(__('You are not authorized to automatically copy Stripe keys', 'woocommerce-gateway-stripe')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | $oauth_url = $this->get_oauth_url(); |
187 | 187 | |
188 | - if ( is_wp_error( $oauth_url ) ) { |
|
188 | + if (is_wp_error($oauth_url)) { |
|
189 | 189 | wp_send_json_error(); |
190 | 190 | } |
191 | 191 | |
192 | - wp_send_json_success( $oauth_url ); |
|
192 | + wp_send_json_success($oauth_url); |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | } |
@@ -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 = __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe' ); |
|
90 | + $this->method_description = __('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe'); |
|
91 | 91 | $this->has_fields = true; |
92 | 92 | $this->supports = array( |
93 | 93 | 'products', |
@@ -114,40 +114,40 @@ 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 ); |
|
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 | 143 | |
144 | 144 | // Note: display error is in the parent class. |
145 | - add_action( 'admin_notices', array( $this, 'display_errors' ), 9999 ); |
|
145 | + add_action('admin_notices', array($this, 'display_errors'), 9999); |
|
146 | 146 | |
147 | - if ( WC_Stripe_Helper::is_pre_orders_exists() ) { |
|
147 | + if (WC_Stripe_Helper::is_pre_orders_exists()) { |
|
148 | 148 | $this->pre_orders = new WC_Stripe_Pre_Orders_Compat(); |
149 | 149 | |
150 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this->pre_orders, 'process_pre_order_release_payment' ) ); |
|
150 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this->pre_orders, 'process_pre_order_release_payment')); |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @since 4.0.2 |
158 | 158 | */ |
159 | 159 | public function is_available() { |
160 | - if ( is_add_payment_method_page() && ! $this->saved_cards ) { |
|
160 | + if (is_add_payment_method_page() && ! $this->saved_cards) { |
|
161 | 161 | return false; |
162 | 162 | } |
163 | 163 | |
@@ -171,13 +171,13 @@ discard block |
||
171 | 171 | * @param int $user_id The ID of the current user. |
172 | 172 | * @param string $load_address The address to load. |
173 | 173 | */ |
174 | - public function show_update_card_notice( $user_id, $load_address ) { |
|
175 | - if ( ! $this->saved_cards || ! WC_Stripe_Payment_Tokens::customer_has_saved_methods( $user_id ) || 'billing' !== $load_address ) { |
|
174 | + public function show_update_card_notice($user_id, $load_address) { |
|
175 | + if ( ! $this->saved_cards || ! WC_Stripe_Payment_Tokens::customer_has_saved_methods($user_id) || 'billing' !== $load_address) { |
|
176 | 176 | return; |
177 | 177 | } |
178 | 178 | |
179 | 179 | /* translators: 1) Opening anchor tag 2) closing anchor tag */ |
180 | - 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' ); |
|
180 | + 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'); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -192,24 +192,24 @@ discard block |
||
192 | 192 | |
193 | 193 | $icons_str = ''; |
194 | 194 | |
195 | - $icons_str .= isset( $icons['visa'] ) ? $icons['visa'] : ''; |
|
196 | - $icons_str .= isset( $icons['amex'] ) ? $icons['amex'] : ''; |
|
197 | - $icons_str .= isset( $icons['mastercard'] ) ? $icons['mastercard'] : ''; |
|
195 | + $icons_str .= isset($icons['visa']) ? $icons['visa'] : ''; |
|
196 | + $icons_str .= isset($icons['amex']) ? $icons['amex'] : ''; |
|
197 | + $icons_str .= isset($icons['mastercard']) ? $icons['mastercard'] : ''; |
|
198 | 198 | |
199 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
200 | - $icons_str .= isset( $icons['discover'] ) ? $icons['discover'] : ''; |
|
201 | - $icons_str .= isset( $icons['jcb'] ) ? $icons['jcb'] : ''; |
|
202 | - $icons_str .= isset( $icons['diners'] ) ? $icons['diners'] : ''; |
|
199 | + if ('USD' === get_woocommerce_currency()) { |
|
200 | + $icons_str .= isset($icons['discover']) ? $icons['discover'] : ''; |
|
201 | + $icons_str .= isset($icons['jcb']) ? $icons['jcb'] : ''; |
|
202 | + $icons_str .= isset($icons['diners']) ? $icons['diners'] : ''; |
|
203 | 203 | } |
204 | 204 | |
205 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
205 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
209 | 209 | * Initialise Gateway Settings Form Fields |
210 | 210 | */ |
211 | 211 | public function init_form_fields() { |
212 | - $this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' ); |
|
212 | + $this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php'); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -218,27 +218,27 @@ discard block |
||
218 | 218 | public function payment_fields() { |
219 | 219 | global $wp; |
220 | 220 | $user = wp_get_current_user(); |
221 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
221 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
222 | 222 | $total = WC()->cart->total; |
223 | 223 | $user_email = ''; |
224 | 224 | $description = $this->get_description(); |
225 | - $description = ! empty( $description ) ? $description : ''; |
|
225 | + $description = ! empty($description) ? $description : ''; |
|
226 | 226 | $firstname = ''; |
227 | 227 | $lastname = ''; |
228 | 228 | |
229 | 229 | // If paying from order, we need to get total from order not cart. |
230 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { // wpcs: csrf ok. |
|
231 | - $order = wc_get_order( wc_clean( $wp->query_vars['order-pay'] ) ); // wpcs: csrf ok, sanitization ok. |
|
230 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { // wpcs: csrf ok. |
|
231 | + $order = wc_get_order(wc_clean($wp->query_vars['order-pay'])); // wpcs: csrf ok, sanitization ok. |
|
232 | 232 | $total = $order->get_total(); |
233 | 233 | $user_email = $order->get_billing_email(); |
234 | 234 | } else { |
235 | - if ( $user->ID ) { |
|
236 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
235 | + if ($user->ID) { |
|
236 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
237 | 237 | $user_email = $user_email ? $user_email : $user->user_email; |
238 | 238 | } |
239 | 239 | } |
240 | 240 | |
241 | - if ( is_add_payment_method_page() ) { |
|
241 | + if (is_add_payment_method_page()) { |
|
242 | 242 | $firstname = $user->user_firstname; |
243 | 243 | $lastname = $user->user_lastname; |
244 | 244 | } |
@@ -247,33 +247,33 @@ discard block |
||
247 | 247 | |
248 | 248 | echo '<div |
249 | 249 | id="stripe-payment-data" |
250 | - data-email="' . esc_attr( $user_email ) . '" |
|
251 | - data-full-name="' . esc_attr( $firstname . ' ' . $lastname ) . '" |
|
252 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
250 | + data-email="' . esc_attr($user_email) . '" |
|
251 | + data-full-name="' . esc_attr($firstname . ' ' . $lastname) . '" |
|
252 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
253 | 253 | >'; |
254 | 254 | |
255 | - if ( $this->testmode ) { |
|
255 | + if ($this->testmode) { |
|
256 | 256 | /* translators: link to Stripe testing page */ |
257 | - $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' ); |
|
257 | + $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'); |
|
258 | 258 | } |
259 | 259 | |
260 | - $description = trim( $description ); |
|
260 | + $description = trim($description); |
|
261 | 261 | |
262 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); // wpcs: xss ok. |
|
262 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); // wpcs: xss ok. |
|
263 | 263 | |
264 | - if ( $display_tokenization ) { |
|
264 | + if ($display_tokenization) { |
|
265 | 265 | $this->tokenization_script(); |
266 | 266 | $this->saved_payment_methods(); |
267 | 267 | } |
268 | 268 | |
269 | 269 | $this->elements_form(); |
270 | 270 | |
271 | - 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. |
|
271 | + 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. |
|
272 | 272 | |
273 | 273 | $this->save_payment_method_checkbox(); |
274 | 274 | } |
275 | 275 | |
276 | - do_action( 'wc_stripe_cards_payment_fields', $this->id ); |
|
276 | + do_action('wc_stripe_cards_payment_fields', $this->id); |
|
277 | 277 | |
278 | 278 | echo '</div>'; |
279 | 279 | |
@@ -288,12 +288,12 @@ discard block |
||
288 | 288 | */ |
289 | 289 | public function elements_form() { |
290 | 290 | ?> |
291 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
292 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
291 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
292 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
293 | 293 | |
294 | - <?php if ( $this->inline_cc_form ) { ?> |
|
294 | + <?php if ($this->inline_cc_form) { ?> |
|
295 | 295 | <label for="card-element"> |
296 | - <?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?> |
|
296 | + <?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?> |
|
297 | 297 | </label> |
298 | 298 | |
299 | 299 | <div id="stripe-card-element" class="wc-stripe-elements-field"> |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | </div> |
302 | 302 | <?php } else { ?> |
303 | 303 | <div class="form-row form-row-wide"> |
304 | - <label for="stripe-card-element"><?php esc_html_e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
304 | + <label for="stripe-card-element"><?php esc_html_e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
305 | 305 | <div class="stripe-card-group"> |
306 | 306 | <div id="stripe-card-element" class="wc-stripe-elements-field"> |
307 | 307 | <!-- a Stripe Element will be inserted here. --> |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | </div> |
313 | 313 | |
314 | 314 | <div class="form-row form-row-first"> |
315 | - <label for="stripe-exp-element"><?php esc_html_e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
315 | + <label for="stripe-exp-element"><?php esc_html_e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
316 | 316 | |
317 | 317 | <div id="stripe-exp-element" class="wc-stripe-elements-field"> |
318 | 318 | <!-- a Stripe Element will be inserted here. --> |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | </div> |
321 | 321 | |
322 | 322 | <div class="form-row form-row-last"> |
323 | - <label for="stripe-cvc-element"><?php esc_html_e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
323 | + <label for="stripe-cvc-element"><?php esc_html_e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
324 | 324 | <div id="stripe-cvc-element" class="wc-stripe-elements-field"> |
325 | 325 | <!-- a Stripe Element will be inserted here. --> |
326 | 326 | </div> |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | <!-- Used to display form errors --> |
332 | 332 | <div class="stripe-source-errors" role="alert"></div> |
333 | 333 | <br /> |
334 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
334 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
335 | 335 | <div class="clear"></div> |
336 | 336 | </fieldset> |
337 | 337 | <?php |
@@ -344,22 +344,22 @@ discard block |
||
344 | 344 | * @version 3.1.0 |
345 | 345 | */ |
346 | 346 | public function admin_scripts() { |
347 | - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
347 | + if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
348 | 348 | return; |
349 | 349 | } |
350 | 350 | |
351 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
351 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
352 | 352 | |
353 | - wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
353 | + wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
354 | 354 | wp_localize_script( |
355 | 355 | 'woocommerce_stripe_admin', |
356 | 356 | 'woocommerce_stripe_admin', |
357 | 357 | array( |
358 | - 'ajax_url' => WC_AJAX::get_endpoint( 'wc_stripe_connect_oauth' ), |
|
359 | - 'wc_stripe_connect_nonce' => wp_create_nonce( '_wc_stripe_connect_nonce' ), |
|
360 | - 'wc_stripe_connect_oauth' => ! $this->secret_key && ! $this->publishable_key && ! get_option( 'stripe_state', false ), |
|
358 | + 'ajax_url' => WC_AJAX::get_endpoint('wc_stripe_connect_oauth'), |
|
359 | + 'wc_stripe_connect_nonce' => wp_create_nonce('_wc_stripe_connect_nonce'), |
|
360 | + 'wc_stripe_connect_oauth' => ! $this->secret_key && ! $this->publishable_key && ! get_option('stripe_state', false), |
|
361 | 361 | 'i18n' => array( |
362 | - 'wc_stripe_connect_text' => __( 'Automatically copy your Stripe account keys.', 'woocommerce-gateway-stripe' ), |
|
362 | + 'wc_stripe_connect_text' => __('Automatically copy your Stripe account keys.', 'woocommerce-gateway-stripe'), |
|
363 | 363 | ), |
364 | 364 | ) |
365 | 365 | ); |
@@ -379,54 +379,54 @@ discard block |
||
379 | 379 | ! is_product() |
380 | 380 | && ! is_cart() |
381 | 381 | && ! is_checkout() |
382 | - && ! isset( $_GET['pay_for_order'] ) // wpcs: csrf ok. |
|
382 | + && ! isset($_GET['pay_for_order']) // wpcs: csrf ok. |
|
383 | 383 | && ! is_add_payment_method_page() |
384 | - && ! isset( $_GET['change_payment_method'] ) // wpcs: csrf ok. |
|
385 | - && ! ( ! empty( get_query_var( 'view-subscription' ) ) && is_callable( 'WCS_Early_Renewal_Manager::is_early_renewal_via_modal_enabled' ) && WCS_Early_Renewal_Manager::is_early_renewal_via_modal_enabled() ) |
|
386 | - || ( is_order_received_page() ) |
|
384 | + && ! isset($_GET['change_payment_method']) // wpcs: csrf ok. |
|
385 | + && ! ( ! empty(get_query_var('view-subscription')) && is_callable('WCS_Early_Renewal_Manager::is_early_renewal_via_modal_enabled') && WCS_Early_Renewal_Manager::is_early_renewal_via_modal_enabled()) |
|
386 | + || (is_order_received_page()) |
|
387 | 387 | ) { |
388 | 388 | return; |
389 | 389 | } |
390 | 390 | |
391 | 391 | // If Stripe is not enabled bail. |
392 | - if ( 'no' === $this->enabled ) { |
|
392 | + if ('no' === $this->enabled) { |
|
393 | 393 | return; |
394 | 394 | } |
395 | 395 | |
396 | 396 | // If keys are not set bail. |
397 | - if ( ! $this->are_keys_set() ) { |
|
398 | - WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
397 | + if ( ! $this->are_keys_set()) { |
|
398 | + WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
399 | 399 | return; |
400 | 400 | } |
401 | 401 | |
402 | 402 | // If no SSL bail. |
403 | - if ( ! $this->testmode && ! is_ssl() ) { |
|
404 | - WC_Stripe_Logger::log( 'Stripe live mode requires SSL.' ); |
|
403 | + if ( ! $this->testmode && ! is_ssl()) { |
|
404 | + WC_Stripe_Logger::log('Stripe live mode requires SSL.'); |
|
405 | 405 | return; |
406 | 406 | } |
407 | 407 | |
408 | 408 | $current_theme = wp_get_theme(); |
409 | 409 | |
410 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
410 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
411 | 411 | |
412 | - wp_register_style( 'stripe_styles', plugins_url( 'assets/css/stripe-styles.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
413 | - wp_enqueue_style( 'stripe_styles' ); |
|
412 | + wp_register_style('stripe_styles', plugins_url('assets/css/stripe-styles.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
413 | + wp_enqueue_style('stripe_styles'); |
|
414 | 414 | |
415 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
416 | - wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
415 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
416 | + wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true); |
|
417 | 417 | |
418 | 418 | $stripe_params = array( |
419 | 419 | 'key' => $this->publishable_key, |
420 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
421 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
420 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
421 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
422 | 422 | ); |
423 | 423 | |
424 | 424 | // If we're on the pay page we need to pass stripe.js the address of the order. |
425 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { // wpcs: csrf ok. |
|
426 | - $order_id = wc_clean( $wp->query_vars['order-pay'] ); // wpcs: csrf ok, sanitization ok, xss ok. |
|
427 | - $order = wc_get_order( $order_id ); |
|
425 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { // wpcs: csrf ok. |
|
426 | + $order_id = wc_clean($wp->query_vars['order-pay']); // wpcs: csrf ok, sanitization ok, xss ok. |
|
427 | + $order = wc_get_order($order_id); |
|
428 | 428 | |
429 | - if ( is_a( $order, 'WC_Order' ) ) { |
|
429 | + if (is_a($order, 'WC_Order')) { |
|
430 | 430 | $stripe_params['billing_first_name'] = $order->get_billing_first_name(); |
431 | 431 | $stripe_params['billing_last_name'] = $order->get_billing_last_name(); |
432 | 432 | $stripe_params['billing_address_1'] = $order->get_billing_address_1(); |
@@ -441,40 +441,40 @@ discard block |
||
441 | 441 | $sepa_elements_options = apply_filters( |
442 | 442 | 'wc_stripe_sepa_elements_options', |
443 | 443 | array( |
444 | - 'supportedCountries' => array( 'SEPA' ), |
|
444 | + 'supportedCountries' => array('SEPA'), |
|
445 | 445 | 'placeholderCountry' => WC()->countries->get_base_country(), |
446 | - 'style' => array( 'base' => array( 'fontSize' => '15px' ) ), |
|
446 | + 'style' => array('base' => array('fontSize' => '15px')), |
|
447 | 447 | ) |
448 | 448 | ); |
449 | 449 | |
450 | - $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' ); |
|
451 | - $stripe_params['no_sepa_owner_msg'] = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' ); |
|
452 | - $stripe_params['no_sepa_iban_msg'] = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' ); |
|
453 | - $stripe_params['payment_intent_error'] = __( 'We couldn\'t initiate the payment. Please try again.', 'woocommerce-gateway-stripe' ); |
|
454 | - $stripe_params['sepa_mandate_notification'] = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' ); |
|
455 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
450 | + $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'); |
|
451 | + $stripe_params['no_sepa_owner_msg'] = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe'); |
|
452 | + $stripe_params['no_sepa_iban_msg'] = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe'); |
|
453 | + $stripe_params['payment_intent_error'] = __('We couldn\'t initiate the payment. Please try again.', 'woocommerce-gateway-stripe'); |
|
454 | + $stripe_params['sepa_mandate_notification'] = apply_filters('wc_stripe_sepa_mandate_notification', 'email'); |
|
455 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
456 | 456 | $stripe_params['inline_cc_form'] = $this->inline_cc_form ? 'yes' : 'no'; |
457 | - $stripe_params['is_checkout'] = ( is_checkout() && empty( $_GET['pay_for_order'] ) ) ? 'yes' : 'no'; // wpcs: csrf ok. |
|
457 | + $stripe_params['is_checkout'] = (is_checkout() && empty($_GET['pay_for_order'])) ? 'yes' : 'no'; // wpcs: csrf ok. |
|
458 | 458 | $stripe_params['return_url'] = $this->get_stripe_return_url(); |
459 | - $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint( '%%endpoint%%' ); |
|
460 | - $stripe_params['stripe_nonce'] = wp_create_nonce( '_wc_stripe_nonce' ); |
|
459 | + $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint('%%endpoint%%'); |
|
460 | + $stripe_params['stripe_nonce'] = wp_create_nonce('_wc_stripe_nonce'); |
|
461 | 461 | $stripe_params['statement_descriptor'] = $this->statement_descriptor; |
462 | - $stripe_params['elements_options'] = apply_filters( 'wc_stripe_elements_options', array() ); |
|
462 | + $stripe_params['elements_options'] = apply_filters('wc_stripe_elements_options', array()); |
|
463 | 463 | $stripe_params['sepa_elements_options'] = $sepa_elements_options; |
464 | - $stripe_params['invalid_owner_name'] = __( 'Billing First Name and Last Name are required.', 'woocommerce-gateway-stripe' ); |
|
465 | - $stripe_params['is_change_payment_page'] = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no'; // wpcs: csrf ok. |
|
466 | - $stripe_params['is_add_payment_page'] = is_wc_endpoint_url( 'add-payment-method' ) ? 'yes' : 'no'; |
|
467 | - $stripe_params['is_pay_for_order_page'] = is_wc_endpoint_url( 'order-pay' ) ? 'yes' : 'no'; |
|
468 | - $stripe_params['elements_styling'] = apply_filters( 'wc_stripe_elements_styling', false ); |
|
469 | - $stripe_params['elements_classes'] = apply_filters( 'wc_stripe_elements_classes', false ); |
|
464 | + $stripe_params['invalid_owner_name'] = __('Billing First Name and Last Name are required.', 'woocommerce-gateway-stripe'); |
|
465 | + $stripe_params['is_change_payment_page'] = isset($_GET['change_payment_method']) ? 'yes' : 'no'; // wpcs: csrf ok. |
|
466 | + $stripe_params['is_add_payment_page'] = is_wc_endpoint_url('add-payment-method') ? 'yes' : 'no'; |
|
467 | + $stripe_params['is_pay_for_order_page'] = is_wc_endpoint_url('order-pay') ? 'yes' : 'no'; |
|
468 | + $stripe_params['elements_styling'] = apply_filters('wc_stripe_elements_styling', false); |
|
469 | + $stripe_params['elements_classes'] = apply_filters('wc_stripe_elements_classes', false); |
|
470 | 470 | |
471 | 471 | // Merge localized messages to be use in JS. |
472 | - $stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() ); |
|
472 | + $stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages()); |
|
473 | 473 | |
474 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
474 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
475 | 475 | |
476 | 476 | $this->tokenization_script(); |
477 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
477 | + wp_enqueue_script('woocommerce_stripe'); |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | /** |
@@ -485,14 +485,14 @@ discard block |
||
485 | 485 | * @param object $prepared_source The object with source details. |
486 | 486 | * @throws WC_Stripe_Exception An exception if the card is prepaid, but prepaid cards are not allowed. |
487 | 487 | */ |
488 | - public function maybe_disallow_prepaid_card( $prepared_source ) { |
|
488 | + public function maybe_disallow_prepaid_card($prepared_source) { |
|
489 | 489 | // Check if we don't allow prepaid credit cards. |
490 | - if ( apply_filters( 'wc_stripe_allow_prepaid_card', true ) || ! $this->is_prepaid_card( $prepared_source->source_object ) ) { |
|
490 | + if (apply_filters('wc_stripe_allow_prepaid_card', true) || ! $this->is_prepaid_card($prepared_source->source_object)) { |
|
491 | 491 | return; |
492 | 492 | } |
493 | 493 | |
494 | - $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' ); |
|
495 | - throw new WC_Stripe_Exception( print_r( $prepared_source->source_object, true ), $localized_message ); |
|
494 | + $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'); |
|
495 | + throw new WC_Stripe_Exception(print_r($prepared_source->source_object, true), $localized_message); |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | /** |
@@ -502,10 +502,10 @@ discard block |
||
502 | 502 | * @param object $prepared_source The source that should be verified. |
503 | 503 | * @throws WC_Stripe_Exception An exception if the source ID is missing. |
504 | 504 | */ |
505 | - public function check_source( $prepared_source ) { |
|
506 | - if ( empty( $prepared_source->source ) ) { |
|
507 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
508 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
505 | + public function check_source($prepared_source) { |
|
506 | + if (empty($prepared_source->source)) { |
|
507 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
508 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
509 | 509 | } |
510 | 510 | } |
511 | 511 | |
@@ -517,13 +517,13 @@ discard block |
||
517 | 517 | * @param WC_Order $order The order those payment is being processed. |
518 | 518 | * @return bool A flag that indicates that the customer does not exist and should be removed. |
519 | 519 | */ |
520 | - public function maybe_remove_non_existent_customer( $error, $order ) { |
|
521 | - if ( ! $this->is_no_such_customer_error( $error ) ) { |
|
520 | + public function maybe_remove_non_existent_customer($error, $order) { |
|
521 | + if ( ! $this->is_no_such_customer_error($error)) { |
|
522 | 522 | return false; |
523 | 523 | } |
524 | 524 | |
525 | - delete_user_option( $order->get_customer_id(), '_stripe_customer_id' ); |
|
526 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
525 | + delete_user_option($order->get_customer_id(), '_stripe_customer_id'); |
|
526 | + $order->delete_meta_data('_stripe_customer_id'); |
|
527 | 527 | $order->save(); |
528 | 528 | |
529 | 529 | return true; |
@@ -538,15 +538,15 @@ discard block |
||
538 | 538 | * @param boolean $force_save_source Whether the payment source must be saved, like when dealing with a Subscription setup. |
539 | 539 | * @return array Redirection data for `process_payment`. |
540 | 540 | */ |
541 | - public function complete_free_order( $order, $prepared_source, $force_save_source ) { |
|
542 | - if ( $force_save_source ) { |
|
543 | - $intent_secret = $this->setup_intent( $order, $prepared_source ); |
|
541 | + public function complete_free_order($order, $prepared_source, $force_save_source) { |
|
542 | + if ($force_save_source) { |
|
543 | + $intent_secret = $this->setup_intent($order, $prepared_source); |
|
544 | 544 | |
545 | - if ( ! empty( $intent_secret ) ) { |
|
545 | + if ( ! empty($intent_secret)) { |
|
546 | 546 | // `get_return_url()` must be called immediately before returning a value. |
547 | 547 | return array( |
548 | 548 | 'result' => 'success', |
549 | - 'redirect' => $this->get_return_url( $order ), |
|
549 | + 'redirect' => $this->get_return_url($order), |
|
550 | 550 | 'setup_intent_secret' => $intent_secret, |
551 | 551 | ); |
552 | 552 | } |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | // Return thank you page redirect. |
561 | 561 | return array( |
562 | 562 | 'result' => 'success', |
563 | - 'redirect' => $this->get_return_url( $order ), |
|
563 | + 'redirect' => $this->get_return_url($order), |
|
564 | 564 | ); |
565 | 565 | } |
566 | 566 | |
@@ -578,81 +578,81 @@ discard block |
||
578 | 578 | * @throws Exception If payment will not be accepted. |
579 | 579 | * @return array|void |
580 | 580 | */ |
581 | - public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false, $use_order_source = false ) { |
|
581 | + public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false, $use_order_source = false) { |
|
582 | 582 | try { |
583 | - $order = wc_get_order( $order_id ); |
|
583 | + $order = wc_get_order($order_id); |
|
584 | 584 | |
585 | 585 | // ToDo: `process_pre_order` saves the source to the order for a later payment. |
586 | 586 | // This might not work well with PaymentIntents. |
587 | - if ( $this->maybe_process_pre_orders( $order_id ) ) { |
|
588 | - return $this->pre_orders->process_pre_order( $order_id ); |
|
587 | + if ($this->maybe_process_pre_orders($order_id)) { |
|
588 | + return $this->pre_orders->process_pre_order($order_id); |
|
589 | 589 | } |
590 | 590 | |
591 | 591 | // Check whether there is an existing intent. |
592 | - $intent = $this->get_intent_from_order( $order ); |
|
593 | - if ( isset( $intent->object ) && 'setup_intent' === $intent->object ) { |
|
592 | + $intent = $this->get_intent_from_order($order); |
|
593 | + if (isset($intent->object) && 'setup_intent' === $intent->object) { |
|
594 | 594 | $intent = false; // This function can only deal with *payment* intents |
595 | 595 | } |
596 | 596 | |
597 | 597 | $stripe_customer_id = null; |
598 | - if ( $intent && ! empty( $intent->customer ) ) { |
|
598 | + if ($intent && ! empty($intent->customer)) { |
|
599 | 599 | $stripe_customer_id = $intent->customer; |
600 | 600 | } |
601 | 601 | |
602 | 602 | // For some payments the source should already be present in the order. |
603 | - if ( $use_order_source ) { |
|
604 | - $prepared_source = $this->prepare_order_source( $order ); |
|
603 | + if ($use_order_source) { |
|
604 | + $prepared_source = $this->prepare_order_source($order); |
|
605 | 605 | } else { |
606 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source, $stripe_customer_id ); |
|
606 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source, $stripe_customer_id); |
|
607 | 607 | } |
608 | 608 | |
609 | - $this->maybe_disallow_prepaid_card( $prepared_source ); |
|
610 | - $this->check_source( $prepared_source ); |
|
611 | - $this->save_source_to_order( $order, $prepared_source ); |
|
609 | + $this->maybe_disallow_prepaid_card($prepared_source); |
|
610 | + $this->check_source($prepared_source); |
|
611 | + $this->save_source_to_order($order, $prepared_source); |
|
612 | 612 | |
613 | - if ( 0 >= $order->get_total() ) { |
|
614 | - return $this->complete_free_order( $order, $prepared_source, $force_save_source ); |
|
613 | + if (0 >= $order->get_total()) { |
|
614 | + return $this->complete_free_order($order, $prepared_source, $force_save_source); |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | // This will throw exception if not valid. |
618 | - $this->validate_minimum_order_amount( $order ); |
|
618 | + $this->validate_minimum_order_amount($order); |
|
619 | 619 | |
620 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
620 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
621 | 621 | |
622 | - if ( $intent ) { |
|
623 | - $intent = $this->update_existing_intent( $intent, $order, $prepared_source ); |
|
622 | + if ($intent) { |
|
623 | + $intent = $this->update_existing_intent($intent, $order, $prepared_source); |
|
624 | 624 | } else { |
625 | - $intent = $this->create_intent( $order, $prepared_source ); |
|
625 | + $intent = $this->create_intent($order, $prepared_source); |
|
626 | 626 | } |
627 | 627 | |
628 | 628 | // Confirm the intent after locking the order to make sure webhooks will not interfere. |
629 | - if ( empty( $intent->error ) ) { |
|
630 | - $this->lock_order_payment( $order, $intent ); |
|
631 | - $intent = $this->confirm_intent( $intent, $order, $prepared_source ); |
|
629 | + if (empty($intent->error)) { |
|
630 | + $this->lock_order_payment($order, $intent); |
|
631 | + $intent = $this->confirm_intent($intent, $order, $prepared_source); |
|
632 | 632 | } |
633 | 633 | |
634 | - if ( ! empty( $intent->error ) ) { |
|
635 | - $this->maybe_remove_non_existent_customer( $intent->error, $order ); |
|
634 | + if ( ! empty($intent->error)) { |
|
635 | + $this->maybe_remove_non_existent_customer($intent->error, $order); |
|
636 | 636 | |
637 | 637 | // We want to retry. |
638 | - if ( $this->is_retryable_error( $intent->error ) ) { |
|
639 | - return $this->retry_after_error( $intent, $order, $retry, $force_save_source, $previous_error, $use_order_source ); |
|
638 | + if ($this->is_retryable_error($intent->error)) { |
|
639 | + return $this->retry_after_error($intent, $order, $retry, $force_save_source, $previous_error, $use_order_source); |
|
640 | 640 | } |
641 | 641 | |
642 | - $this->unlock_order_payment( $order ); |
|
643 | - $this->throw_localized_message( $intent, $order ); |
|
642 | + $this->unlock_order_payment($order); |
|
643 | + $this->throw_localized_message($intent, $order); |
|
644 | 644 | } |
645 | 645 | |
646 | - if ( ! empty( $intent ) ) { |
|
646 | + if ( ! empty($intent)) { |
|
647 | 647 | // Use the last charge within the intent to proceed. |
648 | - $response = end( $intent->charges->data ); |
|
648 | + $response = end($intent->charges->data); |
|
649 | 649 | |
650 | 650 | // If the intent requires a 3DS flow, redirect to it. |
651 | - if ( 'requires_action' === $intent->status ) { |
|
652 | - $this->unlock_order_payment( $order ); |
|
651 | + if ('requires_action' === $intent->status) { |
|
652 | + $this->unlock_order_payment($order); |
|
653 | 653 | |
654 | - if ( is_wc_endpoint_url( 'order-pay' ) ) { |
|
655 | - $redirect_url = add_query_arg( 'wc-stripe-confirmation', 1, $order->get_checkout_payment_url( false ) ); |
|
654 | + if (is_wc_endpoint_url('order-pay')) { |
|
655 | + $redirect_url = add_query_arg('wc-stripe-confirmation', 1, $order->get_checkout_payment_url(false)); |
|
656 | 656 | |
657 | 657 | return array( |
658 | 658 | 'result' => 'success', |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | |
668 | 668 | return array( |
669 | 669 | 'result' => 'success', |
670 | - 'redirect' => $this->get_return_url( $order ), |
|
670 | + 'redirect' => $this->get_return_url($order), |
|
671 | 671 | 'payment_intent_secret' => $intent->client_secret, |
672 | 672 | ); |
673 | 673 | } |
@@ -675,30 +675,30 @@ discard block |
||
675 | 675 | } |
676 | 676 | |
677 | 677 | // Process valid response. |
678 | - $this->process_response( $response, $order ); |
|
678 | + $this->process_response($response, $order); |
|
679 | 679 | |
680 | 680 | // Remove cart. |
681 | - if ( isset( WC()->cart ) ) { |
|
681 | + if (isset(WC()->cart)) { |
|
682 | 682 | WC()->cart->empty_cart(); |
683 | 683 | } |
684 | 684 | |
685 | 685 | // Unlock the order. |
686 | - $this->unlock_order_payment( $order ); |
|
686 | + $this->unlock_order_payment($order); |
|
687 | 687 | |
688 | 688 | // Return thank you page redirect. |
689 | 689 | return array( |
690 | 690 | 'result' => 'success', |
691 | - 'redirect' => $this->get_return_url( $order ), |
|
691 | + 'redirect' => $this->get_return_url($order), |
|
692 | 692 | ); |
693 | 693 | |
694 | - } catch ( WC_Stripe_Exception $e ) { |
|
695 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
696 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
694 | + } catch (WC_Stripe_Exception $e) { |
|
695 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
696 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
697 | 697 | |
698 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
698 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
699 | 699 | |
700 | 700 | /* translators: error message */ |
701 | - $order->update_status( 'failed' ); |
|
701 | + $order->update_status('failed'); |
|
702 | 702 | |
703 | 703 | return array( |
704 | 704 | 'result' => 'fail', |
@@ -714,17 +714,17 @@ discard block |
||
714 | 714 | * |
715 | 715 | * @param int $order_id The ID of the order. |
716 | 716 | */ |
717 | - public function display_order_fee( $order_id ) { |
|
718 | - if ( apply_filters( 'wc_stripe_hide_display_order_fee', false, $order_id ) ) { |
|
717 | + public function display_order_fee($order_id) { |
|
718 | + if (apply_filters('wc_stripe_hide_display_order_fee', false, $order_id)) { |
|
719 | 719 | return; |
720 | 720 | } |
721 | 721 | |
722 | - $order = wc_get_order( $order_id ); |
|
722 | + $order = wc_get_order($order_id); |
|
723 | 723 | |
724 | - $fee = WC_Stripe_Helper::get_stripe_fee( $order ); |
|
725 | - $currency = WC_Stripe_Helper::get_stripe_currency( $order ); |
|
724 | + $fee = WC_Stripe_Helper::get_stripe_fee($order); |
|
725 | + $currency = WC_Stripe_Helper::get_stripe_currency($order); |
|
726 | 726 | |
727 | - if ( ! $fee || ! $currency ) { |
|
727 | + if ( ! $fee || ! $currency) { |
|
728 | 728 | return; |
729 | 729 | } |
730 | 730 | |
@@ -732,12 +732,12 @@ discard block |
||
732 | 732 | |
733 | 733 | <tr> |
734 | 734 | <td class="label stripe-fee"> |
735 | - <?php echo wc_help_tip( __( 'This represents the fee Stripe collects for the transaction.', 'woocommerce-gateway-stripe' ) ); // wpcs: xss ok. ?> |
|
736 | - <?php esc_html_e( 'Stripe Fee:', 'woocommerce-gateway-stripe' ); ?> |
|
735 | + <?php echo wc_help_tip(__('This represents the fee Stripe collects for the transaction.', 'woocommerce-gateway-stripe')); // wpcs: xss ok. ?> |
|
736 | + <?php esc_html_e('Stripe Fee:', 'woocommerce-gateway-stripe'); ?> |
|
737 | 737 | </td> |
738 | 738 | <td width="1%"></td> |
739 | 739 | <td class="total"> |
740 | - - <?php echo wc_price( $fee, array( 'currency' => $currency ) ); // wpcs: xss ok. ?> |
|
740 | + - <?php echo wc_price($fee, array('currency' => $currency)); // wpcs: xss ok. ?> |
|
741 | 741 | </td> |
742 | 742 | </tr> |
743 | 743 | |
@@ -751,17 +751,17 @@ discard block |
||
751 | 751 | * |
752 | 752 | * @param int $order_id The ID of the order. |
753 | 753 | */ |
754 | - public function display_order_payout( $order_id ) { |
|
755 | - if ( apply_filters( 'wc_stripe_hide_display_order_payout', false, $order_id ) ) { |
|
754 | + public function display_order_payout($order_id) { |
|
755 | + if (apply_filters('wc_stripe_hide_display_order_payout', false, $order_id)) { |
|
756 | 756 | return; |
757 | 757 | } |
758 | 758 | |
759 | - $order = wc_get_order( $order_id ); |
|
759 | + $order = wc_get_order($order_id); |
|
760 | 760 | |
761 | - $net = WC_Stripe_Helper::get_stripe_net( $order ); |
|
762 | - $currency = WC_Stripe_Helper::get_stripe_currency( $order ); |
|
761 | + $net = WC_Stripe_Helper::get_stripe_net($order); |
|
762 | + $currency = WC_Stripe_Helper::get_stripe_currency($order); |
|
763 | 763 | |
764 | - if ( ! $net || ! $currency ) { |
|
764 | + if ( ! $net || ! $currency) { |
|
765 | 765 | return; |
766 | 766 | } |
767 | 767 | |
@@ -769,12 +769,12 @@ discard block |
||
769 | 769 | |
770 | 770 | <tr> |
771 | 771 | <td class="label stripe-payout"> |
772 | - <?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. ?> |
|
773 | - <?php esc_html_e( 'Stripe Payout:', 'woocommerce-gateway-stripe' ); ?> |
|
772 | + <?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. ?> |
|
773 | + <?php esc_html_e('Stripe Payout:', 'woocommerce-gateway-stripe'); ?> |
|
774 | 774 | </td> |
775 | 775 | <td width="1%"></td> |
776 | 776 | <td class="total"> |
777 | - <?php echo wc_price( $net, array( 'currency' => $currency ) ); // wpcs: xss ok. ?> |
|
777 | + <?php echo wc_price($net, array('currency' => $currency)); // wpcs: xss ok. ?> |
|
778 | 778 | </td> |
779 | 779 | </tr> |
780 | 780 | |
@@ -790,13 +790,13 @@ discard block |
||
790 | 790 | * |
791 | 791 | * @return string The localized error message. |
792 | 792 | */ |
793 | - public function get_localized_error_message_from_response( $response ) { |
|
793 | + public function get_localized_error_message_from_response($response) { |
|
794 | 794 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
795 | 795 | |
796 | - if ( 'card_error' === $response->error->type ) { |
|
797 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
796 | + if ('card_error' === $response->error->type) { |
|
797 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
798 | 798 | } else { |
799 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
799 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
800 | 800 | } |
801 | 801 | |
802 | 802 | return $localized_message; |
@@ -810,12 +810,12 @@ discard block |
||
810 | 810 | * @param WC_Order $order The order to add a note to. |
811 | 811 | * @throws WC_Stripe_Exception An exception with the right message. |
812 | 812 | */ |
813 | - public function throw_localized_message( $response, $order ) { |
|
814 | - $localized_message = $this->get_localized_error_message_from_response( $response ); |
|
813 | + public function throw_localized_message($response, $order) { |
|
814 | + $localized_message = $this->get_localized_error_message_from_response($response); |
|
815 | 815 | |
816 | - $order->add_order_note( $localized_message ); |
|
816 | + $order->add_order_note($localized_message); |
|
817 | 817 | |
818 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
818 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
819 | 819 | } |
820 | 820 | |
821 | 821 | /** |
@@ -831,22 +831,22 @@ discard block |
||
831 | 831 | * @throws WC_Stripe_Exception If the payment is not accepted. |
832 | 832 | * @return array|void |
833 | 833 | */ |
834 | - public function retry_after_error( $response, $order, $retry, $force_save_source, $previous_error, $use_order_source ) { |
|
835 | - if ( ! $retry ) { |
|
836 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
837 | - $order->add_order_note( $localized_message ); |
|
838 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions. |
|
834 | + public function retry_after_error($response, $order, $retry, $force_save_source, $previous_error, $use_order_source) { |
|
835 | + if ( ! $retry) { |
|
836 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
837 | + $order->add_order_note($localized_message); |
|
838 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); // phpcs:ignore WordPress.PHP.DevelopmentFunctions. |
|
839 | 839 | } |
840 | 840 | |
841 | 841 | // Don't do anymore retries after this. |
842 | - if ( 5 <= $this->retry_interval ) { |
|
843 | - return $this->process_payment( $order->get_id(), false, $force_save_source, $response->error, $previous_error ); |
|
842 | + if (5 <= $this->retry_interval) { |
|
843 | + return $this->process_payment($order->get_id(), false, $force_save_source, $response->error, $previous_error); |
|
844 | 844 | } |
845 | 845 | |
846 | - sleep( $this->retry_interval ); |
|
846 | + sleep($this->retry_interval); |
|
847 | 847 | $this->retry_interval++; |
848 | 848 | |
849 | - return $this->process_payment( $order->get_id(), true, $force_save_source, $response->error, $previous_error, $use_order_source ); |
|
849 | + return $this->process_payment($order->get_id(), true, $force_save_source, $response->error, $previous_error, $use_order_source); |
|
850 | 850 | } |
851 | 851 | |
852 | 852 | /** |
@@ -857,23 +857,23 @@ discard block |
||
857 | 857 | * @param WC_Payment_Gateway[] $gateways A list of all available gateways. |
858 | 858 | * @return WC_Payment_Gateway[] Either the same list or an empty one in the right conditions. |
859 | 859 | */ |
860 | - public function prepare_order_pay_page( $gateways ) { |
|
861 | - if ( ! is_wc_endpoint_url( 'order-pay' ) || ! isset( $_GET['wc-stripe-confirmation'] ) ) { // wpcs: csrf ok. |
|
860 | + public function prepare_order_pay_page($gateways) { |
|
861 | + if ( ! is_wc_endpoint_url('order-pay') || ! isset($_GET['wc-stripe-confirmation'])) { // wpcs: csrf ok. |
|
862 | 862 | return $gateways; |
863 | 863 | } |
864 | 864 | |
865 | 865 | try { |
866 | 866 | $this->prepare_intent_for_order_pay_page(); |
867 | - } catch ( WC_Stripe_Exception $e ) { |
|
867 | + } catch (WC_Stripe_Exception $e) { |
|
868 | 868 | // Just show the full order pay page if there was a problem preparing the Payment Intent |
869 | 869 | return $gateways; |
870 | 870 | } |
871 | 871 | |
872 | - add_filter( 'woocommerce_checkout_show_terms', '__return_false' ); |
|
873 | - add_filter( 'woocommerce_pay_order_button_html', '__return_false' ); |
|
874 | - add_filter( 'woocommerce_available_payment_gateways', '__return_empty_array' ); |
|
875 | - add_filter( 'woocommerce_no_available_payment_methods_message', array( $this, 'change_no_available_methods_message' ) ); |
|
876 | - add_action( 'woocommerce_pay_order_after_submit', array( $this, 'render_payment_intent_inputs' ) ); |
|
872 | + add_filter('woocommerce_checkout_show_terms', '__return_false'); |
|
873 | + add_filter('woocommerce_pay_order_button_html', '__return_false'); |
|
874 | + add_filter('woocommerce_available_payment_gateways', '__return_empty_array'); |
|
875 | + add_filter('woocommerce_no_available_payment_methods_message', array($this, 'change_no_available_methods_message')); |
|
876 | + add_action('woocommerce_pay_order_after_submit', array($this, 'render_payment_intent_inputs')); |
|
877 | 877 | |
878 | 878 | return array(); |
879 | 879 | } |
@@ -886,7 +886,7 @@ discard block |
||
886 | 886 | * @return string the new message. |
887 | 887 | */ |
888 | 888 | public function change_no_available_methods_message() { |
889 | - 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' ) ); |
|
889 | + 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')); |
|
890 | 890 | } |
891 | 891 | |
892 | 892 | /** |
@@ -897,19 +897,19 @@ discard block |
||
897 | 897 | * @throws WC_Stripe_Exception |
898 | 898 | * @since 4.3 |
899 | 899 | */ |
900 | - public function prepare_intent_for_order_pay_page( $order = null ) { |
|
901 | - if ( ! isset( $order ) || empty( $order ) ) { |
|
902 | - $order = wc_get_order( absint( get_query_var( 'order-pay' ) ) ); |
|
900 | + public function prepare_intent_for_order_pay_page($order = null) { |
|
901 | + if ( ! isset($order) || empty($order)) { |
|
902 | + $order = wc_get_order(absint(get_query_var('order-pay'))); |
|
903 | 903 | } |
904 | - $intent = $this->get_intent_from_order( $order ); |
|
904 | + $intent = $this->get_intent_from_order($order); |
|
905 | 905 | |
906 | - if ( ! $intent ) { |
|
907 | - throw new WC_Stripe_Exception( 'Payment Intent not found', __( 'Payment Intent not found for order #' . $order->get_id(), 'woocommerce-gateway-stripe' ) ); |
|
906 | + if ( ! $intent) { |
|
907 | + throw new WC_Stripe_Exception('Payment Intent not found', __('Payment Intent not found for order #' . $order->get_id(), 'woocommerce-gateway-stripe')); |
|
908 | 908 | } |
909 | 909 | |
910 | - if ( 'requires_payment_method' === $intent->status && isset( $intent->last_payment_error ) |
|
911 | - && 'authentication_required' === $intent->last_payment_error->code ) { |
|
912 | - $level3_data = $this->get_level3_data_from_order( $order ); |
|
910 | + if ('requires_payment_method' === $intent->status && isset($intent->last_payment_error) |
|
911 | + && 'authentication_required' === $intent->last_payment_error->code) { |
|
912 | + $level3_data = $this->get_level3_data_from_order($order); |
|
913 | 913 | $intent = WC_Stripe_API::request_with_level3_data( |
914 | 914 | array( |
915 | 915 | 'payment_method' => $intent->last_payment_error->source->id, |
@@ -919,8 +919,8 @@ discard block |
||
919 | 919 | $order |
920 | 920 | ); |
921 | 921 | |
922 | - if ( isset( $intent->error ) ) { |
|
923 | - throw new WC_Stripe_Exception( print_r( $intent, true ), $intent->error->message ); |
|
922 | + if (isset($intent->error)) { |
|
923 | + throw new WC_Stripe_Exception(print_r($intent, true), $intent->error->message); |
|
924 | 924 | } |
925 | 925 | } |
926 | 926 | |
@@ -935,26 +935,26 @@ discard block |
||
935 | 935 | * @throws WC_Stripe_Exception |
936 | 936 | * @since 4.2 |
937 | 937 | */ |
938 | - public function render_payment_intent_inputs( $order = null ) { |
|
939 | - if ( ! isset( $order ) || empty( $order ) ) { |
|
940 | - $order = wc_get_order( absint( get_query_var( 'order-pay' ) ) ); |
|
938 | + public function render_payment_intent_inputs($order = null) { |
|
939 | + if ( ! isset($order) || empty($order)) { |
|
940 | + $order = wc_get_order(absint(get_query_var('order-pay'))); |
|
941 | 941 | } |
942 | - if ( ! isset( $this->order_pay_intent ) ) { |
|
943 | - $this->prepare_intent_for_order_pay_page( $order ); |
|
942 | + if ( ! isset($this->order_pay_intent)) { |
|
943 | + $this->prepare_intent_for_order_pay_page($order); |
|
944 | 944 | } |
945 | 945 | |
946 | 946 | $verification_url = add_query_arg( |
947 | 947 | array( |
948 | 948 | 'order' => $order->get_id(), |
949 | - 'nonce' => wp_create_nonce( 'wc_stripe_confirm_pi' ), |
|
950 | - 'redirect_to' => rawurlencode( $this->get_return_url( $order ) ), |
|
949 | + 'nonce' => wp_create_nonce('wc_stripe_confirm_pi'), |
|
950 | + 'redirect_to' => rawurlencode($this->get_return_url($order)), |
|
951 | 951 | 'is_pay_for_order' => true, |
952 | 952 | ), |
953 | - WC_AJAX::get_endpoint( 'wc_stripe_verify_intent' ) |
|
953 | + WC_AJAX::get_endpoint('wc_stripe_verify_intent') |
|
954 | 954 | ); |
955 | 955 | |
956 | - echo '<input type="hidden" id="stripe-intent-id" value="' . esc_attr( $this->order_pay_intent->client_secret ) . '" />'; |
|
957 | - echo '<input type="hidden" id="stripe-intent-return" value="' . esc_attr( $verification_url ) . '" />'; |
|
956 | + echo '<input type="hidden" id="stripe-intent-id" value="' . esc_attr($this->order_pay_intent->client_secret) . '" />'; |
|
957 | + echo '<input type="hidden" id="stripe-intent-return" value="' . esc_attr($verification_url) . '" />'; |
|
958 | 958 | } |
959 | 959 | |
960 | 960 | /** |
@@ -964,11 +964,11 @@ discard block |
||
964 | 964 | * @param WC_Payment_Token $token Payment Token. |
965 | 965 | * @return string Generated payment method HTML |
966 | 966 | */ |
967 | - public function get_saved_payment_method_option_html( $token ) { |
|
968 | - $html = parent::get_saved_payment_method_option_html( $token ); |
|
967 | + public function get_saved_payment_method_option_html($token) { |
|
968 | + $html = parent::get_saved_payment_method_option_html($token); |
|
969 | 969 | $error_wrapper = '<div class="stripe-source-errors" role="alert"></div>'; |
970 | 970 | |
971 | - return preg_replace( '~</(\w+)>\s*$~', "$error_wrapper</$1>", $html ); |
|
971 | + return preg_replace('~</(\w+)>\s*$~', "$error_wrapper</$1>", $html); |
|
972 | 972 | } |
973 | 973 | |
974 | 974 | /** |
@@ -978,18 +978,18 @@ discard block |
||
978 | 978 | * @since 4.2.0 |
979 | 979 | * @param int $order_id The ID that will be used for the thank you page. |
980 | 980 | */ |
981 | - public function check_intent_status_on_order_page( $order_id ) { |
|
982 | - if ( empty( $order_id ) || absint( $order_id ) <= 0 ) { |
|
981 | + public function check_intent_status_on_order_page($order_id) { |
|
982 | + if (empty($order_id) || absint($order_id) <= 0) { |
|
983 | 983 | return; |
984 | 984 | } |
985 | 985 | |
986 | - $order = wc_get_order( absint( $order_id ) ); |
|
986 | + $order = wc_get_order(absint($order_id)); |
|
987 | 987 | |
988 | - if ( ! $order ) { |
|
988 | + if ( ! $order) { |
|
989 | 989 | return; |
990 | 990 | } |
991 | 991 | |
992 | - $this->verify_intent_after_checkout( $order ); |
|
992 | + $this->verify_intent_after_checkout($order); |
|
993 | 993 | } |
994 | 994 | |
995 | 995 | /** |
@@ -1003,8 +1003,8 @@ discard block |
||
1003 | 1003 | * @param int $order_id The ID of the order which is being paid for. |
1004 | 1004 | * @return array |
1005 | 1005 | */ |
1006 | - public function modify_successful_payment_result( $result, $order_id ) { |
|
1007 | - if ( ! isset( $result['payment_intent_secret'] ) && ! isset( $result['setup_intent_secret'] ) ) { |
|
1006 | + public function modify_successful_payment_result($result, $order_id) { |
|
1007 | + if ( ! isset($result['payment_intent_secret']) && ! isset($result['setup_intent_secret'])) { |
|
1008 | 1008 | // Only redirects with intents need to be modified. |
1009 | 1009 | return $result; |
1010 | 1010 | } |
@@ -1013,16 +1013,16 @@ discard block |
||
1013 | 1013 | $verification_url = add_query_arg( |
1014 | 1014 | array( |
1015 | 1015 | 'order' => $order_id, |
1016 | - 'nonce' => wp_create_nonce( 'wc_stripe_confirm_pi' ), |
|
1017 | - 'redirect_to' => rawurlencode( $result['redirect'] ), |
|
1016 | + 'nonce' => wp_create_nonce('wc_stripe_confirm_pi'), |
|
1017 | + 'redirect_to' => rawurlencode($result['redirect']), |
|
1018 | 1018 | ), |
1019 | - WC_AJAX::get_endpoint( 'wc_stripe_verify_intent' ) |
|
1019 | + WC_AJAX::get_endpoint('wc_stripe_verify_intent') |
|
1020 | 1020 | ); |
1021 | 1021 | |
1022 | - if ( isset( $result['payment_intent_secret'] ) ) { |
|
1023 | - $redirect = sprintf( '#confirm-pi-%s:%s', $result['payment_intent_secret'], rawurlencode( $verification_url ) ); |
|
1024 | - } else if ( isset( $result['setup_intent_secret'] ) ) { |
|
1025 | - $redirect = sprintf( '#confirm-si-%s:%s', $result['setup_intent_secret'], rawurlencode( $verification_url ) ); |
|
1022 | + if (isset($result['payment_intent_secret'])) { |
|
1023 | + $redirect = sprintf('#confirm-pi-%s:%s', $result['payment_intent_secret'], rawurlencode($verification_url)); |
|
1024 | + } else if (isset($result['setup_intent_secret'])) { |
|
1025 | + $redirect = sprintf('#confirm-si-%s:%s', $result['setup_intent_secret'], rawurlencode($verification_url)); |
|
1026 | 1026 | } |
1027 | 1027 | |
1028 | 1028 | return array( |
@@ -1034,8 +1034,8 @@ discard block |
||
1034 | 1034 | /** |
1035 | 1035 | * Proceed with current request using new login session (to ensure consistent nonce). |
1036 | 1036 | */ |
1037 | - public function set_cookie_on_current_request( $cookie ) { |
|
1038 | - $_COOKIE[ LOGGED_IN_COOKIE ] = $cookie; |
|
1037 | + public function set_cookie_on_current_request($cookie) { |
|
1038 | + $_COOKIE[LOGGED_IN_COOKIE] = $cookie; |
|
1039 | 1039 | } |
1040 | 1040 | |
1041 | 1041 | /** |
@@ -1045,48 +1045,48 @@ discard block |
||
1045 | 1045 | * @since 4.2.0 |
1046 | 1046 | * @param WC_Order $order The order which is in a transitional state. |
1047 | 1047 | */ |
1048 | - public function verify_intent_after_checkout( $order ) { |
|
1048 | + public function verify_intent_after_checkout($order) { |
|
1049 | 1049 | $payment_method = $order->get_payment_method(); |
1050 | - if ( $payment_method !== $this->id ) { |
|
1050 | + if ($payment_method !== $this->id) { |
|
1051 | 1051 | // If this is not the payment method, an intent would not be available. |
1052 | 1052 | return; |
1053 | 1053 | } |
1054 | 1054 | |
1055 | - $intent = $this->get_intent_from_order( $order ); |
|
1056 | - if ( ! $intent ) { |
|
1055 | + $intent = $this->get_intent_from_order($order); |
|
1056 | + if ( ! $intent) { |
|
1057 | 1057 | // No intent, redirect to the order received page for further actions. |
1058 | 1058 | return; |
1059 | 1059 | } |
1060 | 1060 | |
1061 | 1061 | // A webhook might have modified or locked the order while the intent was retreived. This ensures we are reading the right status. |
1062 | - clean_post_cache( $order->get_id() ); |
|
1063 | - $order = wc_get_order( $order->get_id() ); |
|
1062 | + clean_post_cache($order->get_id()); |
|
1063 | + $order = wc_get_order($order->get_id()); |
|
1064 | 1064 | |
1065 | - if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
1065 | + if ( ! $order->has_status(array('pending', 'failed'))) { |
|
1066 | 1066 | // If payment has already been completed, this function is redundant. |
1067 | 1067 | return; |
1068 | 1068 | } |
1069 | 1069 | |
1070 | - if ( $this->lock_order_payment( $order, $intent ) ) { |
|
1070 | + if ($this->lock_order_payment($order, $intent)) { |
|
1071 | 1071 | return; |
1072 | 1072 | } |
1073 | 1073 | |
1074 | - if ( 'setup_intent' === $intent->object && 'succeeded' === $intent->status ) { |
|
1074 | + if ('setup_intent' === $intent->object && 'succeeded' === $intent->status) { |
|
1075 | 1075 | WC()->cart->empty_cart(); |
1076 | - if ( WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order( $order ) ) { |
|
1077 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
1076 | + if (WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order($order)) { |
|
1077 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
1078 | 1078 | } else { |
1079 | 1079 | $order->payment_complete(); |
1080 | 1080 | } |
1081 | - } else if ( 'succeeded' === $intent->status || 'requires_capture' === $intent->status ) { |
|
1081 | + } else if ('succeeded' === $intent->status || 'requires_capture' === $intent->status) { |
|
1082 | 1082 | // Proceed with the payment completion. |
1083 | - $this->handle_intent_verification_success( $order, $intent ); |
|
1084 | - } else if ( 'requires_payment_method' === $intent->status ) { |
|
1083 | + $this->handle_intent_verification_success($order, $intent); |
|
1084 | + } else if ('requires_payment_method' === $intent->status) { |
|
1085 | 1085 | // `requires_payment_method` means that SCA got denied for the current payment method. |
1086 | - $this->handle_intent_verification_failure( $order, $intent ); |
|
1086 | + $this->handle_intent_verification_failure($order, $intent); |
|
1087 | 1087 | } |
1088 | 1088 | |
1089 | - $this->unlock_order_payment( $order ); |
|
1089 | + $this->unlock_order_payment($order); |
|
1090 | 1090 | } |
1091 | 1091 | |
1092 | 1092 | /** |
@@ -1096,8 +1096,8 @@ discard block |
||
1096 | 1096 | * @param WC_Order $order The order whose verification succeeded. |
1097 | 1097 | * @param stdClass $intent The Payment Intent object. |
1098 | 1098 | */ |
1099 | - protected function handle_intent_verification_success( $order, $intent ) { |
|
1100 | - $this->process_response( end( $intent->charges->data ), $order ); |
|
1099 | + protected function handle_intent_verification_success($order, $intent) { |
|
1100 | + $this->process_response(end($intent->charges->data), $order); |
|
1101 | 1101 | } |
1102 | 1102 | |
1103 | 1103 | /** |
@@ -1107,8 +1107,8 @@ discard block |
||
1107 | 1107 | * @param WC_Order $order The order whose verification failed. |
1108 | 1108 | * @param stdClass $intent The Payment Intent object. |
1109 | 1109 | */ |
1110 | - protected function handle_intent_verification_failure( $order, $intent ) { |
|
1111 | - $this->failed_sca_auth( $order, $intent ); |
|
1110 | + protected function handle_intent_verification_failure($order, $intent) { |
|
1111 | + $this->failed_sca_auth($order, $intent); |
|
1112 | 1112 | } |
1113 | 1113 | |
1114 | 1114 | /** |
@@ -1118,18 +1118,18 @@ discard block |
||
1118 | 1118 | * @param WC_Order $order The order which should be checked. |
1119 | 1119 | * @param object $intent The intent, associated with the order. |
1120 | 1120 | */ |
1121 | - public function failed_sca_auth( $order, $intent ) { |
|
1121 | + public function failed_sca_auth($order, $intent) { |
|
1122 | 1122 | // If the order has already failed, do not repeat the same message. |
1123 | - if ( $order->has_status( 'failed' ) ) { |
|
1123 | + if ($order->has_status('failed')) { |
|
1124 | 1124 | return; |
1125 | 1125 | } |
1126 | 1126 | |
1127 | 1127 | // Load the right message and update the status. |
1128 | - $status_message = isset( $intent->last_payment_error ) |
|
1128 | + $status_message = isset($intent->last_payment_error) |
|
1129 | 1129 | /* translators: 1) The error message that was received from Stripe. */ |
1130 | - ? sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $intent->last_payment_error->message ) |
|
1131 | - : __( 'Stripe SCA authentication failed.', 'woocommerce-gateway-stripe' ); |
|
1132 | - $order->update_status( 'failed', $status_message ); |
|
1130 | + ? sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $intent->last_payment_error->message) |
|
1131 | + : __('Stripe SCA authentication failed.', 'woocommerce-gateway-stripe'); |
|
1132 | + $order->update_status('failed', $status_message); |
|
1133 | 1133 | } |
1134 | 1134 | |
1135 | 1135 | /** |
@@ -1140,10 +1140,10 @@ discard block |
||
1140 | 1140 | * |
1141 | 1141 | * @return string Checkout URL for the given order. |
1142 | 1142 | */ |
1143 | - public function get_checkout_payment_url( $pay_url, $order ) { |
|
1143 | + public function get_checkout_payment_url($pay_url, $order) { |
|
1144 | 1144 | global $wp; |
1145 | - if ( isset( $_GET['wc-stripe-confirmation'] ) && isset( $wp->query_vars['order-pay'] ) && $wp->query_vars['order-pay'] == $order->get_id() ) { |
|
1146 | - $pay_url = add_query_arg( 'wc-stripe-confirmation', 1, $pay_url ); |
|
1145 | + if (isset($_GET['wc-stripe-confirmation']) && isset($wp->query_vars['order-pay']) && $wp->query_vars['order-pay'] == $order->get_id()) { |
|
1146 | + $pay_url = add_query_arg('wc-stripe-confirmation', 1, $pay_url); |
|
1147 | 1147 | } |
1148 | 1148 | return $pay_url; |
1149 | 1149 | } |
@@ -1153,63 +1153,63 @@ discard block |
||
1153 | 1153 | */ |
1154 | 1154 | public function process_admin_options() { |
1155 | 1155 | // Load all old values before the new settings get saved. |
1156 | - $old_publishable_key = $this->get_option( 'publishable_key' ); |
|
1157 | - $old_secret_key = $this->get_option( 'secret_key' ); |
|
1158 | - $old_test_publishable_key = $this->get_option( 'test_publishable_key' ); |
|
1159 | - $old_test_secret_key = $this->get_option( 'test_secret_key' ); |
|
1156 | + $old_publishable_key = $this->get_option('publishable_key'); |
|
1157 | + $old_secret_key = $this->get_option('secret_key'); |
|
1158 | + $old_test_publishable_key = $this->get_option('test_publishable_key'); |
|
1159 | + $old_test_secret_key = $this->get_option('test_secret_key'); |
|
1160 | 1160 | |
1161 | 1161 | parent::process_admin_options(); |
1162 | 1162 | |
1163 | 1163 | // Load all old values after the new settings have been saved. |
1164 | - $new_publishable_key = $this->get_option( 'publishable_key' ); |
|
1165 | - $new_secret_key = $this->get_option( 'secret_key' ); |
|
1166 | - $new_test_publishable_key = $this->get_option( 'test_publishable_key' ); |
|
1167 | - $new_test_secret_key = $this->get_option( 'test_secret_key' ); |
|
1164 | + $new_publishable_key = $this->get_option('publishable_key'); |
|
1165 | + $new_secret_key = $this->get_option('secret_key'); |
|
1166 | + $new_test_publishable_key = $this->get_option('test_publishable_key'); |
|
1167 | + $new_test_secret_key = $this->get_option('test_secret_key'); |
|
1168 | 1168 | |
1169 | 1169 | // Checks whether a value has transitioned from a non-empty value to a new one. |
1170 | - $has_changed = function( $old_value, $new_value ) { |
|
1171 | - return ! empty( $old_value ) && ( $old_value !== $new_value ); |
|
1170 | + $has_changed = function($old_value, $new_value) { |
|
1171 | + return ! empty($old_value) && ($old_value !== $new_value); |
|
1172 | 1172 | }; |
1173 | 1173 | |
1174 | 1174 | // Look for updates. |
1175 | 1175 | if ( |
1176 | - $has_changed( $old_publishable_key, $new_publishable_key ) |
|
1177 | - || $has_changed( $old_secret_key, $new_secret_key ) |
|
1178 | - || $has_changed( $old_test_publishable_key, $new_test_publishable_key ) |
|
1179 | - || $has_changed( $old_test_secret_key, $new_test_secret_key ) |
|
1176 | + $has_changed($old_publishable_key, $new_publishable_key) |
|
1177 | + || $has_changed($old_secret_key, $new_secret_key) |
|
1178 | + || $has_changed($old_test_publishable_key, $new_test_publishable_key) |
|
1179 | + || $has_changed($old_test_secret_key, $new_test_secret_key) |
|
1180 | 1180 | ) { |
1181 | - update_option( 'wc_stripe_show_changed_keys_notice', 'yes' ); |
|
1181 | + update_option('wc_stripe_show_changed_keys_notice', 'yes'); |
|
1182 | 1182 | } |
1183 | 1183 | } |
1184 | 1184 | |
1185 | - public function validate_publishable_key_field( $key, $value ) { |
|
1186 | - $value = $this->validate_text_field( $key, $value ); |
|
1187 | - if ( ! empty( $value ) && ! preg_match( '/^pk_live_/', $value ) ) { |
|
1188 | - throw new Exception( __( 'The "Live Publishable Key" should start with "pk_live", enter the correct key.', 'woocommerce-gateway-stripe' ) ); |
|
1185 | + public function validate_publishable_key_field($key, $value) { |
|
1186 | + $value = $this->validate_text_field($key, $value); |
|
1187 | + if ( ! empty($value) && ! preg_match('/^pk_live_/', $value)) { |
|
1188 | + throw new Exception(__('The "Live Publishable Key" should start with "pk_live", enter the correct key.', 'woocommerce-gateway-stripe')); |
|
1189 | 1189 | } |
1190 | 1190 | return $value; |
1191 | 1191 | } |
1192 | 1192 | |
1193 | - public function validate_secret_key_field( $key, $value ) { |
|
1194 | - $value = $this->validate_text_field( $key, $value ); |
|
1195 | - if ( ! empty( $value ) && ! preg_match( '/^[rs]k_live_/', $value ) ) { |
|
1196 | - throw new Exception( __( 'The "Live Secret Key" should start with "sk_live" or "rk_live", enter the correct key.', 'woocommerce-gateway-stripe' ) ); |
|
1193 | + public function validate_secret_key_field($key, $value) { |
|
1194 | + $value = $this->validate_text_field($key, $value); |
|
1195 | + if ( ! empty($value) && ! preg_match('/^[rs]k_live_/', $value)) { |
|
1196 | + throw new Exception(__('The "Live Secret Key" should start with "sk_live" or "rk_live", enter the correct key.', 'woocommerce-gateway-stripe')); |
|
1197 | 1197 | } |
1198 | 1198 | return $value; |
1199 | 1199 | } |
1200 | 1200 | |
1201 | - public function validate_test_publishable_key_field( $key, $value ) { |
|
1202 | - $value = $this->validate_text_field( $key, $value ); |
|
1203 | - if ( ! empty( $value ) && ! preg_match( '/^pk_test_/', $value ) ) { |
|
1204 | - throw new Exception( __( 'The "Test Publishable Key" should start with "pk_test", enter the correct key.', 'woocommerce-gateway-stripe' ) ); |
|
1201 | + public function validate_test_publishable_key_field($key, $value) { |
|
1202 | + $value = $this->validate_text_field($key, $value); |
|
1203 | + if ( ! empty($value) && ! preg_match('/^pk_test_/', $value)) { |
|
1204 | + throw new Exception(__('The "Test Publishable Key" should start with "pk_test", enter the correct key.', 'woocommerce-gateway-stripe')); |
|
1205 | 1205 | } |
1206 | 1206 | return $value; |
1207 | 1207 | } |
1208 | 1208 | |
1209 | - public function validate_test_secret_key_field( $key, $value ) { |
|
1210 | - $value = $this->validate_text_field( $key, $value ); |
|
1211 | - if ( ! empty( $value ) && ! preg_match( '/^[rs]k_test_/', $value ) ) { |
|
1212 | - throw new Exception( __( 'The "Test Secret Key" should start with "sk_test" or "rk_test", enter the correct key.', 'woocommerce-gateway-stripe' ) ); |
|
1209 | + public function validate_test_secret_key_field($key, $value) { |
|
1210 | + $value = $this->validate_text_field($key, $value); |
|
1211 | + if ( ! empty($value) && ! preg_match('/^[rs]k_test_/', $value)) { |
|
1212 | + throw new Exception(__('The "Test Secret Key" should start with "sk_test" or "rk_test", enter the correct key.', 'woocommerce-gateway-stripe')); |
|
1213 | 1213 | } |
1214 | 1214 | return $value; |
1215 | 1215 | } |