@@ -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 | /** |
@@ -95,13 +95,13 @@ discard block |
||
95 | 95 | * @param string $api |
96 | 96 | * @return array|WP_Error |
97 | 97 | */ |
98 | - public static function request( $request, $api = 'charges', $method = 'POST' ) { |
|
99 | - WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) ); |
|
98 | + public static function request($request, $api = 'charges', $method = 'POST') { |
|
99 | + WC_Stripe_Logger::log("{$api} request: " . print_r($request, true)); |
|
100 | 100 | |
101 | 101 | $headers = self::get_headers(); |
102 | 102 | |
103 | - if ( 'charges' === $api && 'POST' === $method ) { |
|
104 | - $headers['Idempotency-Key'] = uniqid( 'stripe_' ); |
|
103 | + if ('charges' === $api && 'POST' === $method) { |
|
104 | + $headers['Idempotency-Key'] = uniqid('stripe_'); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | $response = wp_safe_remote_post( |
@@ -109,17 +109,17 @@ discard block |
||
109 | 109 | array( |
110 | 110 | 'method' => $method, |
111 | 111 | 'headers' => $headers, |
112 | - 'body' => apply_filters( 'woocommerce_stripe_request_body', $request, $api ), |
|
112 | + 'body' => apply_filters('woocommerce_stripe_request_body', $request, $api), |
|
113 | 113 | 'timeout' => 70, |
114 | 114 | ) |
115 | 115 | ); |
116 | 116 | |
117 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
118 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
119 | - throw new Exception( __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
117 | + if (is_wp_error($response) || empty($response['body'])) { |
|
118 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
119 | + throw new Exception(__('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
120 | 120 | } |
121 | 121 | |
122 | - return json_decode( $response['body'] ); |
|
122 | + return json_decode($response['body']); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | * @version 4.0.0 |
130 | 130 | * @param string $api |
131 | 131 | */ |
132 | - public static function retrieve( $api ) { |
|
133 | - WC_Stripe_Logger::log( "{$api}" ); |
|
132 | + public static function retrieve($api) { |
|
133 | + WC_Stripe_Logger::log("{$api}"); |
|
134 | 134 | |
135 | 135 | $ua = self::get_user_agent(); |
136 | 136 | |
@@ -143,11 +143,11 @@ discard block |
||
143 | 143 | ) |
144 | 144 | ); |
145 | 145 | |
146 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
147 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
148 | - return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
146 | + if (is_wp_error($response) || empty($response['body'])) { |
|
147 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
148 | + return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
149 | 149 | } |
150 | 150 | |
151 | - return json_decode( $response['body'] ); |
|
151 | + return json_decode($response['body']); |
|
152 | 152 | } |
153 | 153 | } |