@@ -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 | } |
@@ -99,16 +99,16 @@ discard block |
||
| 99 | 99 | * @param bool $with_headers To get the response with headers. |
| 100 | 100 | * @return array|WP_Error |
| 101 | 101 | */ |
| 102 | - public static function request( $request, $api = 'charges', $method = 'POST', $with_headers = false ) { |
|
| 103 | - WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) ); |
|
| 102 | + public static function request($request, $api = 'charges', $method = 'POST', $with_headers = false) { |
|
| 103 | + WC_Stripe_Logger::log("{$api} request: " . print_r($request, true)); |
|
| 104 | 104 | |
| 105 | 105 | $headers = self::get_headers(); |
| 106 | 106 | $idempotency_key = ''; |
| 107 | 107 | |
| 108 | - if ( 'charges' === $api && 'POST' === $method ) { |
|
| 109 | - $customer = ! empty( $request['customer'] ) ? $request['customer'] : ''; |
|
| 110 | - $source = ! empty( $request['source'] ) ? $request['source'] : $customer; |
|
| 111 | - $idempotency_key = apply_filters( 'wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request ); |
|
| 108 | + if ('charges' === $api && 'POST' === $method) { |
|
| 109 | + $customer = ! empty($request['customer']) ? $request['customer'] : ''; |
|
| 110 | + $source = ! empty($request['source']) ? $request['source'] : $customer; |
|
| 111 | + $idempotency_key = apply_filters('wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request); |
|
| 112 | 112 | |
| 113 | 113 | $headers['Idempotency-Key'] = $idempotency_key; |
| 114 | 114 | } |
@@ -118,14 +118,14 @@ discard block |
||
| 118 | 118 | array( |
| 119 | 119 | 'method' => $method, |
| 120 | 120 | 'headers' => $headers, |
| 121 | - 'body' => apply_filters( 'woocommerce_stripe_request_body', $request, $api ), |
|
| 121 | + 'body' => apply_filters('woocommerce_stripe_request_body', $request, $api), |
|
| 122 | 122 | 'timeout' => 70, |
| 123 | 123 | ) |
| 124 | 124 | ); |
| 125 | 125 | |
| 126 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
| 126 | + if (is_wp_error($response) || empty($response['body'])) { |
|
| 127 | 127 | WC_Stripe_Logger::log( |
| 128 | - 'Error Response: ' . print_r( $response, true ) . PHP_EOL . PHP_EOL . 'Failed request: ' . print_r( |
|
| 128 | + 'Error Response: ' . print_r($response, true) . PHP_EOL . PHP_EOL . 'Failed request: ' . print_r( |
|
| 129 | 129 | array( |
| 130 | 130 | 'api' => $api, |
| 131 | 131 | 'request' => $request, |
@@ -135,17 +135,17 @@ discard block |
||
| 135 | 135 | ) |
| 136 | 136 | ); |
| 137 | 137 | |
| 138 | - throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
| 138 | + throw new WC_Stripe_Exception(print_r($response, true), __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - if ( $with_headers ) { |
|
| 141 | + if ($with_headers) { |
|
| 142 | 142 | return array( |
| 143 | - 'headers' => wp_remote_retrieve_headers( $response ), |
|
| 144 | - 'body' => json_decode( $response['body'] ), |
|
| 143 | + 'headers' => wp_remote_retrieve_headers($response), |
|
| 144 | + 'body' => json_decode($response['body']), |
|
| 145 | 145 | ); |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - return json_decode( $response['body'] ); |
|
| 148 | + return json_decode($response['body']); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
@@ -155,8 +155,8 @@ discard block |
||
| 155 | 155 | * @version 4.0.0 |
| 156 | 156 | * @param string $api |
| 157 | 157 | */ |
| 158 | - public static function retrieve( $api ) { |
|
| 159 | - WC_Stripe_Logger::log( "{$api}" ); |
|
| 158 | + public static function retrieve($api) { |
|
| 159 | + WC_Stripe_Logger::log("{$api}"); |
|
| 160 | 160 | |
| 161 | 161 | $response = wp_safe_remote_get( |
| 162 | 162 | self::ENDPOINT . $api, |
@@ -167,11 +167,11 @@ discard block |
||
| 167 | 167 | ) |
| 168 | 168 | ); |
| 169 | 169 | |
| 170 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
| 171 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
| 172 | - return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
| 170 | + if (is_wp_error($response) || empty($response['body'])) { |
|
| 171 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
| 172 | + return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - return json_decode( $response['body'] ); |
|
| 175 | + return json_decode($response['body']); |
|
| 176 | 176 | } |
| 177 | 177 | } |