@@ -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 | $idempotency_key = ''; |
| 104 | 104 | |
| 105 | - if ( 'charges' === $api && 'POST' === $method ) { |
|
| 106 | - $customer = ! empty( $request['customer'] ) ? $request['customer'] : ''; |
|
| 107 | - $source = ! empty( $request['source'] ) ? $request['source'] : $customer; |
|
| 108 | - $idempotency_key = apply_filters( 'wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request ); |
|
| 105 | + if ('charges' === $api && 'POST' === $method) { |
|
| 106 | + $customer = ! empty($request['customer']) ? $request['customer'] : ''; |
|
| 107 | + $source = ! empty($request['source']) ? $request['source'] : $customer; |
|
| 108 | + $idempotency_key = apply_filters('wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request); |
|
| 109 | 109 | |
| 110 | 110 | $headers['Idempotency-Key'] = $idempotency_key; |
| 111 | 111 | } |
@@ -115,25 +115,25 @@ discard block |
||
| 115 | 115 | array( |
| 116 | 116 | 'method' => $method, |
| 117 | 117 | 'headers' => $headers, |
| 118 | - 'body' => apply_filters( 'woocommerce_stripe_request_body', $request, $api ), |
|
| 118 | + 'body' => apply_filters('woocommerce_stripe_request_body', $request, $api), |
|
| 119 | 119 | 'timeout' => 70, |
| 120 | 120 | ) |
| 121 | 121 | ); |
| 122 | 122 | |
| 123 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
| 124 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) . PHP_EOL . PHP_EOL . 'Failed request: ' . print_r( array( |
|
| 123 | + if (is_wp_error($response) || empty($response['body'])) { |
|
| 124 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true) . PHP_EOL . PHP_EOL . 'Failed request: ' . print_r(array( |
|
| 125 | 125 | 'api' => $api, |
| 126 | 126 | 'request' => $request, |
| 127 | 127 | 'idempotency_key' => $idempotency_key, |
| 128 | - ), true ) ); |
|
| 129 | - throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
| 128 | + ), true)); |
|
| 129 | + throw new WC_Stripe_Exception(print_r($response, true), __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - if ( $with_headers ) { |
|
| 133 | - return array( 'headers' => wp_remote_retrieve_headers( $response ), 'body' => json_decode( $response['body'] ) ); |
|
| 132 | + if ($with_headers) { |
|
| 133 | + return array('headers' => wp_remote_retrieve_headers($response), 'body' => json_decode($response['body'])); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - return json_decode( $response['body'] ); |
|
| 136 | + return json_decode($response['body']); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -143,8 +143,8 @@ discard block |
||
| 143 | 143 | * @version 4.0.0 |
| 144 | 144 | * @param string $api |
| 145 | 145 | */ |
| 146 | - public static function retrieve( $api ) { |
|
| 147 | - WC_Stripe_Logger::log( "{$api}" ); |
|
| 146 | + public static function retrieve($api) { |
|
| 147 | + WC_Stripe_Logger::log("{$api}"); |
|
| 148 | 148 | |
| 149 | 149 | $response = wp_safe_remote_get( |
| 150 | 150 | self::ENDPOINT . $api, |
@@ -155,11 +155,11 @@ discard block |
||
| 155 | 155 | ) |
| 156 | 156 | ); |
| 157 | 157 | |
| 158 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
| 159 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
| 160 | - return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
| 158 | + if (is_wp_error($response) || empty($response['body'])) { |
|
| 159 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
| 160 | + return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - return json_decode( $response['body'] ); |
|
| 163 | + return json_decode($response['body']); |
|
| 164 | 164 | } |
| 165 | 165 | } |