@@ -2,12 +2,12 @@ discard block |
||
2 | 2 | |
3 | 3 | class WC_Stripe_Test extends WP_UnitTestCase { |
4 | 4 | public function test_constants_defined() { |
5 | - $this->assertTrue( defined( 'WC_STRIPE_VERSION' ) ); |
|
6 | - $this->assertTrue( defined( 'WC_STRIPE_MIN_PHP_VER' ) ); |
|
7 | - $this->assertTrue( defined( 'WC_STRIPE_MIN_WC_VER' ) ); |
|
8 | - $this->assertTrue( defined( 'WC_STRIPE_MAIN_FILE' ) ); |
|
9 | - $this->assertTrue( defined( 'WC_STRIPE_PLUGIN_URL' ) ); |
|
10 | - $this->assertTrue( defined( 'WC_STRIPE_PLUGIN_PATH' ) ); |
|
5 | + $this->assertTrue(defined('WC_STRIPE_VERSION')); |
|
6 | + $this->assertTrue(defined('WC_STRIPE_MIN_PHP_VER')); |
|
7 | + $this->assertTrue(defined('WC_STRIPE_MIN_WC_VER')); |
|
8 | + $this->assertTrue(defined('WC_STRIPE_MAIN_FILE')); |
|
9 | + $this->assertTrue(defined('WC_STRIPE_PLUGIN_URL')); |
|
10 | + $this->assertTrue(defined('WC_STRIPE_PLUGIN_PATH')); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | * This test will see if we're indeed converting the price correctly. |
16 | 16 | */ |
17 | 17 | public function test_price_conversion_before_send_to_stripe() { |
18 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) ); |
|
19 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 10050, 'JPY' ) ); |
|
20 | - $this->assertEquals( 100, WC_Stripe_Helper::get_stripe_amount( 100.50, 'JPY' ) ); |
|
21 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50 ) ); |
|
22 | - $this->assertInternalType( 'int', WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) ); |
|
18 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(100.50, 'USD')); |
|
19 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(10050, 'JPY')); |
|
20 | + $this->assertEquals(100, WC_Stripe_Helper::get_stripe_amount(100.50, 'JPY')); |
|
21 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(100.50)); |
|
22 | + $this->assertInternalType('int', WC_Stripe_Helper::get_stripe_amount(100.50, 'USD')); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -33,37 +33,37 @@ discard block |
||
33 | 33 | $balance_fee1->net = 10000; |
34 | 34 | $balance_fee1->currency = 'USD'; |
35 | 35 | |
36 | - $this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee1, 'fee' ) ); |
|
36 | + $this->assertEquals(105.00, WC_Stripe_Helper::format_balance_fee($balance_fee1, 'fee')); |
|
37 | 37 | |
38 | 38 | $balance_fee2 = new stdClass(); |
39 | 39 | $balance_fee2->fee = 10500; |
40 | 40 | $balance_fee2->net = 10000; |
41 | 41 | $balance_fee2->currency = 'JPY'; |
42 | 42 | |
43 | - $this->assertEquals( 10500, WC_Stripe_Helper::format_balance_fee( $balance_fee2, 'fee' ) ); |
|
43 | + $this->assertEquals(10500, WC_Stripe_Helper::format_balance_fee($balance_fee2, 'fee')); |
|
44 | 44 | |
45 | 45 | $balance_fee3 = new stdClass(); |
46 | 46 | $balance_fee3->fee = 10500; |
47 | 47 | $balance_fee3->net = 10000; |
48 | 48 | $balance_fee3->currency = 'USD'; |
49 | 49 | |
50 | - $this->assertEquals( 100.00, WC_Stripe_Helper::format_balance_fee( $balance_fee3, 'net' ) ); |
|
50 | + $this->assertEquals(100.00, WC_Stripe_Helper::format_balance_fee($balance_fee3, 'net')); |
|
51 | 51 | |
52 | 52 | $balance_fee4 = new stdClass(); |
53 | 53 | $balance_fee4->fee = 10500; |
54 | 54 | $balance_fee4->net = 10000; |
55 | 55 | $balance_fee4->currency = 'JPY'; |
56 | 56 | |
57 | - $this->assertEquals( 10000, WC_Stripe_Helper::format_balance_fee( $balance_fee4, 'net' ) ); |
|
57 | + $this->assertEquals(10000, WC_Stripe_Helper::format_balance_fee($balance_fee4, 'net')); |
|
58 | 58 | |
59 | 59 | $balance_fee5 = new stdClass(); |
60 | 60 | $balance_fee5->fee = 10500; |
61 | 61 | $balance_fee5->net = 10000; |
62 | 62 | $balance_fee5->currency = 'USD'; |
63 | 63 | |
64 | - $this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) ); |
|
64 | + $this->assertEquals(105.00, WC_Stripe_Helper::format_balance_fee($balance_fee5)); |
|
65 | 65 | |
66 | - $this->assertInternalType( 'string', WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) ); |
|
66 | + $this->assertInternalType('string', WC_Stripe_Helper::format_balance_fee($balance_fee5)); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -76,28 +76,28 @@ discard block |
||
76 | 76 | 'expected' => 'Tests Store', |
77 | 77 | ); |
78 | 78 | |
79 | - $this->assertEquals( $statement_descriptor1['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor1['actual'] ) ); |
|
79 | + $this->assertEquals($statement_descriptor1['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor1['actual'])); |
|
80 | 80 | |
81 | 81 | $statement_descriptor2 = array( |
82 | 82 | 'actual' => 'Test\'s Store > Driving Course Range', |
83 | 83 | 'expected' => 'Tests Store Driving C', |
84 | 84 | ); |
85 | 85 | |
86 | - $this->assertEquals( $statement_descriptor2['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor2['actual'] ) ); |
|
86 | + $this->assertEquals($statement_descriptor2['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor2['actual'])); |
|
87 | 87 | |
88 | 88 | $statement_descriptor3 = array( |
89 | 89 | 'actual' => 'Test\'s Store < Driving Course Range', |
90 | 90 | 'expected' => 'Tests Store Driving C', |
91 | 91 | ); |
92 | 92 | |
93 | - $this->assertEquals( $statement_descriptor3['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor3['actual'] ) ); |
|
93 | + $this->assertEquals($statement_descriptor3['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor3['actual'])); |
|
94 | 94 | |
95 | 95 | $statement_descriptor4 = array( |
96 | 96 | 'actual' => 'Test\'s Store " Driving Course Range', |
97 | 97 | 'expected' => 'Tests Store Driving C', |
98 | 98 | ); |
99 | 99 | |
100 | - $this->assertEquals( $statement_descriptor4['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor4['actual'] ) ); |
|
100 | + $this->assertEquals($statement_descriptor4['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor4['actual'])); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -109,12 +109,12 @@ discard block |
||
109 | 109 | $source = new stdClass(); |
110 | 110 | $source->type = 'three_d_secure'; |
111 | 111 | |
112 | - $this->assertEquals( true, $stripe->is_3ds_card( $source ) ); |
|
112 | + $this->assertEquals(true, $stripe->is_3ds_card($source)); |
|
113 | 113 | |
114 | 114 | $source = new stdClass(); |
115 | 115 | $source->type = 'card'; |
116 | 116 | |
117 | - $this->assertEquals( false, $stripe->is_3ds_card( $source ) ); |
|
117 | + $this->assertEquals(false, $stripe->is_3ds_card($source)); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -128,20 +128,20 @@ discard block |
||
128 | 128 | $source->card = new stdClass(); |
129 | 129 | $source->card->three_d_secure = 'required'; |
130 | 130 | |
131 | - $this->assertEquals( true, $stripe->is_3ds_required( $source ) ); |
|
131 | + $this->assertEquals(true, $stripe->is_3ds_required($source)); |
|
132 | 132 | |
133 | 133 | $source = new stdClass(); |
134 | 134 | $source->type = 'card'; |
135 | 135 | $source->card = new stdClass(); |
136 | 136 | $source->card->three_d_secure = 'optional'; |
137 | 137 | |
138 | - $this->assertEquals( false, $stripe->is_3ds_required( $source ) ); |
|
138 | + $this->assertEquals(false, $stripe->is_3ds_required($source)); |
|
139 | 139 | |
140 | 140 | $source = new stdClass(); |
141 | 141 | $source->type = 'card'; |
142 | 142 | $source->card = new stdClass(); |
143 | 143 | $source->card->three_d_secure = 'not_supported'; |
144 | 144 | |
145 | - $this->assertEquals( false, $stripe->is_3ds_required( $source ) ); |
|
145 | + $this->assertEquals(false, $stripe->is_3ds_required($source)); |
|
146 | 146 | } |
147 | 147 | } |
@@ -1,28 +1,28 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -$_tests_dir = getenv( 'WP_TESTS_DIR' ); |
|
4 | -if ( ! $_tests_dir ) { |
|
3 | +$_tests_dir = getenv('WP_TESTS_DIR'); |
|
4 | +if ( ! $_tests_dir) { |
|
5 | 5 | $_tests_dir = '/tmp/wordpress-tests-lib'; |
6 | 6 | } |
7 | 7 | |
8 | 8 | require_once $_tests_dir . '/includes/functions.php'; |
9 | 9 | |
10 | 10 | function _manually_load_plugin() { |
11 | - $plugin_dir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/'; |
|
11 | + $plugin_dir = dirname(dirname(dirname(dirname(__FILE__)))) . '/'; |
|
12 | 12 | require $plugin_dir . 'woocommerce-gateway-stripe/woocommerce-gateway-stripe.php'; |
13 | 13 | require $plugin_dir . 'woocommerce/woocommerce.php'; |
14 | 14 | } |
15 | 15 | |
16 | -tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); |
|
16 | +tests_add_filter('muplugins_loaded', '_manually_load_plugin'); |
|
17 | 17 | |
18 | 18 | require $_tests_dir . '/includes/bootstrap.php'; |
19 | 19 | |
20 | -$wc_tests_framework_base_dir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/woocommerce/tests/framework/'; |
|
21 | -require_once( $wc_tests_framework_base_dir . 'class-wc-mock-session-handler.php' ); |
|
22 | -require_once( $wc_tests_framework_base_dir . 'class-wc-unit-test-case.php' ); |
|
23 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-product.php' ); |
|
24 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-coupon.php' ); |
|
25 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-fee.php' ); |
|
26 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-shipping.php' ); |
|
27 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-customer.php' ); |
|
28 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-order.php' ); |
|
20 | +$wc_tests_framework_base_dir = dirname(dirname(dirname(dirname(__FILE__)))) . '/woocommerce/tests/framework/'; |
|
21 | +require_once($wc_tests_framework_base_dir . 'class-wc-mock-session-handler.php'); |
|
22 | +require_once($wc_tests_framework_base_dir . 'class-wc-unit-test-case.php'); |
|
23 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-product.php'); |
|
24 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-coupon.php'); |
|
25 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-fee.php'); |
|
26 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-shipping.php'); |
|
27 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-customer.php'); |
|
28 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-order.php'); |
@@ -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,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 | } |
@@ -15,20 +15,20 @@ discard block |
||
15 | 15 | * |
16 | 16 | */ |
17 | 17 | |
18 | -if ( ! defined( 'ABSPATH' ) ) { |
|
18 | +if ( ! defined('ABSPATH')) { |
|
19 | 19 | exit; |
20 | 20 | } |
21 | 21 | |
22 | -if ( ! class_exists( 'WC_Stripe' ) ) : |
|
22 | +if ( ! class_exists('WC_Stripe')) : |
|
23 | 23 | /** |
24 | 24 | * Required minimums and constants |
25 | 25 | */ |
26 | - define( 'WC_STRIPE_VERSION', '4.0.5' ); |
|
27 | - define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' ); |
|
28 | - define( 'WC_STRIPE_MIN_WC_VER', '2.6.0' ); |
|
29 | - define( 'WC_STRIPE_MAIN_FILE', __FILE__ ); |
|
30 | - define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); |
|
31 | - define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); |
|
26 | + define('WC_STRIPE_VERSION', '4.0.5'); |
|
27 | + define('WC_STRIPE_MIN_PHP_VER', '5.6.0'); |
|
28 | + define('WC_STRIPE_MIN_WC_VER', '2.6.0'); |
|
29 | + define('WC_STRIPE_MAIN_FILE', __FILE__); |
|
30 | + define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)))); |
|
31 | + define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__))); |
|
32 | 32 | |
33 | 33 | class WC_Stripe { |
34 | 34 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @return Singleton The *Singleton* instance. |
49 | 49 | */ |
50 | 50 | public static function get_instance() { |
51 | - if ( null === self::$instance ) { |
|
51 | + if (null === self::$instance) { |
|
52 | 52 | self::$instance = new self(); |
53 | 53 | } |
54 | 54 | return self::$instance; |
@@ -81,10 +81,10 @@ discard block |
||
81 | 81 | * *Singleton* via the `new` operator from outside of this class. |
82 | 82 | */ |
83 | 83 | private function __construct() { |
84 | - add_action( 'admin_init', array( $this, 'check_environment' ) ); |
|
85 | - add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 ); |
|
86 | - add_action( 'plugins_loaded', array( $this, 'init' ) ); |
|
87 | - add_action( 'wp_loaded', array( $this, 'hide_notices' ) ); |
|
84 | + add_action('admin_init', array($this, 'check_environment')); |
|
85 | + add_action('admin_notices', array($this, 'admin_notices'), 15); |
|
86 | + add_action('plugins_loaded', array($this, 'init')); |
|
87 | + add_action('wp_loaded', array($this, 'hide_notices')); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -94,44 +94,44 @@ discard block |
||
94 | 94 | * @version 4.0.0 |
95 | 95 | */ |
96 | 96 | public function init() { |
97 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-exception.php' ); |
|
98 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php' ); |
|
99 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php' ); |
|
100 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' ); |
|
97 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-exception.php'); |
|
98 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-logger.php'); |
|
99 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-helper.php'); |
|
100 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php'); |
|
101 | 101 | |
102 | 102 | // Don't hook anything else in the plugin if we're in an incompatible environment. |
103 | - if ( self::get_environment_warning() ) { |
|
103 | + if (self::get_environment_warning()) { |
|
104 | 104 | return; |
105 | 105 | } |
106 | 106 | |
107 | - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
|
108 | - |
|
109 | - require_once( dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php' ); |
|
110 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php' ); |
|
111 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-sepa-payment-token.php' ); |
|
112 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay-registration.php' ); |
|
113 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' ); |
|
114 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php' ); |
|
115 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php' ); |
|
116 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php' ); |
|
117 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php' ); |
|
118 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php' ); |
|
119 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php' ); |
|
120 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php' ); |
|
121 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php' ); |
|
122 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php' ); |
|
123 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-compat.php' ); |
|
124 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-compat.php' ); |
|
125 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php' ); |
|
126 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php' ); |
|
127 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' ); |
|
107 | + load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages'); |
|
108 | + |
|
109 | + require_once(dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php'); |
|
110 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php'); |
|
111 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-sepa-payment-token.php'); |
|
112 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay-registration.php'); |
|
113 | + require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php'); |
|
114 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'); |
|
115 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'); |
|
116 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'); |
|
117 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php'); |
|
118 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php'); |
|
119 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php'); |
|
120 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php'); |
|
121 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php'); |
|
122 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php'); |
|
123 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-compat.php'); |
|
124 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-sepa-compat.php'); |
|
125 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php'); |
|
126 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php'); |
|
127 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php'); |
|
128 | 128 | |
129 | 129 | // REMOVE IN THE FUTURE. |
130 | - require_once( dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php' ); |
|
130 | + require_once(dirname(__FILE__) . '/includes/deprecated/class-wc-stripe-apple-pay.php'); |
|
131 | 131 | |
132 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
133 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
|
134 | - add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) ); |
|
132 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
133 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); |
|
134 | + add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin')); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -141,23 +141,23 @@ discard block |
||
141 | 141 | * @version 4.0.0 |
142 | 142 | */ |
143 | 143 | public function hide_notices() { |
144 | - if ( isset( $_GET['wc-stripe-hide-notice'] ) && isset( $_GET['_wc_stripe_notice_nonce'] ) ) { |
|
145 | - if ( ! wp_verify_nonce( $_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce' ) ) { |
|
146 | - wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe' ) ); |
|
144 | + if (isset($_GET['wc-stripe-hide-notice']) && isset($_GET['_wc_stripe_notice_nonce'])) { |
|
145 | + if ( ! wp_verify_nonce($_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce')) { |
|
146 | + wp_die(__('Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe')); |
|
147 | 147 | } |
148 | 148 | |
149 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
150 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
149 | + if ( ! current_user_can('manage_woocommerce')) { |
|
150 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
151 | 151 | } |
152 | 152 | |
153 | - $notice = wc_clean( $_GET['wc-stripe-hide-notice'] ); |
|
153 | + $notice = wc_clean($_GET['wc-stripe-hide-notice']); |
|
154 | 154 | |
155 | - switch ( $notice ) { |
|
155 | + switch ($notice) { |
|
156 | 156 | case 'ssl': |
157 | - update_option( 'wc_stripe_show_ssl_notice', 'no' ); |
|
157 | + update_option('wc_stripe_show_ssl_notice', 'no'); |
|
158 | 158 | break; |
159 | 159 | case 'keys': |
160 | - update_option( 'wc_stripe_show_keys_notice', 'no' ); |
|
160 | + update_option('wc_stripe_show_keys_notice', 'no'); |
|
161 | 161 | break; |
162 | 162 | } |
163 | 163 | } |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | * @since 1.0.0 |
170 | 170 | * @version 4.0.0 |
171 | 171 | */ |
172 | - public function add_admin_notice( $slug, $class, $message, $dismissible = false ) { |
|
173 | - $this->notices[ $slug ] = array( |
|
172 | + public function add_admin_notice($slug, $class, $message, $dismissible = false) { |
|
173 | + $this->notices[$slug] = array( |
|
174 | 174 | 'class' => $class, |
175 | 175 | 'message' => $message, |
176 | 176 | 'dismissible' => $dismissible, |
@@ -184,21 +184,21 @@ discard block |
||
184 | 184 | * @version 4.0.0 |
185 | 185 | */ |
186 | 186 | public function admin_notices() { |
187 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
187 | + if ( ! current_user_can('manage_woocommerce')) { |
|
188 | 188 | return; |
189 | 189 | } |
190 | 190 | |
191 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
192 | - echo '<div class="' . esc_attr( $notice['class'] ) . '" style="position:relative;">'; |
|
191 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
192 | + echo '<div class="' . esc_attr($notice['class']) . '" style="position:relative;">'; |
|
193 | 193 | |
194 | - if ( $notice['dismissible'] ) { |
|
194 | + if ($notice['dismissible']) { |
|
195 | 195 | ?> |
196 | - <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-stripe-hide-notice', $notice_key ), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce' ) ); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a> |
|
196 | + <a href="<?php echo esc_url(wp_nonce_url(add_query_arg('wc-stripe-hide-notice', $notice_key), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce')); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a> |
|
197 | 197 | <?php |
198 | 198 | } |
199 | 199 | |
200 | 200 | echo '<p>'; |
201 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
201 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
202 | 202 | echo '</p></div>'; |
203 | 203 | } |
204 | 204 | } |
@@ -211,26 +211,26 @@ discard block |
||
211 | 211 | * @version 4.0.0 |
212 | 212 | */ |
213 | 213 | public function get_environment_warning() { |
214 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
214 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
215 | 215 | /* translators: 1) int version 2) int version */ |
216 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
216 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
217 | 217 | |
218 | - return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ); |
|
218 | + return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()); |
|
219 | 219 | } |
220 | 220 | |
221 | - if ( ! defined( 'WC_VERSION' ) ) { |
|
222 | - return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' ); |
|
221 | + if ( ! defined('WC_VERSION')) { |
|
222 | + return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe'); |
|
223 | 223 | } |
224 | 224 | |
225 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
225 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
226 | 226 | /* translators: 1) int version 2) int version */ |
227 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
227 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
228 | 228 | |
229 | - return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ); |
|
229 | + return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION); |
|
230 | 230 | } |
231 | 231 | |
232 | - if ( ! function_exists( 'curl_init' ) ) { |
|
233 | - return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ); |
|
232 | + if ( ! function_exists('curl_init')) { |
|
233 | + return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | return false; |
@@ -244,11 +244,11 @@ discard block |
||
244 | 244 | * @return string Setting link |
245 | 245 | */ |
246 | 246 | public function get_setting_link() { |
247 | - $use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false; |
|
247 | + $use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false; |
|
248 | 248 | |
249 | - $section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' ); |
|
249 | + $section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe'); |
|
250 | 250 | |
251 | - return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); |
|
251 | + return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
@@ -259,65 +259,65 @@ discard block |
||
259 | 259 | * @version 4.0.0 |
260 | 260 | */ |
261 | 261 | public function check_environment() { |
262 | - if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) { |
|
262 | + if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) { |
|
263 | 263 | $this->install(); |
264 | 264 | |
265 | - do_action( 'woocommerce_stripe_updated' ); |
|
265 | + do_action('woocommerce_stripe_updated'); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | $environment_warning = $this->get_environment_warning(); |
269 | 269 | |
270 | - if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
|
271 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
270 | + if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) { |
|
271 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
272 | 272 | } |
273 | 273 | |
274 | - $show_ssl_notice = get_option( 'wc_stripe_show_ssl_notice' ); |
|
275 | - $show_keys_notice = get_option( 'wc_stripe_show_keys_notice' ); |
|
276 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
277 | - $testmode = ( isset( $options['testmode'] ) && 'yes' === $options['testmode'] ) ? true : false; |
|
278 | - $test_pub_key = isset( $options['test_publishable_key'] ) ? $options['test_publishable_key'] : ''; |
|
279 | - $test_secret_key = isset( $options['test_secret_key'] ) ? $options['test_secret_key'] : ''; |
|
280 | - $live_pub_key = isset( $options['publishable_key'] ) ? $options['publishable_key'] : ''; |
|
281 | - $live_secret_key = isset( $options['secret_key'] ) ? $options['secret_key'] : ''; |
|
274 | + $show_ssl_notice = get_option('wc_stripe_show_ssl_notice'); |
|
275 | + $show_keys_notice = get_option('wc_stripe_show_keys_notice'); |
|
276 | + $options = get_option('woocommerce_stripe_settings'); |
|
277 | + $testmode = (isset($options['testmode']) && 'yes' === $options['testmode']) ? true : false; |
|
278 | + $test_pub_key = isset($options['test_publishable_key']) ? $options['test_publishable_key'] : ''; |
|
279 | + $test_secret_key = isset($options['test_secret_key']) ? $options['test_secret_key'] : ''; |
|
280 | + $live_pub_key = isset($options['publishable_key']) ? $options['publishable_key'] : ''; |
|
281 | + $live_secret_key = isset($options['secret_key']) ? $options['secret_key'] : ''; |
|
282 | 282 | |
283 | - if ( isset( $options['enabled'] ) && 'yes' === $options['enabled'] && empty( $show_keys_notice ) ) { |
|
284 | - $secret = WC_Stripe_API::get_secret_key(); |
|
283 | + if (isset($options['enabled']) && 'yes' === $options['enabled'] && empty($show_keys_notice)) { |
|
284 | + $secret = WC_Stripe_API::get_secret_key(); |
|
285 | 285 | |
286 | - if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
|
286 | + if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) { |
|
287 | 287 | $setting_link = $this->get_setting_link(); |
288 | 288 | /* translators: 1) link */ |
289 | - $this->add_admin_notice( 'keys', 'notice notice-warning', sprintf( __( 'Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
289 | + $this->add_admin_notice('keys', 'notice notice-warning', sprintf(__('Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | // Check if keys are entered properly per live/test mode. |
293 | - if ( $testmode ) { |
|
293 | + if ($testmode) { |
|
294 | 294 | if ( |
295 | - ! empty( $test_pub_key ) && ! preg_match( '/^pk_test_/', $test_pub_key ) |
|
296 | - || ( ! empty( $test_secret_key ) && ! preg_match( '/^sk_test_/', $test_secret_key ) |
|
297 | - && ! empty( $test_secret_key ) && ! preg_match( '/^rk_test_/', $test_secret_key ) ) ) |
|
295 | + ! empty($test_pub_key) && ! preg_match('/^pk_test_/', $test_pub_key) |
|
296 | + || ( ! empty($test_secret_key) && ! preg_match('/^sk_test_/', $test_secret_key) |
|
297 | + && ! empty($test_secret_key) && ! preg_match('/^rk_test_/', $test_secret_key)) ) |
|
298 | 298 | { |
299 | 299 | $setting_link = $this->get_setting_link(); |
300 | 300 | /* translators: 1) link */ |
301 | - $this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in test mode however your test keys may not be valid. Test keys start with pk_test and sk_test or rk_test. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
301 | + $this->add_admin_notice('keys', 'notice notice-error', sprintf(__('Stripe is in test mode however your test keys may not be valid. Test keys start with pk_test and sk_test or rk_test. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
302 | 302 | } |
303 | 303 | } else { |
304 | 304 | if ( |
305 | - ! empty( $live_pub_key ) && ! preg_match( '/^pk_live_/', $live_pub_key ) |
|
306 | - || ( ! empty( $live_secret_key ) && ! preg_match( '/^sk_live_/', $live_secret_key ) |
|
307 | - && ! empty( $live_secret_key ) && ! preg_match( '/^rk_live_/', $live_secret_key ) ) ) |
|
305 | + ! empty($live_pub_key) && ! preg_match('/^pk_live_/', $live_pub_key) |
|
306 | + || ( ! empty($live_secret_key) && ! preg_match('/^sk_live_/', $live_secret_key) |
|
307 | + && ! empty($live_secret_key) && ! preg_match('/^rk_live_/', $live_secret_key)) ) |
|
308 | 308 | { |
309 | 309 | $setting_link = $this->get_setting_link(); |
310 | 310 | /* translators: 1) link */ |
311 | - $this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in live mode however your test keys may not be valid. Live keys start with pk_live and sk_live or rk_live. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
311 | + $this->add_admin_notice('keys', 'notice notice-error', sprintf(__('Stripe is in live mode however your test keys may not be valid. Live keys start with pk_live and sk_live or rk_live. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
312 | 312 | } |
313 | 313 | } |
314 | 314 | } |
315 | 315 | |
316 | - if ( empty( $show_ssl_notice ) && isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) { |
|
316 | + if (empty($show_ssl_notice) && isset($options['enabled']) && 'yes' === $options['enabled']) { |
|
317 | 317 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
318 | - if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
318 | + if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
319 | 319 | /* translators: 1) link 2) link */ |
320 | - $this->add_admin_notice( 'ssl', 'notice notice-warning', sprintf( __( 'Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ), 'https://en.wikipedia.org/wiki/Transport_Layer_Security' ), true ); |
|
320 | + $this->add_admin_notice('ssl', 'notice notice-warning', sprintf(__('Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout'), 'https://en.wikipedia.org/wiki/Transport_Layer_Security'), true); |
|
321 | 321 | } |
322 | 322 | } |
323 | 323 | } |
@@ -329,8 +329,8 @@ discard block |
||
329 | 329 | * @version 4.0.0 |
330 | 330 | */ |
331 | 331 | public function update_plugin_version() { |
332 | - delete_option( 'wc_stripe_version' ); |
|
333 | - update_option( 'wc_stripe_version', WC_STRIPE_VERSION ); |
|
332 | + delete_option('wc_stripe_version'); |
|
333 | + update_option('wc_stripe_version', WC_STRIPE_VERSION); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
@@ -340,8 +340,8 @@ discard block |
||
340 | 340 | * @version 3.1.0 |
341 | 341 | */ |
342 | 342 | public function install() { |
343 | - if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) { |
|
344 | - define( 'WC_STRIPE_INSTALLING', true ); |
|
343 | + if ( ! defined('WC_STRIPE_INSTALLING')) { |
|
344 | + define('WC_STRIPE_INSTALLING', true); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | $this->update_plugin_version(); |
@@ -353,13 +353,13 @@ discard block |
||
353 | 353 | * @since 1.0.0 |
354 | 354 | * @version 4.0.0 |
355 | 355 | */ |
356 | - public function plugin_action_links( $links ) { |
|
356 | + public function plugin_action_links($links) { |
|
357 | 357 | $plugin_links = array( |
358 | - '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
359 | - '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
360 | - '<a href="https://woocommerce.com/contact-us/">' . esc_html__( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
358 | + '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
359 | + '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
360 | + '<a href="https://woocommerce.com/contact-us/">' . esc_html__('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
361 | 361 | ); |
362 | - return array_merge( $plugin_links, $links ); |
|
362 | + return array_merge($plugin_links, $links); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
@@ -368,8 +368,8 @@ discard block |
||
368 | 368 | * @since 1.0.0 |
369 | 369 | * @version 4.0.0 |
370 | 370 | */ |
371 | - public function add_gateways( $methods ) { |
|
372 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
371 | + public function add_gateways($methods) { |
|
372 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order') || class_exists('WC_Pre_Orders_Order')) { |
|
373 | 373 | $methods[] = 'WC_Stripe_Compat'; |
374 | 374 | $methods[] = 'WC_Stripe_Sepa_Compat'; |
375 | 375 | } else { |
@@ -394,26 +394,26 @@ discard block |
||
394 | 394 | * @since 4.0.0 |
395 | 395 | * @version 4.0.0 |
396 | 396 | */ |
397 | - public function filter_gateway_order_admin( $sections ) { |
|
398 | - unset( $sections['stripe'] ); |
|
399 | - unset( $sections['stripe_bancontact'] ); |
|
400 | - unset( $sections['stripe_sofort'] ); |
|
401 | - unset( $sections['stripe_giropay'] ); |
|
402 | - unset( $sections['stripe_ideal'] ); |
|
403 | - unset( $sections['stripe_p24'] ); |
|
404 | - unset( $sections['stripe_alipay'] ); |
|
405 | - unset( $sections['stripe_sepa'] ); |
|
406 | - unset( $sections['stripe_bitcoin'] ); |
|
397 | + public function filter_gateway_order_admin($sections) { |
|
398 | + unset($sections['stripe']); |
|
399 | + unset($sections['stripe_bancontact']); |
|
400 | + unset($sections['stripe_sofort']); |
|
401 | + unset($sections['stripe_giropay']); |
|
402 | + unset($sections['stripe_ideal']); |
|
403 | + unset($sections['stripe_p24']); |
|
404 | + unset($sections['stripe_alipay']); |
|
405 | + unset($sections['stripe_sepa']); |
|
406 | + unset($sections['stripe_bitcoin']); |
|
407 | 407 | |
408 | 408 | $sections['stripe'] = 'Stripe'; |
409 | - $sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
410 | - $sections['stripe_sofort'] = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
411 | - $sections['stripe_giropay'] = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
412 | - $sections['stripe_ideal'] = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
413 | - $sections['stripe_p24'] = __( 'Stripe P24', 'woocommerce-gateway-stripe' ); |
|
414 | - $sections['stripe_alipay'] = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
415 | - $sections['stripe_sepa'] = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
416 | - $sections['stripe_bitcoin'] = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' ); |
|
409 | + $sections['stripe_bancontact'] = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
410 | + $sections['stripe_sofort'] = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
411 | + $sections['stripe_giropay'] = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
412 | + $sections['stripe_ideal'] = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
413 | + $sections['stripe_p24'] = __('Stripe P24', 'woocommerce-gateway-stripe'); |
|
414 | + $sections['stripe_alipay'] = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
415 | + $sections['stripe_sepa'] = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
416 | + $sections['stripe_bitcoin'] = __('Stripe Bitcoin', 'woocommerce-gateway-stripe'); |
|
417 | 417 | |
418 | 418 | return $sections; |
419 | 419 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 4.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if ( ! defined('ABSPATH')) { |
|
10 | 10 | exit; |
11 | 11 | } |
12 | 12 | |
@@ -71,36 +71,36 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function __construct() { |
73 | 73 | self::$_this = $this; |
74 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
75 | - $this->testmode = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false; |
|
76 | - $this->publishable_key = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : ''; |
|
77 | - $this->secret_key = ! empty( $this->stripe_settings['secret_key'] ) ? $this->stripe_settings['secret_key'] : ''; |
|
78 | - $this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
79 | - $this->total_label = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : ''; |
|
80 | - |
|
81 | - if ( $this->testmode ) { |
|
82 | - $this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
83 | - $this->secret_key = ! empty( $this->stripe_settings['test_secret_key'] ) ? $this->stripe_settings['test_secret_key'] : ''; |
|
74 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
75 | + $this->testmode = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false; |
|
76 | + $this->publishable_key = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : ''; |
|
77 | + $this->secret_key = ! empty($this->stripe_settings['secret_key']) ? $this->stripe_settings['secret_key'] : ''; |
|
78 | + $this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
79 | + $this->total_label = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : ''; |
|
80 | + |
|
81 | + if ($this->testmode) { |
|
82 | + $this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
83 | + $this->secret_key = ! empty($this->stripe_settings['test_secret_key']) ? $this->stripe_settings['test_secret_key'] : ''; |
|
84 | 84 | } |
85 | 85 | |
86 | - $this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' ); |
|
86 | + $this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)'); |
|
87 | 87 | |
88 | 88 | // Checks if Stripe Gateway is enabled. |
89 | - if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) { |
|
89 | + if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) { |
|
90 | 90 | return; |
91 | 91 | } |
92 | 92 | |
93 | 93 | // Checks if Payment Request is enabled. |
94 | - if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) { |
|
94 | + if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) { |
|
95 | 95 | return; |
96 | 96 | } |
97 | 97 | |
98 | 98 | // Don't load for change payment method page. |
99 | - if ( isset( $_GET['change_payment_method'] ) ) { |
|
99 | + if (isset($_GET['change_payment_method'])) { |
|
100 | 100 | return; |
101 | 101 | } |
102 | 102 | |
103 | - add_action( 'woocommerce_init', array( $this, 'set_session' ) ); |
|
103 | + add_action('woocommerce_init', array($this, 'set_session')); |
|
104 | 104 | $this->init(); |
105 | 105 | } |
106 | 106 | |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @return bool |
112 | 112 | */ |
113 | 113 | public function are_keys_set() { |
114 | - if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) { |
|
114 | + if (empty($this->secret_key) || empty($this->publishable_key)) { |
|
115 | 115 | return false; |
116 | 116 | } |
117 | 117 | |
@@ -135,15 +135,15 @@ discard block |
||
135 | 135 | * @since 4.0.0 |
136 | 136 | */ |
137 | 137 | public function set_session() { |
138 | - if ( ! is_user_logged_in() ) { |
|
138 | + if ( ! is_user_logged_in()) { |
|
139 | 139 | $wc_session = new WC_Session_Handler(); |
140 | 140 | |
141 | - if ( version_compare( WC_VERSION, '3.3', '>=' ) ) { |
|
141 | + if (version_compare(WC_VERSION, '3.3', '>=')) { |
|
142 | 142 | $wc_session->init(); |
143 | 143 | } |
144 | 144 | |
145 | - if ( ! $wc_session->has_session() ) { |
|
146 | - $wc_session->set_customer_session_cookie( true ); |
|
145 | + if ( ! $wc_session->has_session()) { |
|
146 | + $wc_session->set_customer_session_cookie(true); |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | } |
@@ -155,40 +155,40 @@ discard block |
||
155 | 155 | * @version 4.0.0 |
156 | 156 | */ |
157 | 157 | public function init() { |
158 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
158 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
159 | 159 | |
160 | 160 | /* |
161 | 161 | * In order to display the Payment Request button in the correct position, |
162 | 162 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
163 | 163 | * CSS is used to position the button. |
164 | 164 | */ |
165 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
166 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
167 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
165 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
166 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1); |
|
167 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2); |
|
168 | 168 | } else { |
169 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
170 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
169 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1); |
|
170 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2); |
|
171 | 171 | } |
172 | 172 | |
173 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
174 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
173 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1); |
|
174 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2); |
|
175 | 175 | |
176 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
177 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
176 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1); |
|
177 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2); |
|
178 | 178 | |
179 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
180 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
181 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
182 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
183 | - add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) ); |
|
184 | - add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) ); |
|
185 | - add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) ); |
|
186 | - add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) ); |
|
179 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
180 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
181 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
182 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
183 | + add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart')); |
|
184 | + add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data')); |
|
185 | + add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart')); |
|
186 | + add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors')); |
|
187 | 187 | |
188 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
189 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
188 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
189 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
190 | 190 | |
191 | - add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 ); |
|
191 | + add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | * @return string |
200 | 200 | */ |
201 | 201 | public function get_button_type() { |
202 | - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
202 | + return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | * @return string |
211 | 211 | */ |
212 | 212 | public function get_button_theme() { |
213 | - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
213 | + return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | * @return string |
222 | 222 | */ |
223 | 223 | public function get_button_height() { |
224 | - return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64'; |
|
224 | + return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64'; |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -231,40 +231,40 @@ discard block |
||
231 | 231 | * @version 4.0.0 |
232 | 232 | */ |
233 | 233 | public function get_product_data() { |
234 | - if ( ! is_product() ) { |
|
234 | + if ( ! is_product()) { |
|
235 | 235 | return false; |
236 | 236 | } |
237 | 237 | |
238 | 238 | global $post; |
239 | 239 | |
240 | - $product = wc_get_product( $post->ID ); |
|
240 | + $product = wc_get_product($post->ID); |
|
241 | 241 | |
242 | 242 | $data = array(); |
243 | 243 | $items = array(); |
244 | 244 | |
245 | 245 | $items[] = array( |
246 | 246 | 'label' => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(), |
247 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
247 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
248 | 248 | ); |
249 | 249 | |
250 | - if ( wc_tax_enabled() ) { |
|
250 | + if (wc_tax_enabled()) { |
|
251 | 251 | $items[] = array( |
252 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
252 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
253 | 253 | 'amount' => 0, |
254 | 254 | 'pending' => true, |
255 | 255 | ); |
256 | 256 | } |
257 | 257 | |
258 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
258 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
259 | 259 | $items[] = array( |
260 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
260 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
261 | 261 | 'amount' => 0, |
262 | 262 | 'pending' => true, |
263 | 263 | ); |
264 | 264 | |
265 | - $data['shippingOptions'] = array( |
|
265 | + $data['shippingOptions'] = array( |
|
266 | 266 | 'id' => 'pending', |
267 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
267 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
268 | 268 | 'detail' => '', |
269 | 269 | 'amount' => 0, |
270 | 270 | ); |
@@ -272,41 +272,41 @@ discard block |
||
272 | 272 | |
273 | 273 | $data['displayItems'] = $items; |
274 | 274 | $data['total'] = array( |
275 | - 'label' => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ), |
|
276 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
275 | + 'label' => apply_filters('wc_stripe_payment_request_total_label', $this->total_label), |
|
276 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
277 | 277 | 'pending' => true, |
278 | 278 | ); |
279 | 279 | |
280 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
281 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
282 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
280 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
281 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
282 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
283 | 283 | |
284 | - return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product ); |
|
284 | + return apply_filters('wc_stripe_payment_request_product_data', $data, $product); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
288 | 288 | * Filters the gateway title to reflect Payment Request type |
289 | 289 | * |
290 | 290 | */ |
291 | - public function filter_gateway_title( $title, $id ) { |
|
291 | + public function filter_gateway_title($title, $id) { |
|
292 | 292 | global $post; |
293 | 293 | |
294 | - if ( ! is_object( $post ) ) { |
|
294 | + if ( ! is_object($post)) { |
|
295 | 295 | return $title; |
296 | 296 | } |
297 | 297 | |
298 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
299 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
298 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
299 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
300 | 300 | } else { |
301 | - $order = wc_get_order( $post->ID ); |
|
302 | - $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
301 | + $order = wc_get_order($post->ID); |
|
302 | + $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
303 | 303 | } |
304 | 304 | |
305 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
305 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
306 | 306 | return $method_title; |
307 | 307 | } |
308 | 308 | |
309 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
309 | + if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
310 | 310 | return $method_title; |
311 | 311 | } |
312 | 312 | |
@@ -319,16 +319,16 @@ discard block |
||
319 | 319 | * @since 3.1.4 |
320 | 320 | * @version 4.0.0 |
321 | 321 | */ |
322 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
322 | + public function postal_code_validation($valid, $postcode, $country) { |
|
323 | 323 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
324 | 324 | |
325 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
325 | + if ( ! isset($gateways['stripe'])) { |
|
326 | 326 | return $valid; |
327 | 327 | } |
328 | 328 | |
329 | - $payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : ''; |
|
329 | + $payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : ''; |
|
330 | 330 | |
331 | - if ( 'apple_pay' !== $payment_request_type ) { |
|
331 | + if ('apple_pay' !== $payment_request_type) { |
|
332 | 332 | return $valid; |
333 | 333 | } |
334 | 334 | |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | * the order and not let it go through. The remedy for now is just to remove this validation. |
339 | 339 | * Note that this only works with shipping providers that don't validate full postal codes. |
340 | 340 | */ |
341 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
341 | + if ('GB' === $country || 'CA' === $country) { |
|
342 | 342 | return true; |
343 | 343 | } |
344 | 344 | |
@@ -353,29 +353,29 @@ discard block |
||
353 | 353 | * @param int $order_id |
354 | 354 | * @param array $posted_data The posted data from checkout form. |
355 | 355 | */ |
356 | - public function add_order_meta( $order_id, $posted_data ) { |
|
357 | - if ( empty( $_POST['payment_request_type'] ) ) { |
|
356 | + public function add_order_meta($order_id, $posted_data) { |
|
357 | + if (empty($_POST['payment_request_type'])) { |
|
358 | 358 | return; |
359 | 359 | } |
360 | 360 | |
361 | - $order = wc_get_order( $order_id ); |
|
361 | + $order = wc_get_order($order_id); |
|
362 | 362 | |
363 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
363 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
364 | 364 | |
365 | - if ( 'apple_pay' === $payment_request_type ) { |
|
366 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
367 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
365 | + if ('apple_pay' === $payment_request_type) { |
|
366 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
367 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
368 | 368 | } else { |
369 | - $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
369 | + $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
370 | 370 | $order->save(); |
371 | 371 | } |
372 | 372 | } |
373 | 373 | |
374 | - if ( 'payment_request_api' === $payment_request_type ) { |
|
375 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
376 | - update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' ); |
|
374 | + if ('payment_request_api' === $payment_request_type) { |
|
375 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
376 | + update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)'); |
|
377 | 377 | } else { |
378 | - $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
378 | + $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
379 | 379 | $order->save(); |
380 | 380 | } |
381 | 381 | } |
@@ -389,11 +389,11 @@ discard block |
||
389 | 389 | * @return array |
390 | 390 | */ |
391 | 391 | public function supported_product_types() { |
392 | - return apply_filters( 'wc_stripe_payment_request_supported_types', array( |
|
392 | + return apply_filters('wc_stripe_payment_request_supported_types', array( |
|
393 | 393 | 'simple', |
394 | 394 | 'variable', |
395 | 395 | 'variation', |
396 | - ) ); |
|
396 | + )); |
|
397 | 397 | } |
398 | 398 | |
399 | 399 | /** |
@@ -404,15 +404,15 @@ discard block |
||
404 | 404 | * @return bool |
405 | 405 | */ |
406 | 406 | public function allowed_items_in_cart() { |
407 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
408 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
407 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
408 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
409 | 409 | |
410 | - if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
410 | + if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
411 | 411 | return false; |
412 | 412 | } |
413 | 413 | |
414 | 414 | // Pre Orders compatbility where we don't support charge upon release. |
415 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release( WC_Pre_Orders_Cart::get_pre_order_product() ) ) { |
|
415 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product())) { |
|
416 | 416 | return false; |
417 | 417 | } |
418 | 418 | } |
@@ -428,82 +428,82 @@ discard block |
||
428 | 428 | */ |
429 | 429 | public function scripts() { |
430 | 430 | // If keys are not set bail. |
431 | - if ( ! $this->are_keys_set() ) { |
|
432 | - WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
431 | + if ( ! $this->are_keys_set()) { |
|
432 | + WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
433 | 433 | return; |
434 | 434 | } |
435 | 435 | |
436 | 436 | // If no SSL bail. |
437 | - if ( ! $this->testmode && ! is_ssl() ) { |
|
438 | - WC_Stripe_Logger::log( 'Stripe requires SSL.' ); |
|
437 | + if ( ! $this->testmode && ! is_ssl()) { |
|
438 | + WC_Stripe_Logger::log('Stripe requires SSL.'); |
|
439 | 439 | return; |
440 | 440 | } |
441 | 441 | |
442 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
442 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
443 | 443 | return; |
444 | 444 | } |
445 | 445 | |
446 | - if ( is_product() ) { |
|
446 | + if (is_product()) { |
|
447 | 447 | global $post; |
448 | 448 | |
449 | - $product = wc_get_product( $post->ID ); |
|
449 | + $product = wc_get_product($post->ID); |
|
450 | 450 | |
451 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
451 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
452 | 452 | return; |
453 | 453 | } |
454 | 454 | |
455 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
455 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
456 | 456 | return; |
457 | 457 | } |
458 | 458 | } |
459 | 459 | |
460 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
460 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
461 | 461 | |
462 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
463 | - wp_register_script( 'wc_stripe_payment_request', plugins_url( 'assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
462 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
463 | + wp_register_script('wc_stripe_payment_request', plugins_url('assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true); |
|
464 | 464 | |
465 | 465 | wp_localize_script( |
466 | 466 | 'wc_stripe_payment_request', |
467 | 467 | 'wc_stripe_payment_request_params', |
468 | 468 | array( |
469 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
469 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
470 | 470 | 'stripe' => array( |
471 | 471 | 'key' => $this->publishable_key, |
472 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
472 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
473 | 473 | ), |
474 | 474 | 'nonce' => array( |
475 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
476 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
477 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
478 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
479 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
480 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
481 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
482 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
475 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
476 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
477 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
478 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
479 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
480 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
481 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
482 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
483 | 483 | ), |
484 | 484 | 'i18n' => array( |
485 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
485 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
486 | 486 | /* translators: Do not translate the [option] placeholder */ |
487 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
487 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
488 | 488 | ), |
489 | 489 | 'checkout' => array( |
490 | 490 | 'url' => wc_get_checkout_url(), |
491 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
492 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
491 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
492 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
493 | 493 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
494 | 494 | ), |
495 | 495 | 'button' => array( |
496 | 496 | 'type' => $this->get_button_type(), |
497 | 497 | 'theme' => $this->get_button_theme(), |
498 | 498 | 'height' => $this->get_button_height(), |
499 | - 'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US. |
|
499 | + 'locale' => substr(get_locale(), 0, 2), // Default format is en_US. |
|
500 | 500 | ), |
501 | 501 | 'is_product_page' => is_product(), |
502 | 502 | 'product' => $this->get_product_data(), |
503 | 503 | ) |
504 | 504 | ); |
505 | 505 | |
506 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
506 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | /** |
@@ -515,39 +515,39 @@ discard block |
||
515 | 515 | public function display_payment_request_button_html() { |
516 | 516 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
517 | 517 | |
518 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
518 | + if ( ! isset($gateways['stripe'])) { |
|
519 | 519 | return; |
520 | 520 | } |
521 | 521 | |
522 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
522 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
523 | 523 | return; |
524 | 524 | } |
525 | 525 | |
526 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
526 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
527 | 527 | return; |
528 | 528 | } |
529 | 529 | |
530 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
530 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
531 | 531 | return; |
532 | 532 | } |
533 | 533 | |
534 | - if ( is_product() ) { |
|
534 | + if (is_product()) { |
|
535 | 535 | global $post; |
536 | 536 | |
537 | - $product = wc_get_product( $post->ID ); |
|
537 | + $product = wc_get_product($post->ID); |
|
538 | 538 | |
539 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
539 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
540 | 540 | return; |
541 | 541 | } |
542 | 542 | |
543 | 543 | // Pre Orders charge upon release not supported. |
544 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
545 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
544 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
545 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
546 | 546 | return; |
547 | 547 | } |
548 | 548 | } else { |
549 | - if ( ! $this->allowed_items_in_cart() ) { |
|
550 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
549 | + if ( ! $this->allowed_items_in_cart()) { |
|
550 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
551 | 551 | return; |
552 | 552 | } |
553 | 553 | } |
@@ -569,44 +569,44 @@ discard block |
||
569 | 569 | public function display_payment_request_button_separator_html() { |
570 | 570 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
571 | 571 | |
572 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
572 | + if ( ! isset($gateways['stripe'])) { |
|
573 | 573 | return; |
574 | 574 | } |
575 | 575 | |
576 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
576 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
577 | 577 | return; |
578 | 578 | } |
579 | 579 | |
580 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
580 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
581 | 581 | return; |
582 | 582 | } |
583 | 583 | |
584 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
584 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
585 | 585 | return; |
586 | 586 | } |
587 | 587 | |
588 | - if ( is_product() ) { |
|
588 | + if (is_product()) { |
|
589 | 589 | global $post; |
590 | 590 | |
591 | - $product = wc_get_product( $post->ID ); |
|
591 | + $product = wc_get_product($post->ID); |
|
592 | 592 | |
593 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
593 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
594 | 594 | return; |
595 | 595 | } |
596 | 596 | |
597 | 597 | // Pre Orders charge upon release not supported. |
598 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
599 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
598 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
599 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
600 | 600 | return; |
601 | 601 | } |
602 | 602 | } else { |
603 | - if ( ! $this->allowed_items_in_cart() ) { |
|
604 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
603 | + if ( ! $this->allowed_items_in_cart()) { |
|
604 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
605 | 605 | return; |
606 | 606 | } |
607 | 607 | } |
608 | 608 | ?> |
609 | - <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> -</p> |
|
609 | + <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> -</p> |
|
610 | 610 | <?php |
611 | 611 | } |
612 | 612 | |
@@ -617,11 +617,11 @@ discard block |
||
617 | 617 | * @version 4.0.0 |
618 | 618 | */ |
619 | 619 | public function ajax_log_errors() { |
620 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
620 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
621 | 621 | |
622 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
622 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
623 | 623 | |
624 | - WC_Stripe_Logger::log( $errors ); |
|
624 | + WC_Stripe_Logger::log($errors); |
|
625 | 625 | |
626 | 626 | exit; |
627 | 627 | } |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | * @version 4.0.0 |
634 | 634 | */ |
635 | 635 | public function ajax_clear_cart() { |
636 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
636 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
637 | 637 | |
638 | 638 | WC()->cart->empty_cart(); |
639 | 639 | exit; |
@@ -643,10 +643,10 @@ discard block |
||
643 | 643 | * Get cart details. |
644 | 644 | */ |
645 | 645 | public function ajax_get_cart_details() { |
646 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
646 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
647 | 647 | |
648 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
649 | - define( 'WOOCOMMERCE_CART', true ); |
|
648 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
649 | + define('WOOCOMMERCE_CART', true); |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | WC()->cart->calculate_totals(); |
@@ -657,14 +657,14 @@ discard block |
||
657 | 657 | $data = array( |
658 | 658 | 'shipping_required' => WC()->cart->needs_shipping(), |
659 | 659 | 'order_data' => array( |
660 | - 'currency' => strtolower( $currency ), |
|
661 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
660 | + 'currency' => strtolower($currency), |
|
661 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
662 | 662 | ), |
663 | 663 | ); |
664 | 664 | |
665 | 665 | $data['order_data'] += $this->build_display_items(); |
666 | 666 | |
667 | - wp_send_json( $data ); |
|
667 | + wp_send_json($data); |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | /** |
@@ -675,47 +675,47 @@ discard block |
||
675 | 675 | * @see WC_Shipping::get_packages(). |
676 | 676 | */ |
677 | 677 | public function ajax_get_shipping_options() { |
678 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
678 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
679 | 679 | |
680 | 680 | try { |
681 | 681 | // Set the shipping package. |
682 | - $posted = filter_input_array( INPUT_POST, array( |
|
682 | + $posted = filter_input_array(INPUT_POST, array( |
|
683 | 683 | 'country' => FILTER_SANITIZE_STRING, |
684 | 684 | 'state' => FILTER_SANITIZE_STRING, |
685 | 685 | 'postcode' => FILTER_SANITIZE_STRING, |
686 | 686 | 'city' => FILTER_SANITIZE_STRING, |
687 | 687 | 'address' => FILTER_SANITIZE_STRING, |
688 | 688 | 'address_2' => FILTER_SANITIZE_STRING, |
689 | - ) ); |
|
689 | + )); |
|
690 | 690 | |
691 | - $this->calculate_shipping( $posted ); |
|
691 | + $this->calculate_shipping($posted); |
|
692 | 692 | |
693 | 693 | // Set the shipping options. |
694 | 694 | $data = array(); |
695 | 695 | $packages = WC()->shipping->get_packages(); |
696 | 696 | |
697 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
698 | - foreach ( $packages as $package_key => $package ) { |
|
699 | - if ( empty( $package['rates'] ) ) { |
|
700 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
697 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
698 | + foreach ($packages as $package_key => $package) { |
|
699 | + if (empty($package['rates'])) { |
|
700 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
701 | 701 | } |
702 | 702 | |
703 | - foreach ( $package['rates'] as $key => $rate ) { |
|
703 | + foreach ($package['rates'] as $key => $rate) { |
|
704 | 704 | $data['shipping_options'][] = array( |
705 | 705 | 'id' => $rate->id, |
706 | 706 | 'label' => $rate->label, |
707 | 707 | 'detail' => '', |
708 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
708 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
709 | 709 | ); |
710 | 710 | } |
711 | 711 | } |
712 | 712 | } else { |
713 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
713 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
714 | 714 | } |
715 | 715 | |
716 | - if ( isset( $data[0] ) ) { |
|
716 | + if (isset($data[0])) { |
|
717 | 717 | // Auto select the first shipping method. |
718 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
718 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
719 | 719 | } |
720 | 720 | |
721 | 721 | WC()->cart->calculate_totals(); |
@@ -723,12 +723,12 @@ discard block |
||
723 | 723 | $data += $this->build_display_items(); |
724 | 724 | $data['result'] = 'success'; |
725 | 725 | |
726 | - wp_send_json( $data ); |
|
727 | - } catch ( Exception $e ) { |
|
726 | + wp_send_json($data); |
|
727 | + } catch (Exception $e) { |
|
728 | 728 | $data += $this->build_display_items(); |
729 | 729 | $data['result'] = 'invalid_shipping_address'; |
730 | 730 | |
731 | - wp_send_json( $data ); |
|
731 | + wp_send_json($data); |
|
732 | 732 | } |
733 | 733 | } |
734 | 734 | |
@@ -736,22 +736,22 @@ discard block |
||
736 | 736 | * Update shipping method. |
737 | 737 | */ |
738 | 738 | public function ajax_update_shipping_method() { |
739 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
739 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
740 | 740 | |
741 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
742 | - define( 'WOOCOMMERCE_CART', true ); |
|
741 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
742 | + define('WOOCOMMERCE_CART', true); |
|
743 | 743 | } |
744 | 744 | |
745 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
746 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
745 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
746 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
747 | 747 | |
748 | - if ( is_array( $shipping_method ) ) { |
|
749 | - foreach ( $shipping_method as $i => $value ) { |
|
750 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
748 | + if (is_array($shipping_method)) { |
|
749 | + foreach ($shipping_method as $i => $value) { |
|
750 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
751 | 751 | } |
752 | 752 | } |
753 | 753 | |
754 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
754 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
755 | 755 | |
756 | 756 | WC()->cart->calculate_totals(); |
757 | 757 | |
@@ -759,7 +759,7 @@ discard block |
||
759 | 759 | $data += $this->build_display_items(); |
760 | 760 | $data['result'] = 'success'; |
761 | 761 | |
762 | - wp_send_json( $data ); |
|
762 | + wp_send_json($data); |
|
763 | 763 | } |
764 | 764 | |
765 | 765 | /** |
@@ -770,31 +770,31 @@ discard block |
||
770 | 770 | * @return array $data |
771 | 771 | */ |
772 | 772 | public function ajax_get_selected_product_data() { |
773 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
773 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
774 | 774 | |
775 | - $product_id = absint( $_POST['product_id'] ); |
|
776 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
775 | + $product_id = absint($_POST['product_id']); |
|
776 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
777 | 777 | |
778 | - $product = wc_get_product( $product_id ); |
|
778 | + $product = wc_get_product($product_id); |
|
779 | 779 | |
780 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
781 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
780 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
781 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
782 | 782 | |
783 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
784 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
783 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
784 | + $variation_id = $product->get_matching_variation($attributes); |
|
785 | 785 | } else { |
786 | - $data_store = WC_Data_Store::load( 'product' ); |
|
787 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
786 | + $data_store = WC_Data_Store::load('product'); |
|
787 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
788 | 788 | } |
789 | 789 | |
790 | - if ( ! empty( $variation_id ) ) { |
|
791 | - $product = wc_get_product( $variation_id ); |
|
790 | + if ( ! empty($variation_id)) { |
|
791 | + $product = wc_get_product($variation_id); |
|
792 | 792 | } |
793 | - } elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
794 | - $product = wc_get_product( $product_id ); |
|
793 | + } elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
794 | + $product = wc_get_product($product_id); |
|
795 | 795 | } |
796 | 796 | |
797 | - $total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ); |
|
797 | + $total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()); |
|
798 | 798 | |
799 | 799 | $quantity_label = 1 < $qty ? ' (x' . $qty . ')' : ''; |
800 | 800 | |
@@ -802,28 +802,28 @@ discard block |
||
802 | 802 | $items = array(); |
803 | 803 | |
804 | 804 | $items[] = array( |
805 | - 'label' => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label, |
|
806 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
805 | + 'label' => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label, |
|
806 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
807 | 807 | ); |
808 | 808 | |
809 | - if ( wc_tax_enabled() ) { |
|
809 | + if (wc_tax_enabled()) { |
|
810 | 810 | $items[] = array( |
811 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
811 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
812 | 812 | 'amount' => 0, |
813 | 813 | 'pending' => true, |
814 | 814 | ); |
815 | 815 | } |
816 | 816 | |
817 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
817 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
818 | 818 | $items[] = array( |
819 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
819 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
820 | 820 | 'amount' => 0, |
821 | 821 | 'pending' => true, |
822 | 822 | ); |
823 | 823 | |
824 | - $data['shippingOptions'] = array( |
|
824 | + $data['shippingOptions'] = array( |
|
825 | 825 | 'id' => 'pending', |
826 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
826 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
827 | 827 | 'detail' => '', |
828 | 828 | 'amount' => 0, |
829 | 829 | ); |
@@ -832,15 +832,15 @@ discard block |
||
832 | 832 | $data['displayItems'] = $items; |
833 | 833 | $data['total'] = array( |
834 | 834 | 'label' => $this->total_label, |
835 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
835 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
836 | 836 | 'pending' => true, |
837 | 837 | ); |
838 | 838 | |
839 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
840 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
841 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
839 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
840 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
841 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
842 | 842 | |
843 | - wp_send_json( $data ); |
|
843 | + wp_send_json($data); |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | /** |
@@ -851,37 +851,37 @@ discard block |
||
851 | 851 | * @return array $data |
852 | 852 | */ |
853 | 853 | public function ajax_add_to_cart() { |
854 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
854 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
855 | 855 | |
856 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
857 | - define( 'WOOCOMMERCE_CART', true ); |
|
856 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
857 | + define('WOOCOMMERCE_CART', true); |
|
858 | 858 | } |
859 | 859 | |
860 | 860 | WC()->shipping->reset_shipping(); |
861 | 861 | |
862 | - $product_id = absint( $_POST['product_id'] ); |
|
863 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
862 | + $product_id = absint($_POST['product_id']); |
|
863 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
864 | 864 | |
865 | - $product = wc_get_product( $product_id ); |
|
865 | + $product = wc_get_product($product_id); |
|
866 | 866 | |
867 | 867 | // First empty the cart to prevent wrong calculation. |
868 | 868 | WC()->cart->empty_cart(); |
869 | 869 | |
870 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
871 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
870 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
871 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
872 | 872 | |
873 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
874 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
873 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
874 | + $variation_id = $product->get_matching_variation($attributes); |
|
875 | 875 | } else { |
876 | - $data_store = WC_Data_Store::load( 'product' ); |
|
877 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
876 | + $data_store = WC_Data_Store::load('product'); |
|
877 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
878 | 878 | } |
879 | 879 | |
880 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
880 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
881 | 881 | } |
882 | 882 | |
883 | - if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
884 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
883 | + if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
884 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | WC()->cart->calculate_totals(); |
@@ -890,7 +890,7 @@ discard block |
||
890 | 890 | $data += $this->build_display_items(); |
891 | 891 | $data['result'] = 'success'; |
892 | 892 | |
893 | - wp_send_json( $data ); |
|
893 | + wp_send_json($data); |
|
894 | 894 | } |
895 | 895 | |
896 | 896 | /** |
@@ -903,31 +903,31 @@ discard block |
||
903 | 903 | * @version 4.0.0 |
904 | 904 | */ |
905 | 905 | public function normalize_state() { |
906 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
907 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
908 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
909 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
906 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
907 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
908 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
909 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
910 | 910 | |
911 | - if ( $billing_state && $billing_country ) { |
|
912 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
911 | + if ($billing_state && $billing_country) { |
|
912 | + $valid_states = WC()->countries->get_states($billing_country); |
|
913 | 913 | |
914 | 914 | // Valid states found for country. |
915 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
916 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
917 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
915 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
916 | + foreach ($valid_states as $state_abbr => $state) { |
|
917 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
918 | 918 | $_POST['billing_state'] = $state_abbr; |
919 | 919 | } |
920 | 920 | } |
921 | 921 | } |
922 | 922 | } |
923 | 923 | |
924 | - if ( $shipping_state && $shipping_country ) { |
|
925 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
924 | + if ($shipping_state && $shipping_country) { |
|
925 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
926 | 926 | |
927 | 927 | // Valid states found for country. |
928 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
929 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
930 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
928 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
929 | + foreach ($valid_states as $state_abbr => $state) { |
|
930 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
931 | 931 | $_POST['shipping_state'] = $state_abbr; |
932 | 932 | } |
933 | 933 | } |
@@ -942,19 +942,19 @@ discard block |
||
942 | 942 | * @version 4.0.0 |
943 | 943 | */ |
944 | 944 | public function ajax_create_order() { |
945 | - if ( WC()->cart->is_empty() ) { |
|
946 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
945 | + if (WC()->cart->is_empty()) { |
|
946 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
947 | 947 | } |
948 | 948 | |
949 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
950 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
949 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
950 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
951 | 951 | } |
952 | 952 | |
953 | 953 | $this->normalize_state(); |
954 | 954 | |
955 | 955 | WC()->checkout()->process_checkout(); |
956 | 956 | |
957 | - die( 0 ); |
|
957 | + die(0); |
|
958 | 958 | } |
959 | 959 | |
960 | 960 | /** |
@@ -964,7 +964,7 @@ discard block |
||
964 | 964 | * @version 4.0.0 |
965 | 965 | * @param array $address |
966 | 966 | */ |
967 | - protected function calculate_shipping( $address = array() ) { |
|
967 | + protected function calculate_shipping($address = array()) { |
|
968 | 968 | global $states; |
969 | 969 | |
970 | 970 | $country = $address['country']; |
@@ -981,28 +981,28 @@ discard block |
||
981 | 981 | * In some versions of Chrome, state can be a full name. So we need |
982 | 982 | * to convert that to abbreviation as WC is expecting that. |
983 | 983 | */ |
984 | - if ( 2 < strlen( $state ) ) { |
|
985 | - $state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] ); |
|
984 | + if (2 < strlen($state)) { |
|
985 | + $state = array_search(ucfirst(strtolower($state)), $states[$country]); |
|
986 | 986 | } |
987 | 987 | |
988 | 988 | WC()->shipping->reset_shipping(); |
989 | 989 | |
990 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
991 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
990 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
991 | + $postcode = wc_format_postcode($postcode, $country); |
|
992 | 992 | } |
993 | 993 | |
994 | - if ( $country ) { |
|
995 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
996 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
994 | + if ($country) { |
|
995 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
996 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
997 | 997 | } else { |
998 | 998 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
999 | 999 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
1000 | 1000 | } |
1001 | 1001 | |
1002 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
1003 | - WC()->customer->calculated_shipping( true ); |
|
1002 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
1003 | + WC()->customer->calculated_shipping(true); |
|
1004 | 1004 | } else { |
1005 | - WC()->customer->set_calculated_shipping( true ); |
|
1005 | + WC()->customer->set_calculated_shipping(true); |
|
1006 | 1006 | WC()->customer->save(); |
1007 | 1007 | } |
1008 | 1008 | |
@@ -1019,17 +1019,17 @@ discard block |
||
1019 | 1019 | $packages[0]['destination']['address'] = $address_1; |
1020 | 1020 | $packages[0]['destination']['address_2'] = $address_2; |
1021 | 1021 | |
1022 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
1023 | - if ( $item['data']->needs_shipping() ) { |
|
1024 | - if ( isset( $item['line_total'] ) ) { |
|
1022 | + foreach (WC()->cart->get_cart() as $item) { |
|
1023 | + if ($item['data']->needs_shipping()) { |
|
1024 | + if (isset($item['line_total'])) { |
|
1025 | 1025 | $packages[0]['contents_cost'] += $item['line_total']; |
1026 | 1026 | } |
1027 | 1027 | } |
1028 | 1028 | } |
1029 | 1029 | |
1030 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
1030 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
1031 | 1031 | |
1032 | - WC()->shipping->calculate_shipping( $packages ); |
|
1032 | + WC()->shipping->calculate_shipping($packages); |
|
1033 | 1033 | } |
1034 | 1034 | |
1035 | 1035 | /** |
@@ -1038,19 +1038,19 @@ discard block |
||
1038 | 1038 | * @since 3.1.0 |
1039 | 1039 | * @version 4.0.0 |
1040 | 1040 | */ |
1041 | - protected function build_shipping_methods( $shipping_methods ) { |
|
1042 | - if ( empty( $shipping_methods ) ) { |
|
1041 | + protected function build_shipping_methods($shipping_methods) { |
|
1042 | + if (empty($shipping_methods)) { |
|
1043 | 1043 | return array(); |
1044 | 1044 | } |
1045 | 1045 | |
1046 | 1046 | $shipping = array(); |
1047 | 1047 | |
1048 | - foreach ( $shipping_methods as $method ) { |
|
1048 | + foreach ($shipping_methods as $method) { |
|
1049 | 1049 | $shipping[] = array( |
1050 | 1050 | 'id' => $method['id'], |
1051 | 1051 | 'label' => $method['label'], |
1052 | 1052 | 'detail' => '', |
1053 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
1053 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
1054 | 1054 | ); |
1055 | 1055 | } |
1056 | 1056 | |
@@ -1064,69 +1064,69 @@ discard block |
||
1064 | 1064 | * @version 4.0.0 |
1065 | 1065 | */ |
1066 | 1066 | protected function build_display_items() { |
1067 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
1068 | - define( 'WOOCOMMERCE_CART', true ); |
|
1067 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
1068 | + define('WOOCOMMERCE_CART', true); |
|
1069 | 1069 | } |
1070 | 1070 | |
1071 | 1071 | $items = array(); |
1072 | 1072 | $subtotal = 0; |
1073 | 1073 | |
1074 | 1074 | // Default show only subtotal instead of itemization. |
1075 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
1076 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
1075 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
1076 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
1077 | 1077 | $amount = $cart_item['line_subtotal']; |
1078 | - $subtotal += $cart_item['line_subtotal']; |
|
1078 | + $subtotal += $cart_item['line_subtotal']; |
|
1079 | 1079 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
1080 | 1080 | |
1081 | 1081 | $product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
1082 | 1082 | |
1083 | 1083 | $item = array( |
1084 | 1084 | 'label' => $product_name . $quantity_label, |
1085 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
1085 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
1086 | 1086 | ); |
1087 | 1087 | |
1088 | 1088 | $items[] = $item; |
1089 | 1089 | } |
1090 | 1090 | } |
1091 | 1091 | |
1092 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
1093 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
1094 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
1095 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
1096 | - $order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ); |
|
1092 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
1093 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
1094 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
1095 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
1096 | + $order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp); |
|
1097 | 1097 | |
1098 | - if ( wc_tax_enabled() ) { |
|
1098 | + if (wc_tax_enabled()) { |
|
1099 | 1099 | $items[] = array( |
1100 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
1101 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
1100 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
1101 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
1102 | 1102 | ); |
1103 | 1103 | } |
1104 | 1104 | |
1105 | - if ( WC()->cart->needs_shipping() ) { |
|
1105 | + if (WC()->cart->needs_shipping()) { |
|
1106 | 1106 | $items[] = array( |
1107 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
1108 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
1107 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
1108 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
1109 | 1109 | ); |
1110 | 1110 | } |
1111 | 1111 | |
1112 | - if ( WC()->cart->has_discount() ) { |
|
1112 | + if (WC()->cart->has_discount()) { |
|
1113 | 1113 | $items[] = array( |
1114 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
1115 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
1114 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
1115 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
1116 | 1116 | ); |
1117 | 1117 | } |
1118 | 1118 | |
1119 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
1119 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
1120 | 1120 | $cart_fees = WC()->cart->fees; |
1121 | 1121 | } else { |
1122 | 1122 | $cart_fees = WC()->cart->get_fees(); |
1123 | 1123 | } |
1124 | 1124 | |
1125 | 1125 | // Include fees and taxes as display items. |
1126 | - foreach ( $cart_fees as $key => $fee ) { |
|
1126 | + foreach ($cart_fees as $key => $fee) { |
|
1127 | 1127 | $items[] = array( |
1128 | 1128 | 'label' => $fee->name, |
1129 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
1129 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
1130 | 1130 | ); |
1131 | 1131 | } |
1132 | 1132 | |
@@ -1134,7 +1134,7 @@ discard block |
||
1134 | 1134 | 'displayItems' => $items, |
1135 | 1135 | 'total' => array( |
1136 | 1136 | 'label' => $this->total_label, |
1137 | - 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
1137 | + 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
1138 | 1138 | 'pending' => false, |
1139 | 1139 | ), |
1140 | 1140 | ); |
@@ -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( get_current_user_id(), $force_save_source ); |
|
371 | + $prepared_source = $this->prepare_source(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( $prepared_source->source ) ); |
|
383 | + $this->save_instructions($order, $this->get_source_object($prepared_source->source)); |
|
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( |