@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
3 | +if ( ! defined('ABSPATH')) { |
|
4 | 4 | exit; // Exit if accessed directly |
5 | 5 | } |
6 | 6 | |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | * @param string $deprecated Deprecated since WooCommerce 3.0 |
36 | 36 | * @return string |
37 | 37 | */ |
38 | - public function get_display_name( $deprecated = '' ) { |
|
38 | + public function get_display_name($deprecated = '') { |
|
39 | 39 | $display = sprintf( |
40 | 40 | /* translators: last 4 digits of IBAN account */ |
41 | - __( 'SEPA IBAN ending in %s', 'woocommerce-gateway-stripe' ), |
|
41 | + __('SEPA IBAN ending in %s', 'woocommerce-gateway-stripe'), |
|
42 | 42 | $this->get_last4() |
43 | 43 | ); |
44 | 44 | |
@@ -66,11 +66,11 @@ discard block |
||
66 | 66 | * @return boolean True if the passed data is valid |
67 | 67 | */ |
68 | 68 | public function validate() { |
69 | - if ( false === parent::validate() ) { |
|
69 | + if (false === parent::validate()) { |
|
70 | 70 | return false; |
71 | 71 | } |
72 | 72 | |
73 | - if ( ! $this->get_last4( 'edit' ) ) { |
|
73 | + if ( ! $this->get_last4('edit')) { |
|
74 | 74 | return false; |
75 | 75 | } |
76 | 76 | |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | * @param string $context |
86 | 86 | * @return string Last 4 digits |
87 | 87 | */ |
88 | - public function get_last4( $context = 'view' ) { |
|
89 | - return $this->get_prop( 'last4', $context ); |
|
88 | + public function get_last4($context = 'view') { |
|
89 | + return $this->get_prop('last4', $context); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @version 4.0.0 |
96 | 96 | * @param string $last4 |
97 | 97 | */ |
98 | - public function set_last4( $last4 ) { |
|
99 | - $this->set_prop( 'last4', $last4 ); |
|
98 | + public function set_last4($last4) { |
|
99 | + $this->set_prop('last4', $last4); |
|
100 | 100 | } |
101 | 101 | } |
@@ -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 | /** |
@@ -2,12 +2,12 @@ discard block |
||
2 | 2 | |
3 | 3 | class WC_Stripe_Test extends WP_UnitTestCase { |
4 | 4 | public function test_constants_defined() { |
5 | - $this->assertTrue( defined( 'WC_STRIPE_VERSION' ) ); |
|
6 | - $this->assertTrue( defined( 'WC_STRIPE_MIN_PHP_VER' ) ); |
|
7 | - $this->assertTrue( defined( 'WC_STRIPE_MIN_WC_VER' ) ); |
|
8 | - $this->assertTrue( defined( 'WC_STRIPE_MAIN_FILE' ) ); |
|
9 | - $this->assertTrue( defined( 'WC_STRIPE_PLUGIN_URL' ) ); |
|
10 | - $this->assertTrue( defined( 'WC_STRIPE_PLUGIN_PATH' ) ); |
|
5 | + $this->assertTrue(defined('WC_STRIPE_VERSION')); |
|
6 | + $this->assertTrue(defined('WC_STRIPE_MIN_PHP_VER')); |
|
7 | + $this->assertTrue(defined('WC_STRIPE_MIN_WC_VER')); |
|
8 | + $this->assertTrue(defined('WC_STRIPE_MAIN_FILE')); |
|
9 | + $this->assertTrue(defined('WC_STRIPE_PLUGIN_URL')); |
|
10 | + $this->assertTrue(defined('WC_STRIPE_PLUGIN_PATH')); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | * This test will see if we're indeed converting the price correctly. |
16 | 16 | */ |
17 | 17 | public function test_price_conversion_before_send_to_stripe() { |
18 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) ); |
|
19 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 10050, 'JPY' ) ); |
|
20 | - $this->assertEquals( 100, WC_Stripe_Helper::get_stripe_amount( 100.50, 'JPY' ) ); |
|
21 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50 ) ); |
|
22 | - $this->assertInternalType( 'int', WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) ); |
|
18 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(100.50, 'USD')); |
|
19 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(10050, 'JPY')); |
|
20 | + $this->assertEquals(100, WC_Stripe_Helper::get_stripe_amount(100.50, 'JPY')); |
|
21 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(100.50)); |
|
22 | + $this->assertInternalType('int', WC_Stripe_Helper::get_stripe_amount(100.50, 'USD')); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -33,37 +33,37 @@ discard block |
||
33 | 33 | $balance_fee1->net = 10000; |
34 | 34 | $balance_fee1->currency = 'USD'; |
35 | 35 | |
36 | - $this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee1, 'fee' ) ); |
|
36 | + $this->assertEquals(105.00, WC_Stripe_Helper::format_balance_fee($balance_fee1, 'fee')); |
|
37 | 37 | |
38 | 38 | $balance_fee2 = new stdClass(); |
39 | 39 | $balance_fee2->fee = 10500; |
40 | 40 | $balance_fee2->net = 10000; |
41 | 41 | $balance_fee2->currency = 'JPY'; |
42 | 42 | |
43 | - $this->assertEquals( 10500, WC_Stripe_Helper::format_balance_fee( $balance_fee2, 'fee' ) ); |
|
43 | + $this->assertEquals(10500, WC_Stripe_Helper::format_balance_fee($balance_fee2, 'fee')); |
|
44 | 44 | |
45 | 45 | $balance_fee3 = new stdClass(); |
46 | 46 | $balance_fee3->fee = 10500; |
47 | 47 | $balance_fee3->net = 10000; |
48 | 48 | $balance_fee3->currency = 'USD'; |
49 | 49 | |
50 | - $this->assertEquals( 100.00, WC_Stripe_Helper::format_balance_fee( $balance_fee3, 'net' ) ); |
|
50 | + $this->assertEquals(100.00, WC_Stripe_Helper::format_balance_fee($balance_fee3, 'net')); |
|
51 | 51 | |
52 | 52 | $balance_fee4 = new stdClass(); |
53 | 53 | $balance_fee4->fee = 10500; |
54 | 54 | $balance_fee4->net = 10000; |
55 | 55 | $balance_fee4->currency = 'JPY'; |
56 | 56 | |
57 | - $this->assertEquals( 10000, WC_Stripe_Helper::format_balance_fee( $balance_fee4, 'net' ) ); |
|
57 | + $this->assertEquals(10000, WC_Stripe_Helper::format_balance_fee($balance_fee4, 'net')); |
|
58 | 58 | |
59 | 59 | $balance_fee5 = new stdClass(); |
60 | 60 | $balance_fee5->fee = 10500; |
61 | 61 | $balance_fee5->net = 10000; |
62 | 62 | $balance_fee5->currency = 'USD'; |
63 | 63 | |
64 | - $this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) ); |
|
64 | + $this->assertEquals(105.00, WC_Stripe_Helper::format_balance_fee($balance_fee5)); |
|
65 | 65 | |
66 | - $this->assertInternalType( 'string', WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) ); |
|
66 | + $this->assertInternalType('string', WC_Stripe_Helper::format_balance_fee($balance_fee5)); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -76,28 +76,28 @@ discard block |
||
76 | 76 | 'expected' => 'Tests Store', |
77 | 77 | ); |
78 | 78 | |
79 | - $this->assertEquals( $statement_descriptor1['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor1['actual'] ) ); |
|
79 | + $this->assertEquals($statement_descriptor1['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor1['actual'])); |
|
80 | 80 | |
81 | 81 | $statement_descriptor2 = array( |
82 | 82 | 'actual' => 'Test\'s Store > Driving Course Range', |
83 | 83 | 'expected' => 'Tests Store Driving C', |
84 | 84 | ); |
85 | 85 | |
86 | - $this->assertEquals( $statement_descriptor2['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor2['actual'] ) ); |
|
86 | + $this->assertEquals($statement_descriptor2['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor2['actual'])); |
|
87 | 87 | |
88 | 88 | $statement_descriptor3 = array( |
89 | 89 | 'actual' => 'Test\'s Store < Driving Course Range', |
90 | 90 | 'expected' => 'Tests Store Driving C', |
91 | 91 | ); |
92 | 92 | |
93 | - $this->assertEquals( $statement_descriptor3['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor3['actual'] ) ); |
|
93 | + $this->assertEquals($statement_descriptor3['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor3['actual'])); |
|
94 | 94 | |
95 | 95 | $statement_descriptor4 = array( |
96 | 96 | 'actual' => 'Test\'s Store " Driving Course Range', |
97 | 97 | 'expected' => 'Tests Store Driving C', |
98 | 98 | ); |
99 | 99 | |
100 | - $this->assertEquals( $statement_descriptor4['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor4['actual'] ) ); |
|
100 | + $this->assertEquals($statement_descriptor4['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor4['actual'])); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -109,12 +109,12 @@ discard block |
||
109 | 109 | $source = new stdClass(); |
110 | 110 | $source->type = 'three_d_secure'; |
111 | 111 | |
112 | - $this->assertEquals( true, $stripe->is_3ds_card( $source ) ); |
|
112 | + $this->assertEquals(true, $stripe->is_3ds_card($source)); |
|
113 | 113 | |
114 | 114 | $source = new stdClass(); |
115 | 115 | $source->type = 'card'; |
116 | 116 | |
117 | - $this->assertEquals( false, $stripe->is_3ds_card( $source ) ); |
|
117 | + $this->assertEquals(false, $stripe->is_3ds_card($source)); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -128,20 +128,20 @@ discard block |
||
128 | 128 | $source->card = new stdClass(); |
129 | 129 | $source->card->three_d_secure = 'required'; |
130 | 130 | |
131 | - $this->assertEquals( true, $stripe->is_3ds_required( $source ) ); |
|
131 | + $this->assertEquals(true, $stripe->is_3ds_required($source)); |
|
132 | 132 | |
133 | 133 | $source = new stdClass(); |
134 | 134 | $source->type = 'card'; |
135 | 135 | $source->card = new stdClass(); |
136 | 136 | $source->card->three_d_secure = 'optional'; |
137 | 137 | |
138 | - $this->assertEquals( false, $stripe->is_3ds_required( $source ) ); |
|
138 | + $this->assertEquals(false, $stripe->is_3ds_required($source)); |
|
139 | 139 | |
140 | 140 | $source = new stdClass(); |
141 | 141 | $source->type = 'card'; |
142 | 142 | $source->card = new stdClass(); |
143 | 143 | $source->card->three_d_secure = 'not_supported'; |
144 | 144 | |
145 | - $this->assertEquals( false, $stripe->is_3ds_required( $source ) ); |
|
145 | + $this->assertEquals(false, $stripe->is_3ds_required($source)); |
|
146 | 146 | } |
147 | 147 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * Set secret API Key. |
27 | 27 | * @param string $key |
28 | 28 | */ |
29 | - public static function set_secret_key( $secret_key ) { |
|
29 | + public static function set_secret_key($secret_key) { |
|
30 | 30 | self::$secret_key = $secret_key; |
31 | 31 | } |
32 | 32 | |
@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | * @return string |
36 | 36 | */ |
37 | 37 | public static function get_secret_key() { |
38 | - if ( ! self::$secret_key ) { |
|
39 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
38 | + if ( ! self::$secret_key) { |
|
39 | + $options = get_option('woocommerce_stripe_settings'); |
|
40 | 40 | |
41 | - if ( isset( $options['testmode'], $options['secret_key'], $options['test_secret_key'] ) ) { |
|
42 | - self::set_secret_key( 'yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key'] ); |
|
41 | + if (isset($options['testmode'], $options['secret_key'], $options['test_secret_key'])) { |
|
42 | + self::set_secret_key('yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key']); |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 | return self::$secret_key; |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | $user_agent = self::get_user_agent(); |
79 | 79 | $app_info = $user_agent['application']; |
80 | 80 | |
81 | - return apply_filters( 'woocommerce_stripe_request_headers', array( |
|
82 | - 'Authorization' => 'Basic ' . base64_encode( self::get_secret_key() . ':' ), |
|
81 | + return apply_filters('woocommerce_stripe_request_headers', array( |
|
82 | + 'Authorization' => 'Basic ' . base64_encode(self::get_secret_key() . ':'), |
|
83 | 83 | 'Stripe-Version' => self::STRIPE_API_VERSION, |
84 | 84 | 'User-Agent' => $app_info['name'] . '/' . $app_info['version'] . ' (' . $app_info['url'] . ')', |
85 | - 'X-Stripe-Client-User-Agent' => json_encode( $user_agent ), |
|
86 | - ) ); |
|
85 | + 'X-Stripe-Client-User-Agent' => json_encode($user_agent), |
|
86 | + )); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -96,16 +96,16 @@ discard block |
||
96 | 96 | * @param bool $with_headers To get the response with headers. |
97 | 97 | * @return array|WP_Error |
98 | 98 | */ |
99 | - public static function request( $request, $api = 'charges', $method = 'POST', $with_headers = false ) { |
|
100 | - WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) ); |
|
99 | + public static function request($request, $api = 'charges', $method = 'POST', $with_headers = false) { |
|
100 | + WC_Stripe_Logger::log("{$api} request: " . print_r($request, true)); |
|
101 | 101 | |
102 | 102 | $headers = self::get_headers(); |
103 | 103 | |
104 | - if ( 'charges' === $api && 'POST' === $method ) { |
|
105 | - $customer = ! empty( $request['customer'] ) ? $request['customer'] : ''; |
|
106 | - $source = ! empty( $request['source'] ) ? $request['source'] : $customer; |
|
104 | + if ('charges' === $api && 'POST' === $method) { |
|
105 | + $customer = ! empty($request['customer']) ? $request['customer'] : ''; |
|
106 | + $source = ! empty($request['source']) ? $request['source'] : $customer; |
|
107 | 107 | |
108 | - $headers['Idempotency-Key'] = apply_filters( 'wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request ); |
|
108 | + $headers['Idempotency-Key'] = apply_filters('wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | $response = wp_safe_remote_post( |
@@ -113,21 +113,21 @@ discard block |
||
113 | 113 | array( |
114 | 114 | 'method' => $method, |
115 | 115 | 'headers' => $headers, |
116 | - 'body' => apply_filters( 'woocommerce_stripe_request_body', $request, $api ), |
|
116 | + 'body' => apply_filters('woocommerce_stripe_request_body', $request, $api), |
|
117 | 117 | 'timeout' => 70, |
118 | 118 | ) |
119 | 119 | ); |
120 | 120 | |
121 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
122 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
123 | - throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
121 | + if (is_wp_error($response) || empty($response['body'])) { |
|
122 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
123 | + throw new WC_Stripe_Exception(print_r($response, true), __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
124 | 124 | } |
125 | 125 | |
126 | - if ( $with_headers ) { |
|
127 | - return array( 'headers' => wp_remote_retrieve_headers( $response ), 'body' => json_decode( $response['body'] ) ); |
|
126 | + if ($with_headers) { |
|
127 | + return array('headers' => wp_remote_retrieve_headers($response), 'body' => json_decode($response['body'])); |
|
128 | 128 | } |
129 | 129 | |
130 | - return json_decode( $response['body'] ); |
|
130 | + return json_decode($response['body']); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -137,8 +137,8 @@ discard block |
||
137 | 137 | * @version 4.0.0 |
138 | 138 | * @param string $api |
139 | 139 | */ |
140 | - public static function retrieve( $api ) { |
|
141 | - WC_Stripe_Logger::log( "{$api}" ); |
|
140 | + public static function retrieve($api) { |
|
141 | + WC_Stripe_Logger::log("{$api}"); |
|
142 | 142 | |
143 | 143 | $response = wp_safe_remote_get( |
144 | 144 | self::ENDPOINT . $api, |
@@ -149,11 +149,11 @@ discard block |
||
149 | 149 | ) |
150 | 150 | ); |
151 | 151 | |
152 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
153 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
154 | - return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
152 | + if (is_wp_error($response) || empty($response['body'])) { |
|
153 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
154 | + return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
155 | 155 | } |
156 | 156 | |
157 | - return json_decode( $response['body'] ); |
|
157 | + return json_decode($response['body']); |
|
158 | 158 | } |
159 | 159 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @since 4.0.6 |
6 | 6 | */ |
7 | 7 | |
8 | -if ( ! defined( 'ABSPATH' ) ) { |
|
8 | +if ( ! defined('ABSPATH')) { |
|
9 | 9 | exit; |
10 | 10 | } |
11 | 11 | |
@@ -60,21 +60,21 @@ discard block |
||
60 | 60 | public $apple_pay_verify_notice; |
61 | 61 | |
62 | 62 | public function __construct() { |
63 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
64 | - $this->stripe_enabled = $this->get_option( 'enabled' ); |
|
65 | - $this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
66 | - $this->apple_pay_domain_set = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' ); |
|
63 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
64 | + $this->stripe_enabled = $this->get_option('enabled'); |
|
65 | + $this->payment_request = 'yes' === $this->get_option('payment_request', 'yes'); |
|
66 | + $this->apple_pay_domain_set = 'yes' === $this->get_option('apple_pay_domain_set', 'no'); |
|
67 | 67 | $this->apple_pay_verify_notice = ''; |
68 | - $this->testmode = 'yes' === $this->get_option( 'testmode', 'no' ); |
|
69 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
68 | + $this->testmode = 'yes' === $this->get_option('testmode', 'no'); |
|
69 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
70 | 70 | |
71 | - if ( empty( $this->stripe_settings ) ) { |
|
71 | + if (empty($this->stripe_settings)) { |
|
72 | 72 | return; |
73 | 73 | } |
74 | 74 | |
75 | 75 | $this->init_apple_pay(); |
76 | 76 | |
77 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
77 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -85,13 +85,13 @@ discard block |
||
85 | 85 | * @param string default |
86 | 86 | * @return string $setting_value |
87 | 87 | */ |
88 | - public function get_option( $setting = '', $default = '' ) { |
|
89 | - if ( empty( $this->stripe_settings ) ) { |
|
88 | + public function get_option($setting = '', $default = '') { |
|
89 | + if (empty($this->stripe_settings)) { |
|
90 | 90 | return $default; |
91 | 91 | } |
92 | 92 | |
93 | - if ( ! empty( $this->stripe_settings[ $setting ] ) ) { |
|
94 | - return $this->stripe_settings[ $setting ]; |
|
93 | + if ( ! empty($this->stripe_settings[$setting])) { |
|
94 | + return $this->stripe_settings[$setting]; |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | return $default; |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | public function init_apple_pay() { |
107 | 107 | if ( |
108 | 108 | is_admin() && |
109 | - isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && |
|
110 | - isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] && |
|
111 | - isset( $_GET['section'] ) && 'stripe' === $_GET['section'] && |
|
109 | + isset($_GET['page']) && 'wc-settings' === $_GET['page'] && |
|
110 | + isset($_GET['tab']) && 'checkout' === $_GET['tab'] && |
|
111 | + isset($_GET['section']) && 'stripe' === $_GET['section'] && |
|
112 | 112 | $this->payment_request |
113 | 113 | ) { |
114 | 114 | $this->process_apple_pay_verification(); |
@@ -122,9 +122,9 @@ discard block |
||
122 | 122 | * @version 3.1.0 |
123 | 123 | * @param string $secret_key |
124 | 124 | */ |
125 | - private function register_apple_pay_domain( $secret_key = '' ) { |
|
126 | - if ( empty( $secret_key ) ) { |
|
127 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
125 | + private function register_apple_pay_domain($secret_key = '') { |
|
126 | + if (empty($secret_key)) { |
|
127 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -138,23 +138,23 @@ discard block |
||
138 | 138 | 'Authorization' => 'Bearer ' . $secret_key, |
139 | 139 | ); |
140 | 140 | |
141 | - $response = wp_remote_post( $endpoint, array( |
|
141 | + $response = wp_remote_post($endpoint, array( |
|
142 | 142 | 'headers' => $headers, |
143 | - 'body' => http_build_query( $data ), |
|
144 | - ) ); |
|
143 | + 'body' => http_build_query($data), |
|
144 | + )); |
|
145 | 145 | |
146 | - if ( is_wp_error( $response ) ) { |
|
146 | + if (is_wp_error($response)) { |
|
147 | 147 | /* translators: error message */ |
148 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
148 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
149 | 149 | } |
150 | 150 | |
151 | - if ( 200 !== $response['response']['code'] ) { |
|
152 | - $parsed_response = json_decode( $response['body'] ); |
|
151 | + if (200 !== $response['response']['code']) { |
|
152 | + $parsed_response = json_decode($response['body']); |
|
153 | 153 | |
154 | 154 | $this->apple_pay_verify_notice = $parsed_response->error->message; |
155 | 155 | |
156 | 156 | /* translators: error message */ |
157 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) ); |
|
157 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message)); |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
@@ -166,45 +166,45 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function process_apple_pay_verification() { |
168 | 168 | try { |
169 | - $path = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] ); |
|
169 | + $path = untrailingslashit($_SERVER['DOCUMENT_ROOT']); |
|
170 | 170 | $dir = '.well-known'; |
171 | 171 | $file = 'apple-developer-merchantid-domain-association'; |
172 | 172 | $fullpath = $path . '/' . $dir . '/' . $file; |
173 | 173 | |
174 | - if ( $this->apple_pay_domain_set && file_exists( $fullpath ) ) { |
|
174 | + if ($this->apple_pay_domain_set && file_exists($fullpath)) { |
|
175 | 175 | return; |
176 | 176 | } |
177 | 177 | |
178 | - if ( ! file_exists( $path . '/' . $dir ) ) { |
|
179 | - if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) { // @codingStandardsIgnoreLine |
|
180 | - throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
178 | + if ( ! file_exists($path . '/' . $dir)) { |
|
179 | + if ( ! @mkdir($path . '/' . $dir, 0755)) { // @codingStandardsIgnoreLine |
|
180 | + throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe')); |
|
181 | 181 | } |
182 | 182 | } |
183 | 183 | |
184 | - if ( ! file_exists( $fullpath ) ) { |
|
185 | - if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { // @codingStandardsIgnoreLine |
|
186 | - throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
184 | + if ( ! file_exists($fullpath)) { |
|
185 | + if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { // @codingStandardsIgnoreLine |
|
186 | + throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe')); |
|
187 | 187 | } |
188 | 188 | } |
189 | 189 | |
190 | 190 | // At this point then the domain association folder and file should be available. |
191 | 191 | // Proceed to verify/and or verify again. |
192 | - $this->register_apple_pay_domain( $this->secret_key ); |
|
192 | + $this->register_apple_pay_domain($this->secret_key); |
|
193 | 193 | |
194 | 194 | // No errors to this point, verification success! |
195 | 195 | $this->stripe_settings['apple_pay_domain_set'] = 'yes'; |
196 | 196 | $this->apple_pay_domain_set = true; |
197 | 197 | |
198 | - update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); |
|
198 | + update_option('woocommerce_stripe_settings', $this->stripe_settings); |
|
199 | 199 | |
200 | - WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' ); |
|
200 | + WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!'); |
|
201 | 201 | |
202 | - } catch ( Exception $e ) { |
|
202 | + } catch (Exception $e) { |
|
203 | 203 | $this->stripe_settings['apple_pay_domain_set'] = 'no'; |
204 | 204 | |
205 | - update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); |
|
205 | + update_option('woocommerce_stripe_settings', $this->stripe_settings); |
|
206 | 206 | |
207 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
207 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
208 | 208 | } |
209 | 209 | } |
210 | 210 | |
@@ -214,11 +214,11 @@ discard block |
||
214 | 214 | * @since 4.0.6 |
215 | 215 | */ |
216 | 216 | public function admin_notices() { |
217 | - if ( ! $this->stripe_enabled ) { |
|
217 | + if ( ! $this->stripe_enabled) { |
|
218 | 218 | return; |
219 | 219 | } |
220 | 220 | |
221 | - if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) { |
|
221 | + if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) { |
|
222 | 222 | $allowed_html = array( |
223 | 223 | 'a' => array( |
224 | 224 | 'href' => array(), |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | ), |
227 | 227 | ); |
228 | 228 | |
229 | - echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>'; |
|
229 | + echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>'; |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -234,9 +234,9 @@ discard block |
||
234 | 234 | * when setting screen is displayed. So if domain verification is not set, |
235 | 235 | * something went wrong so lets notify user. |
236 | 236 | */ |
237 | - if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) { |
|
237 | + if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) { |
|
238 | 238 | /* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */ |
239 | - echo '<div class="error stripe-apple-pay-message"><p>' . sprintf( __( 'Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>'; |
|
239 | + echo '<div class="error stripe-apple-pay-message"><p>' . sprintf(__('Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', '</a>') . '</p></div>'; |
|
240 | 240 | } |
241 | 241 | } |
242 | 242 | } |
@@ -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,30 +13,30 @@ 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_show_alipay_notice' ); |
|
24 | - delete_option( 'wc_stripe_show_bancontact_notice' ); |
|
25 | - delete_option( 'wc_stripe_show_bitcoin_notice' ); |
|
26 | - delete_option( 'wc_stripe_show_eps_notice' ); |
|
27 | - delete_option( 'wc_stripe_show_giropay_notice' ); |
|
28 | - delete_option( 'wc_stripe_show_ideal_notice' ); |
|
29 | - delete_option( 'wc_stripe_show_multibanco_notice' ); |
|
30 | - delete_option( 'wc_stripe_show_p24_notice' ); |
|
31 | - delete_option( 'wc_stripe_show_sepa_notice' ); |
|
32 | - delete_option( 'wc_stripe_show_sofort_notice' ); |
|
33 | - delete_option( 'wc_stripe_version' ); |
|
34 | - delete_option( 'woocommerce_stripe_bancontact_settings' ); |
|
35 | - delete_option( 'woocommerce_stripe_alipay_settings' ); |
|
36 | - delete_option( 'woocommerce_stripe_bitcoin_settings' ); |
|
37 | - delete_option( 'woocommerce_stripe_ideal_settings' ); |
|
38 | - delete_option( 'woocommerce_stripe_p24_settings' ); |
|
39 | - delete_option( 'woocommerce_stripe_giropay_settings' ); |
|
40 | - delete_option( 'woocommerce_stripe_sepa_settings' ); |
|
41 | - 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_show_alipay_notice'); |
|
24 | + delete_option('wc_stripe_show_bancontact_notice'); |
|
25 | + delete_option('wc_stripe_show_bitcoin_notice'); |
|
26 | + delete_option('wc_stripe_show_eps_notice'); |
|
27 | + delete_option('wc_stripe_show_giropay_notice'); |
|
28 | + delete_option('wc_stripe_show_ideal_notice'); |
|
29 | + delete_option('wc_stripe_show_multibanco_notice'); |
|
30 | + delete_option('wc_stripe_show_p24_notice'); |
|
31 | + delete_option('wc_stripe_show_sepa_notice'); |
|
32 | + delete_option('wc_stripe_show_sofort_notice'); |
|
33 | + delete_option('wc_stripe_version'); |
|
34 | + delete_option('woocommerce_stripe_bancontact_settings'); |
|
35 | + delete_option('woocommerce_stripe_alipay_settings'); |
|
36 | + delete_option('woocommerce_stripe_bitcoin_settings'); |
|
37 | + delete_option('woocommerce_stripe_ideal_settings'); |
|
38 | + delete_option('woocommerce_stripe_p24_settings'); |
|
39 | + delete_option('woocommerce_stripe_giropay_settings'); |
|
40 | + delete_option('woocommerce_stripe_sepa_settings'); |
|
41 | + delete_option('woocommerce_stripe_sofort_settings'); |
|
42 | 42 | } |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
7 | 7 | * DEPRECATED DO NOT USE!! |
8 | 8 | */ |
9 | -if ( ! class_exists( 'WC_Stripe_Apple_Pay' ) ) { |
|
9 | +if ( ! class_exists('WC_Stripe_Apple_Pay')) { |
|
10 | 10 | class WC_Stripe_Apple_Pay { |
11 | 11 | /** |
12 | 12 | * This Instance. |
@@ -20,15 +20,15 @@ discard block |
||
20 | 20 | } |
21 | 21 | |
22 | 22 | public static function instance() { |
23 | - WC_Stripe_Logger::log( 'DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance. This class will be removed by version 4.2' ); |
|
23 | + WC_Stripe_Logger::log('DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance. This class will be removed by version 4.2'); |
|
24 | 24 | return self::$_this; |
25 | 25 | } |
26 | 26 | |
27 | - public function __get( $var ) { |
|
27 | + public function __get($var) { |
|
28 | 28 | return null; |
29 | 29 | } |
30 | 30 | |
31 | - public function __call( $name, $arguments ) { |
|
31 | + public function __call($name, $arguments) { |
|
32 | 32 | return null; |
33 | 33 | } |
34 | 34 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -22,14 +22,14 @@ discard block |
||
22 | 22 | * @param object $order |
23 | 23 | * @return string $currency |
24 | 24 | */ |
25 | - public static function get_stripe_currency( $order = null ) { |
|
26 | - if ( is_null( $order ) ) { |
|
25 | + public static function get_stripe_currency($order = null) { |
|
26 | + if (is_null($order)) { |
|
27 | 27 | return false; |
28 | 28 | } |
29 | 29 | |
30 | 30 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
31 | 31 | |
32 | - return WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, self::META_NAME_STRIPE_CURRENCY, true ) : $order->get_meta( self::META_NAME_STRIPE_CURRENCY, true ); |
|
32 | + return WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, self::META_NAME_STRIPE_CURRENCY, true) : $order->get_meta(self::META_NAME_STRIPE_CURRENCY, true); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -39,14 +39,14 @@ discard block |
||
39 | 39 | * @param object $order |
40 | 40 | * @param string $currency |
41 | 41 | */ |
42 | - public static function update_stripe_currency( $order = null, $currency ) { |
|
43 | - if ( is_null( $order ) ) { |
|
42 | + public static function update_stripe_currency($order = null, $currency) { |
|
43 | + if (is_null($order)) { |
|
44 | 44 | return false; |
45 | 45 | } |
46 | 46 | |
47 | 47 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
48 | 48 | |
49 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_STRIPE_CURRENCY, $currency ) : $order->update_meta_data( self::META_NAME_STRIPE_CURRENCY, $currency ); |
|
49 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_STRIPE_CURRENCY, $currency) : $order->update_meta_data(self::META_NAME_STRIPE_CURRENCY, $currency); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -56,22 +56,22 @@ discard block |
||
56 | 56 | * @param object $order |
57 | 57 | * @return string $amount |
58 | 58 | */ |
59 | - public static function get_stripe_fee( $order = null ) { |
|
60 | - if ( is_null( $order ) ) { |
|
59 | + public static function get_stripe_fee($order = null) { |
|
60 | + if (is_null($order)) { |
|
61 | 61 | return false; |
62 | 62 | } |
63 | 63 | |
64 | 64 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
65 | 65 | |
66 | - $amount = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, self::META_NAME_FEE, true ) : $order->get_meta( self::META_NAME_FEE, true ); |
|
66 | + $amount = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, self::META_NAME_FEE, true) : $order->get_meta(self::META_NAME_FEE, true); |
|
67 | 67 | |
68 | 68 | // If not found let's check for legacy name. |
69 | - if ( empty( $amount ) ) { |
|
70 | - $amount = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, self::LEGACY_META_NAME_FEE, true ) : $order->get_meta( self::LEGACY_META_NAME_FEE, true ); |
|
69 | + if (empty($amount)) { |
|
70 | + $amount = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, self::LEGACY_META_NAME_FEE, true) : $order->get_meta(self::LEGACY_META_NAME_FEE, true); |
|
71 | 71 | |
72 | 72 | // If found update to new name. |
73 | - if ( $amount ) { |
|
74 | - self::update_stripe_fee( $order, $amount ); |
|
73 | + if ($amount) { |
|
74 | + self::update_stripe_fee($order, $amount); |
|
75 | 75 | } |
76 | 76 | } |
77 | 77 | |
@@ -85,14 +85,14 @@ discard block |
||
85 | 85 | * @param object $order |
86 | 86 | * @param float $amount |
87 | 87 | */ |
88 | - public static function update_stripe_fee( $order = null, $amount = 0.0 ) { |
|
89 | - if ( is_null( $order ) ) { |
|
88 | + public static function update_stripe_fee($order = null, $amount = 0.0) { |
|
89 | + if (is_null($order)) { |
|
90 | 90 | return false; |
91 | 91 | } |
92 | 92 | |
93 | 93 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
94 | 94 | |
95 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $amount ) : $order->update_meta_data( self::META_NAME_FEE, $amount ); |
|
95 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $amount) : $order->update_meta_data(self::META_NAME_FEE, $amount); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -101,15 +101,15 @@ discard block |
||
101 | 101 | * @since 4.1.0 |
102 | 102 | * @param object $order |
103 | 103 | */ |
104 | - public static function delete_stripe_fee( $order = null ) { |
|
105 | - if ( is_null( $order ) ) { |
|
104 | + public static function delete_stripe_fee($order = null) { |
|
105 | + if (is_null($order)) { |
|
106 | 106 | return false; |
107 | 107 | } |
108 | 108 | |
109 | 109 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
110 | 110 | |
111 | - delete_post_meta( $order_id, self::META_NAME_FEE ); |
|
112 | - delete_post_meta( $order_id, self::LEGACY_META_NAME_FEE ); |
|
111 | + delete_post_meta($order_id, self::META_NAME_FEE); |
|
112 | + delete_post_meta($order_id, self::LEGACY_META_NAME_FEE); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -119,22 +119,22 @@ discard block |
||
119 | 119 | * @param object $order |
120 | 120 | * @return string $amount |
121 | 121 | */ |
122 | - public static function get_stripe_net( $order = null ) { |
|
123 | - if ( is_null( $order ) ) { |
|
122 | + public static function get_stripe_net($order = null) { |
|
123 | + if (is_null($order)) { |
|
124 | 124 | return false; |
125 | 125 | } |
126 | 126 | |
127 | 127 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
128 | 128 | |
129 | - $amount = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, self::META_NAME_NET, true ) : $order->get_meta( self::META_NAME_NET, true ); |
|
129 | + $amount = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, self::META_NAME_NET, true) : $order->get_meta(self::META_NAME_NET, true); |
|
130 | 130 | |
131 | 131 | // If not found let's check for legacy name. |
132 | - if ( empty( $amount ) ) { |
|
133 | - $amount = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, self::LEGACY_META_NAME_NET, true ) : $order->get_meta( self::LEGACY_META_NAME_NET, true ); |
|
132 | + if (empty($amount)) { |
|
133 | + $amount = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, self::LEGACY_META_NAME_NET, true) : $order->get_meta(self::LEGACY_META_NAME_NET, true); |
|
134 | 134 | |
135 | 135 | // If found update to new name. |
136 | - if ( $amount ) { |
|
137 | - self::update_stripe_net( $order, $amount ); |
|
136 | + if ($amount) { |
|
137 | + self::update_stripe_net($order, $amount); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
@@ -148,14 +148,14 @@ discard block |
||
148 | 148 | * @param object $order |
149 | 149 | * @param float $amount |
150 | 150 | */ |
151 | - public static function update_stripe_net( $order = null, $amount = 0.0 ) { |
|
152 | - if ( is_null( $order ) ) { |
|
151 | + public static function update_stripe_net($order = null, $amount = 0.0) { |
|
152 | + if (is_null($order)) { |
|
153 | 153 | return false; |
154 | 154 | } |
155 | 155 | |
156 | 156 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
157 | 157 | |
158 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $amount ) : $order->update_meta_data( self::META_NAME_NET, $amount ); |
|
158 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $amount) : $order->update_meta_data(self::META_NAME_NET, $amount); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -164,15 +164,15 @@ discard block |
||
164 | 164 | * @since 4.1.0 |
165 | 165 | * @param object $order |
166 | 166 | */ |
167 | - public static function delete_stripe_net( $order = null ) { |
|
168 | - if ( is_null( $order ) ) { |
|
167 | + public static function delete_stripe_net($order = null) { |
|
168 | + if (is_null($order)) { |
|
169 | 169 | return false; |
170 | 170 | } |
171 | 171 | |
172 | 172 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
173 | 173 | |
174 | - delete_post_meta( $order_id, self::META_NAME_NET ); |
|
175 | - delete_post_meta( $order_id, self::LEGACY_META_NAME_NET ); |
|
174 | + delete_post_meta($order_id, self::META_NAME_NET); |
|
175 | + delete_post_meta($order_id, self::LEGACY_META_NAME_NET); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -183,15 +183,15 @@ discard block |
||
183 | 183 | * |
184 | 184 | * @return float|int |
185 | 185 | */ |
186 | - public static function get_stripe_amount( $total, $currency = '' ) { |
|
187 | - if ( ! $currency ) { |
|
186 | + public static function get_stripe_amount($total, $currency = '') { |
|
187 | + if ( ! $currency) { |
|
188 | 188 | $currency = get_woocommerce_currency(); |
189 | 189 | } |
190 | 190 | |
191 | - if ( in_array( strtolower( $currency ), self::no_decimal_currencies() ) ) { |
|
192 | - return absint( $total ); |
|
191 | + if (in_array(strtolower($currency), self::no_decimal_currencies())) { |
|
192 | + return absint($total); |
|
193 | 193 | } else { |
194 | - return absint( wc_format_decimal( ( (float) $total * 100 ), wc_get_price_decimals() ) ); // In cents. |
|
194 | + return absint(wc_format_decimal(((float) $total * 100), wc_get_price_decimals())); // In cents. |
|
195 | 195 | } |
196 | 196 | } |
197 | 197 | |
@@ -203,25 +203,25 @@ discard block |
||
203 | 203 | * @return array |
204 | 204 | */ |
205 | 205 | public static function get_localized_messages() { |
206 | - return apply_filters( 'wc_stripe_localized_messages', array( |
|
207 | - 'invalid_number' => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ), |
|
208 | - 'invalid_expiry_month' => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ), |
|
209 | - 'invalid_expiry_year' => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ), |
|
210 | - 'invalid_cvc' => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ), |
|
211 | - 'incorrect_number' => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ), |
|
212 | - 'incomplete_number' => __( 'The card number is incomplete.', 'woocommerce-gateway-stripe' ), |
|
213 | - 'incomplete_cvc' => __( 'The card\'s security code is incomplete.', 'woocommerce-gateway-stripe' ), |
|
214 | - 'incomplete_expiry' => __( 'The card\'s expiration date is incomplete.', 'woocommerce-gateway-stripe' ), |
|
215 | - 'expired_card' => __( 'The card has expired.', 'woocommerce-gateway-stripe' ), |
|
216 | - 'incorrect_cvc' => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ), |
|
217 | - 'incorrect_zip' => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ), |
|
218 | - 'invalid_expiry_year_past' => __( 'The card\'s expiration year is in the past', 'woocommerce-gateway-stripe' ), |
|
219 | - 'card_declined' => __( 'The card was declined.', 'woocommerce-gateway-stripe' ), |
|
220 | - 'missing' => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ), |
|
221 | - 'processing_error' => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ), |
|
222 | - 'invalid_request_error' => __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ), |
|
223 | - 'invalid_sofort_country' => __( 'The billing country is not accepted by SOFORT. Please try another country.', 'woocommerce-gateway-stripe' ), |
|
224 | - ) ); |
|
206 | + return apply_filters('wc_stripe_localized_messages', array( |
|
207 | + 'invalid_number' => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'), |
|
208 | + 'invalid_expiry_month' => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'), |
|
209 | + 'invalid_expiry_year' => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'), |
|
210 | + 'invalid_cvc' => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'), |
|
211 | + 'incorrect_number' => __('The card number is incorrect.', 'woocommerce-gateway-stripe'), |
|
212 | + 'incomplete_number' => __('The card number is incomplete.', 'woocommerce-gateway-stripe'), |
|
213 | + 'incomplete_cvc' => __('The card\'s security code is incomplete.', 'woocommerce-gateway-stripe'), |
|
214 | + 'incomplete_expiry' => __('The card\'s expiration date is incomplete.', 'woocommerce-gateway-stripe'), |
|
215 | + 'expired_card' => __('The card has expired.', 'woocommerce-gateway-stripe'), |
|
216 | + 'incorrect_cvc' => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'), |
|
217 | + 'incorrect_zip' => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'), |
|
218 | + 'invalid_expiry_year_past' => __('The card\'s expiration year is in the past', 'woocommerce-gateway-stripe'), |
|
219 | + 'card_declined' => __('The card was declined.', 'woocommerce-gateway-stripe'), |
|
220 | + 'missing' => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'), |
|
221 | + 'processing_error' => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'), |
|
222 | + 'invalid_request_error' => __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe'), |
|
223 | + 'invalid_sofort_country' => __('The billing country is not accepted by SOFORT. Please try another country.', 'woocommerce-gateway-stripe'), |
|
224 | + )); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -258,24 +258,24 @@ discard block |
||
258 | 258 | * @param string $type Type of number to format |
259 | 259 | * @return string |
260 | 260 | */ |
261 | - public static function format_balance_fee( $balance_transaction, $type = 'fee' ) { |
|
262 | - if ( ! is_object( $balance_transaction ) ) { |
|
261 | + public static function format_balance_fee($balance_transaction, $type = 'fee') { |
|
262 | + if ( ! is_object($balance_transaction)) { |
|
263 | 263 | return; |
264 | 264 | } |
265 | 265 | |
266 | - if ( in_array( strtolower( $balance_transaction->currency ), self::no_decimal_currencies() ) ) { |
|
267 | - if ( 'fee' === $type ) { |
|
266 | + if (in_array(strtolower($balance_transaction->currency), self::no_decimal_currencies())) { |
|
267 | + if ('fee' === $type) { |
|
268 | 268 | return $balance_transaction->fee; |
269 | 269 | } |
270 | 270 | |
271 | 271 | return $balance_transaction->net; |
272 | 272 | } |
273 | 273 | |
274 | - if ( 'fee' === $type ) { |
|
275 | - return number_format( $balance_transaction->fee / 100, 2, '.', '' ); |
|
274 | + if ('fee' === $type) { |
|
275 | + return number_format($balance_transaction->fee / 100, 2, '.', ''); |
|
276 | 276 | } |
277 | 277 | |
278 | - return number_format( $balance_transaction->net / 100, 2, '.', '' ); |
|
278 | + return number_format($balance_transaction->net / 100, 2, '.', ''); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | */ |
284 | 284 | public static function get_minimum_amount() { |
285 | 285 | // Check order amount |
286 | - switch ( get_woocommerce_currency() ) { |
|
286 | + switch (get_woocommerce_currency()) { |
|
287 | 287 | case 'USD': |
288 | 288 | case 'CAD': |
289 | 289 | case 'EUR': |
@@ -328,14 +328,14 @@ discard block |
||
328 | 328 | * @param string $method The payment method to get the settings from. |
329 | 329 | * @param string $setting The name of the setting to get. |
330 | 330 | */ |
331 | - public static function get_settings( $method = null, $setting = null ) { |
|
332 | - $all_settings = null === $method ? get_option( 'woocommerce_stripe_settings', array() ) : get_option( 'woocommerce_stripe_' . $method . '_settings', array() ); |
|
331 | + public static function get_settings($method = null, $setting = null) { |
|
332 | + $all_settings = null === $method ? get_option('woocommerce_stripe_settings', array()) : get_option('woocommerce_stripe_' . $method . '_settings', array()); |
|
333 | 333 | |
334 | - if ( null === $setting ) { |
|
334 | + if (null === $setting) { |
|
335 | 335 | return $all_settings; |
336 | 336 | } |
337 | 337 | |
338 | - return isset( $all_settings[ $setting ] ) ? $all_settings[ $setting ] : ''; |
|
338 | + return isset($all_settings[$setting]) ? $all_settings[$setting] : ''; |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | * @return bool |
346 | 346 | */ |
347 | 347 | public static function is_pre_orders_exists() { |
348 | - return class_exists( 'WC_Pre_Orders_Order' ); |
|
348 | + return class_exists('WC_Pre_Orders_Order'); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | /** |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | * @return bool |
357 | 357 | */ |
358 | 358 | public static function is_pre_30() { |
359 | - return version_compare( WC_VERSION, '3.0.0', '<' ); |
|
359 | + return version_compare(WC_VERSION, '3.0.0', '<'); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | /** |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | * @return string |
370 | 370 | */ |
371 | 371 | public static function get_webhook_url() { |
372 | - return add_query_arg( 'wc-api', 'wc_stripe', trailingslashit( get_home_url() ) ); |
|
372 | + return add_query_arg('wc-api', 'wc_stripe', trailingslashit(get_home_url())); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | /** |
@@ -379,13 +379,13 @@ discard block |
||
379 | 379 | * @version 4.0.0 |
380 | 380 | * @param string $source_id |
381 | 381 | */ |
382 | - public static function get_order_by_source_id( $source_id ) { |
|
382 | + public static function get_order_by_source_id($source_id) { |
|
383 | 383 | global $wpdb; |
384 | 384 | |
385 | - $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 ) ); |
|
385 | + $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)); |
|
386 | 386 | |
387 | - if ( ! empty( $order_id ) ) { |
|
388 | - return wc_get_order( $order_id ); |
|
387 | + if ( ! empty($order_id)) { |
|
388 | + return wc_get_order($order_id); |
|
389 | 389 | } |
390 | 390 | |
391 | 391 | return false; |
@@ -398,13 +398,13 @@ discard block |
||
398 | 398 | * @version 4.0.0 |
399 | 399 | * @param string $charge_id |
400 | 400 | */ |
401 | - public static function get_order_by_charge_id( $charge_id ) { |
|
401 | + public static function get_order_by_charge_id($charge_id) { |
|
402 | 402 | global $wpdb; |
403 | 403 | |
404 | - $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 ) ); |
|
404 | + $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)); |
|
405 | 405 | |
406 | - if ( ! empty( $order_id ) ) { |
|
407 | - return wc_get_order( $order_id ); |
|
406 | + if ( ! empty($order_id)) { |
|
407 | + return wc_get_order($order_id); |
|
408 | 408 | } |
409 | 409 | |
410 | 410 | return false; |
@@ -420,13 +420,13 @@ discard block |
||
420 | 420 | * @param string $statement_descriptor |
421 | 421 | * @return string $statement_descriptor Sanitized statement descriptor |
422 | 422 | */ |
423 | - public static function clean_statement_descriptor( $statement_descriptor = '' ) { |
|
424 | - $disallowed_characters = array( '<', '>', '"', "'" ); |
|
423 | + public static function clean_statement_descriptor($statement_descriptor = '') { |
|
424 | + $disallowed_characters = array('<', '>', '"', "'"); |
|
425 | 425 | |
426 | 426 | // Remove special characters. |
427 | - $statement_descriptor = str_replace( $disallowed_characters, '', $statement_descriptor ); |
|
427 | + $statement_descriptor = str_replace($disallowed_characters, '', $statement_descriptor); |
|
428 | 428 | |
429 | - $statement_descriptor = substr( trim( $statement_descriptor ), 0, 22 ); |
|
429 | + $statement_descriptor = substr(trim($statement_descriptor), 0, 22); |
|
430 | 430 | |
431 | 431 | return $statement_descriptor; |
432 | 432 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -15,19 +15,19 @@ discard block |
||
15 | 15 | public function __construct() { |
16 | 16 | parent::__construct(); |
17 | 17 | |
18 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
19 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
20 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
21 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
22 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
18 | + if (class_exists('WC_Subscriptions_Order')) { |
|
19 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
20 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
21 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
22 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
23 | 23 | |
24 | 24 | // display the credit card used for a subscription in the "My Subscriptions" table |
25 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
25 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
26 | 26 | |
27 | 27 | // allow store managers to manually set Stripe as the payment method on a subscription |
28 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
29 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
30 | - add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
28 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
29 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
30 | + add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
31 | 31 | } |
32 | 32 | } |
33 | 33 | |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | * @since 4.0.0 |
48 | 48 | * @version 4.0.0 |
49 | 49 | */ |
50 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
51 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
50 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
51 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
52 | 52 | return false; |
53 | 53 | } |
54 | 54 | |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | * @param int $order_id |
61 | 61 | * @return boolean |
62 | 62 | */ |
63 | - public function has_subscription( $order_id ) { |
|
64 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
63 | + public function has_subscription($order_id) { |
|
64 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * @return bool |
72 | 72 | */ |
73 | 73 | public function is_subs_change_payment() { |
74 | - return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) ); |
|
74 | + return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method'])); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -80,24 +80,24 @@ discard block |
||
80 | 80 | * @since 4.0.4 |
81 | 81 | * @param int $order_id |
82 | 82 | */ |
83 | - public function change_subs_payment_method( $order_id ) { |
|
83 | + public function change_subs_payment_method($order_id) { |
|
84 | 84 | try { |
85 | - $subscription = wc_get_order( $order_id ); |
|
86 | - $prepared_source = $this->prepare_source( get_current_user_id(), true ); |
|
85 | + $subscription = wc_get_order($order_id); |
|
86 | + $prepared_source = $this->prepare_source(get_current_user_id(), true); |
|
87 | 87 | $source_object = $prepared_source->source_object; |
88 | 88 | |
89 | 89 | // Check if we don't allow prepaid credit cards. |
90 | - if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) && $this->is_prepaid_card( $source_object ) ) { |
|
91 | - $localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
92 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message ); |
|
90 | + if ( ! apply_filters('wc_stripe_allow_prepaid_card', true) && $this->is_prepaid_card($source_object)) { |
|
91 | + $localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
92 | + throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message); |
|
93 | 93 | } |
94 | 94 | |
95 | - if ( empty( $prepared_source->source ) ) { |
|
96 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
97 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
95 | + if (empty($prepared_source->source)) { |
|
96 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
97 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
98 | 98 | } |
99 | 99 | |
100 | - $this->save_source_to_order( $subscription, $prepared_source ); |
|
100 | + $this->save_source_to_order($subscription, $prepared_source); |
|
101 | 101 | |
102 | 102 | /* |
103 | 103 | * Check if card 3DS is required or optional with 3DS setting. |
@@ -106,41 +106,41 @@ discard block |
||
106 | 106 | * Note that if we need to save source, the original source must be first |
107 | 107 | * attached to a customer in Stripe before it can be charged. |
108 | 108 | */ |
109 | - if ( $this->is_3ds_required( $source_object ) ) { |
|
109 | + if ($this->is_3ds_required($source_object)) { |
|
110 | 110 | $order = $subscription->get_parent(); |
111 | - $response = $this->create_3ds_source( $order, $source_object, $subscription->get_view_order_url() ); |
|
111 | + $response = $this->create_3ds_source($order, $source_object, $subscription->get_view_order_url()); |
|
112 | 112 | |
113 | - if ( ! empty( $response->error ) ) { |
|
113 | + if ( ! empty($response->error)) { |
|
114 | 114 | $localized_message = $response->error->message; |
115 | 115 | |
116 | - $order->add_order_note( $localized_message ); |
|
116 | + $order->add_order_note($localized_message); |
|
117 | 117 | |
118 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
118 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | // Update order meta with 3DS source. |
122 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
123 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
122 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
123 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
124 | 124 | } else { |
125 | - $subscription->update_meta_data( '_stripe_source_id', $response->id ); |
|
125 | + $subscription->update_meta_data('_stripe_source_id', $response->id); |
|
126 | 126 | $subscription->save(); |
127 | 127 | } |
128 | 128 | |
129 | - WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' ); |
|
129 | + WC_Stripe_Logger::log('Info: Redirecting to 3DS...'); |
|
130 | 130 | |
131 | 131 | return array( |
132 | 132 | 'result' => 'success', |
133 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
133 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
134 | 134 | ); |
135 | 135 | } |
136 | 136 | |
137 | 137 | return array( |
138 | 138 | 'result' => 'success', |
139 | - 'redirect' => $this->get_return_url( $subscription ), |
|
139 | + 'redirect' => $this->get_return_url($subscription), |
|
140 | 140 | ); |
141 | - } catch ( WC_Stripe_Exception $e ) { |
|
142 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
143 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
141 | + } catch (WC_Stripe_Exception $e) { |
|
142 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
143 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
144 | 144 | } |
145 | 145 | } |
146 | 146 | |
@@ -149,16 +149,16 @@ discard block |
||
149 | 149 | * @param int $order_id |
150 | 150 | * @return array |
151 | 151 | */ |
152 | - public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) { |
|
153 | - if ( $this->has_subscription( $order_id ) ) { |
|
154 | - if ( $this->is_subs_change_payment() ) { |
|
155 | - return $this->change_subs_payment_method( $order_id ); |
|
152 | + public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) { |
|
153 | + if ($this->has_subscription($order_id)) { |
|
154 | + if ($this->is_subs_change_payment()) { |
|
155 | + return $this->change_subs_payment_method($order_id); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | // Regular payment with force customer enabled |
159 | - return parent::process_payment( $order_id, $retry, true, $previous_error ); |
|
159 | + return parent::process_payment($order_id, $retry, true, $previous_error); |
|
160 | 160 | } else { |
161 | - return parent::process_payment( $order_id, $retry, $force_save_source, $previous_error ); |
|
161 | + return parent::process_payment($order_id, $retry, $force_save_source, $previous_error); |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
@@ -168,8 +168,8 @@ discard block |
||
168 | 168 | * @param $amount_to_charge float The amount to charge. |
169 | 169 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
170 | 170 | */ |
171 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
172 | - $this->process_subscription_payment( $amount_to_charge, $renewal_order, true, false ); |
|
171 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
172 | + $this->process_subscription_payment($amount_to_charge, $renewal_order, true, false); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -183,89 +183,89 @@ discard block |
||
183 | 183 | * @param bool $retry Should we retry the process? |
184 | 184 | * @param object $previous_error |
185 | 185 | */ |
186 | - public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) { |
|
186 | + public function process_subscription_payment($amount = 0.0, $renewal_order, $retry = true, $previous_error) { |
|
187 | 187 | try { |
188 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
188 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
189 | 189 | /* translators: minimum amount */ |
190 | - return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
190 | + return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | $order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id(); |
194 | 194 | |
195 | 195 | // Get source from order |
196 | - $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
196 | + $prepared_source = $this->prepare_order_source($renewal_order); |
|
197 | 197 | $source_object = $prepared_source->source_object; |
198 | 198 | |
199 | - if ( ! $prepared_source->customer ) { |
|
200 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
199 | + if ( ! $prepared_source->customer) { |
|
200 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
201 | 201 | } |
202 | 202 | |
203 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
203 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
204 | 204 | |
205 | 205 | /* If we're doing a retry and source is chargeable, we need to pass |
206 | 206 | * a different idempotency key and retry for success. |
207 | 207 | */ |
208 | - if ( is_object( $source_object ) && empty( $source_object->error ) && $this->need_update_idempotency_key( $source_object, $previous_error ) ) { |
|
209 | - add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 ); |
|
208 | + if (is_object($source_object) && empty($source_object->error) && $this->need_update_idempotency_key($source_object, $previous_error)) { |
|
209 | + add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2); |
|
210 | 210 | } |
211 | 211 | |
212 | - if ( ( $this->is_no_such_source_error( $previous_error ) || $this->is_no_linked_source_error( $previous_error ) ) && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
212 | + if (($this->is_no_such_source_error($previous_error) || $this->is_no_linked_source_error($previous_error)) && apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
213 | 213 | // Passing empty source will charge customer default. |
214 | 214 | $prepared_source->source = ''; |
215 | 215 | } |
216 | 216 | |
217 | - $request = $this->generate_payment_request( $renewal_order, $prepared_source ); |
|
217 | + $request = $this->generate_payment_request($renewal_order, $prepared_source); |
|
218 | 218 | $request['capture'] = 'true'; |
219 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
220 | - $response = WC_Stripe_API::request( $request ); |
|
219 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
220 | + $response = WC_Stripe_API::request($request); |
|
221 | 221 | |
222 | - if ( ! empty( $response->error ) ) { |
|
222 | + if ( ! empty($response->error)) { |
|
223 | 223 | // We want to retry. |
224 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
225 | - if ( $retry ) { |
|
224 | + if ($this->is_retryable_error($response->error)) { |
|
225 | + if ($retry) { |
|
226 | 226 | // Don't do anymore retries after this. |
227 | - if ( 5 <= $this->retry_interval ) { |
|
228 | - return $this->process_subscription_payment( $amount, $renewal_order, false, $response->error ); |
|
227 | + if (5 <= $this->retry_interval) { |
|
228 | + return $this->process_subscription_payment($amount, $renewal_order, false, $response->error); |
|
229 | 229 | } |
230 | 230 | |
231 | - sleep( $this->retry_interval ); |
|
231 | + sleep($this->retry_interval); |
|
232 | 232 | |
233 | 233 | $this->retry_interval++; |
234 | 234 | |
235 | - return $this->process_subscription_payment( $amount, $renewal_order, true, $response->error ); |
|
235 | + return $this->process_subscription_payment($amount, $renewal_order, true, $response->error); |
|
236 | 236 | } else { |
237 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
238 | - $renewal_order->add_order_note( $localized_message ); |
|
239 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
237 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
238 | + $renewal_order->add_order_note($localized_message); |
|
239 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
240 | 240 | } |
241 | 241 | } |
242 | 242 | |
243 | 243 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
244 | 244 | |
245 | - if ( 'card_error' === $response->error->type ) { |
|
246 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
245 | + if ('card_error' === $response->error->type) { |
|
246 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
247 | 247 | } else { |
248 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
248 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
249 | 249 | } |
250 | 250 | |
251 | - $renewal_order->add_order_note( $localized_message ); |
|
251 | + $renewal_order->add_order_note($localized_message); |
|
252 | 252 | |
253 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
253 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
254 | 254 | } |
255 | 255 | |
256 | - do_action( 'wc_gateway_stripe_process_payment', $response, $renewal_order ); |
|
256 | + do_action('wc_gateway_stripe_process_payment', $response, $renewal_order); |
|
257 | 257 | |
258 | - $this->process_response( $response, $renewal_order ); |
|
259 | - } catch ( WC_Stripe_Exception $e ) { |
|
260 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
258 | + $this->process_response($response, $renewal_order); |
|
259 | + } catch (WC_Stripe_Exception $e) { |
|
260 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
261 | 261 | |
262 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $renewal_order ); |
|
262 | + do_action('wc_gateway_stripe_process_payment_error', $e, $renewal_order); |
|
263 | 263 | |
264 | 264 | /* translators: error message */ |
265 | - $renewal_order->update_status( 'failed' ); |
|
265 | + $renewal_order->update_status('failed'); |
|
266 | 266 | |
267 | - if ( $renewal_order->has_status( array( 'pending', 'failed' ) ) ) { |
|
268 | - $this->send_failed_order_email( $order_id ); |
|
267 | + if ($renewal_order->has_status(array('pending', 'failed'))) { |
|
268 | + $this->send_failed_order_email($order_id); |
|
269 | 269 | } |
270 | 270 | } |
271 | 271 | } |
@@ -276,24 +276,24 @@ discard block |
||
276 | 276 | * @since 3.1.0 |
277 | 277 | * @version 4.0.0 |
278 | 278 | */ |
279 | - public function save_source_to_order( $order, $source ) { |
|
280 | - parent::save_source_to_order( $order, $source ); |
|
279 | + public function save_source_to_order($order, $source) { |
|
280 | + parent::save_source_to_order($order, $source); |
|
281 | 281 | |
282 | 282 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
283 | 283 | |
284 | 284 | // Also store it on the subscriptions being purchased or paid for in the order |
285 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
286 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
287 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
288 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
285 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
286 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
287 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
288 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
289 | 289 | } else { |
290 | 290 | $subscriptions = array(); |
291 | 291 | } |
292 | 292 | |
293 | - foreach ( $subscriptions as $subscription ) { |
|
293 | + foreach ($subscriptions as $subscription) { |
|
294 | 294 | $subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id(); |
295 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
296 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
295 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
296 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
297 | 297 | } |
298 | 298 | } |
299 | 299 | |
@@ -301,21 +301,21 @@ discard block |
||
301 | 301 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
302 | 302 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
303 | 303 | */ |
304 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
305 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
306 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
304 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
305 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
306 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
307 | 307 | // For BW compat will remove in future |
308 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
309 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
308 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
309 | + $this->delete_renewal_meta($resubscribe_order); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | /** |
313 | 313 | * Don't transfer Stripe fee/ID meta to renewal orders. |
314 | 314 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
315 | 315 | */ |
316 | - public function delete_renewal_meta( $renewal_order ) { |
|
317 | - WC_Stripe_Helper::delete_stripe_fee( $renewal_order ); |
|
318 | - WC_Stripe_Helper::delete_stripe_net( $renewal_order ); |
|
316 | + public function delete_renewal_meta($renewal_order) { |
|
317 | + WC_Stripe_Helper::delete_stripe_fee($renewal_order); |
|
318 | + WC_Stripe_Helper::delete_stripe_net($renewal_order); |
|
319 | 319 | |
320 | 320 | return $renewal_order; |
321 | 321 | } |
@@ -329,14 +329,14 @@ discard block |
||
329 | 329 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
330 | 330 | * @return void |
331 | 331 | */ |
332 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
333 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
334 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
335 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
332 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
333 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
334 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
335 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
336 | 336 | |
337 | 337 | } else { |
338 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
339 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
338 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
339 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
340 | 340 | } |
341 | 341 | } |
342 | 342 | |
@@ -349,21 +349,21 @@ discard block |
||
349 | 349 | * @param WC_Subscription $subscription An instance of a subscription object |
350 | 350 | * @return array |
351 | 351 | */ |
352 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
353 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
352 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
353 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
354 | 354 | |
355 | 355 | // For BW compat will remove in future. |
356 | - if ( empty( $source_id ) ) { |
|
357 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
356 | + if (empty($source_id)) { |
|
357 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
358 | 358 | |
359 | 359 | // Take this opportunity to update the key name. |
360 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id ); |
|
360 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id); |
|
361 | 361 | } |
362 | 362 | |
363 | - $payment_meta[ $this->id ] = array( |
|
363 | + $payment_meta[$this->id] = array( |
|
364 | 364 | 'post_meta' => array( |
365 | 365 | '_stripe_customer_id' => array( |
366 | - 'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
366 | + 'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
367 | 367 | 'label' => 'Stripe Customer ID', |
368 | 368 | ), |
369 | 369 | '_stripe_source_id' => array( |
@@ -386,22 +386,22 @@ discard block |
||
386 | 386 | * @param array $payment_meta associative array of meta data required for automatic payments |
387 | 387 | * @return array |
388 | 388 | */ |
389 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
390 | - if ( $this->id === $payment_method_id ) { |
|
389 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
390 | + if ($this->id === $payment_method_id) { |
|
391 | 391 | |
392 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
393 | - throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); |
|
394 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
395 | - throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
392 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
393 | + throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe')); |
|
394 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
395 | + throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe')); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | if ( |
399 | - ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
400 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) ) |
|
401 | - && ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
402 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) { |
|
399 | + ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
400 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_')) |
|
401 | + && ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
402 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) { |
|
403 | 403 | |
404 | - throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
404 | + throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe')); |
|
405 | 405 | } |
406 | 406 | } |
407 | 407 | } |
@@ -414,92 +414,92 @@ discard block |
||
414 | 414 | * @param WC_Subscription $subscription the subscription details |
415 | 415 | * @return string the subscription payment method |
416 | 416 | */ |
417 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
417 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
418 | 418 | $customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id(); |
419 | 419 | |
420 | 420 | // bail for other payment methods |
421 | - if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
421 | + if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
422 | 422 | return $payment_method_to_display; |
423 | 423 | } |
424 | 424 | |
425 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
425 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
426 | 426 | |
427 | 427 | // For BW compat will remove in future. |
428 | - if ( empty( $stripe_source_id ) ) { |
|
429 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
428 | + if (empty($stripe_source_id)) { |
|
429 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
430 | 430 | |
431 | 431 | // Take this opportunity to update the key name. |
432 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
432 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | $stripe_customer = new WC_Stripe_Customer(); |
436 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
436 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
437 | 437 | |
438 | 438 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
439 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
439 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
440 | 440 | $user_id = $customer_user; |
441 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
442 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
441 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
442 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
443 | 443 | |
444 | 444 | // For BW compat will remove in future. |
445 | - if ( empty( $stripe_source_id ) ) { |
|
446 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
445 | + if (empty($stripe_source_id)) { |
|
446 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
447 | 447 | |
448 | 448 | // Take this opportunity to update the key name. |
449 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
449 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
450 | 450 | } |
451 | 451 | } |
452 | 452 | |
453 | 453 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
454 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
455 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
456 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
454 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
455 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
456 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
457 | 457 | |
458 | 458 | // For BW compat will remove in future. |
459 | - if ( empty( $stripe_source_id ) ) { |
|
460 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
459 | + if (empty($stripe_source_id)) { |
|
460 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
461 | 461 | |
462 | 462 | // Take this opportunity to update the key name. |
463 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id ); |
|
463 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id); |
|
464 | 464 | } |
465 | 465 | } |
466 | 466 | |
467 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
467 | + $stripe_customer->set_id($stripe_customer_id); |
|
468 | 468 | $sources = $stripe_customer->get_sources(); |
469 | 469 | |
470 | - if ( $sources ) { |
|
470 | + if ($sources) { |
|
471 | 471 | $card = false; |
472 | 472 | $found_source = false; |
473 | - foreach ( $sources as $source ) { |
|
474 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
473 | + foreach ($sources as $source) { |
|
474 | + if (isset($source->type) && 'card' === $source->type) { |
|
475 | 475 | $card = $source->card; |
476 | - } elseif ( isset( $source->object ) && 'card' === $source->object ) { |
|
476 | + } elseif (isset($source->object) && 'card' === $source->object) { |
|
477 | 477 | $card = $source; |
478 | 478 | } |
479 | 479 | |
480 | - if ( $source->id === $stripe_source_id ) { |
|
480 | + if ($source->id === $stripe_source_id) { |
|
481 | 481 | $found_source = true; |
482 | 482 | |
483 | - if ( $card ) { |
|
483 | + if ($card) { |
|
484 | 484 | /* translators: 1) card brand 2) last 4 digits */ |
485 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
485 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
486 | 486 | } else { |
487 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
487 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
488 | 488 | } |
489 | 489 | break; |
490 | 490 | } |
491 | 491 | } |
492 | 492 | |
493 | - if ( ! $found_source ) { |
|
494 | - if ( 'card' === $sources[0]->type ) { |
|
493 | + if ( ! $found_source) { |
|
494 | + if ('card' === $sources[0]->type) { |
|
495 | 495 | $card = $sources[0]->card; |
496 | 496 | } |
497 | 497 | |
498 | - if ( $card ) { |
|
498 | + if ($card) { |
|
499 | 499 | /* translators: 1) card brand 2) last 4 digits */ |
500 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
500 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
501 | 501 | } else { |
502 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
502 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
503 | 503 | } |
504 | 504 | } |
505 | 505 | } |