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