@@ -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; |
@@ -81,10 +81,10 @@ discard block |
||
81 | 81 | return apply_filters( |
82 | 82 | 'woocommerce_stripe_request_headers', |
83 | 83 | array( |
84 | - 'Authorization' => 'Basic ' . base64_encode( self::get_secret_key() . ':' ), |
|
84 | + 'Authorization' => 'Basic ' . base64_encode(self::get_secret_key() . ':'), |
|
85 | 85 | 'Stripe-Version' => self::STRIPE_API_VERSION, |
86 | 86 | 'User-Agent' => $app_info['name'] . '/' . $app_info['version'] . ' (' . $app_info['url'] . ')', |
87 | - 'X-Stripe-Client-User-Agent' => json_encode( $user_agent ), |
|
87 | + 'X-Stripe-Client-User-Agent' => json_encode($user_agent), |
|
88 | 88 | ) |
89 | 89 | ); |
90 | 90 | } |
@@ -101,16 +101,16 @@ discard block |
||
101 | 101 | * @return stdClass|array |
102 | 102 | * @throws WC_Stripe_Exception |
103 | 103 | */ |
104 | - public static function request( $request, $api = 'charges', $method = 'POST', $with_headers = false ) { |
|
105 | - WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) ); |
|
104 | + public static function request($request, $api = 'charges', $method = 'POST', $with_headers = false) { |
|
105 | + WC_Stripe_Logger::log("{$api} request: " . print_r($request, true)); |
|
106 | 106 | |
107 | 107 | $headers = self::get_headers(); |
108 | 108 | $idempotency_key = ''; |
109 | 109 | |
110 | - if ( 'charges' === $api && 'POST' === $method ) { |
|
111 | - $customer = ! empty( $request['customer'] ) ? $request['customer'] : ''; |
|
112 | - $source = ! empty( $request['source'] ) ? $request['source'] : $customer; |
|
113 | - $idempotency_key = apply_filters( 'wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request ); |
|
110 | + if ('charges' === $api && 'POST' === $method) { |
|
111 | + $customer = ! empty($request['customer']) ? $request['customer'] : ''; |
|
112 | + $source = ! empty($request['source']) ? $request['source'] : $customer; |
|
113 | + $idempotency_key = apply_filters('wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request); |
|
114 | 114 | |
115 | 115 | $headers['Idempotency-Key'] = $idempotency_key; |
116 | 116 | } |
@@ -120,14 +120,14 @@ discard block |
||
120 | 120 | array( |
121 | 121 | 'method' => $method, |
122 | 122 | 'headers' => $headers, |
123 | - 'body' => apply_filters( 'woocommerce_stripe_request_body', $request, $api ), |
|
123 | + 'body' => apply_filters('woocommerce_stripe_request_body', $request, $api), |
|
124 | 124 | 'timeout' => 70, |
125 | 125 | ) |
126 | 126 | ); |
127 | 127 | |
128 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
128 | + if (is_wp_error($response) || empty($response['body'])) { |
|
129 | 129 | WC_Stripe_Logger::log( |
130 | - 'Error Response: ' . print_r( $response, true ) . PHP_EOL . PHP_EOL . 'Failed request: ' . print_r( |
|
130 | + 'Error Response: ' . print_r($response, true) . PHP_EOL . PHP_EOL . 'Failed request: ' . print_r( |
|
131 | 131 | array( |
132 | 132 | 'api' => $api, |
133 | 133 | 'request' => $request, |
@@ -137,17 +137,17 @@ discard block |
||
137 | 137 | ) |
138 | 138 | ); |
139 | 139 | |
140 | - throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
140 | + throw new WC_Stripe_Exception(print_r($response, true), __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
141 | 141 | } |
142 | 142 | |
143 | - if ( $with_headers ) { |
|
143 | + if ($with_headers) { |
|
144 | 144 | return array( |
145 | - 'headers' => wp_remote_retrieve_headers( $response ), |
|
146 | - 'body' => json_decode( $response['body'] ), |
|
145 | + 'headers' => wp_remote_retrieve_headers($response), |
|
146 | + 'body' => json_decode($response['body']), |
|
147 | 147 | ); |
148 | 148 | } |
149 | 149 | |
150 | - return json_decode( $response['body'] ); |
|
150 | + return json_decode($response['body']); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -157,8 +157,8 @@ discard block |
||
157 | 157 | * @version 4.0.0 |
158 | 158 | * @param string $api |
159 | 159 | */ |
160 | - public static function retrieve( $api ) { |
|
161 | - WC_Stripe_Logger::log( "{$api}" ); |
|
160 | + public static function retrieve($api) { |
|
161 | + WC_Stripe_Logger::log("{$api}"); |
|
162 | 162 | |
163 | 163 | $response = wp_safe_remote_get( |
164 | 164 | self::ENDPOINT . $api, |
@@ -169,11 +169,11 @@ discard block |
||
169 | 169 | ) |
170 | 170 | ); |
171 | 171 | |
172 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
173 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
174 | - return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
172 | + if (is_wp_error($response) || empty($response['body'])) { |
|
173 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
174 | + return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
175 | 175 | } |
176 | 176 | |
177 | - return json_decode( $response['body'] ); |
|
177 | + return json_decode($response['body']); |
|
178 | 178 | } |
179 | 179 | } |