Completed
Pull Request — master (#653)
by Gabor
03:10
created
includes/class-wc-stripe-api.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if ( ! defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
104
-		if ( 'charges' === $api && 'POST' === $method ) {
105
-			$customer = ! empty( $request['customer'] ) ? $request['customer'] : '';
106
-			$source   = ! empty( $request['source'] ) ? $request['source'] : $customer;
104
+		if ('charges' === $api && 'POST' === $method) {
105
+			$customer = ! empty($request['customer']) ? $request['customer'] : '';
106
+			$source   = ! empty($request['source']) ? $request['source'] : $customer;
107 107
 
108
-			$headers['Idempotency-Key'] = apply_filters( 'wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request );
108
+			$headers['Idempotency-Key'] = apply_filters('wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request);
109 109
 		}
110 110
 
111 111
 		$response = wp_safe_remote_post(
@@ -113,24 +113,24 @@  discard block
 block discarded – undo
113 113
 			array(
114 114
 				'method'  => $method,
115 115
 				'headers' => $headers,
116
-				'body'    => apply_filters( 'woocommerce_stripe_request_body', $request, $api ),
116
+				'body'    => apply_filters('woocommerce_stripe_request_body', $request, $api),
117 117
 				'timeout' => 70,
118 118
 			)
119 119
 		);
120 120
 
121
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
122
-			WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) . PHP_EOL . PHP_EOL . 'Failed request: ' . print_r( array(
121
+		if (is_wp_error($response) || empty($response['body'])) {
122
+			WC_Stripe_Logger::log('Error Response: ' . print_r($response, true) . PHP_EOL . PHP_EOL . 'Failed request: ' . print_r(array(
123 123
 				'api'     => $api,
124 124
 				'request' => $request,
125
-			), true ) );
126
-			throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
125
+			), true));
126
+			throw new WC_Stripe_Exception(print_r($response, true), __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
127 127
 		}
128 128
 
129
-		if ( $with_headers ) {
130
-			return array( 'headers' => wp_remote_retrieve_headers( $response ), 'body' => json_decode( $response['body'] ) );
129
+		if ($with_headers) {
130
+			return array('headers' => wp_remote_retrieve_headers($response), 'body' => json_decode($response['body']));
131 131
 		}
132 132
 
133
-		return json_decode( $response['body'] );
133
+		return json_decode($response['body']);
134 134
 	}
135 135
 
136 136
 	/**
@@ -140,8 +140,8 @@  discard block
 block discarded – undo
140 140
 	 * @version 4.0.0
141 141
 	 * @param string $api
142 142
 	 */
143
-	public static function retrieve( $api ) {
144
-		WC_Stripe_Logger::log( "{$api}" );
143
+	public static function retrieve($api) {
144
+		WC_Stripe_Logger::log("{$api}");
145 145
 
146 146
 		$response = wp_safe_remote_get(
147 147
 			self::ENDPOINT . $api,
@@ -152,11 +152,11 @@  discard block
 block discarded – undo
152 152
 			)
153 153
 		);
154 154
 
155
-		if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
156
-			WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) );
157
-			return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
155
+		if (is_wp_error($response) || empty($response['body'])) {
156
+			WC_Stripe_Logger::log('Error Response: ' . print_r($response, true));
157
+			return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe'));
158 158
 		}
159 159
 
160
-		return json_decode( $response['body'] );
160
+		return json_decode($response['body']);
161 161
 	}
162 162
 }
Please login to merge, or discard this patch.