@@ -1,46 +1,46 @@ |
||
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;"> %s </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;"> %s </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 | ); |
@@ -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,27 +76,27 @@ 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 | } |
@@ -1,14 +1,14 @@ discard block |
||
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 |
||
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'); |
@@ -1,10 +1,10 @@ discard block |
||
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 |
||
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 | } |
@@ -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." ); |
|
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 | } |
@@ -7,7 +7,7 @@ discard block |
||
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 |
||
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 | /** |
@@ -14,20 +14,20 @@ discard block |
||
14 | 14 | * |
15 | 15 | */ |
16 | 16 | |
17 | -if ( ! defined( 'ABSPATH' ) ) { |
|
17 | +if ( ! defined('ABSPATH')) { |
|
18 | 18 | exit; |
19 | 19 | } |
20 | 20 | |
21 | -if ( ! class_exists( 'WC_Stripe' ) ) : |
|
21 | +if ( ! class_exists('WC_Stripe')) : |
|
22 | 22 | /** |
23 | 23 | * Required minimums and constants |
24 | 24 | */ |
25 | - define( 'WC_STRIPE_VERSION', '4.0.3' ); |
|
26 | - define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' ); |
|
27 | - define( 'WC_STRIPE_MIN_WC_VER', '2.6.0' ); |
|
28 | - define( 'WC_STRIPE_MAIN_FILE', __FILE__ ); |
|
29 | - define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); |
|
30 | - define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); |
|
25 | + define('WC_STRIPE_VERSION', '4.0.3'); |
|
26 | + define('WC_STRIPE_MIN_PHP_VER', '5.6.0'); |
|
27 | + define('WC_STRIPE_MIN_WC_VER', '2.6.0'); |
|
28 | + define('WC_STRIPE_MAIN_FILE', __FILE__); |
|
29 | + define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)))); |
|
30 | + define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__))); |
|
31 | 31 | |
32 | 32 | class WC_Stripe { |
33 | 33 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @return Singleton The *Singleton* instance. |
48 | 48 | */ |
49 | 49 | public static function get_instance() { |
50 | - if ( null === self::$instance ) { |
|
50 | + if (null === self::$instance) { |
|
51 | 51 | self::$instance = new self(); |
52 | 52 | } |
53 | 53 | return self::$instance; |
@@ -80,10 +80,10 @@ discard block |
||
80 | 80 | * *Singleton* via the `new` operator from outside of this class. |
81 | 81 | */ |
82 | 82 | private function __construct() { |
83 | - add_action( 'admin_init', array( $this, 'check_environment' ) ); |
|
84 | - add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 ); |
|
85 | - add_action( 'plugins_loaded', array( $this, 'init' ) ); |
|
86 | - add_action( 'wp_loaded', array( $this, 'hide_notices' ) ); |
|
83 | + add_action('admin_init', array($this, 'check_environment')); |
|
84 | + add_action('admin_notices', array($this, 'admin_notices'), 15); |
|
85 | + add_action('plugins_loaded', array($this, 'init')); |
|
86 | + add_action('wp_loaded', array($this, 'hide_notices')); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -93,43 +93,43 @@ discard block |
||
93 | 93 | * @version 4.0.0 |
94 | 94 | */ |
95 | 95 | public function init() { |
96 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-exception.php' ); |
|
97 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php' ); |
|
98 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php' ); |
|
99 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' ); |
|
96 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-exception.php'); |
|
97 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-logger.php'); |
|
98 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-helper.php'); |
|
99 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php'); |
|
100 | 100 | |
101 | 101 | // Don't hook anything else in the plugin if we're in an incompatible environment |
102 | - if ( self::get_environment_warning() ) { |
|
102 | + if (self::get_environment_warning()) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
|
107 | - |
|
108 | - require_once( dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php' ); |
|
109 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php' ); |
|
110 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-sepa-payment-token.php' ); |
|
111 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' ); |
|
112 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php' ); |
|
113 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php' ); |
|
114 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php' ); |
|
115 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php' ); |
|
116 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php' ); |
|
117 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php' ); |
|
118 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php' ); |
|
119 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php' ); |
|
120 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php' ); |
|
121 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-compat.php' ); |
|
122 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-compat.php' ); |
|
123 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php' ); |
|
124 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php' ); |
|
125 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' ); |
|
106 | + load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages'); |
|
107 | + |
|
108 | + require_once(dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php'); |
|
109 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php'); |
|
110 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-sepa-payment-token.php'); |
|
111 | + require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php'); |
|
112 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'); |
|
113 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'); |
|
114 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'); |
|
115 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php'); |
|
116 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php'); |
|
117 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php'); |
|
118 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php'); |
|
119 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php'); |
|
120 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php'); |
|
121 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-compat.php'); |
|
122 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-sepa-compat.php'); |
|
123 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php'); |
|
124 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php'); |
|
125 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php'); |
|
126 | 126 | |
127 | 127 | // REMOVE IN THE FUTURE. |
128 | - require_once( dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php' ); |
|
128 | + require_once(dirname(__FILE__) . '/includes/deprecated/class-wc-stripe-apple-pay.php'); |
|
129 | 129 | |
130 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
131 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
|
132 | - add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) ); |
|
130 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
131 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); |
|
132 | + add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin')); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -139,23 +139,23 @@ discard block |
||
139 | 139 | * @version 4.0.0 |
140 | 140 | */ |
141 | 141 | public function hide_notices() { |
142 | - if ( isset( $_GET['wc-stripe-hide-notice'] ) && isset( $_GET['_wc_stripe_notice_nonce'] ) ) { |
|
143 | - if ( ! wp_verify_nonce( $_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce' ) ) { |
|
144 | - wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe' ) ); |
|
142 | + if (isset($_GET['wc-stripe-hide-notice']) && isset($_GET['_wc_stripe_notice_nonce'])) { |
|
143 | + if ( ! wp_verify_nonce($_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce')) { |
|
144 | + wp_die(__('Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe')); |
|
145 | 145 | } |
146 | 146 | |
147 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
148 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
147 | + if ( ! current_user_can('manage_woocommerce')) { |
|
148 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
149 | 149 | } |
150 | 150 | |
151 | - $notice = wc_clean( $_GET['wc-stripe-hide-notice'] ); |
|
151 | + $notice = wc_clean($_GET['wc-stripe-hide-notice']); |
|
152 | 152 | |
153 | - switch ( $notice ) { |
|
153 | + switch ($notice) { |
|
154 | 154 | case 'ssl': |
155 | - update_option( 'wc_stripe_show_ssl_notice', 'no' ); |
|
155 | + update_option('wc_stripe_show_ssl_notice', 'no'); |
|
156 | 156 | break; |
157 | 157 | case 'keys': |
158 | - update_option( 'wc_stripe_show_keys_notice', 'no' ); |
|
158 | + update_option('wc_stripe_show_keys_notice', 'no'); |
|
159 | 159 | break; |
160 | 160 | } |
161 | 161 | } |
@@ -167,8 +167,8 @@ discard block |
||
167 | 167 | * @since 1.0.0 |
168 | 168 | * @version 4.0.0 |
169 | 169 | */ |
170 | - public function add_admin_notice( $slug, $class, $message, $dismissible = false ) { |
|
171 | - $this->notices[ $slug ] = array( |
|
170 | + public function add_admin_notice($slug, $class, $message, $dismissible = false) { |
|
171 | + $this->notices[$slug] = array( |
|
172 | 172 | 'class' => $class, |
173 | 173 | 'message' => $message, |
174 | 174 | 'dismissible' => $dismissible, |
@@ -182,21 +182,21 @@ discard block |
||
182 | 182 | * @version 4.0.0 |
183 | 183 | */ |
184 | 184 | public function admin_notices() { |
185 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
185 | + if ( ! current_user_can('manage_woocommerce')) { |
|
186 | 186 | return; |
187 | 187 | } |
188 | 188 | |
189 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
190 | - echo '<div class="' . esc_attr( $notice['class'] ) . '" style="position:relative;">'; |
|
189 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
190 | + echo '<div class="' . esc_attr($notice['class']) . '" style="position:relative;">'; |
|
191 | 191 | |
192 | - if ( $notice['dismissible'] ) { |
|
192 | + if ($notice['dismissible']) { |
|
193 | 193 | ?> |
194 | - <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> |
|
194 | + <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> |
|
195 | 195 | <?php |
196 | 196 | } |
197 | 197 | |
198 | 198 | echo '<p>'; |
199 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
199 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
200 | 200 | echo '</p></div>'; |
201 | 201 | } |
202 | 202 | } |
@@ -209,26 +209,26 @@ discard block |
||
209 | 209 | * @version 4.0.0 |
210 | 210 | */ |
211 | 211 | public function get_environment_warning() { |
212 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
212 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
213 | 213 | /* translators: 1) int version 2) int version */ |
214 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
214 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
215 | 215 | |
216 | - return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ); |
|
216 | + return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()); |
|
217 | 217 | } |
218 | 218 | |
219 | - if ( ! defined( 'WC_VERSION' ) ) { |
|
220 | - return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' ); |
|
219 | + if ( ! defined('WC_VERSION')) { |
|
220 | + return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe'); |
|
221 | 221 | } |
222 | 222 | |
223 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
223 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
224 | 224 | /* translators: 1) int version 2) int version */ |
225 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
225 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
226 | 226 | |
227 | - return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ); |
|
227 | + return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION); |
|
228 | 228 | } |
229 | 229 | |
230 | - if ( ! function_exists( 'curl_init' ) ) { |
|
231 | - return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ); |
|
230 | + if ( ! function_exists('curl_init')) { |
|
231 | + return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | return false; |
@@ -242,11 +242,11 @@ discard block |
||
242 | 242 | * @return string Setting link |
243 | 243 | */ |
244 | 244 | public function get_setting_link() { |
245 | - $use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false; |
|
245 | + $use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false; |
|
246 | 246 | |
247 | - $section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' ); |
|
247 | + $section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe'); |
|
248 | 248 | |
249 | - return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); |
|
249 | + return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
@@ -257,63 +257,63 @@ discard block |
||
257 | 257 | * @version 4.0.0 |
258 | 258 | */ |
259 | 259 | public function check_environment() { |
260 | - if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) { |
|
260 | + if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) { |
|
261 | 261 | $this->install(); |
262 | 262 | |
263 | - do_action( 'woocommerce_stripe_updated' ); |
|
263 | + do_action('woocommerce_stripe_updated'); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | $environment_warning = $this->get_environment_warning(); |
267 | 267 | |
268 | - if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
|
269 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
268 | + if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) { |
|
269 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
270 | 270 | } |
271 | 271 | |
272 | - $show_ssl_notice = get_option( 'wc_stripe_show_ssl_notice' ); |
|
273 | - $show_keys_notice = get_option( 'wc_stripe_show_keys_notice' ); |
|
274 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
272 | + $show_ssl_notice = get_option('wc_stripe_show_ssl_notice'); |
|
273 | + $show_keys_notice = get_option('wc_stripe_show_keys_notice'); |
|
274 | + $options = get_option('woocommerce_stripe_settings'); |
|
275 | 275 | $testmode = 'yes' === $options['testmode'] ? true : false; |
276 | 276 | $test_pub_key = $options['test_publishable_key']; |
277 | 277 | $test_secret_key = $options['test_secret_key']; |
278 | 278 | $live_pub_key = $options['publishable_key']; |
279 | 279 | $live_secret_key = $options['secret_key']; |
280 | 280 | |
281 | - if ( isset( $options['enabled'] ) && 'yes' === $options['enabled'] && empty( $show_keys_notice ) ) { |
|
282 | - $secret = WC_Stripe_API::get_secret_key(); |
|
281 | + if (isset($options['enabled']) && 'yes' === $options['enabled'] && empty($show_keys_notice)) { |
|
282 | + $secret = WC_Stripe_API::get_secret_key(); |
|
283 | 283 | |
284 | - if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
|
284 | + if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) { |
|
285 | 285 | $setting_link = $this->get_setting_link(); |
286 | 286 | /* translators: 1) link */ |
287 | - $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 ); |
|
287 | + $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); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | // Check if keys are entered properly per live/test mode. |
291 | - if ( $testmode ) { |
|
291 | + if ($testmode) { |
|
292 | 292 | if ( |
293 | - ! empty( $test_pub_key ) && ! preg_match( '/^pk_test_/', $test_pub_key ) |
|
294 | - || ! empty( $test_secret_key ) && ! preg_match( '/^sk_test_/', $test_secret_key ) ) |
|
293 | + ! empty($test_pub_key) && ! preg_match('/^pk_test_/', $test_pub_key) |
|
294 | + || ! empty($test_secret_key) && ! preg_match('/^sk_test_/', $test_secret_key) ) |
|
295 | 295 | { |
296 | 296 | $setting_link = $this->get_setting_link(); |
297 | 297 | /* translators: 1) link */ |
298 | - $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. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
298 | + $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. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
299 | 299 | } |
300 | 300 | } else { |
301 | 301 | if ( |
302 | - ! empty( $live_pub_key ) && ! preg_match( '/^pk_live_/', $live_pub_key ) |
|
303 | - || ! empty( $live_secret_key ) && ! preg_match( '/^sk_live_/', $live_secret_key ) ) |
|
302 | + ! empty($live_pub_key) && ! preg_match('/^pk_live_/', $live_pub_key) |
|
303 | + || ! empty($live_secret_key) && ! preg_match('/^sk_live_/', $live_secret_key) ) |
|
304 | 304 | { |
305 | 305 | $setting_link = $this->get_setting_link(); |
306 | 306 | /* translators: 1) link */ |
307 | - $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. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
307 | + $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. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
308 | 308 | } |
309 | 309 | } |
310 | 310 | } |
311 | 311 | |
312 | - if ( empty( $show_ssl_notice ) && isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) { |
|
312 | + if (empty($show_ssl_notice) && isset($options['enabled']) && 'yes' === $options['enabled']) { |
|
313 | 313 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
314 | - if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
314 | + if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
315 | 315 | /* translators: 1) link 2) link */ |
316 | - $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 ); |
|
316 | + $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); |
|
317 | 317 | } |
318 | 318 | } |
319 | 319 | } |
@@ -325,8 +325,8 @@ discard block |
||
325 | 325 | * @version 4.0.0 |
326 | 326 | */ |
327 | 327 | public function update_plugin_version() { |
328 | - delete_option( 'wc_stripe_version' ); |
|
329 | - update_option( 'wc_stripe_version', WC_STRIPE_VERSION ); |
|
328 | + delete_option('wc_stripe_version'); |
|
329 | + update_option('wc_stripe_version', WC_STRIPE_VERSION); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | /** |
@@ -336,8 +336,8 @@ discard block |
||
336 | 336 | * @version 3.1.0 |
337 | 337 | */ |
338 | 338 | public function install() { |
339 | - if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) { |
|
340 | - define( 'WC_STRIPE_INSTALLING', true ); |
|
339 | + if ( ! defined('WC_STRIPE_INSTALLING')) { |
|
340 | + define('WC_STRIPE_INSTALLING', true); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | $this->update_plugin_version(); |
@@ -349,13 +349,13 @@ discard block |
||
349 | 349 | * @since 1.0.0 |
350 | 350 | * @version 4.0.0 |
351 | 351 | */ |
352 | - public function plugin_action_links( $links ) { |
|
352 | + public function plugin_action_links($links) { |
|
353 | 353 | $plugin_links = array( |
354 | - '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
355 | - '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
356 | - '<a href="https://woocommerce.com/contact-us/">' . esc_html__( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
354 | + '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
355 | + '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
356 | + '<a href="https://woocommerce.com/contact-us/">' . esc_html__('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
357 | 357 | ); |
358 | - return array_merge( $plugin_links, $links ); |
|
358 | + return array_merge($plugin_links, $links); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | /** |
@@ -364,8 +364,8 @@ discard block |
||
364 | 364 | * @since 1.0.0 |
365 | 365 | * @version 4.0.0 |
366 | 366 | */ |
367 | - public function add_gateways( $methods ) { |
|
368 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
367 | + public function add_gateways($methods) { |
|
368 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order') || class_exists('WC_Pre_Orders_Order')) { |
|
369 | 369 | $methods[] = 'WC_Stripe_Compat'; |
370 | 370 | $methods[] = 'WC_Stripe_Sepa_Compat'; |
371 | 371 | } else { |
@@ -390,26 +390,26 @@ discard block |
||
390 | 390 | * @since 4.0.0 |
391 | 391 | * @version 4.0.0 |
392 | 392 | */ |
393 | - public function filter_gateway_order_admin( $sections ) { |
|
394 | - unset( $sections['stripe'] ); |
|
395 | - unset( $sections['stripe_bancontact'] ); |
|
396 | - unset( $sections['stripe_sofort'] ); |
|
397 | - unset( $sections['stripe_giropay'] ); |
|
398 | - unset( $sections['stripe_ideal'] ); |
|
399 | - unset( $sections['stripe_p24'] ); |
|
400 | - unset( $sections['stripe_alipay'] ); |
|
401 | - unset( $sections['stripe_sepa'] ); |
|
402 | - unset( $sections['stripe_bitcoin'] ); |
|
393 | + public function filter_gateway_order_admin($sections) { |
|
394 | + unset($sections['stripe']); |
|
395 | + unset($sections['stripe_bancontact']); |
|
396 | + unset($sections['stripe_sofort']); |
|
397 | + unset($sections['stripe_giropay']); |
|
398 | + unset($sections['stripe_ideal']); |
|
399 | + unset($sections['stripe_p24']); |
|
400 | + unset($sections['stripe_alipay']); |
|
401 | + unset($sections['stripe_sepa']); |
|
402 | + unset($sections['stripe_bitcoin']); |
|
403 | 403 | |
404 | 404 | $sections['stripe'] = 'Stripe'; |
405 | - $sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
406 | - $sections['stripe_sofort'] = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
407 | - $sections['stripe_giropay'] = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
408 | - $sections['stripe_ideal'] = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
409 | - $sections['stripe_p24'] = __( 'Stripe P24', 'woocommerce-gateway-stripe' ); |
|
410 | - $sections['stripe_alipay'] = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
411 | - $sections['stripe_sepa'] = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
412 | - $sections['stripe_bitcoin'] = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' ); |
|
405 | + $sections['stripe_bancontact'] = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
406 | + $sections['stripe_sofort'] = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
407 | + $sections['stripe_giropay'] = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
408 | + $sections['stripe_ideal'] = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
409 | + $sections['stripe_p24'] = __('Stripe P24', 'woocommerce-gateway-stripe'); |
|
410 | + $sections['stripe_alipay'] = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
411 | + $sections['stripe_sepa'] = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
412 | + $sections['stripe_bitcoin'] = __('Stripe Bitcoin', 'woocommerce-gateway-stripe'); |
|
413 | 413 | |
414 | 414 | return $sections; |
415 | 415 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -17,15 +17,15 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -32,10 +32,10 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |