@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @since 4.0.6 |
6 | 6 | */ |
7 | 7 | |
8 | -if ( ! defined( 'ABSPATH' ) ) { |
|
8 | +if ( ! defined('ABSPATH')) { |
|
9 | 9 | exit; |
10 | 10 | } |
11 | 11 | |
@@ -60,16 +60,16 @@ discard block |
||
60 | 60 | public $apple_pay_verify_notice; |
61 | 61 | |
62 | 62 | public function __construct() { |
63 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
64 | - $this->stripe_enabled = $this->get_option( 'enabled' ); |
|
65 | - $this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
66 | - $this->apple_pay_domain_set = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' ); |
|
63 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
64 | + $this->stripe_enabled = $this->get_option('enabled'); |
|
65 | + $this->payment_request = 'yes' === $this->get_option('payment_request', 'yes'); |
|
66 | + $this->apple_pay_domain_set = 'yes' === $this->get_option('apple_pay_domain_set', 'no'); |
|
67 | 67 | $this->apple_pay_verify_notice = ''; |
68 | - $this->testmode = 'yes' === $this->get_option( 'testmode', 'no' ); |
|
69 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
68 | + $this->testmode = 'yes' === $this->get_option('testmode', 'no'); |
|
69 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
70 | 70 | $this->init_apple_pay(); |
71 | 71 | |
72 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
72 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | * @param string default |
81 | 81 | * @return string $setting_value |
82 | 82 | */ |
83 | - public function get_option( $setting = '', $default = '' ) { |
|
84 | - if ( empty( $this->stripe_settings ) ) { |
|
83 | + public function get_option($setting = '', $default = '') { |
|
84 | + if (empty($this->stripe_settings)) { |
|
85 | 85 | return $default; |
86 | 86 | } |
87 | 87 | |
88 | - if ( ! empty( $this->stripe_settings[ $setting ] ) ) { |
|
89 | - return $this->stripe_settings[ $setting ]; |
|
88 | + if ( ! empty($this->stripe_settings[$setting])) { |
|
89 | + return $this->stripe_settings[$setting]; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | return $default; |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | public function init_apple_pay() { |
102 | 102 | if ( |
103 | 103 | is_admin() && |
104 | - isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && |
|
105 | - isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] && |
|
106 | - isset( $_GET['section'] ) && 'stripe' === $_GET['section'] && |
|
104 | + isset($_GET['page']) && 'wc-settings' === $_GET['page'] && |
|
105 | + isset($_GET['tab']) && 'checkout' === $_GET['tab'] && |
|
106 | + isset($_GET['section']) && 'stripe' === $_GET['section'] && |
|
107 | 107 | $this->payment_request |
108 | 108 | ) { |
109 | 109 | $this->process_apple_pay_verification(); |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | * @version 3.1.0 |
118 | 118 | * @param string $secret_key |
119 | 119 | */ |
120 | - private function register_apple_pay_domain( $secret_key = '' ) { |
|
121 | - if ( empty( $secret_key ) ) { |
|
122 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
120 | + private function register_apple_pay_domain($secret_key = '') { |
|
121 | + if (empty($secret_key)) { |
|
122 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -133,23 +133,23 @@ discard block |
||
133 | 133 | 'Authorization' => 'Bearer ' . $secret_key, |
134 | 134 | ); |
135 | 135 | |
136 | - $response = wp_remote_post( $endpoint, array( |
|
136 | + $response = wp_remote_post($endpoint, array( |
|
137 | 137 | 'headers' => $headers, |
138 | - 'body' => http_build_query( $data ), |
|
139 | - ) ); |
|
138 | + 'body' => http_build_query($data), |
|
139 | + )); |
|
140 | 140 | |
141 | - if ( is_wp_error( $response ) ) { |
|
141 | + if (is_wp_error($response)) { |
|
142 | 142 | /* translators: error message */ |
143 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
143 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
144 | 144 | } |
145 | 145 | |
146 | - if ( 200 !== $response['response']['code'] ) { |
|
147 | - $parsed_response = json_decode( $response['body'] ); |
|
146 | + if (200 !== $response['response']['code']) { |
|
147 | + $parsed_response = json_decode($response['body']); |
|
148 | 148 | |
149 | 149 | $this->apple_pay_verify_notice = $parsed_response->error->message; |
150 | 150 | |
151 | 151 | /* translators: error message */ |
152 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) ); |
|
152 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message)); |
|
153 | 153 | } |
154 | 154 | } |
155 | 155 | |
@@ -161,45 +161,45 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public function process_apple_pay_verification() { |
163 | 163 | try { |
164 | - $path = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] ); |
|
164 | + $path = untrailingslashit($_SERVER['DOCUMENT_ROOT']); |
|
165 | 165 | $dir = '.well-known'; |
166 | 166 | $file = 'apple-developer-merchantid-domain-association'; |
167 | 167 | $fullpath = $path . '/' . $dir . '/' . $file; |
168 | 168 | |
169 | - if ( $this->apple_pay_domain_set && file_exists( $fullpath ) ) { |
|
169 | + if ($this->apple_pay_domain_set && file_exists($fullpath)) { |
|
170 | 170 | return; |
171 | 171 | } |
172 | 172 | |
173 | - if ( ! file_exists( $path . '/' . $dir ) ) { |
|
174 | - if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) { // @codingStandardsIgnoreLine |
|
175 | - throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
173 | + if ( ! file_exists($path . '/' . $dir)) { |
|
174 | + if ( ! @mkdir($path . '/' . $dir, 0755)) { // @codingStandardsIgnoreLine |
|
175 | + throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe')); |
|
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
179 | - if ( ! file_exists( $fullpath ) ) { |
|
180 | - if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { // @codingStandardsIgnoreLine |
|
181 | - throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
179 | + if ( ! file_exists($fullpath)) { |
|
180 | + if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { // @codingStandardsIgnoreLine |
|
181 | + throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe')); |
|
182 | 182 | } |
183 | 183 | } |
184 | 184 | |
185 | 185 | // At this point then the domain association folder and file should be available. |
186 | 186 | // Proceed to verify/and or verify again. |
187 | - $this->register_apple_pay_domain( $this->secret_key ); |
|
187 | + $this->register_apple_pay_domain($this->secret_key); |
|
188 | 188 | |
189 | 189 | // No errors to this point, verification success! |
190 | 190 | $this->stripe_settings['apple_pay_domain_set'] = 'yes'; |
191 | 191 | $this->apple_pay_domain_set = true; |
192 | 192 | |
193 | - update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); |
|
193 | + update_option('woocommerce_stripe_settings', $this->stripe_settings); |
|
194 | 194 | |
195 | - WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' ); |
|
195 | + WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!'); |
|
196 | 196 | |
197 | - } catch ( Exception $e ) { |
|
197 | + } catch (Exception $e) { |
|
198 | 198 | $this->stripe_settings['apple_pay_domain_set'] = 'no'; |
199 | 199 | |
200 | - update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); |
|
200 | + update_option('woocommerce_stripe_settings', $this->stripe_settings); |
|
201 | 201 | |
202 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
202 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
203 | 203 | } |
204 | 204 | } |
205 | 205 | |
@@ -209,11 +209,11 @@ discard block |
||
209 | 209 | * @since 4.0.6 |
210 | 210 | */ |
211 | 211 | public function admin_notices() { |
212 | - if ( ! $this->stripe_enabled ) { |
|
212 | + if ( ! $this->stripe_enabled) { |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | |
216 | - if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) { |
|
216 | + if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) { |
|
217 | 217 | $allowed_html = array( |
218 | 218 | 'a' => array( |
219 | 219 | 'href' => array(), |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | ), |
222 | 222 | ); |
223 | 223 | |
224 | - echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>'; |
|
224 | + echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>'; |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -229,9 +229,9 @@ discard block |
||
229 | 229 | * when setting screen is displayed. So if domain verification is not set, |
230 | 230 | * something went wrong so lets notify user. |
231 | 231 | */ |
232 | - if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) { |
|
232 | + if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) { |
|
233 | 233 | /* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */ |
234 | - echo '<div class="error stripe-apple-pay-message"><p>' . sprintf( __( 'Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>'; |
|
234 | + echo '<div class="error stripe-apple-pay-message"><p>' . sprintf(__('Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', '</a>') . '</p></div>'; |
|
235 | 235 | } |
236 | 236 | } |
237 | 237 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_sofort'; |
60 | - $this->method_title = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
99 | 99 | * @version 4.0.0 |
100 | 100 | */ |
101 | 101 | public function check_environment() { |
102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | $environment_warning = $this->get_environment_warning(); |
107 | 107 | |
108 | - if ( $environment_warning ) { |
|
109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
108 | + if ($environment_warning) { |
|
109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
110 | 110 | } |
111 | 111 | |
112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
115 | 115 | echo '</p></div>'; |
116 | 116 | } |
117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @version 4.0.0 |
125 | 125 | */ |
126 | 126 | public function get_environment_warning() { |
127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
128 | - $message = __( 'SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
128 | + $message = __('SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
129 | 129 | |
130 | 130 | return $message; |
131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * @return array |
142 | 142 | */ |
143 | 143 | public function get_supported_currency() { |
144 | - return apply_filters( 'wc_stripe_sofort_supported_currencies', array( |
|
144 | + return apply_filters('wc_stripe_sofort_supported_currencies', array( |
|
145 | 145 | 'EUR', |
146 | - ) ); |
|
146 | + )); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @return bool |
155 | 155 | */ |
156 | 156 | public function is_available() { |
157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | |
176 | 176 | $icons_str .= $icons['sofort']; |
177 | 177 | |
178 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
178 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -186,19 +186,19 @@ discard block |
||
186 | 186 | * @access public |
187 | 187 | */ |
188 | 188 | public function payment_scripts() { |
189 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
189 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
190 | 190 | return; |
191 | 191 | } |
192 | 192 | |
193 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
194 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
193 | + wp_enqueue_style('stripe_paymentfonts'); |
|
194 | + wp_enqueue_script('woocommerce_stripe'); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
198 | 198 | * Initialize Gateway Settings Form Fields. |
199 | 199 | */ |
200 | 200 | public function init_form_fields() { |
201 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php' ); |
|
201 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php'); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -209,25 +209,25 @@ discard block |
||
209 | 209 | $total = WC()->cart->total; |
210 | 210 | |
211 | 211 | // If paying from order, we need to get total from order not cart. |
212 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
213 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
212 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
213 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
214 | 214 | $total = $order->get_total(); |
215 | 215 | } |
216 | 216 | |
217 | - if ( is_add_payment_method_page() ) { |
|
218 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
219 | - $total = ''; |
|
217 | + if (is_add_payment_method_page()) { |
|
218 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
219 | + $total = ''; |
|
220 | 220 | } else { |
221 | 221 | $pay_button_text = ''; |
222 | 222 | } |
223 | 223 | |
224 | 224 | echo '<div |
225 | 225 | id="stripe-sofort-payment-data" |
226 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
227 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
226 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
227 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
228 | 228 | |
229 | - if ( $this->description ) { |
|
230 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
229 | + if ($this->description) { |
|
230 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | echo '</div>'; |
@@ -241,28 +241,28 @@ discard block |
||
241 | 241 | * @param object $order |
242 | 242 | * @return mixed |
243 | 243 | */ |
244 | - public function create_source( $order ) { |
|
244 | + public function create_source($order) { |
|
245 | 245 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
246 | 246 | $bank_country = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
247 | - $return_url = $this->get_stripe_return_url( $order ); |
|
247 | + $return_url = $this->get_stripe_return_url($order); |
|
248 | 248 | $post_data = array(); |
249 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
250 | - $post_data['currency'] = strtolower( $currency ); |
|
249 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
250 | + $post_data['currency'] = strtolower($currency); |
|
251 | 251 | $post_data['type'] = 'sofort'; |
252 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
253 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
252 | + $post_data['owner'] = $this->get_owner_details($order); |
|
253 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
254 | 254 | $post_data['sofort'] = array( |
255 | 255 | 'country' => $bank_country, |
256 | 256 | 'preferred_language' => $this->get_locale(), |
257 | 257 | ); |
258 | 258 | |
259 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
260 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
259 | + if ( ! empty($this->statement_descriptor)) { |
|
260 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
261 | 261 | } |
262 | 262 | |
263 | - WC_Stripe_Logger::log( 'Info: Begin creating SOFORT source' ); |
|
263 | + WC_Stripe_Logger::log('Info: Begin creating SOFORT source'); |
|
264 | 264 | |
265 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_sofort_source', $post_data, $order ), 'sources' ); |
|
265 | + return WC_Stripe_API::request(apply_filters('wc_stripe_sofort_source', $post_data, $order), 'sources'); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -276,59 +276,59 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @return array|void |
278 | 278 | */ |
279 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
279 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
280 | 280 | try { |
281 | - $order = wc_get_order( $order_id ); |
|
281 | + $order = wc_get_order($order_id); |
|
282 | 282 | |
283 | 283 | // This will throw exception if not valid. |
284 | - $this->validate_minimum_order_amount( $order ); |
|
284 | + $this->validate_minimum_order_amount($order); |
|
285 | 285 | |
286 | 286 | // This comes from the create account checkbox in the checkout page. |
287 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
287 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
288 | 288 | |
289 | - if ( $create_account ) { |
|
289 | + if ($create_account) { |
|
290 | 290 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
291 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
291 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
292 | 292 | $new_stripe_customer->create_customer(); |
293 | 293 | } |
294 | 294 | |
295 | - $response = $this->create_source( $order ); |
|
295 | + $response = $this->create_source($order); |
|
296 | 296 | |
297 | - if ( ! empty( $response->error ) ) { |
|
298 | - $order->add_order_note( $response->error->message ); |
|
297 | + if ( ! empty($response->error)) { |
|
298 | + $order->add_order_note($response->error->message); |
|
299 | 299 | |
300 | 300 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
301 | 301 | |
302 | - if ( 'invalid_sofort_country' === $response->error->code ) { |
|
303 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
302 | + if ('invalid_sofort_country' === $response->error->code) { |
|
303 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
304 | 304 | } else { |
305 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
305 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
306 | 306 | } |
307 | 307 | |
308 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
308 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
309 | 309 | } |
310 | 310 | |
311 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
312 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
311 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
312 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
313 | 313 | } else { |
314 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
314 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
315 | 315 | $order->save(); |
316 | 316 | } |
317 | 317 | |
318 | - WC_Stripe_Logger::log( 'Info: Redirecting to SOFORT...' ); |
|
318 | + WC_Stripe_Logger::log('Info: Redirecting to SOFORT...'); |
|
319 | 319 | |
320 | 320 | return array( |
321 | 321 | 'result' => 'success', |
322 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
322 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
323 | 323 | ); |
324 | - } catch ( WC_Stripe_Exception $e ) { |
|
325 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
326 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
324 | + } catch (WC_Stripe_Exception $e) { |
|
325 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
326 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
327 | 327 | |
328 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
328 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
329 | 329 | |
330 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
331 | - $this->send_failed_order_email( $order_id ); |
|
330 | + if ($order->has_status(array('pending', 'failed'))) { |
|
331 | + $this->send_failed_order_email($order_id); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_bancontact'; |
60 | - $this->method_title = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
99 | 99 | * @version 4.0.0 |
100 | 100 | */ |
101 | 101 | public function check_environment() { |
102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | $environment_warning = $this->get_environment_warning(); |
107 | 107 | |
108 | - if ( $environment_warning ) { |
|
109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
108 | + if ($environment_warning) { |
|
109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
110 | 110 | } |
111 | 111 | |
112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
115 | 115 | echo '</p></div>'; |
116 | 116 | } |
117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @version 4.0.0 |
125 | 125 | */ |
126 | 126 | public function get_environment_warning() { |
127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
128 | - $message = __( 'Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
128 | + $message = __('Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
129 | 129 | |
130 | 130 | return $message; |
131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * @return array |
142 | 142 | */ |
143 | 143 | public function get_supported_currency() { |
144 | - return apply_filters( 'wc_stripe_bancontact_supported_currencies', array( |
|
144 | + return apply_filters('wc_stripe_bancontact_supported_currencies', array( |
|
145 | 145 | 'EUR', |
146 | - ) ); |
|
146 | + )); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @return bool |
155 | 155 | */ |
156 | 156 | public function is_available() { |
157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | |
176 | 176 | $icons_str .= $icons['bancontact']; |
177 | 177 | |
178 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
178 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -186,19 +186,19 @@ discard block |
||
186 | 186 | * @access public |
187 | 187 | */ |
188 | 188 | public function payment_scripts() { |
189 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
189 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
190 | 190 | return; |
191 | 191 | } |
192 | 192 | |
193 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
194 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
193 | + wp_enqueue_style('stripe_paymentfonts'); |
|
194 | + wp_enqueue_script('woocommerce_stripe'); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
198 | 198 | * Initialize Gateway Settings Form Fields. |
199 | 199 | */ |
200 | 200 | public function init_form_fields() { |
201 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php' ); |
|
201 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php'); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -209,25 +209,25 @@ discard block |
||
209 | 209 | $total = WC()->cart->total; |
210 | 210 | |
211 | 211 | // If paying from order, we need to get total from order not cart. |
212 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
213 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
212 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
213 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
214 | 214 | $total = $order->get_total(); |
215 | 215 | } |
216 | 216 | |
217 | - if ( is_add_payment_method_page() ) { |
|
218 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
219 | - $total = ''; |
|
217 | + if (is_add_payment_method_page()) { |
|
218 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
219 | + $total = ''; |
|
220 | 220 | } else { |
221 | 221 | $pay_button_text = ''; |
222 | 222 | } |
223 | 223 | |
224 | 224 | echo '<div |
225 | 225 | id="stripe-bancontact-payment-data" |
226 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
227 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
226 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
227 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
228 | 228 | |
229 | - if ( $this->description ) { |
|
230 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
229 | + if ($this->description) { |
|
230 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | echo '</div>'; |
@@ -241,25 +241,25 @@ discard block |
||
241 | 241 | * @param object $order |
242 | 242 | * @return mixed |
243 | 243 | */ |
244 | - public function create_source( $order ) { |
|
244 | + public function create_source($order) { |
|
245 | 245 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
246 | 246 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
247 | - $return_url = $this->get_stripe_return_url( $order ); |
|
247 | + $return_url = $this->get_stripe_return_url($order); |
|
248 | 248 | $post_data = array(); |
249 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
250 | - $post_data['currency'] = strtolower( $currency ); |
|
249 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
250 | + $post_data['currency'] = strtolower($currency); |
|
251 | 251 | $post_data['type'] = 'bancontact'; |
252 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
253 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
254 | - $post_data['bancontact'] = array( 'preferred_language' => $this->get_locale() ); |
|
252 | + $post_data['owner'] = $this->get_owner_details($order); |
|
253 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
254 | + $post_data['bancontact'] = array('preferred_language' => $this->get_locale()); |
|
255 | 255 | |
256 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
257 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
256 | + if ( ! empty($this->statement_descriptor)) { |
|
257 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
258 | 258 | } |
259 | 259 | |
260 | - WC_Stripe_Logger::log( 'Info: Begin creating Bancontact source' ); |
|
260 | + WC_Stripe_Logger::log('Info: Begin creating Bancontact source'); |
|
261 | 261 | |
262 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_bancontact_source', $post_data, $order ), 'sources' ); |
|
262 | + return WC_Stripe_API::request(apply_filters('wc_stripe_bancontact_source', $post_data, $order), 'sources'); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
@@ -273,51 +273,51 @@ discard block |
||
273 | 273 | * |
274 | 274 | * @return array|void |
275 | 275 | */ |
276 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
276 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
277 | 277 | try { |
278 | - $order = wc_get_order( $order_id ); |
|
278 | + $order = wc_get_order($order_id); |
|
279 | 279 | |
280 | 280 | // This will throw exception if not valid. |
281 | - $this->validate_minimum_order_amount( $order ); |
|
281 | + $this->validate_minimum_order_amount($order); |
|
282 | 282 | |
283 | 283 | // This comes from the create account checkbox in the checkout page. |
284 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
284 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
285 | 285 | |
286 | - if ( $create_account ) { |
|
286 | + if ($create_account) { |
|
287 | 287 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
288 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
288 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
289 | 289 | $new_stripe_customer->create_customer(); |
290 | 290 | } |
291 | 291 | |
292 | - $response = $this->create_source( $order ); |
|
292 | + $response = $this->create_source($order); |
|
293 | 293 | |
294 | - if ( ! empty( $response->error ) ) { |
|
295 | - $order->add_order_note( $response->error->message ); |
|
294 | + if ( ! empty($response->error)) { |
|
295 | + $order->add_order_note($response->error->message); |
|
296 | 296 | |
297 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
297 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
298 | 298 | } |
299 | 299 | |
300 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
301 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
300 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
301 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
302 | 302 | } else { |
303 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
303 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
304 | 304 | $order->save(); |
305 | 305 | } |
306 | 306 | |
307 | - WC_Stripe_Logger::log( 'Info: Redirecting to Bancontact...' ); |
|
307 | + WC_Stripe_Logger::log('Info: Redirecting to Bancontact...'); |
|
308 | 308 | |
309 | 309 | return array( |
310 | 310 | 'result' => 'success', |
311 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
311 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
312 | 312 | ); |
313 | - } catch ( WC_Stripe_Exception $e ) { |
|
314 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
315 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
313 | + } catch (WC_Stripe_Exception $e) { |
|
314 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
315 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
316 | 316 | |
317 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
317 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
318 | 318 | |
319 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
320 | - $this->send_failed_order_email( $order_id ); |
|
319 | + if ($order->has_status(array('pending', 'failed'))) { |
|
320 | + $this->send_failed_order_email($order_id); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | public function __construct() { |
102 | 102 | $this->retry_interval = 2; |
103 | 103 | $this->id = 'stripe'; |
104 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
104 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
105 | 105 | /* translators: 1) link to Stripe register page 2) link to Stripe api keys page */ |
106 | - $this->method_description = sprintf( __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys' ); |
|
106 | + $this->method_description = sprintf(__('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys'); |
|
107 | 107 | $this->has_fields = true; |
108 | 108 | $this->supports = array( |
109 | 109 | 'products', |
@@ -130,32 +130,32 @@ discard block |
||
130 | 130 | $this->init_settings(); |
131 | 131 | |
132 | 132 | // Get setting values. |
133 | - $this->title = $this->get_option( 'title' ); |
|
134 | - $this->description = $this->get_option( 'description' ); |
|
135 | - $this->enabled = $this->get_option( 'enabled' ); |
|
136 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
137 | - $this->inline_cc_form = 'yes' === $this->get_option( 'inline_cc_form' ); |
|
138 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
139 | - $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) ); |
|
140 | - $this->three_d_secure = 'yes' === $this->get_option( 'three_d_secure' ); |
|
141 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
142 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
143 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
144 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
145 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
146 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
147 | - $this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
148 | - |
|
149 | - if ( $this->stripe_checkout ) { |
|
150 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
133 | + $this->title = $this->get_option('title'); |
|
134 | + $this->description = $this->get_option('description'); |
|
135 | + $this->enabled = $this->get_option('enabled'); |
|
136 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
137 | + $this->inline_cc_form = 'yes' === $this->get_option('inline_cc_form'); |
|
138 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
139 | + $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor')); |
|
140 | + $this->three_d_secure = 'yes' === $this->get_option('three_d_secure'); |
|
141 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
142 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
143 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
144 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
145 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
146 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
147 | + $this->payment_request = 'yes' === $this->get_option('payment_request', 'yes'); |
|
148 | + |
|
149 | + if ($this->stripe_checkout) { |
|
150 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
151 | 151 | } |
152 | 152 | |
153 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
153 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
154 | 154 | |
155 | 155 | // Hooks. |
156 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
157 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
|
158 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
156 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
157 | + add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); |
|
158 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * @return bool |
166 | 166 | */ |
167 | 167 | public function are_keys_set() { |
168 | - if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) { |
|
168 | + if (empty($this->secret_key) || empty($this->publishable_key)) { |
|
169 | 169 | return false; |
170 | 170 | } |
171 | 171 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * @since 4.0.2 |
179 | 179 | */ |
180 | 180 | public function is_available() { |
181 | - if ( is_add_payment_method_page() && ! $this->saved_cards ) { |
|
181 | + if (is_add_payment_method_page() && ! $this->saved_cards) { |
|
182 | 182 | return false; |
183 | 183 | } |
184 | 184 | |
@@ -201,24 +201,24 @@ discard block |
||
201 | 201 | $icons_str .= $icons['amex']; |
202 | 202 | $icons_str .= $icons['mastercard']; |
203 | 203 | |
204 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
204 | + if ('USD' === get_woocommerce_currency()) { |
|
205 | 205 | $icons_str .= $icons['discover']; |
206 | 206 | $icons_str .= $icons['jcb']; |
207 | 207 | $icons_str .= $icons['diners']; |
208 | 208 | } |
209 | 209 | |
210 | - if ( $this->bitcoin && $this->stripe_checkout ) { |
|
210 | + if ($this->bitcoin && $this->stripe_checkout) { |
|
211 | 211 | $icons_str .= $icons['bitcoin']; |
212 | 212 | } |
213 | 213 | |
214 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
214 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
218 | 218 | * Initialise Gateway Settings Form Fields |
219 | 219 | */ |
220 | 220 | public function init_form_fields() { |
221 | - $this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' ); |
|
221 | + $this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php'); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -226,68 +226,68 @@ discard block |
||
226 | 226 | */ |
227 | 227 | public function payment_fields() { |
228 | 228 | $user = wp_get_current_user(); |
229 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
229 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
230 | 230 | $total = WC()->cart->total; |
231 | 231 | $user_email = ''; |
232 | 232 | |
233 | 233 | // If paying from order, we need to get total from order not cart. |
234 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
235 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
234 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
235 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
236 | 236 | $total = $order->get_total(); |
237 | 237 | $user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
238 | 238 | } else { |
239 | - if ( $user->ID ) { |
|
240 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
239 | + if ($user->ID) { |
|
240 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
241 | 241 | $user_email = $user_email ? $user_email : $user->user_email; |
242 | 242 | } |
243 | 243 | } |
244 | 244 | |
245 | - if ( is_add_payment_method_page() ) { |
|
246 | - $pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' ); |
|
247 | - $total = ''; |
|
245 | + if (is_add_payment_method_page()) { |
|
246 | + $pay_button_text = __('Add Card', 'woocommerce-gateway-stripe'); |
|
247 | + $total = ''; |
|
248 | 248 | } else { |
249 | 249 | $pay_button_text = ''; |
250 | 250 | } |
251 | 251 | |
252 | 252 | echo '<div |
253 | 253 | id="stripe-payment-data" |
254 | - data-panel-label="' . esc_attr( $pay_button_text ) . '" |
|
254 | + data-panel-label="' . esc_attr($pay_button_text) . '" |
|
255 | 255 | data-description="" |
256 | - data-email="' . esc_attr( $user_email ) . '" |
|
257 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
258 | - data-name="' . esc_attr( $this->statement_descriptor ) . '" |
|
259 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
260 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
261 | - data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '" |
|
262 | - data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', $this->get_locale() ) ) . '" |
|
263 | - data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '" |
|
264 | - data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">'; |
|
265 | - |
|
266 | - if ( $this->description ) { |
|
267 | - if ( $this->testmode ) { |
|
256 | + data-email="' . esc_attr($user_email) . '" |
|
257 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
258 | + data-name="' . esc_attr($this->statement_descriptor) . '" |
|
259 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
260 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
261 | + data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '" |
|
262 | + data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', $this->get_locale())) . '" |
|
263 | + data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '" |
|
264 | + data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">'; |
|
265 | + |
|
266 | + if ($this->description) { |
|
267 | + if ($this->testmode) { |
|
268 | 268 | /* translators: link to Stripe testing page */ |
269 | - $this->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 documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' ); |
|
270 | - $this->description = trim( $this->description ); |
|
269 | + $this->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 documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing'); |
|
270 | + $this->description = trim($this->description); |
|
271 | 271 | } |
272 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
272 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
273 | 273 | } |
274 | 274 | |
275 | - if ( $display_tokenization ) { |
|
275 | + if ($display_tokenization) { |
|
276 | 276 | $this->tokenization_script(); |
277 | 277 | $this->saved_payment_methods(); |
278 | 278 | } |
279 | 279 | |
280 | - if ( ! $this->stripe_checkout ) { |
|
281 | - if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) { |
|
280 | + if ( ! $this->stripe_checkout) { |
|
281 | + if (apply_filters('wc_stripe_use_elements_checkout_form', true)) { |
|
282 | 282 | $this->elements_form(); |
283 | 283 | } else { |
284 | - WC_Stripe_Logger::log( 'DEPRECATED! Since version 4.0. Stripe Elements is used. This legacy credit card form will be removed by version 5.0!' ); |
|
284 | + WC_Stripe_Logger::log('DEPRECATED! Since version 4.0. Stripe Elements is used. This legacy credit card form will be removed by version 5.0!'); |
|
285 | 285 | $this->form(); |
286 | 286 | echo '<div class="stripe-source-errors" role="alert"></div>'; |
287 | 287 | } |
288 | 288 | } |
289 | 289 | |
290 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
290 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
291 | 291 | $this->save_payment_method_checkbox(); |
292 | 292 | } |
293 | 293 | |
@@ -302,12 +302,12 @@ discard block |
||
302 | 302 | */ |
303 | 303 | public function elements_form() { |
304 | 304 | ?> |
305 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
306 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
305 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
306 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
307 | 307 | |
308 | - <?php if ( $this->inline_cc_form ) { ?> |
|
308 | + <?php if ($this->inline_cc_form) { ?> |
|
309 | 309 | <label for="card-element"> |
310 | - <?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?> |
|
310 | + <?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?> |
|
311 | 311 | </label> |
312 | 312 | |
313 | 313 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | </div> |
316 | 316 | <?php } else { ?> |
317 | 317 | <div class="form-row form-row-wide"> |
318 | - <label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
318 | + <label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
319 | 319 | |
320 | 320 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
321 | 321 | <!-- a Stripe Element will be inserted here. --> |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | </div> |
324 | 324 | |
325 | 325 | <div class="form-row form-row-first"> |
326 | - <label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
326 | + <label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
327 | 327 | |
328 | 328 | <div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
329 | 329 | <!-- a Stripe Element will be inserted here. --> |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | </div> |
332 | 332 | |
333 | 333 | <div class="form-row form-row-last"> |
334 | - <label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
334 | + <label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
335 | 335 | <div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
336 | 336 | <!-- a Stripe Element will be inserted here. --> |
337 | 337 | </div> |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | |
342 | 342 | <!-- Used to display form errors --> |
343 | 343 | <div class="stripe-source-errors" role="alert"></div> |
344 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
344 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
345 | 345 | <div class="clear"></div> |
346 | 346 | </fieldset> |
347 | 347 | <?php |
@@ -354,13 +354,13 @@ discard block |
||
354 | 354 | * @version 3.1.0 |
355 | 355 | */ |
356 | 356 | public function admin_scripts() { |
357 | - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
357 | + if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
358 | 358 | return; |
359 | 359 | } |
360 | 360 | |
361 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
361 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
362 | 362 | |
363 | - wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
363 | + wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | /** |
@@ -372,46 +372,46 @@ discard block |
||
372 | 372 | * @version 4.0.0 |
373 | 373 | */ |
374 | 374 | public function payment_scripts() { |
375 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
375 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
376 | 376 | return; |
377 | 377 | } |
378 | 378 | |
379 | 379 | // If Stripe is not enabled bail. |
380 | - if ( 'no' === $this->enabled ) { |
|
380 | + if ('no' === $this->enabled) { |
|
381 | 381 | return; |
382 | 382 | } |
383 | 383 | |
384 | 384 | // If keys are not set bail. |
385 | - if ( ! $this->are_keys_set() ) { |
|
386 | - WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
385 | + if ( ! $this->are_keys_set()) { |
|
386 | + WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
387 | 387 | return; |
388 | 388 | } |
389 | 389 | |
390 | 390 | // If no SSL bail. |
391 | - if ( ! $this->testmode && ! is_ssl() ) { |
|
392 | - WC_Stripe_Logger::log( 'Stripe requires SSL.' ); |
|
391 | + if ( ! $this->testmode && ! is_ssl()) { |
|
392 | + WC_Stripe_Logger::log('Stripe requires SSL.'); |
|
393 | 393 | return; |
394 | 394 | } |
395 | 395 | |
396 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
396 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
397 | 397 | |
398 | - wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' ); |
|
399 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
400 | - wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true ); |
|
401 | - wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true ); |
|
402 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
403 | - wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripev2', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
398 | + wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5'); |
|
399 | + wp_enqueue_style('stripe_paymentfonts'); |
|
400 | + wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true); |
|
401 | + wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true); |
|
402 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
403 | + wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripev2', 'stripe'), WC_STRIPE_VERSION, true); |
|
404 | 404 | |
405 | 405 | $stripe_params = array( |
406 | 406 | 'key' => $this->publishable_key, |
407 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
408 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
407 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
408 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
409 | 409 | ); |
410 | 410 | |
411 | 411 | // If we're on the pay page we need to pass stripe.js the address of the order. |
412 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { |
|
413 | - $order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); |
|
414 | - $order = wc_get_order( $order_id ); |
|
412 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { |
|
413 | + $order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); |
|
414 | + $order = wc_get_order($order_id); |
|
415 | 415 | |
416 | 416 | $stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
417 | 417 | $stripe_params['billing_last_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
@@ -423,38 +423,38 @@ discard block |
||
423 | 423 | $stripe_params['billing_country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
424 | 424 | } |
425 | 425 | |
426 | - $stripe_params['no_prepaid_card_msg'] = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
427 | - $stripe_params['no_sepa_owner_msg'] = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' ); |
|
428 | - $stripe_params['no_sepa_iban_msg'] = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' ); |
|
429 | - $stripe_params['sepa_mandate_notification'] = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' ); |
|
430 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
426 | + $stripe_params['no_prepaid_card_msg'] = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
427 | + $stripe_params['no_sepa_owner_msg'] = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe'); |
|
428 | + $stripe_params['no_sepa_iban_msg'] = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe'); |
|
429 | + $stripe_params['sepa_mandate_notification'] = apply_filters('wc_stripe_sepa_mandate_notification', 'email'); |
|
430 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
431 | 431 | $stripe_params['inline_cc_form'] = $this->inline_cc_form ? 'yes' : 'no'; |
432 | - $stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no'; |
|
433 | - $stripe_params['is_checkout'] = ( is_checkout() && empty( $_GET['pay_for_order'] ) ); |
|
432 | + $stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no'; |
|
433 | + $stripe_params['is_checkout'] = (is_checkout() && empty($_GET['pay_for_order'])); |
|
434 | 434 | $stripe_params['return_url'] = $this->get_stripe_return_url(); |
435 | - $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint( '%%endpoint%%' ); |
|
436 | - $stripe_params['stripe_nonce'] = wp_create_nonce( '_wc_stripe_nonce' ); |
|
435 | + $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint('%%endpoint%%'); |
|
436 | + $stripe_params['stripe_nonce'] = wp_create_nonce('_wc_stripe_nonce'); |
|
437 | 437 | $stripe_params['statement_descriptor'] = $this->statement_descriptor; |
438 | - $stripe_params['use_elements'] = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no'; |
|
439 | - $stripe_params['elements_options'] = apply_filters( 'wc_stripe_elements_options', array() ); |
|
438 | + $stripe_params['use_elements'] = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no'; |
|
439 | + $stripe_params['elements_options'] = apply_filters('wc_stripe_elements_options', array()); |
|
440 | 440 | $stripe_params['is_stripe_checkout'] = $this->stripe_checkout ? 'yes' : 'no'; |
441 | - $stripe_params['is_change_payment_page'] = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no'; |
|
442 | - $stripe_params['validate_modal_checkout'] = apply_filters( 'wc_stripe_validate_model_checkout', true ) ? 'yes' : 'no'; |
|
443 | - $stripe_params['elements_styling'] = apply_filters( 'wc_stripe_elements_styling', false ); |
|
444 | - $stripe_params['elements_classes'] = apply_filters( 'wc_stripe_elements_classes', false ); |
|
441 | + $stripe_params['is_change_payment_page'] = isset($_GET['change_payment_method']) ? 'yes' : 'no'; |
|
442 | + $stripe_params['validate_modal_checkout'] = apply_filters('wc_stripe_validate_model_checkout', true) ? 'yes' : 'no'; |
|
443 | + $stripe_params['elements_styling'] = apply_filters('wc_stripe_elements_styling', false); |
|
444 | + $stripe_params['elements_classes'] = apply_filters('wc_stripe_elements_classes', false); |
|
445 | 445 | |
446 | 446 | // merge localized messages to be use in JS |
447 | - $stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() ); |
|
447 | + $stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages()); |
|
448 | 448 | |
449 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
450 | - wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
449 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
450 | + wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
451 | 451 | |
452 | - if ( $this->stripe_checkout ) { |
|
453 | - wp_enqueue_script( 'stripe_checkout' ); |
|
452 | + if ($this->stripe_checkout) { |
|
453 | + wp_enqueue_script('stripe_checkout'); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | $this->tokenization_script(); |
457 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
457 | + wp_enqueue_script('woocommerce_stripe'); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | /** |
@@ -470,43 +470,43 @@ discard block |
||
470 | 470 | * |
471 | 471 | * @return array|void |
472 | 472 | */ |
473 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
473 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
474 | 474 | try { |
475 | - $order = wc_get_order( $order_id ); |
|
475 | + $order = wc_get_order($order_id); |
|
476 | 476 | |
477 | 477 | // This comes from the create account checkbox in the checkout page. |
478 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
478 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
479 | 479 | |
480 | - if ( $create_account ) { |
|
480 | + if ($create_account) { |
|
481 | 481 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
482 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
482 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
483 | 483 | $new_stripe_customer->create_customer(); |
484 | 484 | } |
485 | 485 | |
486 | 486 | $source_object = $this->get_source_object(); |
487 | - $prepared_source = $this->prepare_source( $source_object, get_current_user_id(), $force_save_source ); |
|
487 | + $prepared_source = $this->prepare_source($source_object, get_current_user_id(), $force_save_source); |
|
488 | 488 | |
489 | 489 | // Check if we don't allow prepaid credit cards. |
490 | - if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) { |
|
491 | - if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) { |
|
492 | - $localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
493 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message ); |
|
490 | + if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) { |
|
491 | + if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) { |
|
492 | + $localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
493 | + throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message); |
|
494 | 494 | } |
495 | 495 | } |
496 | 496 | |
497 | - if ( empty( $prepared_source->source ) ) { |
|
498 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
499 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
497 | + if (empty($prepared_source->source)) { |
|
498 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
499 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
500 | 500 | } |
501 | 501 | |
502 | - $this->save_source_to_order( $order, $prepared_source ); |
|
502 | + $this->save_source_to_order($order, $prepared_source); |
|
503 | 503 | |
504 | 504 | // Result from Stripe API request. |
505 | 505 | $response = null; |
506 | 506 | |
507 | - if ( $order->get_total() > 0 ) { |
|
507 | + if ($order->get_total() > 0) { |
|
508 | 508 | // This will throw exception if not valid. |
509 | - $this->validate_minimum_order_amount( $order ); |
|
509 | + $this->validate_minimum_order_amount($order); |
|
510 | 510 | |
511 | 511 | /* |
512 | 512 | * Check if card 3DS is required or optional with 3DS setting. |
@@ -515,109 +515,109 @@ discard block |
||
515 | 515 | * Note that if we need to save source, the original source must be first |
516 | 516 | * attached to a customer in Stripe before it can be charged. |
517 | 517 | */ |
518 | - if ( $this->is_3ds_required( $source_object ) ) { |
|
519 | - $response = $this->create_3ds_source( $order, $source_object ); |
|
518 | + if ($this->is_3ds_required($source_object)) { |
|
519 | + $response = $this->create_3ds_source($order, $source_object); |
|
520 | 520 | |
521 | - if ( ! empty( $response->error ) ) { |
|
521 | + if ( ! empty($response->error)) { |
|
522 | 522 | $localized_message = $response->error->message; |
523 | 523 | |
524 | - $order->add_order_note( $localized_message ); |
|
524 | + $order->add_order_note($localized_message); |
|
525 | 525 | |
526 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
526 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | // Update order meta with 3DS source. |
530 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
531 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
530 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
531 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
532 | 532 | } else { |
533 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
533 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
534 | 534 | $order->save(); |
535 | 535 | } |
536 | 536 | |
537 | - WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' ); |
|
537 | + WC_Stripe_Logger::log('Info: Redirecting to 3DS...'); |
|
538 | 538 | |
539 | 539 | return array( |
540 | 540 | 'result' => 'success', |
541 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
541 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
542 | 542 | ); |
543 | 543 | } |
544 | 544 | |
545 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
545 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
546 | 546 | |
547 | 547 | // Make the request. |
548 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
548 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source)); |
|
549 | 549 | |
550 | - if ( ! empty( $response->error ) ) { |
|
550 | + if ( ! empty($response->error)) { |
|
551 | 551 | // If it is an API error such connection or server, let's retry. |
552 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
553 | - if ( $retry ) { |
|
554 | - sleep( 5 ); |
|
555 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
552 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
553 | + if ($retry) { |
|
554 | + sleep(5); |
|
555 | + return $this->process_payment($order_id, false, $force_save_source); |
|
556 | 556 | } else { |
557 | 557 | $localized_message = 'API connection error and retries exhausted.'; |
558 | - $order->add_order_note( $localized_message ); |
|
559 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
558 | + $order->add_order_note($localized_message); |
|
559 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
560 | 560 | } |
561 | 561 | } |
562 | 562 | |
563 | 563 | // We want to retry. |
564 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
565 | - if ( $retry ) { |
|
564 | + if ($this->is_retryable_error($response->error)) { |
|
565 | + if ($retry) { |
|
566 | 566 | // Don't do anymore retries after this. |
567 | - if ( 5 <= $this->retry_interval ) { |
|
567 | + if (5 <= $this->retry_interval) { |
|
568 | 568 | |
569 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
569 | + return $this->process_payment($order_id, false, $force_save_source); |
|
570 | 570 | } |
571 | 571 | |
572 | - sleep( $this->retry_interval ); |
|
572 | + sleep($this->retry_interval); |
|
573 | 573 | |
574 | 574 | $this->retry_interval++; |
575 | - return $this->process_payment( $order_id, true, $force_save_source ); |
|
575 | + return $this->process_payment($order_id, true, $force_save_source); |
|
576 | 576 | } else { |
577 | - $localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' ); |
|
578 | - $order->add_order_note( $localized_message ); |
|
579 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
577 | + $localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe'); |
|
578 | + $order->add_order_note($localized_message); |
|
579 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
580 | 580 | } |
581 | 581 | } |
582 | 582 | |
583 | 583 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
584 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
585 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
586 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
587 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
584 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
585 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
586 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
587 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
588 | 588 | } else { |
589 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
590 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
589 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
590 | + $order->delete_meta_data('_stripe_customer_id'); |
|
591 | 591 | $order->save(); |
592 | 592 | } |
593 | 593 | |
594 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
595 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) { |
|
594 | + return $this->process_payment($order_id, false, $force_save_source); |
|
595 | + } elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) { |
|
596 | 596 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
597 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
597 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
598 | 598 | $wc_token->delete(); |
599 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
600 | - $order->add_order_note( $localized_message ); |
|
601 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
599 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
600 | + $order->add_order_note($localized_message); |
|
601 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
605 | 605 | |
606 | - if ( 'card_error' === $response->error->type ) { |
|
607 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
606 | + if ('card_error' === $response->error->type) { |
|
607 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
608 | 608 | } else { |
609 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
609 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
610 | 610 | } |
611 | 611 | |
612 | - $order->add_order_note( $localized_message ); |
|
612 | + $order->add_order_note($localized_message); |
|
613 | 613 | |
614 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
614 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
615 | 615 | } |
616 | 616 | |
617 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
617 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
618 | 618 | |
619 | 619 | // Process valid response. |
620 | - $this->process_response( $response, $order ); |
|
620 | + $this->process_response($response, $order); |
|
621 | 621 | } else { |
622 | 622 | $order->payment_complete(); |
623 | 623 | } |
@@ -628,17 +628,17 @@ discard block |
||
628 | 628 | // Return thank you page redirect. |
629 | 629 | return array( |
630 | 630 | 'result' => 'success', |
631 | - 'redirect' => $this->get_return_url( $order ), |
|
631 | + 'redirect' => $this->get_return_url($order), |
|
632 | 632 | ); |
633 | 633 | |
634 | - } catch ( WC_Stripe_Exception $e ) { |
|
635 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
636 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
634 | + } catch (WC_Stripe_Exception $e) { |
|
635 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
636 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
637 | 637 | |
638 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
638 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
639 | 639 | |
640 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
641 | - $this->send_failed_order_email( $order_id ); |
|
640 | + if ($order->has_status(array('pending', 'failed'))) { |
|
641 | + $this->send_failed_order_email($order_id); |
|
642 | 642 | } |
643 | 643 | |
644 | 644 | return array( |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
7 | 7 | * DEPRECATED DO NOT USE!! |
8 | 8 | */ |
9 | -if ( ! class_exists( 'WC_Stripe_Apple_Pay' ) ) { |
|
9 | +if ( ! class_exists('WC_Stripe_Apple_Pay')) { |
|
10 | 10 | class WC_Stripe_Apple_Pay { |
11 | 11 | /** |
12 | 12 | * This Instance. |
@@ -20,15 +20,15 @@ discard block |
||
20 | 20 | } |
21 | 21 | |
22 | 22 | public static function instance() { |
23 | - WC_Stripe_Logger::log( 'DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance. This class will be removed by version 5.0' ); |
|
23 | + WC_Stripe_Logger::log('DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance. This class will be removed by version 5.0'); |
|
24 | 24 | return self::$_this; |
25 | 25 | } |
26 | 26 | |
27 | - public function __get( $var ) { |
|
27 | + public function __get($var) { |
|
28 | 28 | return null; |
29 | 29 | } |
30 | 30 | |
31 | - public function __call( $name, $arguments ) { |
|
31 | + public function __call($name, $arguments) { |
|
32 | 32 | return null; |
33 | 33 | } |
34 | 34 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function __construct() { |
66 | 66 | $this->id = 'stripe_bitcoin'; |
67 | - $this->method_title = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' ); |
|
67 | + $this->method_title = __('Stripe Bitcoin', 'woocommerce-gateway-stripe'); |
|
68 | 68 | /* translators: link */ |
69 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
69 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
70 | 70 | $this->supports = array( |
71 | 71 | 'products', |
72 | 72 | 'refunds', |
@@ -78,29 +78,29 @@ discard block |
||
78 | 78 | // Load the settings. |
79 | 79 | $this->init_settings(); |
80 | 80 | |
81 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
82 | - $this->title = $this->get_option( 'title' ); |
|
83 | - $this->description = $this->get_option( 'description' ); |
|
84 | - $this->enabled = $this->get_option( 'enabled' ); |
|
85 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
86 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
87 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
88 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
89 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
90 | - |
|
91 | - if ( $this->testmode ) { |
|
92 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
93 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
81 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
82 | + $this->title = $this->get_option('title'); |
|
83 | + $this->description = $this->get_option('description'); |
|
84 | + $this->enabled = $this->get_option('enabled'); |
|
85 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
86 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
87 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
88 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
89 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
90 | + |
|
91 | + if ($this->testmode) { |
|
92 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
93 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
94 | 94 | } |
95 | 95 | |
96 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
97 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
98 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
99 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
100 | - add_action( 'woocommerce_thankyou_stripe_bitcoin', array( $this, 'thankyou_page' ) ); |
|
96 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
97 | + add_action('admin_notices', array($this, 'check_environment')); |
|
98 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
99 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
100 | + add_action('woocommerce_thankyou_stripe_bitcoin', array($this, 'thankyou_page')); |
|
101 | 101 | |
102 | 102 | // Customer Emails. |
103 | - add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 ); |
|
103 | + add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -110,19 +110,19 @@ discard block |
||
110 | 110 | * @version 4.0.0 |
111 | 111 | */ |
112 | 112 | public function check_environment() { |
113 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
113 | + if ( ! current_user_can('manage_woocommerce')) { |
|
114 | 114 | return; |
115 | 115 | } |
116 | 116 | |
117 | 117 | $environment_warning = $this->get_environment_warning(); |
118 | 118 | |
119 | - if ( $environment_warning ) { |
|
120 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
119 | + if ($environment_warning) { |
|
120 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
121 | 121 | } |
122 | 122 | |
123 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
124 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
125 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
123 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
124 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
125 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
126 | 126 | echo '</p></div>'; |
127 | 127 | } |
128 | 128 | } |
@@ -136,12 +136,12 @@ discard block |
||
136 | 136 | */ |
137 | 137 | public function get_environment_warning() { |
138 | 138 | // Add deprecated notice to logs. |
139 | - if ( 'yes' === $this->enabled ) { |
|
140 | - WC_Stripe_Logger::log( 'DEPRECATED! Stripe will no longer support Bitcoin and will cease to function on April 23, 2018. Please plan accordingly.' ); |
|
139 | + if ('yes' === $this->enabled) { |
|
140 | + WC_Stripe_Logger::log('DEPRECATED! Stripe will no longer support Bitcoin and will cease to function on April 23, 2018. Please plan accordingly.'); |
|
141 | 141 | } |
142 | 142 | |
143 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
144 | - $message = __( 'Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe' ); |
|
143 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
144 | + $message = __('Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe'); |
|
145 | 145 | |
146 | 146 | return $message; |
147 | 147 | } |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | * @return array |
158 | 158 | */ |
159 | 159 | public function get_supported_currency() { |
160 | - return apply_filters( 'wc_stripe_bitcoin_supported_currencies', array( |
|
160 | + return apply_filters('wc_stripe_bitcoin_supported_currencies', array( |
|
161 | 161 | 'USD', |
162 | - ) ); |
|
162 | + )); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | * @return bool |
171 | 171 | */ |
172 | 172 | public function is_available() { |
173 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
173 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
174 | 174 | return false; |
175 | 175 | } |
176 | 176 | |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | |
192 | 192 | $icons_str .= $icons['bitcoin']; |
193 | 193 | |
194 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
194 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
@@ -202,19 +202,19 @@ discard block |
||
202 | 202 | * @access public |
203 | 203 | */ |
204 | 204 | public function payment_scripts() { |
205 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
205 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
206 | 206 | return; |
207 | 207 | } |
208 | 208 | |
209 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
210 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
209 | + wp_enqueue_style('stripe_paymentfonts'); |
|
210 | + wp_enqueue_script('woocommerce_stripe'); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
214 | 214 | * Initialize Gateway Settings Form Fields. |
215 | 215 | */ |
216 | 216 | public function init_form_fields() { |
217 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php' ); |
|
217 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php'); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -225,25 +225,25 @@ discard block |
||
225 | 225 | $total = WC()->cart->total; |
226 | 226 | |
227 | 227 | // If paying from order, we need to get total from order not cart. |
228 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
229 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
228 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
229 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
230 | 230 | $total = $order->get_total(); |
231 | 231 | } |
232 | 232 | |
233 | - if ( is_add_payment_method_page() ) { |
|
234 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
235 | - $total = ''; |
|
233 | + if (is_add_payment_method_page()) { |
|
234 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
235 | + $total = ''; |
|
236 | 236 | } else { |
237 | 237 | $pay_button_text = ''; |
238 | 238 | } |
239 | 239 | |
240 | 240 | echo '<div |
241 | 241 | id="stripe-bitcoin-payment-data" |
242 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
243 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
242 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
243 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
244 | 244 | |
245 | - if ( $this->description ) { |
|
246 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
245 | + if ($this->description) { |
|
246 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | echo '</div>'; |
@@ -254,8 +254,8 @@ discard block |
||
254 | 254 | * |
255 | 255 | * @param int $order_id |
256 | 256 | */ |
257 | - public function thankyou_page( $order_id ) { |
|
258 | - $this->get_instructions( $order_id ); |
|
257 | + public function thankyou_page($order_id) { |
|
258 | + $this->get_instructions($order_id); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | /** |
@@ -267,13 +267,13 @@ discard block |
||
267 | 267 | * @param bool $sent_to_admin |
268 | 268 | * @param bool $plain_text |
269 | 269 | */ |
270 | - public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { |
|
270 | + public function email_instructions($order, $sent_to_admin, $plain_text = false) { |
|
271 | 271 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
272 | 272 | |
273 | 273 | $payment_method = WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method(); |
274 | 274 | |
275 | - if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status( 'on-hold' ) ) { |
|
276 | - $this->get_instructions( $order_id, $plain_text ); |
|
275 | + if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status('on-hold')) { |
|
276 | + $this->get_instructions($order_id, $plain_text); |
|
277 | 277 | } |
278 | 278 | } |
279 | 279 | |
@@ -284,38 +284,38 @@ discard block |
||
284 | 284 | * @version 4.0.0 |
285 | 285 | * @param int $order_id |
286 | 286 | */ |
287 | - public function get_instructions( $order_id, $plain_text = false ) { |
|
288 | - $data = get_post_meta( $order_id, '_stripe_bitcoin', true ); |
|
287 | + public function get_instructions($order_id, $plain_text = false) { |
|
288 | + $data = get_post_meta($order_id, '_stripe_bitcoin', true); |
|
289 | 289 | |
290 | - if ( $plain_text ) { |
|
291 | - esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
290 | + if ($plain_text) { |
|
291 | + esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
292 | 292 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
293 | - esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
293 | + esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
294 | 294 | echo $data['amount'] . "\n\n"; |
295 | 295 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
296 | - esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
296 | + esc_html_e('Receiver:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
297 | 297 | echo $data['address'] . "\n\n"; |
298 | 298 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
299 | - esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
299 | + esc_html_e('URI:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
300 | 300 | echo $data['uri'] . "\n\n"; |
301 | 301 | } else { |
302 | 302 | ?> |
303 | - <h3><?php esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ); ?></h3> |
|
303 | + <h3><?php esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe'); ?></h3> |
|
304 | 304 | <ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details"> |
305 | 305 | <li class="woocommerce-order-overview__order order"> |
306 | - <?php esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ); ?> |
|
306 | + <?php esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe'); ?> |
|
307 | 307 | <strong><?php echo $data['amount']; ?></strong> |
308 | 308 | </li> |
309 | 309 | <li class="woocommerce-order-overview__order order"> |
310 | - <?php esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ); ?> |
|
310 | + <?php esc_html_e('Receiver:', 'woocommerce-gateway-stripe'); ?> |
|
311 | 311 | <strong><?php echo $data['address']; ?></strong> |
312 | 312 | </li> |
313 | 313 | <li class="woocommerce-order-overview__order order"> |
314 | - <?php esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ); ?> |
|
314 | + <?php esc_html_e('URI:', 'woocommerce-gateway-stripe'); ?> |
|
315 | 315 | <strong> |
316 | 316 | <?php |
317 | 317 | /* translators: link */ |
318 | - printf( __( '<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe' ), $data['uri'] ); |
|
318 | + printf(__('<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe'), $data['uri']); |
|
319 | 319 | ?> |
320 | 320 | </strong> |
321 | 321 | </li> |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | * @param object $order |
333 | 333 | * @param object $source_object |
334 | 334 | */ |
335 | - public function save_instructions( $order, $source_object ) { |
|
335 | + public function save_instructions($order, $source_object) { |
|
336 | 336 | $data = array( |
337 | 337 | 'amount' => $source_object->bitcoin->amount, |
338 | 338 | 'address' => $source_object->bitcoin->address, |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | |
342 | 342 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
343 | 343 | |
344 | - update_post_meta( $order_id, '_stripe_bitcoin', $data ); |
|
344 | + update_post_meta($order_id, '_stripe_bitcoin', $data); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | /** |
@@ -355,37 +355,37 @@ discard block |
||
355 | 355 | * |
356 | 356 | * @return array|void |
357 | 357 | */ |
358 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
358 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
359 | 359 | try { |
360 | - $order = wc_get_order( $order_id ); |
|
360 | + $order = wc_get_order($order_id); |
|
361 | 361 | |
362 | 362 | // This comes from the create account checkbox in the checkout page. |
363 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
363 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
364 | 364 | |
365 | - if ( $create_account ) { |
|
365 | + if ($create_account) { |
|
366 | 366 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
367 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
367 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
368 | 368 | $new_stripe_customer->create_customer(); |
369 | 369 | } |
370 | 370 | |
371 | - $prepared_source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), $force_save_source ); |
|
371 | + $prepared_source = $this->prepare_source($this->get_source_object(), get_current_user_id(), $force_save_source); |
|
372 | 372 | |
373 | - if ( empty( $prepared_source->source ) ) { |
|
374 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
375 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
373 | + if (empty($prepared_source->source)) { |
|
374 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
375 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
376 | 376 | } |
377 | 377 | |
378 | - $this->save_source_to_order( $order, $prepared_source ); |
|
378 | + $this->save_source_to_order($order, $prepared_source); |
|
379 | 379 | |
380 | 380 | // This will throw exception if not valid. |
381 | - $this->validate_minimum_order_amount( $order ); |
|
381 | + $this->validate_minimum_order_amount($order); |
|
382 | 382 | |
383 | - $this->save_instructions( $order, $this->get_source_object() ); |
|
383 | + $this->save_instructions($order, $this->get_source_object()); |
|
384 | 384 | |
385 | 385 | // Mark as on-hold (we're awaiting the payment). |
386 | - $order->update_status( 'on-hold', __( 'Awaiting Bitcoin payment', 'woocommerce-gateway-stripe' ) ); |
|
386 | + $order->update_status('on-hold', __('Awaiting Bitcoin payment', 'woocommerce-gateway-stripe')); |
|
387 | 387 | |
388 | - wc_reduce_stock_levels( $order_id ); |
|
388 | + wc_reduce_stock_levels($order_id); |
|
389 | 389 | |
390 | 390 | // Remove cart. |
391 | 391 | WC()->cart->empty_cart(); |
@@ -393,16 +393,16 @@ discard block |
||
393 | 393 | // Return thankyou redirect. |
394 | 394 | return array( |
395 | 395 | 'result' => 'success', |
396 | - 'redirect' => $this->get_return_url( $order ), |
|
396 | + 'redirect' => $this->get_return_url($order), |
|
397 | 397 | ); |
398 | - } catch ( WC_Stripe_Exception $e ) { |
|
399 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
400 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
398 | + } catch (WC_Stripe_Exception $e) { |
|
399 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
400 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
401 | 401 | |
402 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
402 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
403 | 403 | |
404 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
405 | - $this->send_failed_order_email( $order_id ); |
|
404 | + if ($order->has_status(array('pending', 'failed'))) { |
|
405 | + $this->send_failed_order_email($order_id); |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | */ |
21 | 21 | public function __construct() { |
22 | 22 | $this->retry_interval = 2; |
23 | - add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) ); |
|
23 | + add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook')); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -30,24 +30,24 @@ discard block |
||
30 | 30 | * @version 4.0.0 |
31 | 31 | */ |
32 | 32 | public function check_for_webhook() { |
33 | - if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) |
|
34 | - || ! isset( $_GET['wc-api'] ) |
|
35 | - || ( 'wc_stripe' !== $_GET['wc-api'] ) |
|
33 | + if (('POST' !== $_SERVER['REQUEST_METHOD']) |
|
34 | + || ! isset($_GET['wc-api']) |
|
35 | + || ('wc_stripe' !== $_GET['wc-api']) |
|
36 | 36 | ) { |
37 | 37 | return; |
38 | 38 | } |
39 | 39 | |
40 | - $request_body = file_get_contents( 'php://input' ); |
|
41 | - $request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER ); |
|
40 | + $request_body = file_get_contents('php://input'); |
|
41 | + $request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER); |
|
42 | 42 | |
43 | 43 | // Validate it to make sure it is legit. |
44 | - if ( $this->is_valid_request( $request_headers, $request_body ) ) { |
|
45 | - $this->process_webhook( $request_body ); |
|
46 | - status_header( 200 ); |
|
44 | + if ($this->is_valid_request($request_headers, $request_body)) { |
|
45 | + $this->process_webhook($request_body); |
|
46 | + status_header(200); |
|
47 | 47 | exit; |
48 | 48 | } else { |
49 | - WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) ); |
|
50 | - status_header( 400 ); |
|
49 | + WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true)); |
|
50 | + status_header(400); |
|
51 | 51 | exit; |
52 | 52 | } |
53 | 53 | } |
@@ -62,12 +62,12 @@ discard block |
||
62 | 62 | * @param string $request_body The request body from Stripe. |
63 | 63 | * @return bool |
64 | 64 | */ |
65 | - public function is_valid_request( $request_headers = null, $request_body = null ) { |
|
66 | - if ( null === $request_headers || null === $request_body ) { |
|
65 | + public function is_valid_request($request_headers = null, $request_body = null) { |
|
66 | + if (null === $request_headers || null === $request_body) { |
|
67 | 67 | return false; |
68 | 68 | } |
69 | 69 | |
70 | - if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) { |
|
70 | + if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) { |
|
71 | 71 | return false; |
72 | 72 | } |
73 | 73 | |
@@ -83,11 +83,11 @@ discard block |
||
83 | 83 | * @version 4.0.0 |
84 | 84 | */ |
85 | 85 | public function get_request_headers() { |
86 | - if ( ! function_exists( 'getallheaders' ) ) { |
|
86 | + if ( ! function_exists('getallheaders')) { |
|
87 | 87 | $headers = []; |
88 | - foreach ( $_SERVER as $name => $value ) { |
|
89 | - if ( 'HTTP_' === substr( $name, 0, 5 ) ) { |
|
90 | - $headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value; |
|
88 | + foreach ($_SERVER as $name => $value) { |
|
89 | + if ('HTTP_' === substr($name, 0, 5)) { |
|
90 | + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
@@ -106,30 +106,30 @@ discard block |
||
106 | 106 | * @param object $notification |
107 | 107 | * @param bool $retry |
108 | 108 | */ |
109 | - public function process_webhook_payment( $notification, $retry = true ) { |
|
109 | + public function process_webhook_payment($notification, $retry = true) { |
|
110 | 110 | // The following 2 payment methods are synchronous so does not need to be handle via webhook. |
111 | - if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type ) { |
|
111 | + if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type) { |
|
112 | 112 | return; |
113 | 113 | } |
114 | 114 | |
115 | - $order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id ); |
|
115 | + $order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id); |
|
116 | 116 | |
117 | - if ( ! $order ) { |
|
118 | - WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id ); |
|
117 | + if ( ! $order) { |
|
118 | + WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id); |
|
119 | 119 | return; |
120 | 120 | } |
121 | 121 | |
122 | 122 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
123 | 123 | $source_id = $notification->data->object->id; |
124 | 124 | |
125 | - $is_pending_receiver = ( 'receiver' === $notification->data->object->flow ); |
|
125 | + $is_pending_receiver = ('receiver' === $notification->data->object->flow); |
|
126 | 126 | |
127 | 127 | try { |
128 | - if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() ) { |
|
128 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status()) { |
|
129 | 129 | return; |
130 | 130 | } |
131 | 131 | |
132 | - if ( 'on-hold' === $order->get_status() && ! $is_pending_receiver ) { |
|
132 | + if ('on-hold' === $order->get_status() && ! $is_pending_receiver) { |
|
133 | 133 | return; |
134 | 134 | } |
135 | 135 | |
@@ -137,100 +137,100 @@ discard block |
||
137 | 137 | $response = null; |
138 | 138 | |
139 | 139 | // This will throw exception if not valid. |
140 | - $this->validate_minimum_order_amount( $order ); |
|
140 | + $this->validate_minimum_order_amount($order); |
|
141 | 141 | |
142 | - WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
142 | + WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
143 | 143 | |
144 | 144 | // Prep source object. |
145 | 145 | $source_object = new stdClass(); |
146 | 146 | $source_object->token_id = ''; |
147 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
147 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
148 | 148 | $source_object->source = $source_id; |
149 | 149 | |
150 | 150 | // Make the request. |
151 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) ); |
|
151 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object)); |
|
152 | 152 | |
153 | - if ( ! empty( $response->error ) ) { |
|
153 | + if ( ! empty($response->error)) { |
|
154 | 154 | // If it is an API error such connection or server, let's retry. |
155 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
156 | - if ( $retry ) { |
|
157 | - sleep( 5 ); |
|
158 | - return $this->process_webhook_payment( $notification, false ); |
|
155 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
156 | + if ($retry) { |
|
157 | + sleep(5); |
|
158 | + return $this->process_webhook_payment($notification, false); |
|
159 | 159 | } else { |
160 | 160 | $localized_message = 'API connection error and retries exhausted.'; |
161 | - $order->add_order_note( $localized_message ); |
|
162 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
161 | + $order->add_order_note($localized_message); |
|
162 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
163 | 163 | } |
164 | 164 | } |
165 | 165 | |
166 | 166 | // We want to retry. |
167 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
168 | - if ( $retry ) { |
|
167 | + if ($this->is_retryable_error($response->error)) { |
|
168 | + if ($retry) { |
|
169 | 169 | // Don't do anymore retries after this. |
170 | - if ( 5 <= $this->retry_interval ) { |
|
170 | + if (5 <= $this->retry_interval) { |
|
171 | 171 | |
172 | - return $this->process_webhook_payment( $notification, false ); |
|
172 | + return $this->process_webhook_payment($notification, false); |
|
173 | 173 | } |
174 | 174 | |
175 | - sleep( $this->retry_interval ); |
|
175 | + sleep($this->retry_interval); |
|
176 | 176 | |
177 | 177 | $this->retry_interval++; |
178 | - return $this->process_webhook_payment( $notification, true ); |
|
178 | + return $this->process_webhook_payment($notification, true); |
|
179 | 179 | } else { |
180 | - $localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' ); |
|
181 | - $order->add_order_note( $localized_message ); |
|
182 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
180 | + $localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe'); |
|
181 | + $order->add_order_note($localized_message); |
|
182 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
183 | 183 | } |
184 | 184 | } |
185 | 185 | |
186 | 186 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
187 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
188 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
189 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
190 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
187 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
188 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
189 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
190 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
191 | 191 | } else { |
192 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
193 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
192 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
193 | + $order->delete_meta_data('_stripe_customer_id'); |
|
194 | 194 | $order->save(); |
195 | 195 | } |
196 | 196 | |
197 | - return $this->process_webhook_payment( $notification, false ); |
|
197 | + return $this->process_webhook_payment($notification, false); |
|
198 | 198 | |
199 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) { |
|
199 | + } elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) { |
|
200 | 200 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
201 | - $wc_token = WC_Payment_Tokens::get( $source_object->token_id ); |
|
201 | + $wc_token = WC_Payment_Tokens::get($source_object->token_id); |
|
202 | 202 | $wc_token->delete(); |
203 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
204 | - $order->add_order_note( $message ); |
|
205 | - throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
203 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
204 | + $order->add_order_note($message); |
|
205 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
209 | 209 | |
210 | - if ( 'card_error' === $response->error->type ) { |
|
211 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
210 | + if ('card_error' === $response->error->type) { |
|
211 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
212 | 212 | } else { |
213 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
213 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
214 | 214 | } |
215 | 215 | |
216 | - $order->add_order_note( $localized_message ); |
|
216 | + $order->add_order_note($localized_message); |
|
217 | 217 | |
218 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
218 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
219 | 219 | } |
220 | 220 | |
221 | - do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order ); |
|
221 | + do_action('wc_gateway_stripe_process_webhook_payment', $response, $order); |
|
222 | 222 | |
223 | - $this->process_response( $response, $order ); |
|
223 | + $this->process_response($response, $order); |
|
224 | 224 | |
225 | - } catch ( WC_Stripe_Exception $e ) { |
|
226 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
225 | + } catch (WC_Stripe_Exception $e) { |
|
226 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
227 | 227 | |
228 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $e, $order ); |
|
228 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $e, $order); |
|
229 | 229 | |
230 | - $statuses = array( 'pending', 'failed' ); |
|
230 | + $statuses = array('pending', 'failed'); |
|
231 | 231 | |
232 | - if ( $order->has_status( $statuses ) ) { |
|
233 | - $this->send_failed_order_email( $order_id ); |
|
232 | + if ($order->has_status($statuses)) { |
|
233 | + $this->send_failed_order_email($order_id); |
|
234 | 234 | } |
235 | 235 | } |
236 | 236 | } |
@@ -243,20 +243,20 @@ discard block |
||
243 | 243 | * @since 4.0.0 |
244 | 244 | * @param object $notification |
245 | 245 | */ |
246 | - public function process_webhook_dispute( $notification ) { |
|
247 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
246 | + public function process_webhook_dispute($notification) { |
|
247 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
248 | 248 | |
249 | - if ( ! $order ) { |
|
250 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
249 | + if ( ! $order) { |
|
250 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge); |
|
251 | 251 | return; |
252 | 252 | } |
253 | 253 | |
254 | - $order->update_status( 'on-hold', __( 'A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe' ) ); |
|
254 | + $order->update_status('on-hold', __('A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe')); |
|
255 | 255 | |
256 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
256 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
257 | 257 | |
258 | 258 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
259 | - $this->send_failed_order_email( $order_id ); |
|
259 | + $this->send_failed_order_email($order_id); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -267,41 +267,41 @@ discard block |
||
267 | 267 | * @version 4.0.0 |
268 | 268 | * @param object $notification |
269 | 269 | */ |
270 | - public function process_webhook_capture( $notification ) { |
|
271 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
270 | + public function process_webhook_capture($notification) { |
|
271 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
272 | 272 | |
273 | - if ( ! $order ) { |
|
274 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
273 | + if ( ! $order) { |
|
274 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
275 | 275 | return; |
276 | 276 | } |
277 | 277 | |
278 | 278 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
279 | 279 | |
280 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
281 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
282 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
280 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
281 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
282 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
283 | 283 | |
284 | - if ( $charge && 'no' === $captured ) { |
|
285 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
284 | + if ($charge && 'no' === $captured) { |
|
285 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
286 | 286 | |
287 | 287 | // Store other data such as fees |
288 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
288 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
289 | 289 | |
290 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
291 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
290 | + if (isset($notification->data->object->balance_transaction)) { |
|
291 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
292 | 292 | } |
293 | 293 | |
294 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
294 | + if (is_callable(array($order, 'save'))) { |
|
295 | 295 | $order->save(); |
296 | 296 | } |
297 | 297 | |
298 | 298 | /* translators: transaction id */ |
299 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
299 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
300 | 300 | |
301 | 301 | // Check and see if capture is partial. |
302 | - if ( $this->is_partial_capture( $notification ) ) { |
|
303 | - $order->set_total( $this->get_partial_amount_to_charge( $notification ) ); |
|
304 | - $order->add_note( __( 'This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe' ) ); |
|
302 | + if ($this->is_partial_capture($notification)) { |
|
303 | + $order->set_total($this->get_partial_amount_to_charge($notification)); |
|
304 | + $order->add_note(__('This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe')); |
|
305 | 305 | $order->save(); |
306 | 306 | } |
307 | 307 | } |
@@ -316,38 +316,38 @@ discard block |
||
316 | 316 | * @version 4.0.0 |
317 | 317 | * @param object $notification |
318 | 318 | */ |
319 | - public function process_webhook_charge_succeeded( $notification ) { |
|
319 | + public function process_webhook_charge_succeeded($notification) { |
|
320 | 320 | // The following payment methods are synchronous so does not need to be handle via webhook. |
321 | - if ( ( isset( $notification->data->object->source->type ) && 'card' === $notification->data->object->source->type ) || ( isset( $notification->data->object->source->type ) && 'three_d_secure' === $notification->data->object->source->type ) ) { |
|
321 | + if ((isset($notification->data->object->source->type) && 'card' === $notification->data->object->source->type) || (isset($notification->data->object->source->type) && 'three_d_secure' === $notification->data->object->source->type)) { |
|
322 | 322 | return; |
323 | 323 | } |
324 | 324 | |
325 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
325 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
326 | 326 | |
327 | - if ( ! $order ) { |
|
328 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
327 | + if ( ! $order) { |
|
328 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
329 | 329 | return; |
330 | 330 | } |
331 | 331 | |
332 | 332 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
333 | 333 | |
334 | - if ( 'on-hold' !== $order->get_status() ) { |
|
334 | + if ('on-hold' !== $order->get_status()) { |
|
335 | 335 | return; |
336 | 336 | } |
337 | 337 | |
338 | 338 | // Store other data such as fees |
339 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
339 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
340 | 340 | |
341 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
342 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
341 | + if (isset($notification->data->object->balance_transaction)) { |
|
342 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
343 | 343 | } |
344 | 344 | |
345 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
345 | + if (is_callable(array($order, 'save'))) { |
|
346 | 346 | $order->save(); |
347 | 347 | } |
348 | 348 | |
349 | 349 | /* translators: transaction id */ |
350 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
350 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
@@ -358,23 +358,23 @@ discard block |
||
358 | 358 | * @version 4.0.0 |
359 | 359 | * @param object $notification |
360 | 360 | */ |
361 | - public function process_webhook_charge_failed( $notification ) { |
|
362 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
361 | + public function process_webhook_charge_failed($notification) { |
|
362 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
363 | 363 | |
364 | - if ( ! $order ) { |
|
365 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
364 | + if ( ! $order) { |
|
365 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
366 | 366 | return; |
367 | 367 | } |
368 | 368 | |
369 | 369 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
370 | 370 | |
371 | - if ( 'on-hold' !== $order->get_status() ) { |
|
371 | + if ('on-hold' !== $order->get_status()) { |
|
372 | 372 | return; |
373 | 373 | } |
374 | 374 | |
375 | - $order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) ); |
|
375 | + $order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe')); |
|
376 | 376 | |
377 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
377 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
378 | 378 | } |
379 | 379 | |
380 | 380 | /** |
@@ -385,23 +385,23 @@ discard block |
||
385 | 385 | * @version 4.0.0 |
386 | 386 | * @param object $notification |
387 | 387 | */ |
388 | - public function process_webhook_source_canceled( $notification ) { |
|
389 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
388 | + public function process_webhook_source_canceled($notification) { |
|
389 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
390 | 390 | |
391 | - if ( ! $order ) { |
|
392 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
391 | + if ( ! $order) { |
|
392 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
393 | 393 | return; |
394 | 394 | } |
395 | 395 | |
396 | 396 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
397 | 397 | |
398 | - if ( 'on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status() ) { |
|
398 | + if ('on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status()) { |
|
399 | 399 | return; |
400 | 400 | } |
401 | 401 | |
402 | - $order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) ); |
|
402 | + $order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe')); |
|
403 | 403 | |
404 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
404 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | /** |
@@ -412,42 +412,42 @@ discard block |
||
412 | 412 | * @version 4.0.0 |
413 | 413 | * @param object $notification |
414 | 414 | */ |
415 | - public function process_webhook_refund( $notification ) { |
|
416 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
415 | + public function process_webhook_refund($notification) { |
|
416 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
417 | 417 | |
418 | - if ( ! $order ) { |
|
419 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
418 | + if ( ! $order) { |
|
419 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
420 | 420 | return; |
421 | 421 | } |
422 | 422 | |
423 | 423 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
424 | 424 | |
425 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
426 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
427 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
428 | - $refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_refund_id', true ) : $order->get_meta( '_stripe_refund_id', true ); |
|
425 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
426 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
427 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
428 | + $refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_refund_id', true) : $order->get_meta('_stripe_refund_id', true); |
|
429 | 429 | |
430 | 430 | // If the refund ID matches, don't continue to prevent double refunding. |
431 | - if ( $notification->data->object->refunds->data[0]->id === $refund_id ) { |
|
431 | + if ($notification->data->object->refunds->data[0]->id === $refund_id) { |
|
432 | 432 | return; |
433 | 433 | } |
434 | 434 | |
435 | 435 | // Only refund captured charge. |
436 | - if ( $charge ) { |
|
437 | - $reason = ( isset( $captured ) && 'yes' === $captured ) ? __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' ); |
|
436 | + if ($charge) { |
|
437 | + $reason = (isset($captured) && 'yes' === $captured) ? __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe') : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe'); |
|
438 | 438 | |
439 | 439 | // Create the refund. |
440 | - $refund = wc_create_refund( array( |
|
440 | + $refund = wc_create_refund(array( |
|
441 | 441 | 'order_id' => $order_id, |
442 | - 'amount' => $this->get_refund_amount( $notification ), |
|
442 | + 'amount' => $this->get_refund_amount($notification), |
|
443 | 443 | 'reason' => $reason, |
444 | - ) ); |
|
444 | + )); |
|
445 | 445 | |
446 | - if ( is_wp_error( $refund ) ) { |
|
447 | - WC_Stripe_Logger::log( $refund->get_error_message() ); |
|
446 | + if (is_wp_error($refund)) { |
|
447 | + WC_Stripe_Logger::log($refund->get_error_message()); |
|
448 | 448 | } |
449 | 449 | |
450 | - $order->add_order_note( $reason ); |
|
450 | + $order->add_order_note($reason); |
|
451 | 451 | } |
452 | 452 | } |
453 | 453 | } |
@@ -458,17 +458,17 @@ discard block |
||
458 | 458 | * @since 4.0.6 |
459 | 459 | * @param object $notification |
460 | 460 | */ |
461 | - public function process_review_opened( $notification ) { |
|
462 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
461 | + public function process_review_opened($notification) { |
|
462 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
463 | 463 | |
464 | - if ( ! $order ) { |
|
465 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
464 | + if ( ! $order) { |
|
465 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge); |
|
466 | 466 | return; |
467 | 467 | } |
468 | 468 | |
469 | - if ( $notification->data->object->open ) { |
|
469 | + if ($notification->data->object->open) { |
|
470 | 470 | /* translators: token is the reason returned. */ |
471 | - $order->update_status( 'on-hold', sprintf( __( 'A review has been opened for this order. Action is needed. Please go to your Stripe Dashboard to review the issue. Reason: (%s)', 'woocommerce-gateway-stripe' ), $notification->data->object->reason ) ); |
|
471 | + $order->update_status('on-hold', sprintf(__('A review has been opened for this order. Action is needed. Please go to your Stripe Dashboard to review the issue. Reason: (%s)', 'woocommerce-gateway-stripe'), $notification->data->object->reason)); |
|
472 | 472 | } |
473 | 473 | } |
474 | 474 | |
@@ -478,21 +478,21 @@ discard block |
||
478 | 478 | * @since 4.0.6 |
479 | 479 | * @param object $notification |
480 | 480 | */ |
481 | - public function process_review_closed( $notification ) { |
|
482 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
481 | + public function process_review_closed($notification) { |
|
482 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
483 | 483 | |
484 | - if ( ! $order ) { |
|
485 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
484 | + if ( ! $order) { |
|
485 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge); |
|
486 | 486 | return; |
487 | 487 | } |
488 | 488 | |
489 | 489 | /* translators: token is the reason returned. */ |
490 | - $message = sprintf( __( 'The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe' ), $notification->data->object->reason ); |
|
490 | + $message = sprintf(__('The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe'), $notification->data->object->reason); |
|
491 | 491 | |
492 | - if ( 'on-hold' === $order->get_status() ) { |
|
493 | - $order->update_status( 'processing', $message ); |
|
492 | + if ('on-hold' === $order->get_status()) { |
|
493 | + $order->update_status('processing', $message); |
|
494 | 494 | } else { |
495 | - $order->add_note( $message ); |
|
495 | + $order->add_note($message); |
|
496 | 496 | } |
497 | 497 | } |
498 | 498 | |
@@ -503,7 +503,7 @@ discard block |
||
503 | 503 | * @version 4.0.0 |
504 | 504 | * @param object $notification |
505 | 505 | */ |
506 | - public function is_partial_capture( $notification ) { |
|
506 | + public function is_partial_capture($notification) { |
|
507 | 507 | return 0 < $notification->data->object->amount_refunded; |
508 | 508 | } |
509 | 509 | |
@@ -514,11 +514,11 @@ discard block |
||
514 | 514 | * @version 4.0.0 |
515 | 515 | * @param object $notification |
516 | 516 | */ |
517 | - public function get_refund_amount( $notification ) { |
|
518 | - if ( $this->is_partial_capture( $notification ) ) { |
|
517 | + public function get_refund_amount($notification) { |
|
518 | + if ($this->is_partial_capture($notification)) { |
|
519 | 519 | $amount = $notification->data->object->amount_refunded / 100; |
520 | 520 | |
521 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
521 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
522 | 522 | $amount = $notification->data->object->amount_refunded; |
523 | 523 | } |
524 | 524 | |
@@ -535,12 +535,12 @@ discard block |
||
535 | 535 | * @version 4.0.0 |
536 | 536 | * @param object $notification |
537 | 537 | */ |
538 | - public function get_partial_amount_to_charge( $notification ) { |
|
539 | - if ( $this->is_partial_capture( $notification ) ) { |
|
540 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100; |
|
538 | + public function get_partial_amount_to_charge($notification) { |
|
539 | + if ($this->is_partial_capture($notification)) { |
|
540 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100; |
|
541 | 541 | |
542 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
543 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ); |
|
542 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
543 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded); |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | return $amount; |
@@ -556,44 +556,44 @@ discard block |
||
556 | 556 | * @version 4.0.0 |
557 | 557 | * @param string $request_body |
558 | 558 | */ |
559 | - public function process_webhook( $request_body ) { |
|
560 | - $notification = json_decode( $request_body ); |
|
559 | + public function process_webhook($request_body) { |
|
560 | + $notification = json_decode($request_body); |
|
561 | 561 | |
562 | - switch ( $notification->type ) { |
|
562 | + switch ($notification->type) { |
|
563 | 563 | case 'source.chargeable': |
564 | - $this->process_webhook_payment( $notification ); |
|
564 | + $this->process_webhook_payment($notification); |
|
565 | 565 | break; |
566 | 566 | |
567 | 567 | case 'source.canceled': |
568 | - $this->process_webhook_source_canceled( $notification ); |
|
568 | + $this->process_webhook_source_canceled($notification); |
|
569 | 569 | break; |
570 | 570 | |
571 | 571 | case 'charge.succeeded': |
572 | - $this->process_webhook_charge_succeeded( $notification ); |
|
572 | + $this->process_webhook_charge_succeeded($notification); |
|
573 | 573 | break; |
574 | 574 | |
575 | 575 | case 'charge.failed': |
576 | - $this->process_webhook_charge_failed( $notification ); |
|
576 | + $this->process_webhook_charge_failed($notification); |
|
577 | 577 | break; |
578 | 578 | |
579 | 579 | case 'charge.captured': |
580 | - $this->process_webhook_capture( $notification ); |
|
580 | + $this->process_webhook_capture($notification); |
|
581 | 581 | break; |
582 | 582 | |
583 | 583 | case 'charge.dispute.created': |
584 | - $this->process_webhook_dispute( $notification ); |
|
584 | + $this->process_webhook_dispute($notification); |
|
585 | 585 | break; |
586 | 586 | |
587 | 587 | case 'charge.refunded': |
588 | - $this->process_webhook_refund( $notification ); |
|
588 | + $this->process_webhook_refund($notification); |
|
589 | 589 | break; |
590 | 590 | |
591 | 591 | case 'review.opened': |
592 | - $this->process_review_opened( $notification ); |
|
592 | + $this->process_review_opened($notification); |
|
593 | 593 | break; |
594 | 594 | |
595 | 595 | case 'review.closed': |
596 | - $this->process_review_closed( $notification ); |
|
596 | + $this->process_review_closed($notification); |
|
597 | 597 | break; |
598 | 598 | |
599 | 599 | } |