@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * Set secret API Key. |
| 26 | 26 | * @param string $key |
| 27 | 27 | */ |
| 28 | - public static function set_secret_key( $secret_key ) { |
|
| 28 | + public static function set_secret_key($secret_key) { |
|
| 29 | 29 | self::$secret_key = $secret_key; |
| 30 | 30 | } |
| 31 | 31 | |
@@ -34,11 +34,11 @@ discard block |
||
| 34 | 34 | * @return string |
| 35 | 35 | */ |
| 36 | 36 | public static function get_secret_key() { |
| 37 | - if ( ! self::$secret_key ) { |
|
| 38 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
| 37 | + if ( ! self::$secret_key) { |
|
| 38 | + $options = get_option('woocommerce_stripe_settings'); |
|
| 39 | 39 | |
| 40 | - if ( isset( $options['testmode'], $options['secret_key'], $options['test_secret_key'] ) ) { |
|
| 41 | - self::set_secret_key( 'yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key'] ); |
|
| 40 | + if (isset($options['testmode'], $options['secret_key'], $options['test_secret_key'])) { |
|
| 41 | + self::set_secret_key('yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key']); |
|
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | return self::$secret_key; |
@@ -51,38 +51,38 @@ discard block |
||
| 51 | 51 | * @param string $api |
| 52 | 52 | * @return array|WP_Error |
| 53 | 53 | */ |
| 54 | - public static function request( $request, $api = 'charges', $method = 'POST' ) { |
|
| 55 | - self::log( "{$api} request: " . print_r( $request, true ) ); |
|
| 54 | + public static function request($request, $api = 'charges', $method = 'POST') { |
|
| 55 | + self::log("{$api} request: " . print_r($request, true)); |
|
| 56 | 56 | |
| 57 | 57 | $response = wp_safe_remote_post( |
| 58 | 58 | self::ENDPOINT . $api, |
| 59 | 59 | array( |
| 60 | 60 | 'method' => $method, |
| 61 | 61 | 'headers' => array( |
| 62 | - 'Authorization' => 'Basic ' . base64_encode( self::get_secret_key() . ':' ), |
|
| 62 | + 'Authorization' => 'Basic ' . base64_encode(self::get_secret_key() . ':'), |
|
| 63 | 63 | 'Stripe-Version' => '2016-03-07', |
| 64 | 64 | ), |
| 65 | - 'body' => apply_filters( 'woocommerce_stripe_request_body', $request, $api ), |
|
| 65 | + 'body' => apply_filters('woocommerce_stripe_request_body', $request, $api), |
|
| 66 | 66 | 'timeout' => 70, |
| 67 | 67 | 'user-agent' => 'WooCommerce ' . WC()->version, |
| 68 | 68 | ) |
| 69 | 69 | ); |
| 70 | 70 | |
| 71 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
| 72 | - self::log( 'Error Response: ' . print_r( $response, true ) ); |
|
| 73 | - return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the payment gateway.', 'woocommerce-gateway-stripe' ) ); |
|
| 71 | + if (is_wp_error($response) || empty($response['body'])) { |
|
| 72 | + self::log('Error Response: ' . print_r($response, true)); |
|
| 73 | + return new WP_Error('stripe_error', __('There was a problem connecting to the payment gateway.', 'woocommerce-gateway-stripe')); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - $parsed_response = json_decode( $response['body'] ); |
|
| 76 | + $parsed_response = json_decode($response['body']); |
|
| 77 | 77 | |
| 78 | 78 | // Handle response |
| 79 | - if ( ! empty( $parsed_response->error ) ) { |
|
| 80 | - if ( ! empty( $parsed_response->error->code ) ) { |
|
| 79 | + if ( ! empty($parsed_response->error)) { |
|
| 80 | + if ( ! empty($parsed_response->error->code)) { |
|
| 81 | 81 | $code = $parsed_response->error->code; |
| 82 | 82 | } else { |
| 83 | 83 | $code = 'stripe_error'; |
| 84 | 84 | } |
| 85 | - return new WP_Error( $code, $parsed_response->error->message ); |
|
| 85 | + return new WP_Error($code, $parsed_response->error->message); |
|
| 86 | 86 | } else { |
| 87 | 87 | return $parsed_response; |
| 88 | 88 | } |
@@ -96,11 +96,11 @@ discard block |
||
| 96 | 96 | * |
| 97 | 97 | * @param string $message |
| 98 | 98 | */ |
| 99 | - public static function log( $message ) { |
|
| 100 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
| 99 | + public static function log($message) { |
|
| 100 | + $options = get_option('woocommerce_stripe_settings'); |
|
| 101 | 101 | |
| 102 | - if ( 'yes' === $options['logging'] ) { |
|
| 103 | - WC_Stripe::log( $message ); |
|
| 102 | + if ('yes' === $options['logging']) { |
|
| 103 | + WC_Stripe::log($message); |
|
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | } |