Completed
Push — master ( ca4b93...bb9186 )
by Roy
07:44
created
includes/admin/stripe-p24-settings.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -1,46 +1,46 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
6 6
 $webhook_url = WC_Stripe_Helper::get_webhook_url();
7 7
 
8
-return apply_filters( 'wc_stripe_p24_settings',
8
+return apply_filters('wc_stripe_p24_settings',
9 9
 	array(
10 10
 		'geo_target' => array(
11
-			'description' => __( 'Relevant Payer Geography: Poland', 'woocommerce-gateway-stripe' ),
11
+			'description' => __('Relevant Payer Geography: Poland', 'woocommerce-gateway-stripe'),
12 12
 			'type'        => 'title',
13 13
 		),
14 14
 		'activation' => array(
15
-			'description' => __( 'Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe' ),
15
+			'description' => __('Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe'),
16 16
 			'type'   => 'title',
17 17
 		),
18 18
 		'enabled' => array(
19
-			'title'       => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ),
20
-			'label'       => __( 'Enable Stripe P24', 'woocommerce-gateway-stripe' ),
19
+			'title'       => __('Enable/Disable', 'woocommerce-gateway-stripe'),
20
+			'label'       => __('Enable Stripe P24', 'woocommerce-gateway-stripe'),
21 21
 			'type'        => 'checkbox',
22 22
 			'description' => '',
23 23
 			'default'     => 'no',
24 24
 		),
25 25
 		'title' => array(
26
-			'title'       => __( 'Title', 'woocommerce-gateway-stripe' ),
26
+			'title'       => __('Title', 'woocommerce-gateway-stripe'),
27 27
 			'type'        => 'text',
28
-			'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
29
-			'default'     => __( 'Przelewy24 (P24)', 'woocommerce-gateway-stripe' ),
28
+			'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'),
29
+			'default'     => __('Przelewy24 (P24)', 'woocommerce-gateway-stripe'),
30 30
 			'desc_tip'    => true,
31 31
 		),
32 32
 		'description' => array(
33
-			'title'       => __( 'Description', 'woocommerce-gateway-stripe' ),
33
+			'title'       => __('Description', 'woocommerce-gateway-stripe'),
34 34
 			'type'        => 'text',
35
-			'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
36
-			'default'     => __( 'You will be redirected to P24.', 'woocommerce-gateway-stripe' ),
35
+			'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'),
36
+			'default'     => __('You will be redirected to P24.', 'woocommerce-gateway-stripe'),
37 37
 			'desc_tip'    => true,
38 38
 		),
39 39
 		'webhook' => array(
40
-			'title'       => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ),
40
+			'title'       => __('Webhook Endpoints', 'woocommerce-gateway-stripe'),
41 41
 			'type'        => 'title',
42 42
 			/* translators: webhook URL */
43
-			'description' => sprintf( __( 'You must add the webhook endpoint <strong style="background-color:#ddd;">&nbsp;&nbsp;%s&nbsp;&nbsp;</strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe' ), $webhook_url ),
43
+			'description' => sprintf(__('You must add the webhook endpoint <strong style="background-color:#ddd;">&nbsp;&nbsp;%s&nbsp;&nbsp;</strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe'), $webhook_url),
44 44
 		),
45 45
 	)
46 46
 );
Please login to merge, or discard this patch.
tests/phpunit/test-wc-stripe.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -2,12 +2,12 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,27 +76,27 @@  discard block
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
tests/phpunit/bootstrap.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -1,14 +1,14 @@  discard block
 block discarded – undo
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
 }
@@ -17,20 +17,20 @@  discard block
 block discarded – undo
17 17
 	return true;
18 18
 }
19 19
 
20
-function woothemes_queue_update( $file, $file_id, $product_id ) {
20
+function woothemes_queue_update($file, $file_id, $product_id) {
21 21
 	return true;
22 22
 }
23 23
 
24
-tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
24
+tests_add_filter('muplugins_loaded', '_manually_load_plugin');
25 25
 
26 26
 require $_tests_dir . '/includes/bootstrap.php';
27 27
 
28
-$wc_tests_framework_base_dir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/woocommerce/tests/framework/';
29
-require_once( $wc_tests_framework_base_dir . 'class-wc-mock-session-handler.php' );
30
-require_once( $wc_tests_framework_base_dir . 'class-wc-unit-test-case.php' );
31
-require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-product.php' );
32
-require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-coupon.php' );
33
-require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-fee.php' );
34
-require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-shipping.php' );
35
-require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-customer.php' );
36
-require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-order.php' );
28
+$wc_tests_framework_base_dir = dirname(dirname(dirname(dirname(__FILE__)))) . '/woocommerce/tests/framework/';
29
+require_once($wc_tests_framework_base_dir . 'class-wc-mock-session-handler.php');
30
+require_once($wc_tests_framework_base_dir . 'class-wc-unit-test-case.php');
31
+require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-product.php');
32
+require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-coupon.php');
33
+require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-fee.php');
34
+require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-shipping.php');
35
+require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-customer.php');
36
+require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-order.php');
Please login to merge, or discard this patch.
uninstall.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit; // Exit if accessed directly
4 4
 }
5 5
 
6 6
 // if uninstall not called from WordPress exit
7
-if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
7
+if ( ! defined('WP_UNINSTALL_PLUGIN')) {
8 8
 	exit;
9 9
 }
10 10
 
@@ -13,20 +13,20 @@  discard block
 block discarded – undo
13 13
  * wp-config.php. This is to prevent data loss when deleting the plugin from the backend
14 14
  * and to ensure only the site owner can perform this action.
15 15
  */
16
-if ( defined( 'WC_REMOVE_ALL_DATA' ) && true === WC_REMOVE_ALL_DATA ) {
16
+if (defined('WC_REMOVE_ALL_DATA') && true === WC_REMOVE_ALL_DATA) {
17 17
 	// Delete options.
18
-	delete_option( 'woocommerce_stripe_settings' );
19
-	delete_option( 'wc_stripe_show_request_api_notice' );
20
-	delete_option( 'wc_stripe_show_apple_pay_notice' );
21
-	delete_option( 'wc_stripe_show_ssl_notice' );
22
-	delete_option( 'wc_stripe_show_keys_notice' );
23
-	delete_option( 'wc_stripe_version' );
24
-	delete_option( 'woocommerce_stripe_bancontact_settings' );
25
-	delete_option( 'woocommerce_stripe_alipay_settings' );
26
-	delete_option( 'woocommerce_stripe_bitcoin_settings' );
27
-	delete_option( 'woocommerce_stripe_ideal_settings' );
28
-	delete_option( 'woocommerce_stripe_p24_settings' );
29
-	delete_option( 'woocommerce_stripe_giropay_settings' );
30
-	delete_option( 'woocommerce_stripe_sepa_settings' );
31
-	delete_option( 'woocommerce_stripe_sofort_settings' );
18
+	delete_option('woocommerce_stripe_settings');
19
+	delete_option('wc_stripe_show_request_api_notice');
20
+	delete_option('wc_stripe_show_apple_pay_notice');
21
+	delete_option('wc_stripe_show_ssl_notice');
22
+	delete_option('wc_stripe_show_keys_notice');
23
+	delete_option('wc_stripe_version');
24
+	delete_option('woocommerce_stripe_bancontact_settings');
25
+	delete_option('woocommerce_stripe_alipay_settings');
26
+	delete_option('woocommerce_stripe_bitcoin_settings');
27
+	delete_option('woocommerce_stripe_ideal_settings');
28
+	delete_option('woocommerce_stripe_p24_settings');
29
+	delete_option('woocommerce_stripe_giropay_settings');
30
+	delete_option('woocommerce_stripe_sepa_settings');
31
+	delete_option('woocommerce_stripe_sofort_settings');
32 32
 }
Please login to merge, or discard this patch.
includes/deprecated/class-wc-stripe-apple-pay.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
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
 block discarded – undo
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." );
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.");
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
 	}
Please login to merge, or discard this patch.
includes/class-wc-stripe-exception.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  * @since 4.0.2
8 8
  */
9 9
 
10
-if ( ! defined( 'ABSPATH' ) ) {
10
+if ( ! defined('ABSPATH')) {
11 11
 	exit; // Exit if accessed directly
12 12
 }
13 13
 
@@ -23,9 +23,9 @@  discard block
 block discarded – undo
23 23
 	 * @param string $error_message Full response
24 24
 	 * @param string $localized_message user-friendly translated error message
25 25
 	 */
26
-	public function __construct( $error_message = '', $localized_message = '' ) {
26
+	public function __construct($error_message = '', $localized_message = '') {
27 27
 		$this->localized_message = $localized_message;
28
-		parent::__construct( $error_message );
28
+		parent::__construct($error_message);
29 29
 	}
30 30
 
31 31
 	/**
Please login to merge, or discard this patch.
includes/class-wc-stripe-helper.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -17,15 +17,15 @@  discard block
 block discarded – undo
17 17
 	 *
18 18
 	 * @return float|int
19 19
 	 */
20
-	public static function get_stripe_amount( $total, $currency = '' ) {
21
-		if ( ! $currency ) {
20
+	public static function get_stripe_amount($total, $currency = '') {
21
+		if ( ! $currency) {
22 22
 			$currency = get_woocommerce_currency();
23 23
 		}
24 24
 
25
-		if ( in_array( strtolower( $currency ), self::no_decimal_currencies() ) ) {
26
-			return absint( $total );
25
+		if (in_array(strtolower($currency), self::no_decimal_currencies())) {
26
+			return absint($total);
27 27
 		} else {
28
-			return absint( wc_format_decimal( ( (float) $total * 100 ), wc_get_price_decimals() ) ); // In cents.
28
+			return absint(wc_format_decimal(((float) $total * 100), wc_get_price_decimals())); // In cents.
29 29
 		}
30 30
 	}
31 31
 
@@ -37,25 +37,25 @@  discard block
 block discarded – undo
37 37
 	 * @return array
38 38
 	 */
39 39
 	public static function get_localized_messages() {
40
-		return apply_filters( 'wc_stripe_localized_messages', array(
41
-			'invalid_number'           => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ),
42
-			'invalid_expiry_month'     => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ),
43
-			'invalid_expiry_year'      => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ),
44
-			'invalid_cvc'              => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ),
45
-			'incorrect_number'         => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ),
46
-			'incomplete_number'        => __( 'The card number is incomplete.', 'woocommerce-gateway-stripe' ),
47
-			'incomplete_cvc'           => __( 'The card\'s security code is incomplete.', 'woocommerce-gateway-stripe' ),
48
-			'incomplete_expiry'        => __( 'The card\'s expiration date is incomplete.', 'woocommerce-gateway-stripe' ),
49
-			'expired_card'             => __( 'The card has expired.', 'woocommerce-gateway-stripe' ),
50
-			'incorrect_cvc'            => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ),
51
-			'incorrect_zip'            => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ),
52
-			'invalid_expiry_year_past' => __( 'The card\'s expiration year is in the past', 'woocommerce-gateway-stripe' ),
53
-			'card_declined'            => __( 'The card was declined.', 'woocommerce-gateway-stripe' ),
54
-			'missing'                  => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ),
55
-			'processing_error'         => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ),
56
-			'invalid_request_error'    => __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ),
57
-			'invalid_sofort_country'   => __( 'The billing country is not accepted by SOFORT. Please try another country.', 'woocommerce-gateway-stripe' ),
58
-		) );
40
+		return apply_filters('wc_stripe_localized_messages', array(
41
+			'invalid_number'           => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'),
42
+			'invalid_expiry_month'     => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'),
43
+			'invalid_expiry_year'      => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'),
44
+			'invalid_cvc'              => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'),
45
+			'incorrect_number'         => __('The card number is incorrect.', 'woocommerce-gateway-stripe'),
46
+			'incomplete_number'        => __('The card number is incomplete.', 'woocommerce-gateway-stripe'),
47
+			'incomplete_cvc'           => __('The card\'s security code is incomplete.', 'woocommerce-gateway-stripe'),
48
+			'incomplete_expiry'        => __('The card\'s expiration date is incomplete.', 'woocommerce-gateway-stripe'),
49
+			'expired_card'             => __('The card has expired.', 'woocommerce-gateway-stripe'),
50
+			'incorrect_cvc'            => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'),
51
+			'incorrect_zip'            => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'),
52
+			'invalid_expiry_year_past' => __('The card\'s expiration year is in the past', 'woocommerce-gateway-stripe'),
53
+			'card_declined'            => __('The card was declined.', 'woocommerce-gateway-stripe'),
54
+			'missing'                  => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'),
55
+			'processing_error'         => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'),
56
+			'invalid_request_error'    => __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe'),
57
+			'invalid_sofort_country'   => __('The billing country is not accepted by SOFORT. Please try another country.', 'woocommerce-gateway-stripe'),
58
+		));
59 59
 	}
60 60
 
61 61
 	/**
@@ -92,24 +92,24 @@  discard block
 block discarded – undo
92 92
 	 * @param string $type Type of number to format
93 93
 	 * @return string
94 94
 	 */
95
-	public static function format_balance_fee( $balance_transaction, $type = 'fee' ) {
96
-		if ( ! is_object( $balance_transaction ) ) {
95
+	public static function format_balance_fee($balance_transaction, $type = 'fee') {
96
+		if ( ! is_object($balance_transaction)) {
97 97
 			return;
98 98
 		}
99 99
 
100
-		if ( in_array( strtolower( $balance_transaction->currency ), self::no_decimal_currencies() ) ) {
101
-			if ( 'fee' === $type ) {
100
+		if (in_array(strtolower($balance_transaction->currency), self::no_decimal_currencies())) {
101
+			if ('fee' === $type) {
102 102
 				return $balance_transaction->fee;
103 103
 			}
104 104
 
105 105
 			return $balance_transaction->net;
106 106
 		}
107 107
 
108
-		if ( 'fee' === $type ) {
109
-			return number_format( $balance_transaction->fee / 100, 2, '.', '' );
108
+		if ('fee' === $type) {
109
+			return number_format($balance_transaction->fee / 100, 2, '.', '');
110 110
 		}
111 111
 
112
-		return number_format( $balance_transaction->net / 100, 2, '.', '' );
112
+		return number_format($balance_transaction->net / 100, 2, '.', '');
113 113
 	}
114 114
 
115 115
 	/**
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 	 */
118 118
 	public static function get_minimum_amount() {
119 119
 		// Check order amount
120
-		switch ( get_woocommerce_currency() ) {
120
+		switch (get_woocommerce_currency()) {
121 121
 			case 'USD':
122 122
 			case 'CAD':
123 123
 			case 'EUR':
@@ -162,14 +162,14 @@  discard block
 block discarded – undo
162 162
 	 * @param string $method The payment method to get the settings from.
163 163
 	 * @param string $setting The name of the setting to get.
164 164
 	 */
165
-	public static function get_settings( $method = null, $setting = null ) {
166
-		$all_settings = null === $method ? get_option( 'woocommerce_stripe_settings', array() ) : get_option( 'woocommerce_stripe_' . $method . '_settings', array() );
165
+	public static function get_settings($method = null, $setting = null) {
166
+		$all_settings = null === $method ? get_option('woocommerce_stripe_settings', array()) : get_option('woocommerce_stripe_' . $method . '_settings', array());
167 167
 
168
-		if ( null === $setting ) {
168
+		if (null === $setting) {
169 169
 			return $all_settings;
170 170
 		}
171 171
 
172
-		return isset( $all_settings[ $setting ] ) ? $all_settings[ $setting ] : '';
172
+		return isset($all_settings[$setting]) ? $all_settings[$setting] : '';
173 173
 	}
174 174
 
175 175
 	/**
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	 * @return bool
181 181
 	 */
182 182
 	public static function is_pre_30() {
183
-		return version_compare( WC_VERSION, '3.0.0', '<' );
183
+		return version_compare(WC_VERSION, '3.0.0', '<');
184 184
 	}
185 185
 
186 186
 	/**
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 	 * @return string
194 194
 	 */
195 195
 	public static function get_webhook_url() {
196
-		return add_query_arg( 'wc-api', 'wc_stripe', trailingslashit( get_home_url() ) );
196
+		return add_query_arg('wc-api', 'wc_stripe', trailingslashit(get_home_url()));
197 197
 	}
198 198
 
199 199
 	/**
@@ -203,13 +203,13 @@  discard block
 block discarded – undo
203 203
 	 * @version 4.0.0
204 204
 	 * @param string $source_id
205 205
 	 */
206
-	public static function get_order_by_source_id( $source_id ) {
206
+	public static function get_order_by_source_id($source_id) {
207 207
 		global $wpdb;
208 208
 
209
-		$order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $source_id ) );
209
+		$order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $source_id));
210 210
 
211
-		if ( ! empty( $order_id ) ) {
212
-			return wc_get_order( $order_id );
211
+		if ( ! empty($order_id)) {
212
+			return wc_get_order($order_id);
213 213
 		}
214 214
 
215 215
 		return false;
@@ -222,13 +222,13 @@  discard block
 block discarded – undo
222 222
 	 * @version 4.0.0
223 223
 	 * @param string $charge_id
224 224
 	 */
225
-	public static function get_order_by_charge_id( $charge_id ) {
225
+	public static function get_order_by_charge_id($charge_id) {
226 226
 		global $wpdb;
227 227
 
228
-		$order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $charge_id ) );
228
+		$order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $charge_id));
229 229
 
230
-		if ( ! empty( $order_id ) ) {
231
-			return wc_get_order( $order_id );
230
+		if ( ! empty($order_id)) {
231
+			return wc_get_order($order_id);
232 232
 		}
233 233
 
234 234
 		return false;
@@ -244,13 +244,13 @@  discard block
 block discarded – undo
244 244
 	 * @param string $statement_descriptor
245 245
 	 * @return string $statement_descriptor Sanitized statement descriptor
246 246
 	 */
247
-	public static function clean_statement_descriptor( $statement_descriptor = '' ) {
248
-		$disallowed_characters = array( '<', '>', '"', "'" );
247
+	public static function clean_statement_descriptor($statement_descriptor = '') {
248
+		$disallowed_characters = array('<', '>', '"', "'");
249 249
 
250 250
 		// Remove special characters.
251
-		$statement_descriptor = str_replace( $disallowed_characters, '', $statement_descriptor );
251
+		$statement_descriptor = str_replace($disallowed_characters, '', $statement_descriptor);
252 252
 
253
-		$statement_descriptor = substr( trim( $statement_descriptor ), 0, 22 );
253
+		$statement_descriptor = substr(trim($statement_descriptor), 0, 22);
254 254
 
255 255
 		return $statement_descriptor;
256 256
 	}
Please login to merge, or discard this patch.
includes/class-wc-stripe-customer.php 1 patch
Spacing   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -32,10 +32,10 @@  discard block
 block discarded – undo
32 32
 	 * Constructor
33 33
 	 * @param int $user_id The WP user ID
34 34
 	 */
35
-	public function __construct( $user_id = 0 ) {
36
-		if ( $user_id ) {
37
-			$this->set_user_id( $user_id );
38
-			$this->set_id( get_user_meta( $user_id, '_stripe_customer_id', true ) );
35
+	public function __construct($user_id = 0) {
36
+		if ($user_id) {
37
+			$this->set_user_id($user_id);
38
+			$this->set_id(get_user_meta($user_id, '_stripe_customer_id', true));
39 39
 		}
40 40
 	}
41 41
 
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
 	 * Set Stripe customer ID.
52 52
 	 * @param [type] $id [description]
53 53
 	 */
54
-	public function set_id( $id ) {
55
-		$this->id = wc_clean( $id );
54
+	public function set_id($id) {
55
+		$this->id = wc_clean($id);
56 56
 	}
57 57
 
58 58
 	/**
@@ -60,15 +60,15 @@  discard block
 block discarded – undo
60 60
 	 * @return int
61 61
 	 */
62 62
 	public function get_user_id() {
63
-		return absint( $this->user_id );
63
+		return absint($this->user_id);
64 64
 	}
65 65
 
66 66
 	/**
67 67
 	 * Set User ID used by WordPress.
68 68
 	 * @param int $user_id
69 69
 	 */
70
-	public function set_user_id( $user_id ) {
71
-		$this->user_id = absint( $user_id );
70
+	public function set_user_id($user_id) {
71
+		$this->user_id = absint($user_id);
72 72
 	}
73 73
 
74 74
 	/**
@@ -76,13 +76,13 @@  discard block
 block discarded – undo
76 76
 	 * @return WP_User
77 77
 	 */
78 78
 	protected function get_user() {
79
-		return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false;
79
+		return $this->get_user_id() ? get_user_by('id', $this->get_user_id()) : false;
80 80
 	}
81 81
 
82 82
 	/**
83 83
 	 * Store data from the Stripe API about this customer
84 84
 	 */
85
-	public function set_customer_data( $data ) {
85
+	public function set_customer_data($data) {
86 86
 		$this->customer_data = $data;
87 87
 	}
88 88
 
@@ -90,14 +90,14 @@  discard block
 block discarded – undo
90 90
 	 * Get data from the Stripe API about this customer
91 91
 	 */
92 92
 	public function get_customer_data() {
93
-		$this->customer_data = get_transient( 'stripe_customer_' . $this->get_id() );
93
+		$this->customer_data = get_transient('stripe_customer_' . $this->get_id());
94 94
 
95
-		if ( empty( $this->customer_data ) && $this->get_id() && false === $this->customer_data ) {
96
-			$response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() );
95
+		if (empty($this->customer_data) && $this->get_id() && false === $this->customer_data) {
96
+			$response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id());
97 97
 
98
-			if ( empty( $response->error ) ) {
99
-				$this->set_customer_data( $response );
100
-				set_transient( 'stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48 );
98
+			if (empty($response->error)) {
99
+				$this->set_customer_data($response);
100
+				set_transient('stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48);
101 101
 			}
102 102
 		}
103 103
 
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 		$data   = $this->get_customer_data();
113 113
 		$source = '';
114 114
 
115
-		if ( $data ) {
115
+		if ($data) {
116 116
 			$source = $data->default_source;
117 117
 		}
118 118
 
@@ -124,13 +124,13 @@  discard block
 block discarded – undo
124 124
 	 * @param array $args
125 125
 	 * @return WP_Error|int
126 126
 	 */
127
-	public function create_customer( $args = array() ) {
128
-		$billing_email = isset( $_POST['billing_email'] ) ? filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL ) : '';
127
+	public function create_customer($args = array()) {
128
+		$billing_email = isset($_POST['billing_email']) ? filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL) : '';
129 129
 		$user = $this->get_user();
130 130
 
131
-		if ( $user ) {
132
-			$billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true );
133
-			$billing_last_name  = get_user_meta( $user->ID, 'billing_last_name', true );
131
+		if ($user) {
132
+			$billing_first_name = get_user_meta($user->ID, 'billing_first_name', true);
133
+			$billing_last_name  = get_user_meta($user->ID, 'billing_last_name', true);
134 134
 
135 135
 			$defaults = array(
136 136
 				'email'       => $user->user_email,
@@ -145,24 +145,24 @@  discard block
 block discarded – undo
145 145
 
146 146
 		$metadata = array();
147 147
 
148
-		$defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user );
148
+		$defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user);
149 149
 
150
-		$args     = wp_parse_args( $args, $defaults );
151
-		$response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' );
150
+		$args     = wp_parse_args($args, $defaults);
151
+		$response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers');
152 152
 
153
-		if ( ! empty( $response->error ) ) {
154
-			throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
153
+		if ( ! empty($response->error)) {
154
+			throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
155 155
 		}
156 156
 
157
-		$this->set_id( $response->id );
157
+		$this->set_id($response->id);
158 158
 		$this->clear_cache();
159
-		$this->set_customer_data( $response );
159
+		$this->set_customer_data($response);
160 160
 
161
-		if ( $this->get_user_id() ) {
162
-			update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id );
161
+		if ($this->get_user_id()) {
162
+			update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id);
163 163
 		}
164 164
 
165
-		do_action( 'woocommerce_stripe_add_customer', $args, $response );
165
+		do_action('woocommerce_stripe_add_customer', $args, $response);
166 166
 
167 167
 		return $response->id;
168 168
 	}
@@ -173,72 +173,72 @@  discard block
 block discarded – undo
173 173
 	 * @param bool $retry
174 174
 	 * @return WP_Error|int
175 175
 	 */
176
-	public function add_source( $source_id, $retry = true ) {
177
-		if ( ! $this->get_id() ) {
178
-			$this->set_id( $this->create_customer() );
176
+	public function add_source($source_id, $retry = true) {
177
+		if ( ! $this->get_id()) {
178
+			$this->set_id($this->create_customer());
179 179
 		}
180 180
 
181
-		$response = WC_Stripe_API::request( array(
181
+		$response = WC_Stripe_API::request(array(
182 182
 			'source' => $source_id,
183
-		), 'customers/' . $this->get_id() . '/sources' );
183
+		), 'customers/' . $this->get_id() . '/sources');
184 184
 
185
-		if ( ! empty( $response->error ) ) {
185
+		if ( ! empty($response->error)) {
186 186
 			// It is possible the WC user once was linked to a customer on Stripe
187 187
 			// but no longer exists. Instead of failing, lets try to create a
188 188
 			// new customer.
189
-			if ( preg_match( '/No such customer/i', $response->error->message ) ) {
190
-				delete_user_meta( $this->get_user_id(), '_stripe_customer_id' );
189
+			if (preg_match('/No such customer/i', $response->error->message)) {
190
+				delete_user_meta($this->get_user_id(), '_stripe_customer_id');
191 191
 				$this->create_customer();
192
-				return $this->add_source( $source_id, false );
192
+				return $this->add_source($source_id, false);
193 193
 			} else {
194 194
 				return $response;
195 195
 			}
196
-		} elseif ( empty( $response->id ) ) {
197
-			return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) );
196
+		} elseif (empty($response->id)) {
197
+			return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe'));
198 198
 		}
199 199
 
200 200
 		// Add token to WooCommerce.
201
-		if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) {
202
-			if ( ! empty( $response->type ) ) {
203
-				switch ( $response->type ) {
201
+		if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) {
202
+			if ( ! empty($response->type)) {
203
+				switch ($response->type) {
204 204
 					case 'alipay':
205 205
 						break;
206 206
 					case 'sepa_debit':
207 207
 						$wc_token = new WC_Payment_Token_SEPA();
208
-						$wc_token->set_token( $response->id );
209
-						$wc_token->set_gateway_id( 'stripe_sepa' );
210
-						$wc_token->set_last4( $response->sepa_debit->last4 );
208
+						$wc_token->set_token($response->id);
209
+						$wc_token->set_gateway_id('stripe_sepa');
210
+						$wc_token->set_last4($response->sepa_debit->last4);
211 211
 						break;
212 212
 					default:
213
-						if ( 'source' === $response->object && 'card' === $response->type ) {
213
+						if ('source' === $response->object && 'card' === $response->type) {
214 214
 							$wc_token = new WC_Payment_Token_CC();
215
-							$wc_token->set_token( $response->id );
216
-							$wc_token->set_gateway_id( 'stripe' );
217
-							$wc_token->set_card_type( strtolower( $response->card->brand ) );
218
-							$wc_token->set_last4( $response->card->last4 );
219
-							$wc_token->set_expiry_month( $response->card->exp_month );
220
-							$wc_token->set_expiry_year( $response->card->exp_year );
215
+							$wc_token->set_token($response->id);
216
+							$wc_token->set_gateway_id('stripe');
217
+							$wc_token->set_card_type(strtolower($response->card->brand));
218
+							$wc_token->set_last4($response->card->last4);
219
+							$wc_token->set_expiry_month($response->card->exp_month);
220
+							$wc_token->set_expiry_year($response->card->exp_year);
221 221
 						}
222 222
 						break;
223 223
 				}
224 224
 			} else {
225 225
 				// Legacy.
226 226
 				$wc_token = new WC_Payment_Token_CC();
227
-				$wc_token->set_token( $response->id );
228
-				$wc_token->set_gateway_id( 'stripe' );
229
-				$wc_token->set_card_type( strtolower( $response->brand ) );
230
-				$wc_token->set_last4( $response->last4 );
231
-				$wc_token->set_expiry_month( $response->exp_month );
232
-				$wc_token->set_expiry_year( $response->exp_year );
227
+				$wc_token->set_token($response->id);
228
+				$wc_token->set_gateway_id('stripe');
229
+				$wc_token->set_card_type(strtolower($response->brand));
230
+				$wc_token->set_last4($response->last4);
231
+				$wc_token->set_expiry_month($response->exp_month);
232
+				$wc_token->set_expiry_year($response->exp_year);
233 233
 			}
234 234
 
235
-			$wc_token->set_user_id( $this->get_user_id() );
235
+			$wc_token->set_user_id($this->get_user_id());
236 236
 			$wc_token->save();
237 237
 		}
238 238
 
239 239
 		$this->clear_cache();
240 240
 
241
-		do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id );
241
+		do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id);
242 242
 
243 243
 		return $response->id;
244 244
 	}
@@ -250,42 +250,42 @@  discard block
 block discarded – undo
250 250
 	 * @return array
251 251
 	 */
252 252
 	public function get_sources() {
253
-		if ( ! $this->get_id() ) {
253
+		if ( ! $this->get_id()) {
254 254
 			return array();
255 255
 		}
256 256
 
257
-		$sources = get_transient( 'stripe_sources_' . $this->get_id() );
257
+		$sources = get_transient('stripe_sources_' . $this->get_id());
258 258
 
259
-		$response = WC_Stripe_API::request( array(
259
+		$response = WC_Stripe_API::request(array(
260 260
 			'limit'       => 100,
261
-		), 'customers/' . $this->get_id() . '/sources', 'GET' );
261
+		), 'customers/' . $this->get_id() . '/sources', 'GET');
262 262
 
263
-		if ( ! empty( $response->error ) ) {
263
+		if ( ! empty($response->error)) {
264 264
 			return array();
265 265
 		}
266 266
 
267
-		if ( is_array( $response->data ) ) {
267
+		if (is_array($response->data)) {
268 268
 			$sources = $response->data;
269 269
 		}
270 270
 
271
-		return empty( $sources ) ? array() : $sources;
271
+		return empty($sources) ? array() : $sources;
272 272
 	}
273 273
 
274 274
 	/**
275 275
 	 * Delete a source from stripe.
276 276
 	 * @param string $source_id
277 277
 	 */
278
-	public function delete_source( $source_id ) {
279
-		if ( ! $this->get_id() ) {
278
+	public function delete_source($source_id) {
279
+		if ( ! $this->get_id()) {
280 280
 			return false;
281 281
 		}
282 282
 
283
-		$response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' );
283
+		$response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE');
284 284
 
285 285
 		$this->clear_cache();
286 286
 
287
-		if ( empty( $response->error ) ) {
288
-			do_action( 'wc_stripe_delete_source', $this->get_id(), $response );
287
+		if (empty($response->error)) {
288
+			do_action('wc_stripe_delete_source', $this->get_id(), $response);
289 289
 
290 290
 			return true;
291 291
 		}
@@ -297,15 +297,15 @@  discard block
 block discarded – undo
297 297
 	 * Set default source in Stripe
298 298
 	 * @param string $source_id
299 299
 	 */
300
-	public function set_default_source( $source_id ) {
301
-		$response = WC_Stripe_API::request( array(
302
-			'default_source' => sanitize_text_field( $source_id ),
303
-		), 'customers/' . $this->get_id(), 'POST' );
300
+	public function set_default_source($source_id) {
301
+		$response = WC_Stripe_API::request(array(
302
+			'default_source' => sanitize_text_field($source_id),
303
+		), 'customers/' . $this->get_id(), 'POST');
304 304
 
305 305
 		$this->clear_cache();
306 306
 
307
-		if ( empty( $response->error ) ) {
308
-			do_action( 'wc_stripe_set_default_source', $this->get_id(), $response );
307
+		if (empty($response->error)) {
308
+			do_action('wc_stripe_set_default_source', $this->get_id(), $response);
309 309
 
310 310
 			return true;
311 311
 		}
@@ -317,8 +317,8 @@  discard block
 block discarded – undo
317 317
 	 * Deletes caches for this users cards.
318 318
 	 */
319 319
 	public function clear_cache() {
320
-		delete_transient( 'stripe_sources_' . $this->get_id() );
321
-		delete_transient( 'stripe_customer_' . $this->get_id() );
320
+		delete_transient('stripe_sources_' . $this->get_id());
321
+		delete_transient('stripe_customer_' . $this->get_id());
322 322
 		$this->customer_data = array();
323 323
 	}
324 324
 }
Please login to merge, or discard this patch.
includes/class-wc-stripe-order-handler.php 1 patch
Spacing   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -20,12 +20,12 @@  discard block
 block discarded – undo
20 20
 	public function __construct() {
21 21
 		self::$_this = $this;
22 22
 
23
-		add_action( 'wp', array( $this, 'maybe_process_redirect_order' ) );
24
-		add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) );
25
-		add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) );
26
-		add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) );
27
-		add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) );
28
-		add_action( 'wc_ajax_wc_stripe_validate_checkout', array( $this, 'validate_checkout' ) );
23
+		add_action('wp', array($this, 'maybe_process_redirect_order'));
24
+		add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment'));
25
+		add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment'));
26
+		add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment'));
27
+		add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment'));
28
+		add_action('wc_ajax_wc_stripe_validate_checkout', array($this, 'validate_checkout'));
29 29
 	}
30 30
 
31 31
 	/**
@@ -46,25 +46,25 @@  discard block
 block discarded – undo
46 46
 	 * @since 4.0.0
47 47
 	 * @version 4.0.0
48 48
 	 */
49
-	public function process_redirect_payment( $order_id, $retry = true ) {
49
+	public function process_redirect_payment($order_id, $retry = true) {
50 50
 		try {
51
-			$source = wc_clean( $_GET['source'] );
51
+			$source = wc_clean($_GET['source']);
52 52
 
53
-			if ( empty( $source ) ) {
53
+			if (empty($source)) {
54 54
 				return;
55 55
 			}
56 56
 
57
-			if ( empty( $order_id ) ) {
57
+			if (empty($order_id)) {
58 58
 				return;
59 59
 			}
60 60
 
61
-			$order = wc_get_order( $order_id );
61
+			$order = wc_get_order($order_id);
62 62
 
63
-			if ( ! is_object( $order ) ) {
63
+			if ( ! is_object($order)) {
64 64
 				return;
65 65
 			}
66 66
 
67
-			if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status() ) {
67
+			if ('processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status()) {
68 68
 				return;
69 69
 			}
70 70
 
@@ -72,108 +72,108 @@  discard block
 block discarded – undo
72 72
 			$response = null;
73 73
 
74 74
 			// This will throw exception if not valid.
75
-			$this->validate_minimum_order_amount( $order );
75
+			$this->validate_minimum_order_amount($order);
76 76
 
77
-			WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
77
+			WC_Stripe_Logger::log("Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}");
78 78
 
79 79
 			/**
80 80
 			 * First check if the source is chargeable at this time. If not,
81 81
 			 * webhook will take care of it later.
82 82
 			 */
83
-			$source_info = WC_Stripe_API::retrieve( 'sources/' . $source );
83
+			$source_info = WC_Stripe_API::retrieve('sources/' . $source);
84 84
 
85
-			if ( ! empty( $source_info->error ) ) {
86
-				throw new WC_Stripe_Exception( print_r( $source_info, true ), $source_info->error->message );
85
+			if ( ! empty($source_info->error)) {
86
+				throw new WC_Stripe_Exception(print_r($source_info, true), $source_info->error->message);
87 87
 			}
88 88
 
89
-			if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) {
90
-				throw new WC_Stripe_Exception( print_r( $source_info, true ), __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ) );
89
+			if ('failed' === $source_info->status || 'canceled' === $source_info->status) {
90
+				throw new WC_Stripe_Exception(print_r($source_info, true), __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe'));
91 91
 			}
92 92
 
93 93
 			// If already consumed, then ignore request.
94
-			if ( 'consumed' === $source_info->status ) {
94
+			if ('consumed' === $source_info->status) {
95 95
 				return;
96 96
 			}
97 97
 
98 98
 			// If not chargeable, then ignore request.
99
-			if ( 'chargeable' !== $source_info->status ) {
99
+			if ('chargeable' !== $source_info->status) {
100 100
 				return;
101 101
 			}
102 102
 
103 103
 			// Prep source object.
104 104
 			$source_object           = new stdClass();
105 105
 			$source_object->token_id = '';
106
-			$source_object->customer = $this->get_stripe_customer_id( $order );
106
+			$source_object->customer = $this->get_stripe_customer_id($order);
107 107
 			$source_object->source   = $source_info->id;
108 108
 
109 109
 			// Make the request.
110
-			$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) );
110
+			$response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object));
111 111
 
112
-			if ( ! empty( $response->error ) ) {
112
+			if ( ! empty($response->error)) {
113 113
 				// If it is an API error such connection or server, let's retry.
114
-				if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) {
115
-					if ( $retry ) {
116
-						sleep( 5 );
117
-						return $this->process_redirect_payment( $order_id, false );
114
+				if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) {
115
+					if ($retry) {
116
+						sleep(5);
117
+						return $this->process_redirect_payment($order_id, false);
118 118
 					} else {
119 119
 						$message = 'API connection error and retries exhausted.';
120
-						$order->add_order_note( $message );
121
-						throw new WC_Stripe_Exception( print_r( $response, true ), $message );
120
+						$order->add_order_note($message);
121
+						throw new WC_Stripe_Exception(print_r($response, true), $message);
122 122
 					}
123 123
 				}
124 124
 
125 125
 				// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
126
-				if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) {
127
-					if ( WC_Stripe_Helper::is_pre_30() ) {
128
-						delete_user_meta( $order->customer_user, '_stripe_customer_id' );
129
-						delete_post_meta( $order_id, '_stripe_customer_id' );
126
+				if (preg_match('/No such customer/i', $response->error->message) && $retry) {
127
+					if (WC_Stripe_Helper::is_pre_30()) {
128
+						delete_user_meta($order->customer_user, '_stripe_customer_id');
129
+						delete_post_meta($order_id, '_stripe_customer_id');
130 130
 					} else {
131
-						delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' );
132
-						$order->delete_meta_data( '_stripe_customer_id' );
131
+						delete_user_meta($order->get_customer_id(), '_stripe_customer_id');
132
+						$order->delete_meta_data('_stripe_customer_id');
133 133
 						$order->save();
134 134
 					}
135 135
 
136
-					return $this->process_redirect_payment( $order_id, false );
136
+					return $this->process_redirect_payment($order_id, false);
137 137
 
138
-				} elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) {
138
+				} elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) {
139 139
 					// Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message.
140 140
 
141
-					$wc_token = WC_Payment_Tokens::get( $source_object->token_id );
141
+					$wc_token = WC_Payment_Tokens::get($source_object->token_id);
142 142
 					$wc_token->delete();
143
-					$message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' );
144
-					$order->add_order_note( $message );
145
-					throw new WC_Stripe_Exception( print_r( $response, true ), $message );
143
+					$message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe');
144
+					$order->add_order_note($message);
145
+					throw new WC_Stripe_Exception(print_r($response, true), $message);
146 146
 				}
147 147
 
148 148
 				$localized_messages = WC_Stripe_Helper::get_localized_messages();
149 149
 
150
-				if ( 'card_error' === $response->error->type ) {
151
-					$message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message;
150
+				if ('card_error' === $response->error->type) {
151
+					$message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message;
152 152
 				} else {
153
-					$message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message;
153
+					$message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message;
154 154
 				}
155 155
 
156
-				throw new WC_Stripe_Exception( print_r( $response, true ), $message );
156
+				throw new WC_Stripe_Exception(print_r($response, true), $message);
157 157
 			}
158 158
 
159
-			do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order );
159
+			do_action('wc_gateway_stripe_process_redirect_payment', $response, $order);
160 160
 
161
-			$this->process_response( $response, $order );
161
+			$this->process_response($response, $order);
162 162
 
163
-		} catch ( WC_Stripe_Exception $e ) {
164
-			WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() );
163
+		} catch (WC_Stripe_Exception $e) {
164
+			WC_Stripe_Logger::log('Error: ' . $e->getMessage());
165 165
 
166
-			do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order );
166
+			do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order);
167 167
 
168 168
 			/* translators: error message */
169
-			$order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ) );
169
+			$order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage()));
170 170
 
171
-			if ( $order->has_status( array( 'pending', 'failed' ) ) ) {
172
-				$this->send_failed_order_email( $order_id );
171
+			if ($order->has_status(array('pending', 'failed'))) {
172
+				$this->send_failed_order_email($order_id);
173 173
 			}
174 174
 
175
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
176
-			wp_safe_redirect( wc_get_checkout_url() );
175
+			wc_add_notice($e->getLocalizedMessage(), 'error');
176
+			wp_safe_redirect(wc_get_checkout_url());
177 177
 			exit;
178 178
 		}
179 179
 	}
@@ -185,13 +185,13 @@  discard block
 block discarded – undo
185 185
 	 * @version 4.0.0
186 186
 	 */
187 187
 	public function maybe_process_redirect_order() {
188
-		if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) {
188
+		if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) {
189 189
 			return;
190 190
 		}
191 191
 
192
-		$order_id = wc_clean( $_GET['order_id'] );
192
+		$order_id = wc_clean($_GET['order_id']);
193 193
 
194
-		$this->process_redirect_payment( $order_id );
194
+		$this->process_redirect_payment($order_id);
195 195
 	}
196 196
 
197 197
 	/**
@@ -201,52 +201,52 @@  discard block
 block discarded – undo
201 201
 	 * @version 4.0.0
202 202
 	 * @param  int $order_id
203 203
 	 */
204
-	public function capture_payment( $order_id ) {
205
-		$order = wc_get_order( $order_id );
204
+	public function capture_payment($order_id) {
205
+		$order = wc_get_order($order_id);
206 206
 
207
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
208
-			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
209
-			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true );
207
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
208
+			$charge   = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
209
+			$captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true);
210 210
 
211
-			if ( $charge && 'no' === $captured ) {
211
+			if ($charge && 'no' === $captured) {
212 212
 				$order_total = $order->get_total();
213 213
 
214
-				if ( 0 < $order->get_total_refunded() ) {
214
+				if (0 < $order->get_total_refunded()) {
215 215
 					$order_total = $order_total - $order->get_total_refunded();
216 216
 				}
217 217
 
218
-				$result = WC_Stripe_API::request( array(
219
-					'amount'   => WC_Stripe_Helper::get_stripe_amount( $order_total ),
218
+				$result = WC_Stripe_API::request(array(
219
+					'amount'   => WC_Stripe_Helper::get_stripe_amount($order_total),
220 220
 					'expand[]' => 'balance_transaction',
221
-				), 'charges/' . $charge . '/capture' );
221
+				), 'charges/' . $charge . '/capture');
222 222
 
223
-				if ( ! empty( $result->error ) ) {
223
+				if ( ! empty($result->error)) {
224 224
 					/* translators: error message */
225
-					$order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) );
225
+					$order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message));
226 226
 				} else {
227 227
 					/* translators: transaction id */
228
-					$order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
229
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' );
228
+					$order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
229
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes');
230 230
 
231 231
 					// Store other data such as fees
232
-					WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id );
232
+					WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id);
233 233
 
234
-					if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) {
234
+					if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) {
235 235
 						// Fees and Net needs to both come from Stripe to be accurate as the returned
236 236
 						// values are in the local currency of the Stripe account, not from WC.
237
-						$fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'fee' ) : 0;
238
-						$net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'net' ) : 0;
239
-						WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_FEE, $fee ) : $order->update_meta_data( parent::META_NAME_FEE, $fee );
240
-						WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_NET, $net ) : $order->update_meta_data( parent::META_NAME_NET, $net );
237
+						$fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'fee') : 0;
238
+						$net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'net') : 0;
239
+						WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_FEE, $fee) : $order->update_meta_data(parent::META_NAME_FEE, $fee);
240
+						WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_NET, $net) : $order->update_meta_data(parent::META_NAME_NET, $net);
241 241
 					}
242 242
 
243
-					if ( is_callable( array( $order, 'save' ) ) ) {
243
+					if (is_callable(array($order, 'save'))) {
244 244
 						$order->save();
245 245
 					}
246 246
 				}
247 247
 
248 248
 				// This hook fires when admin manually changes order status to processing or completed.
249
-				do_action( 'woocommerce_stripe_process_manual_capture', $order, $result );
249
+				do_action('woocommerce_stripe_process_manual_capture', $order, $result);
250 250
 			}
251 251
 		}
252 252
 	}
@@ -258,32 +258,32 @@  discard block
 block discarded – undo
258 258
 	 * @version 4.0.0
259 259
 	 * @param  int $order_id
260 260
 	 */
261
-	public function cancel_payment( $order_id ) {
262
-		$order = wc_get_order( $order_id );
261
+	public function cancel_payment($order_id) {
262
+		$order = wc_get_order($order_id);
263 263
 
264
-		if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) {
265
-			$charge_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id();
264
+		if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) {
265
+			$charge_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id();
266 266
 
267
-			if ( $charge_id ) {
268
-				$result = WC_Stripe_API::request( array(
269
-					'amount' => WC_Stripe_Helper::get_stripe_amount( $order->get_total() ),
270
-				), 'charges/' . $charge_id . '/refund' );
267
+			if ($charge_id) {
268
+				$result = WC_Stripe_API::request(array(
269
+					'amount' => WC_Stripe_Helper::get_stripe_amount($order->get_total()),
270
+				), 'charges/' . $charge_id . '/refund');
271 271
 
272
-				if ( ! empty( $result->error ) ) {
273
-					$order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->error->message );
272
+				if ( ! empty($result->error)) {
273
+					$order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->error->message);
274 274
 				} else {
275 275
 					/* translators: transaction id */
276
-					$order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) );
277
-					WC_Stripe_Helper::is_pre_30() ? delete_post_meta( $order_id, '_stripe_charge_captured' ) : $order->delete_meta_data( '_stripe_charge_captured' );
278
-					WC_Stripe_Helper::is_pre_30() ? delete_post_meta( $order_id, '_transaction_id' ) : $order->delete_meta_data( '_stripe_transaction_id' );
276
+					$order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id));
277
+					WC_Stripe_Helper::is_pre_30() ? delete_post_meta($order_id, '_stripe_charge_captured') : $order->delete_meta_data('_stripe_charge_captured');
278
+					WC_Stripe_Helper::is_pre_30() ? delete_post_meta($order_id, '_transaction_id') : $order->delete_meta_data('_stripe_transaction_id');
279 279
 
280
-					if ( is_callable( array( $order, 'save' ) ) ) {
280
+					if (is_callable(array($order, 'save'))) {
281 281
 						$order->save();
282 282
 					}
283 283
 				}
284 284
 
285 285
 				// This hook fires when admin manually changes order status to cancel.
286
-				do_action( 'woocommerce_stripe_process_manual_cancel', $order, $result );
286
+				do_action('woocommerce_stripe_process_manual_cancel', $order, $result);
287 287
 			}
288 288
 		}
289 289
 	}
@@ -296,21 +296,21 @@  discard block
 block discarded – undo
296 296
 	 * @param string $field
297 297
 	 * @return string $error_field
298 298
 	 */
299
-	public function normalize_field( $field ) {
299
+	public function normalize_field($field) {
300 300
 		$checkout_fields = WC()->checkout->get_checkout_fields();
301 301
 		$org_str         = array();
302 302
 		$replace_str     = array();
303 303
 
304
-		if ( array_key_exists( $field, $checkout_fields['billing'] ) ) {
305
-			$error_field = __( 'Billing', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['billing'][ $field ]['label'];
306
-		} elseif ( array_key_exists( $field, $checkout_fields['shipping'] ) ) {
307
-			$error_field = __( 'Shipping', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['shipping'][ $field ]['label'];
308
-		} elseif ( array_key_exists( $field, $checkout_fields['order'] ) ) {
309
-			$error_field = $checkout_fields['order'][ $field ]['label'];
310
-		} elseif ( array_key_exists( $field, $checkout_fields['account'] ) ) {
311
-			$error_field = $checkout_fields['account'][ $field ]['label'];
304
+		if (array_key_exists($field, $checkout_fields['billing'])) {
305
+			$error_field = __('Billing', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['billing'][$field]['label'];
306
+		} elseif (array_key_exists($field, $checkout_fields['shipping'])) {
307
+			$error_field = __('Shipping', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['shipping'][$field]['label'];
308
+		} elseif (array_key_exists($field, $checkout_fields['order'])) {
309
+			$error_field = $checkout_fields['order'][$field]['label'];
310
+		} elseif (array_key_exists($field, $checkout_fields['account'])) {
311
+			$error_field = $checkout_fields['account'][$field]['label'];
312 312
 		} else {
313
-			$error_field = str_replace( '_', ' ', $field );
313
+			$error_field = str_replace('_', ' ', $field);
314 314
 
315 315
 			$org_str[]     = 'stripe';
316 316
 			$replace_str[] = '';
@@ -325,9 +325,9 @@  discard block
 block discarded – undo
325 325
 			$replace_str[] = 'SOFORT';
326 326
 
327 327
 			$org_str[]     = 'owner';
328
-			$replace_str[] = __( 'Owner', 'woocommerce-gateway-stripe' );
328
+			$replace_str[] = __('Owner', 'woocommerce-gateway-stripe');
329 329
 
330
-			$error_field   = str_replace( $org_str, $replace_str, $error_field );
330
+			$error_field   = str_replace($org_str, $replace_str, $error_field);
331 331
 		}
332 332
 
333 333
 		return $error_field;
@@ -340,138 +340,138 @@  discard block
 block discarded – undo
340 340
 	 * @version 4.0.0
341 341
 	 */
342 342
 	public function validate_checkout() {
343
-		if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_nonce' ) ) {
344
-			wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-stripe' ) );
343
+		if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_nonce')) {
344
+			wp_die(__('Cheatin&#8217; huh?', 'woocommerce-gateway-stripe'));
345 345
 		}
346 346
 
347 347
 		$errors = new WP_Error();
348
-		parse_str( $_POST['required_fields'], $required_fields );
349
-		parse_str( $_POST['all_fields'], $all_fields );
350
-		$source_type = isset( $_POST['source_type'] ) ? wc_clean( $_POST['source_type'] ) : '';
348
+		parse_str($_POST['required_fields'], $required_fields);
349
+		parse_str($_POST['all_fields'], $all_fields);
350
+		$source_type = isset($_POST['source_type']) ? wc_clean($_POST['source_type']) : '';
351 351
 		$validate_shipping_fields = false;
352 352
 		$create_account = false;
353 353
 
354
-		$all_fields      = apply_filters( 'wc_stripe_validate_checkout_all_fields', $all_fields );
355
-		$required_fields = apply_filters( 'wc_stripe_validate_checkout_required_fields', $required_fields );
354
+		$all_fields      = apply_filters('wc_stripe_validate_checkout_all_fields', $all_fields);
355
+		$required_fields = apply_filters('wc_stripe_validate_checkout_required_fields', $required_fields);
356 356
 
357
-		array_walk_recursive( $required_fields, 'wc_clean' );
358
-		array_walk_recursive( $all_fields, 'wc_clean' );
357
+		array_walk_recursive($required_fields, 'wc_clean');
358
+		array_walk_recursive($all_fields, 'wc_clean');
359 359
 
360 360
 		/**
361 361
 		 * If ship to different address checkbox is checked then we need
362 362
 		 * to validate shipping fields too.
363 363
 		 */
364
-		if ( isset( $all_fields['ship_to_different_address'] ) ) {
364
+		if (isset($all_fields['ship_to_different_address'])) {
365 365
 			$validate_shipping_fields = true;
366 366
 		}
367 367
 
368 368
 		// Check if createaccount is checked.
369
-		if ( isset( $all_fields['createaccount'] ) ) {
369
+		if (isset($all_fields['createaccount'])) {
370 370
 			$create_account = true;
371 371
 		}
372 372
 
373 373
 		// Check if required fields are empty.
374
-		foreach ( $required_fields as $field => $field_value ) {
374
+		foreach ($required_fields as $field => $field_value) {
375 375
 			// Check for shipping field.
376
-			if ( preg_match( '/^shipping_/', $field ) && ! $validate_shipping_fields ) {
376
+			if (preg_match('/^shipping_/', $field) && ! $validate_shipping_fields) {
377 377
 				continue;
378 378
 			}
379 379
 
380 380
 			// Check create account name.
381
-			if ( 'account_username' === $field && ! $create_account ) {
381
+			if ('account_username' === $field && ! $create_account) {
382 382
 				continue;
383 383
 			}
384 384
 
385 385
 			// Check create account password.
386
-			if ( 'account_password' === $field && ! $create_account ) {
386
+			if ('account_password' === $field && ! $create_account) {
387 387
 				continue;
388 388
 			}
389 389
 
390
-			if ( empty( $field_value ) || '-1' === $field_value ) {
391
-				$error_field = $this->normalize_field( $field );
390
+			if (empty($field_value) || '-1' === $field_value) {
391
+				$error_field = $this->normalize_field($field);
392 392
 				/* translators: error field name */
393
-				$errors->add( 'validation', sprintf( __( '<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe' ), $error_field ) );
393
+				$errors->add('validation', sprintf(__('<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe'), $error_field));
394 394
 			}
395 395
 		}
396 396
 
397 397
 		// Check if email is valid format.
398
-		if ( ! empty( $required_fields['billing_email'] ) && ! is_email( $required_fields['billing_email'] ) ) {
399
-			$errors->add( 'validation', __( 'Email is not valid', 'woocommerce-gateway-stripe' ) );
398
+		if ( ! empty($required_fields['billing_email']) && ! is_email($required_fields['billing_email'])) {
399
+			$errors->add('validation', __('Email is not valid', 'woocommerce-gateway-stripe'));
400 400
 		}
401 401
 
402 402
 		// Check if phone number is valid format.
403
-		if ( ! empty( $required_fields['billing_phone'] ) ) {
404
-			$phone = wc_format_phone_number( $required_fields['billing_phone'] );
403
+		if ( ! empty($required_fields['billing_phone'])) {
404
+			$phone = wc_format_phone_number($required_fields['billing_phone']);
405 405
 
406
-			if ( '' !== $phone && ! WC_Validation::is_phone( $phone ) ) {
406
+			if ('' !== $phone && ! WC_Validation::is_phone($phone)) {
407 407
 				/* translators: %s: phone number */
408
-				$errors->add( 'validation', __( 'Please enter a valid phone number.', 'woocommerce-gateway-stripe' ) );
408
+				$errors->add('validation', __('Please enter a valid phone number.', 'woocommerce-gateway-stripe'));
409 409
 			}
410 410
 		}
411 411
 
412 412
 		// Check if postal code is valid format.
413
-		if ( ! empty( $required_fields['billing_postcode'] ) ) {
414
-			$country = isset( $required_fields['billing_country'] ) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
415
-			$postcode = wc_format_postcode( $required_fields['billing_postcode'], $country );
413
+		if ( ! empty($required_fields['billing_postcode'])) {
414
+			$country = isset($required_fields['billing_country']) ? $required_fields['billing_country'] : WC()->customer->get_billing_country();
415
+			$postcode = wc_format_postcode($required_fields['billing_postcode'], $country);
416 416
 
417
-			if ( '' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
418
-				$errors->add( 'validation', __( 'Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
417
+			if ('' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
418
+				$errors->add('validation', __('Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe'));
419 419
 			}
420 420
 		}
421 421
 
422 422
 		// Don't check this on add payment method page.
423
-		if ( ( isset( $_POST['is_add_payment_page'] ) && 'no' === $_POST['is_add_payment_page'] ) ) {
424
-			if ( empty( $all_fields['woocommerce_checkout_update_totals'] ) && empty( $all_fields['terms'] ) && apply_filters( 'woocommerce_checkout_show_terms', wc_get_page_id( 'terms' ) > 0 ) ) {
425
-				$errors->add( 'terms', __( 'You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe' ) );
423
+		if ((isset($_POST['is_add_payment_page']) && 'no' === $_POST['is_add_payment_page'])) {
424
+			if (empty($all_fields['woocommerce_checkout_update_totals']) && empty($all_fields['terms']) && apply_filters('woocommerce_checkout_show_terms', wc_get_page_id('terms') > 0)) {
425
+				$errors->add('terms', __('You must accept our Terms &amp; Conditions.', 'woocommerce-gateway-stripe'));
426 426
 			}
427 427
 		}
428 428
 
429
-		if ( WC()->cart->needs_shipping() && $validate_shipping_fields ) {
429
+		if (WC()->cart->needs_shipping() && $validate_shipping_fields) {
430 430
 			// Check if postal code is valid format.
431
-			if ( ! empty( $required_fields['shipping_postcode'] ) ) {
432
-				$country = isset( $required_fields['shipping_country'] ) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
433
-				$postcode = wc_format_postcode( $required_fields['shipping_postcode'], $country );
431
+			if ( ! empty($required_fields['shipping_postcode'])) {
432
+				$country = isset($required_fields['shipping_country']) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country();
433
+				$postcode = wc_format_postcode($required_fields['shipping_postcode'], $country);
434 434
 
435
-				if ( '' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) {
436
-					$errors->add( 'validation', __( 'Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe' ) );
435
+				if ('' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) {
436
+					$errors->add('validation', __('Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe'));
437 437
 				}
438 438
 			}
439 439
 		}
440 440
 
441
-		if ( WC()->cart->needs_shipping() ) {
441
+		if (WC()->cart->needs_shipping()) {
442 442
 			$shipping_country = WC()->customer->get_shipping_country();
443 443
 
444
-			if ( empty( $shipping_country ) ) {
445
-				$errors->add( 'shipping', __( 'Please enter an address to continue.', 'woocommerce-gateway-stripe' ) );
446
-			} elseif ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) ) {
444
+			if (empty($shipping_country)) {
445
+				$errors->add('shipping', __('Please enter an address to continue.', 'woocommerce-gateway-stripe'));
446
+			} elseif ( ! in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) {
447 447
 				/* translators: country name */
448
-				$errors->add( 'shipping', sprintf( __( 'Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe' ), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country() ) );
448
+				$errors->add('shipping', sprintf(__('Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe'), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country()));
449 449
 			} else {
450
-				$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
450
+				$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
451 451
 
452
-				foreach ( WC()->shipping->get_packages() as $i => $package ) {
453
-					if ( ! isset( $chosen_shipping_methods[ $i ], $package['rates'][ $chosen_shipping_methods[ $i ] ] ) ) {
454
-						$errors->add( 'shipping', __( 'No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe' ) );
452
+				foreach (WC()->shipping->get_packages() as $i => $package) {
453
+					if ( ! isset($chosen_shipping_methods[$i], $package['rates'][$chosen_shipping_methods[$i]])) {
454
+						$errors->add('shipping', __('No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe'));
455 455
 					}
456 456
 				}
457 457
 			}
458 458
 		}
459 459
 
460
-		if ( WC()->cart->needs_payment() ) {
460
+		if (WC()->cart->needs_payment()) {
461 461
 			$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
462 462
 
463
-			if ( ! isset( $available_gateways[ $all_fields['payment_method'] ] ) ) {
464
-				$errors->add( 'payment', __( 'Invalid payment method.', 'woocommerce-gateway-stripe' ) );
463
+			if ( ! isset($available_gateways[$all_fields['payment_method']])) {
464
+				$errors->add('payment', __('Invalid payment method.', 'woocommerce-gateway-stripe'));
465 465
 			} else {
466
-				$available_gateways[ $all_fields['payment_method'] ]->validate_fields();
466
+				$available_gateways[$all_fields['payment_method']]->validate_fields();
467 467
 			}
468 468
 		}
469 469
 
470
-		if ( 0 === count( $errors->errors ) ) {
471
-			wp_send_json( 'success' );
470
+		if (0 === count($errors->errors)) {
471
+			wp_send_json('success');
472 472
 		} else {
473
-			foreach ( $errors->get_error_messages() as $message ) {
474
-				wc_add_notice( $message, 'error' );
473
+			foreach ($errors->get_error_messages() as $message) {
474
+				wc_add_notice($message, 'error');
475 475
 			}
476 476
 
477 477
 			$this->send_ajax_failure_response();
@@ -485,9 +485,9 @@  discard block
 block discarded – undo
485 485
 	 * @version 4.0.0
486 486
 	 */
487 487
 	public function send_ajax_failure_response() {
488
-		if ( is_ajax() ) {
488
+		if (is_ajax()) {
489 489
 			// only print notices if not reloading the checkout, otherwise they're lost in the page reload.
490
-			if ( ! isset( WC()->session->reload_checkout ) ) {
490
+			if ( ! isset(WC()->session->reload_checkout)) {
491 491
 				ob_start();
492 492
 				wc_print_notices();
493 493
 				$messages = ob_get_clean();
@@ -495,14 +495,14 @@  discard block
 block discarded – undo
495 495
 
496 496
 			$response = array(
497 497
 				'result'   => 'failure',
498
-				'messages' => isset( $messages ) ? $messages : '',
499
-				'refresh'  => isset( WC()->session->refresh_totals ),
500
-				'reload'   => isset( WC()->session->reload_checkout ),
498
+				'messages' => isset($messages) ? $messages : '',
499
+				'refresh'  => isset(WC()->session->refresh_totals),
500
+				'reload'   => isset(WC()->session->reload_checkout),
501 501
 			);
502 502
 
503
-			unset( WC()->session->refresh_totals, WC()->session->reload_checkout );
503
+			unset(WC()->session->refresh_totals, WC()->session->reload_checkout);
504 504
 
505
-			wp_send_json( $response );
505
+			wp_send_json($response);
506 506
 		}
507 507
 	}
508 508
 }
Please login to merge, or discard this patch.