@@ -34,9 +34,9 @@ discard block |
||
34 | 34 | public function setUp() { |
35 | 35 | parent::setUp(); |
36 | 36 | |
37 | - $this->wc_stripe_subs_compat = $this->getMockBuilder( 'WC_Stripe_Subs_Compat' ) |
|
37 | + $this->wc_stripe_subs_compat = $this->getMockBuilder('WC_Stripe_Subs_Compat') |
|
38 | 38 | ->disableOriginalConstructor() |
39 | - ->setMethods( array( 'prepare_source', 'has_subscription' ) ) |
|
39 | + ->setMethods(array('prepare_source', 'has_subscription')) |
|
40 | 40 | ->getMock(); |
41 | 41 | |
42 | 42 | // Mocked in order to get metadata[payment_type] = recurring in the HTTP request. |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function tearDown() { |
56 | 56 | parent::tearDown(); |
57 | - delete_option( 'woocommerce_stripe_settings' ); |
|
57 | + delete_option('woocommerce_stripe_settings'); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -70,21 +70,21 @@ discard block |
||
70 | 70 | public function test_initial_intent_parameters() { |
71 | 71 | $initial_order = WC_Helper_Order::create_order(); |
72 | 72 | $order_id = $initial_order->get_id(); |
73 | - $stripe_amount = WC_Stripe_Helper::get_stripe_amount( $initial_order->get_total() ); |
|
74 | - $currency = strtolower( $initial_order->get_currency() ); |
|
73 | + $stripe_amount = WC_Stripe_Helper::get_stripe_amount($initial_order->get_total()); |
|
74 | + $currency = strtolower($initial_order->get_currency()); |
|
75 | 75 | $customer = 'cus_123abc'; |
76 | 76 | $source = 'src_123abc'; |
77 | - $statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
77 | + $statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
78 | 78 | $intents_api_endpoint = 'https://api.stripe.com/v1/payment_intents'; |
79 | 79 | $urls_used = array(); |
80 | 80 | |
81 | - $initial_order->set_payment_method( 'stripe' ); |
|
81 | + $initial_order->set_payment_method('stripe'); |
|
82 | 82 | $initial_order->save(); |
83 | 83 | |
84 | 84 | // Arrange: Mock prepare_source() so that we have a customer and source. |
85 | 85 | $this->wc_stripe_subs_compat |
86 | - ->expects( $this->any() ) |
|
87 | - ->method( 'prepare_source' ) |
|
86 | + ->expects($this->any()) |
|
87 | + ->method('prepare_source') |
|
88 | 88 | ->will( |
89 | 89 | $this->returnValue( |
90 | 90 | (object) array( |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | |
99 | 99 | // Emulate a subscription. |
100 | 100 | $this->wc_stripe_subs_compat |
101 | - ->expects( $this->any() ) |
|
102 | - ->method( 'has_subscription' ) |
|
103 | - ->will( $this->returnValue( true ) ); |
|
101 | + ->expects($this->any()) |
|
102 | + ->method('has_subscription') |
|
103 | + ->will($this->returnValue(true)); |
|
104 | 104 | |
105 | - $pre_http_request_response_callback = function( $preempt, $request_args, $url ) use ( |
|
105 | + $pre_http_request_response_callback = function($preempt, $request_args, $url) use ( |
|
106 | 106 | $stripe_amount, |
107 | 107 | $currency, |
108 | 108 | $customer, |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | &$urls_used |
114 | 114 | ) { |
115 | 115 | // Add all urls to array so we can later make assertions about which endpoints were used. |
116 | - array_push( $urls_used, $url ); |
|
116 | + array_push($urls_used, $url); |
|
117 | 117 | // Continue without mocking the request if it's not the endpoint we care about. |
118 | - if ( 0 !== strpos( $url, $intents_api_endpoint ) ) { |
|
118 | + if (0 !== strpos($url, $intents_api_endpoint)) { |
|
119 | 119 | return false; |
120 | 120 | } |
121 | 121 | |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | $response = array( |
124 | 124 | 'headers' => array(), |
125 | 125 | // Too bad we aren't dynamically setting things 'cus_123abc' when using this file. |
126 | - 'body' => file_get_contents( 'tests/phpunit/dummy-data/subscription_signup_response_success.json' ), |
|
126 | + 'body' => file_get_contents('tests/phpunit/dummy-data/subscription_signup_response_success.json'), |
|
127 | 127 | 'response' => array( |
128 | 128 | 'code' => 200, |
129 | 129 | 'message' => 'OK', |
@@ -133,17 +133,17 @@ discard block |
||
133 | 133 | ); |
134 | 134 | |
135 | 135 | // Respond with a successfull intent for confirmations. |
136 | - if ( $url !== $intents_api_endpoint ) { |
|
137 | - $response['body'] = str_replace( 'requires_confirmation', 'succeeded', $response['body'] ); |
|
136 | + if ($url !== $intents_api_endpoint) { |
|
137 | + $response['body'] = str_replace('requires_confirmation', 'succeeded', $response['body']); |
|
138 | 138 | return $response; |
139 | 139 | } |
140 | 140 | |
141 | 141 | // Assert: the request method is POST. |
142 | - $this->assertArrayHasKey( 'method', $request_args ); |
|
143 | - $this->assertSame( 'POST', $request_args['method'] ); |
|
142 | + $this->assertArrayHasKey('method', $request_args); |
|
143 | + $this->assertSame('POST', $request_args['method']); |
|
144 | 144 | |
145 | 145 | // Assert: the request has a body. |
146 | - $this->assertArrayHasKey( 'body', $request_args ); |
|
146 | + $this->assertArrayHasKey('body', $request_args); |
|
147 | 147 | |
148 | 148 | // Assert: the request body contains these values. |
149 | 149 | $expected_request_body_values = array( |
@@ -153,11 +153,11 @@ discard block |
||
153 | 153 | 'statement_descriptor' => $statement_descriptor, |
154 | 154 | 'customer' => $customer, |
155 | 155 | 'setup_future_usage' => 'off_session', |
156 | - 'payment_method_types' => array( 'card' ), |
|
156 | + 'payment_method_types' => array('card'), |
|
157 | 157 | ); |
158 | - foreach ( $expected_request_body_values as $key => $value ) { |
|
159 | - $this->assertArrayHasKey( $key, $request_args['body'] ); |
|
160 | - $this->assertSame( $value, $request_args['body'][ $key ] ); |
|
158 | + foreach ($expected_request_body_values as $key => $value) { |
|
159 | + $this->assertArrayHasKey($key, $request_args['body']); |
|
160 | + $this->assertSame($value, $request_args['body'][$key]); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | // Assert: the request body contains these keys, without checking for their value. |
@@ -165,45 +165,45 @@ discard block |
||
165 | 165 | 'description', |
166 | 166 | 'capture_method', |
167 | 167 | ); |
168 | - foreach ( $expected_request_body_keys as $key ) { |
|
169 | - $this->assertArrayHasKey( $key, $request_args['body'] ); |
|
168 | + foreach ($expected_request_body_keys as $key) { |
|
169 | + $this->assertArrayHasKey($key, $request_args['body']); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | // Assert: the body metadata contains the order ID. |
173 | - $this->assertSame( $order_id, absint( $request_args['body']['metadata']['order_id'] ) ); |
|
173 | + $this->assertSame($order_id, absint($request_args['body']['metadata']['order_id'])); |
|
174 | 174 | |
175 | 175 | // // Assert: the body metadata has these keys, without checking for their value. |
176 | 176 | $expected_metadata_keys = array( |
177 | 177 | 'customer_name', |
178 | 178 | 'customer_email', |
179 | 179 | ); |
180 | - foreach ( $expected_metadata_keys as $key ) { |
|
181 | - $this->assertArrayHasKey( $key, $request_args['body']['metadata'] ); |
|
180 | + foreach ($expected_metadata_keys as $key) { |
|
181 | + $this->assertArrayHasKey($key, $request_args['body']['metadata']); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | // Return dummy content as the response. |
185 | 185 | return $response; |
186 | 186 | }; |
187 | - add_filter( 'pre_http_request', $pre_http_request_response_callback, 10, 3 ); |
|
187 | + add_filter('pre_http_request', $pre_http_request_response_callback, 10, 3); |
|
188 | 188 | |
189 | 189 | // Act: call process_subscription_payment(). |
190 | 190 | // We need to use `wc_stripe_subs_compat` here because we mocked this class earlier. |
191 | - $result = $this->wc_stripe_subs_compat->process_payment( $order_id ); |
|
191 | + $result = $this->wc_stripe_subs_compat->process_payment($order_id); |
|
192 | 192 | |
193 | 193 | // Assert: nothing was returned. |
194 | - $this->assertEquals( $result['result'], 'success' ); |
|
195 | - $this->assertArrayHasKey( 'redirect', $result ); |
|
194 | + $this->assertEquals($result['result'], 'success'); |
|
195 | + $this->assertArrayHasKey('redirect', $result); |
|
196 | 196 | |
197 | - $order = wc_get_order( $order_id ); |
|
198 | - $this->assertNotFalse( $order ); |
|
199 | - $order_data = $order->get_meta( '_stripe_intent_id' ); |
|
197 | + $order = wc_get_order($order_id); |
|
198 | + $this->assertNotFalse($order); |
|
199 | + $order_data = $order->get_meta('_stripe_intent_id'); |
|
200 | 200 | |
201 | - $this->assertEquals( $order_data, 'pi_123abc' ); |
|
201 | + $this->assertEquals($order_data, 'pi_123abc'); |
|
202 | 202 | |
203 | 203 | // Assert: called payment intents. |
204 | - $this->assertTrue( in_array( $intents_api_endpoint, $urls_used, true ) ); |
|
204 | + $this->assertTrue(in_array($intents_api_endpoint, $urls_used, true)); |
|
205 | 205 | |
206 | 206 | // Clean up. |
207 | - remove_filter( 'pre_http_request', array( $this, 'pre_http_request_response_success' ) ); |
|
207 | + remove_filter('pre_http_request', array($this, 'pre_http_request_response_success')); |
|
208 | 208 | } |
209 | 209 | } |
@@ -34,17 +34,17 @@ discard block |
||
34 | 34 | public function setUp() { |
35 | 35 | parent::setUp(); |
36 | 36 | |
37 | - $this->wc_stripe_subs_compat = $this->getMockBuilder( 'WC_Stripe_Subs_Compat' ) |
|
37 | + $this->wc_stripe_subs_compat = $this->getMockBuilder('WC_Stripe_Subs_Compat') |
|
38 | 38 | ->disableOriginalConstructor() |
39 | - ->setMethods( array( 'prepare_order_source', 'has_subscription', 'ensure_subscription_has_customer_id' ) ) |
|
39 | + ->setMethods(array('prepare_order_source', 'has_subscription', 'ensure_subscription_has_customer_id')) |
|
40 | 40 | ->getMock(); |
41 | 41 | |
42 | 42 | // Mocked in order to get metadata[payment_type] = recurring in the HTTP request. |
43 | 43 | $this->wc_stripe_subs_compat |
44 | - ->expects( $this->any() ) |
|
45 | - ->method( 'has_subscription' ) |
|
44 | + ->expects($this->any()) |
|
45 | + ->method('has_subscription') |
|
46 | 46 | ->will( |
47 | - $this->returnValue( true ) |
|
47 | + $this->returnValue(true) |
|
48 | 48 | ); |
49 | 49 | |
50 | 50 | $this->statement_descriptor = 'This is a statement descriptor.'; |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | public function tearDown() { |
63 | 63 | parent::tearDown(); |
64 | 64 | |
65 | - delete_option( 'woocommerce_stripe_settings' ); |
|
65 | + delete_option('woocommerce_stripe_settings'); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -79,22 +79,22 @@ discard block |
||
79 | 79 | // Arrange: Some variables we'll use later. |
80 | 80 | $renewal_order = WC_Helper_Order::create_order(); |
81 | 81 | $amount = 20; // WC Subs sends an amount to be used, instead of using the order amount. |
82 | - $stripe_amount = WC_Stripe_Helper::get_stripe_amount( $amount ); |
|
83 | - $currency = strtolower( $renewal_order->get_currency() ); |
|
82 | + $stripe_amount = WC_Stripe_Helper::get_stripe_amount($amount); |
|
83 | + $currency = strtolower($renewal_order->get_currency()); |
|
84 | 84 | $customer = 'cus_123abc'; |
85 | 85 | $source = 'src_123abc'; |
86 | - $statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
86 | + $statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
87 | 87 | $should_retry = false; |
88 | 88 | $previous_error = false; |
89 | 89 | $payments_intents_api_endpoint = 'https://api.stripe.com/v1/payment_intents'; |
90 | 90 | $urls_used = array(); |
91 | 91 | |
92 | - $renewal_order->set_payment_method( 'stripe' ); |
|
92 | + $renewal_order->set_payment_method('stripe'); |
|
93 | 93 | |
94 | 94 | // Arrange: Mock prepare_order_source() so that we have a customer and source. |
95 | 95 | $this->wc_stripe_subs_compat |
96 | - ->expects( $this->any() ) |
|
97 | - ->method( 'prepare_order_source' ) |
|
96 | + ->expects($this->any()) |
|
97 | + ->method('prepare_order_source') |
|
98 | 98 | ->will( |
99 | 99 | $this->returnValue( |
100 | 100 | (object) array( |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | |
109 | 109 | // Arrange: Add filter that will return a mocked HTTP response for the payment_intent call. |
110 | 110 | // Note: There are assertions in the callback function. |
111 | - $pre_http_request_response_callback = function( $preempt, $request_args, $url ) use ( |
|
111 | + $pre_http_request_response_callback = function($preempt, $request_args, $url) use ( |
|
112 | 112 | $renewal_order, |
113 | 113 | $stripe_amount, |
114 | 114 | $currency, |
@@ -119,35 +119,35 @@ discard block |
||
119 | 119 | &$urls_used |
120 | 120 | ) { |
121 | 121 | // Add all urls to array so we can later make assertions about which endpoints were used. |
122 | - array_push( $urls_used, $url ); |
|
122 | + array_push($urls_used, $url); |
|
123 | 123 | |
124 | 124 | // Continue without mocking the request if it's not the endpoint we care about. |
125 | - if ( $payments_intents_api_endpoint !== $url ) { |
|
125 | + if ($payments_intents_api_endpoint !== $url) { |
|
126 | 126 | return false; |
127 | 127 | } |
128 | 128 | |
129 | 129 | // Assert: the request method is POST. |
130 | - $this->assertArrayHasKey( 'method', $request_args ); |
|
131 | - $this->assertSame( 'POST', $request_args['method'] ); |
|
130 | + $this->assertArrayHasKey('method', $request_args); |
|
131 | + $this->assertSame('POST', $request_args['method']); |
|
132 | 132 | |
133 | 133 | // Assert: the request has a body. |
134 | - $this->assertArrayHasKey( 'body', $request_args ); |
|
134 | + $this->assertArrayHasKey('body', $request_args); |
|
135 | 135 | |
136 | 136 | // Assert: the request body contains these values. |
137 | 137 | $expected_request_body_values = array( |
138 | 138 | 'source' => $source, |
139 | 139 | 'amount' => $stripe_amount, |
140 | 140 | 'currency' => $currency, |
141 | - 'payment_method_types' => array( 'card' ), |
|
141 | + 'payment_method_types' => array('card'), |
|
142 | 142 | 'customer' => $customer, |
143 | 143 | 'off_session' => 'true', |
144 | 144 | 'confirm' => 'true', |
145 | 145 | 'confirmation_method' => 'automatic', |
146 | 146 | 'statement_descriptor' => $statement_descriptor, |
147 | 147 | ); |
148 | - foreach ( $expected_request_body_values as $key => $value ) { |
|
149 | - $this->assertArrayHasKey( $key, $request_args['body'] ); |
|
150 | - $this->assertSame( $value, $request_args['body'][ $key ] ); |
|
148 | + foreach ($expected_request_body_values as $key => $value) { |
|
149 | + $this->assertArrayHasKey($key, $request_args['body']); |
|
150 | + $this->assertSame($value, $request_args['body'][$key]); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | // Assert: the request body contains these keys, without checking for their value. |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | 'description', |
156 | 156 | 'metadata', |
157 | 157 | ); |
158 | - foreach ( $expected_request_body_keys as $key ) { |
|
159 | - $this->assertArrayHasKey( $key, $request_args['body'] ); |
|
158 | + foreach ($expected_request_body_keys as $key) { |
|
159 | + $this->assertArrayHasKey($key, $request_args['body']); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | // Assert: the body metadata has these values. |
@@ -165,9 +165,9 @@ discard block |
||
165 | 165 | 'order_id' => $order_id, |
166 | 166 | 'payment_type' => 'recurring', |
167 | 167 | ); |
168 | - foreach ( $expected_metadata_values as $key => $value ) { |
|
169 | - $this->assertArrayHasKey( $key, $request_args['body']['metadata'] ); |
|
170 | - $this->assertSame( $value, $request_args['body']['metadata'][ $key ] ); |
|
168 | + foreach ($expected_metadata_values as $key => $value) { |
|
169 | + $this->assertArrayHasKey($key, $request_args['body']['metadata']); |
|
170 | + $this->assertSame($value, $request_args['body']['metadata'][$key]); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | // Assert: the body metadata has these keys, without checking for their value. |
@@ -176,8 +176,8 @@ discard block |
||
176 | 176 | 'customer_email', |
177 | 177 | 'site_url', |
178 | 178 | ); |
179 | - foreach ( $expected_metadata_keys as $key ) { |
|
180 | - $this->assertArrayHasKey( $key, $request_args['body']['metadata'] ); |
|
179 | + foreach ($expected_metadata_keys as $key) { |
|
180 | + $this->assertArrayHasKey($key, $request_args['body']['metadata']); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | // Assert: the request body does not contains these keys. |
@@ -186,15 +186,15 @@ discard block |
||
186 | 186 | 'capture_method', // The default ('automatic') is what we want in this case, so we leave it off. |
187 | 187 | 'expand[]', |
188 | 188 | ); |
189 | - foreach ( $expected_missing_request_body_keys as $key ) { |
|
190 | - $this->assertArrayNotHasKey( $key, $request_args['body'] ); |
|
189 | + foreach ($expected_missing_request_body_keys as $key) { |
|
190 | + $this->assertArrayNotHasKey($key, $request_args['body']); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | // Arrange: return dummy content as the response. |
194 | 194 | return array( |
195 | 195 | 'headers' => array(), |
196 | 196 | // Too bad we aren't dynamically setting things 'cus_123abc' when using this file. |
197 | - 'body' => file_get_contents( 'tests/phpunit/dummy-data/subscription_renewal_response_success.json' ), |
|
197 | + 'body' => file_get_contents('tests/phpunit/dummy-data/subscription_renewal_response_success.json'), |
|
198 | 198 | 'response' => array( |
199 | 199 | 'code' => 200, |
200 | 200 | 'message' => 'OK', |
@@ -204,48 +204,48 @@ discard block |
||
204 | 204 | ); |
205 | 205 | }; |
206 | 206 | |
207 | - add_filter( 'pre_http_request', $pre_http_request_response_callback, 10, 3 ); |
|
207 | + add_filter('pre_http_request', $pre_http_request_response_callback, 10, 3); |
|
208 | 208 | |
209 | 209 | // Arrange: Make sure to check that an action we care about was called |
210 | 210 | // by hooking into it. |
211 | 211 | $mock_action_process_payment = new MockAction(); |
212 | 212 | add_action( |
213 | 213 | 'wc_gateway_stripe_process_payment', |
214 | - [ &$mock_action_process_payment, 'action' ] |
|
214 | + [&$mock_action_process_payment, 'action'] |
|
215 | 215 | ); |
216 | 216 | |
217 | 217 | // Act: call process_subscription_payment(). |
218 | 218 | // We need to use `wc_stripe_subs_compat` here because we mocked this class earlier. |
219 | - $result = $this->wc_stripe_subs_compat->process_subscription_payment( 20, $renewal_order, $should_retry, $previous_error ); |
|
219 | + $result = $this->wc_stripe_subs_compat->process_subscription_payment(20, $renewal_order, $should_retry, $previous_error); |
|
220 | 220 | |
221 | 221 | // Assert: nothing was returned. |
222 | - $this->assertEquals( $result, null ); |
|
222 | + $this->assertEquals($result, null); |
|
223 | 223 | |
224 | 224 | // Assert that we saved the payment intent to the order. |
225 | - $order = wc_get_order( $renewal_order->get_id() ); |
|
226 | - $this->assertNotFalse( $order ); |
|
227 | - $order_data = $order->get_meta( '_stripe_intent_id' ); |
|
225 | + $order = wc_get_order($renewal_order->get_id()); |
|
226 | + $this->assertNotFalse($order); |
|
227 | + $order_data = $order->get_meta('_stripe_intent_id'); |
|
228 | 228 | |
229 | - $this->assertEquals( $order_data, 'pi_123abc' ); |
|
229 | + $this->assertEquals($order_data, 'pi_123abc'); |
|
230 | 230 | |
231 | 231 | // Transaction ID was saved to order. |
232 | 232 | $order_transaction_id = $order->get_transaction_id(); |
233 | - $this->assertEquals( $order_transaction_id, 'ch_123abc' ); |
|
233 | + $this->assertEquals($order_transaction_id, 'ch_123abc'); |
|
234 | 234 | |
235 | 235 | // Assert: the order was marked as processing (this is done in process_response()). |
236 | - $this->assertEquals( $order->get_status(), 'processing' ); |
|
236 | + $this->assertEquals($order->get_status(), 'processing'); |
|
237 | 237 | |
238 | 238 | // Assert: called payment intents. |
239 | - $this->assertTrue( in_array( $payments_intents_api_endpoint, $urls_used ) ); |
|
239 | + $this->assertTrue(in_array($payments_intents_api_endpoint, $urls_used)); |
|
240 | 240 | |
241 | 241 | // Assert: Our hook was called once. |
242 | - $this->assertEquals( 1, $mock_action_process_payment->get_call_count() ); |
|
242 | + $this->assertEquals(1, $mock_action_process_payment->get_call_count()); |
|
243 | 243 | |
244 | 244 | // Assert: Only our hook was called. |
245 | - $this->assertEquals( array( 'wc_gateway_stripe_process_payment' ), $mock_action_process_payment->get_tags() ); |
|
245 | + $this->assertEquals(array('wc_gateway_stripe_process_payment'), $mock_action_process_payment->get_tags()); |
|
246 | 246 | |
247 | 247 | // Clean up. |
248 | - remove_filter( 'pre_http_request', array( $this, 'pre_http_request_response_success' ) ); |
|
248 | + remove_filter('pre_http_request', array($this, 'pre_http_request_response_success')); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
@@ -262,8 +262,8 @@ discard block |
||
262 | 262 | // Arrange: Some variables we'll use later. |
263 | 263 | $renewal_order = WC_Helper_Order::create_order(); |
264 | 264 | $amount = 20; |
265 | - $stripe_amount = WC_Stripe_Helper::get_stripe_amount( $amount ); |
|
266 | - $currency = strtolower( $renewal_order->get_currency() ); |
|
265 | + $stripe_amount = WC_Stripe_Helper::get_stripe_amount($amount); |
|
266 | + $currency = strtolower($renewal_order->get_currency()); |
|
267 | 267 | $customer = 'cus_123abc'; |
268 | 268 | $source = 'src_123abc'; |
269 | 269 | $should_retry = false; |
@@ -273,8 +273,8 @@ discard block |
||
273 | 273 | |
274 | 274 | // Arrange: Mock prepare_order_source() so that we have a customer and source. |
275 | 275 | $this->wc_stripe_subs_compat |
276 | - ->expects( $this->any() ) |
|
277 | - ->method( 'prepare_order_source' ) |
|
276 | + ->expects($this->any()) |
|
277 | + ->method('prepare_order_source') |
|
278 | 278 | ->will( |
279 | 279 | $this->returnValue( |
280 | 280 | (object) array( |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | ); |
288 | 288 | |
289 | 289 | // Arrange: Add filter that will return a mocked HTTP response for the payment_intent call. |
290 | - $pre_http_request_response_callback = function( $preempt, $request_args, $url ) use ( |
|
290 | + $pre_http_request_response_callback = function($preempt, $request_args, $url) use ( |
|
291 | 291 | $renewal_order, |
292 | 292 | $stripe_amount, |
293 | 293 | $currency, |
@@ -297,10 +297,10 @@ discard block |
||
297 | 297 | &$urls_used |
298 | 298 | ) { |
299 | 299 | // Add all urls to array so we can later make assertions about which endpoints were used. |
300 | - array_push( $urls_used, $url ); |
|
300 | + array_push($urls_used, $url); |
|
301 | 301 | |
302 | 302 | // Continue without mocking the request if it's not the endpoint we care about. |
303 | - if ( $payments_intents_api_endpoint !== $url ) { |
|
303 | + if ($payments_intents_api_endpoint !== $url) { |
|
304 | 304 | return false; |
305 | 305 | } |
306 | 306 | |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | return array( |
309 | 309 | 'headers' => array(), |
310 | 310 | // Too bad we aren't dynamically setting things 'cus_123abc' when using this file. |
311 | - 'body' => file_get_contents( 'tests/phpunit/dummy-data/subscription_renewal_response_authentication_required.json' ), |
|
311 | + 'body' => file_get_contents('tests/phpunit/dummy-data/subscription_renewal_response_authentication_required.json'), |
|
312 | 312 | 'response' => array( |
313 | 313 | 'code' => 402, |
314 | 314 | 'message' => 'Payment Required', |
@@ -317,48 +317,48 @@ discard block |
||
317 | 317 | 'filename' => null, |
318 | 318 | ); |
319 | 319 | }; |
320 | - add_filter( 'pre_http_request', $pre_http_request_response_callback, 10, 3 ); |
|
320 | + add_filter('pre_http_request', $pre_http_request_response_callback, 10, 3); |
|
321 | 321 | |
322 | 322 | // Arrange: Make sure to check that an action we care about was called |
323 | 323 | // by hooking into it. |
324 | 324 | $mock_action_process_payment = new MockAction(); |
325 | 325 | add_action( |
326 | 326 | 'wc_gateway_stripe_process_payment_authentication_required', |
327 | - [ &$mock_action_process_payment, 'action' ] |
|
327 | + [&$mock_action_process_payment, 'action'] |
|
328 | 328 | ); |
329 | 329 | |
330 | 330 | // Act: call process_subscription_payment(). |
331 | 331 | // We need to use `wc_stripe_subs_compat` here because we mocked this class earlier. |
332 | - $result = $this->wc_stripe_subs_compat->process_subscription_payment( 20, $renewal_order, $should_retry, $previous_error ); |
|
332 | + $result = $this->wc_stripe_subs_compat->process_subscription_payment(20, $renewal_order, $should_retry, $previous_error); |
|
333 | 333 | |
334 | 334 | // Assert: nothing was returned. |
335 | - $this->assertEquals( $result, null ); |
|
335 | + $this->assertEquals($result, null); |
|
336 | 336 | |
337 | 337 | // Assert that we saved the payment intent to the order. |
338 | - $order = wc_get_order( $renewal_order->get_id() ); |
|
339 | - $this->assertNotFalse( $order ); |
|
340 | - $order_data = $order->get_meta( '_stripe_intent_id' ); |
|
338 | + $order = wc_get_order($renewal_order->get_id()); |
|
339 | + $this->assertNotFalse($order); |
|
340 | + $order_data = $order->get_meta('_stripe_intent_id'); |
|
341 | 341 | $order_transaction_id = $order->get_transaction_id(); |
342 | 342 | |
343 | 343 | // Intent was saved to order even though there was an error in the response body. |
344 | - $this->assertEquals( $order_data, 'pi_123abc' ); |
|
344 | + $this->assertEquals($order_data, 'pi_123abc'); |
|
345 | 345 | |
346 | 346 | // Transaction ID was saved to order. |
347 | - $this->assertEquals( $order_transaction_id, 'ch_123abc' ); |
|
347 | + $this->assertEquals($order_transaction_id, 'ch_123abc'); |
|
348 | 348 | |
349 | 349 | // Assert: the order was marked as failed. |
350 | - $this->assertEquals( $order->get_status(), 'failed' ); |
|
350 | + $this->assertEquals($order->get_status(), 'failed'); |
|
351 | 351 | |
352 | 352 | // Assert: called payment intents. |
353 | - $this->assertTrue( in_array( $payments_intents_api_endpoint, $urls_used ) ); |
|
353 | + $this->assertTrue(in_array($payments_intents_api_endpoint, $urls_used)); |
|
354 | 354 | |
355 | 355 | // Assert: Our hook was called once. |
356 | - $this->assertEquals( 1, $mock_action_process_payment->get_call_count() ); |
|
356 | + $this->assertEquals(1, $mock_action_process_payment->get_call_count()); |
|
357 | 357 | |
358 | 358 | // Assert: Only our hook was called. |
359 | - $this->assertEquals( array( 'wc_gateway_stripe_process_payment_authentication_required' ), $mock_action_process_payment->get_tags() ); |
|
359 | + $this->assertEquals(array('wc_gateway_stripe_process_payment_authentication_required'), $mock_action_process_payment->get_tags()); |
|
360 | 360 | |
361 | 361 | // Clean up. |
362 | - remove_filter( 'pre_http_request', array( $this, 'pre_http_request_response_success' ) ); |
|
362 | + remove_filter('pre_http_request', array($this, 'pre_http_request_response_success')); |
|
363 | 363 | } |
364 | 364 | } |