Completed
Pull Request — master (#1285)
by
unknown
01:38
created
includes/class-wc-stripe-session.php 1 patch
Spacing   +25 added lines, -25 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
 
@@ -34,8 +34,8 @@  discard block
 block discarded – undo
34 34
 	 * Set the Stripe session ID.
35 35
 	 * @param string $id Stripe session ID.
36 36
 	 */
37
-	public function set_id( $id ) {
38
-		$this->id = wc_clean( $id );
37
+	public function set_id($id) {
38
+		$this->id = wc_clean($id);
39 39
 	}
40 40
 
41 41
 	/**
@@ -44,9 +44,9 @@  discard block
 block discarded – undo
44 44
 	 * @param  array $args Additional arguments (optional).
45 45
 	 * @return array
46 46
 	 */
47
-	protected function generate_session_request( $args = array() ) {
47
+	protected function generate_session_request($args = array()) {
48 48
 		$defaults = [
49
-			'payment_method_types' => [ 'card', 'ideal' ],
49
+			'payment_method_types' => ['card', 'ideal'],
50 50
 			'line_items' => [
51 51
 				[
52 52
 					'price_data' => [
@@ -64,25 +64,25 @@  discard block
 block discarded – undo
64 64
 			'cancel_url' => wc_get_checkout_url()
65 65
 		];
66 66
 
67
-		return wp_parse_args( $args, $defaults );
67
+		return wp_parse_args($args, $defaults);
68 68
 	}
69 69
 
70 70
 	/**
71 71
 	 * Create a session via API.
72 72
 	 * @return WP_Error|string Session ID
73 73
 	 */
74
-	public function create_session( $args ) {
75
-		error_log( 'in create_session' );
76
-		$args     = $this->generate_session_request( $args );
77
-		$response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_session_args', $args ), 'checkout/sessions' );
74
+	public function create_session($args) {
75
+		error_log('in create_session');
76
+		$args     = $this->generate_session_request($args);
77
+		$response = WC_Stripe_API::request(apply_filters('wc_stripe_create_session_args', $args), 'checkout/sessions');
78 78
 
79
-		if ( ! empty( $response->error ) ) {
80
-			throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
79
+		if ( ! empty($response->error)) {
80
+			throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
81 81
 		}
82 82
 
83
-		$this->set_id( $response->id );
83
+		$this->set_id($response->id);
84 84
 
85
-		do_action( 'woocommerce_stripe_add_customer', $args, $response );
85
+		do_action('woocommerce_stripe_add_customer', $args, $response);
86 86
 
87 87
 		return $this->get_id();
88 88
 	}
@@ -94,27 +94,27 @@  discard block
 block discarded – undo
94 94
 	 *
95 95
 	 * @throws WC_Stripe_Exception
96 96
 	 */
97
-	public function update_customer( $args = array() ) {
98
-		if ( empty( $this->get_id() ) ) {
99
-			throw new WC_Stripe_Exception( 'id_required_to_update_session', __( 'Attempting to update a Stripe session without a session ID.', 'woocommerce-gateway-stripe' ) );
97
+	public function update_customer($args = array()) {
98
+		if (empty($this->get_id())) {
99
+			throw new WC_Stripe_Exception('id_required_to_update_session', __('Attempting to update a Stripe session without a session ID.', 'woocommerce-gateway-stripe'));
100 100
 		}
101 101
 
102
-		$args     = $this->generate_session_request( $args );
103
-		$args     = apply_filters( 'wc_stripe_update_session_args', $args );
104
-		$response = WC_Stripe_API::request( $args, 'sessions/' . $this->get_id() );
102
+		$args     = $this->generate_session_request($args);
103
+		$args     = apply_filters('wc_stripe_update_session_args', $args);
104
+		$response = WC_Stripe_API::request($args, 'sessions/' . $this->get_id());
105 105
 
106
-		if ( ! empty( $response->error ) ) {
107
-			if ( $this->is_no_such_session_error( $response->error ) ) {
106
+		if ( ! empty($response->error)) {
107
+			if ($this->is_no_such_session_error($response->error)) {
108 108
 				// This can happen when switching the main Stripe account or importing users from another site.
109 109
 				// If not already retrying, recreate the customer and then try updating it again.
110 110
 				$this->recreate_session();
111
-				return $this->update_session( $args ); // TODO retry limit
111
+				return $this->update_session($args); // TODO retry limit
112 112
 			}
113 113
 
114
-			throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message );
114
+			throw new WC_Stripe_Exception(print_r($response, true), $response->error->message);
115 115
 		}
116 116
 
117
-		do_action( 'woocommerce_stripe_update_session', $args, $response );
117
+		do_action('woocommerce_stripe_update_session', $args, $response);
118 118
 
119 119
 		return $this->get_id();
120 120
 	}
Please login to merge, or discard this patch.
includes/payment-methods/class-wc-gateway-stripe-checkout.php 1 patch
Spacing   +23 added lines, -23 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
 
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
 	 */
31 31
 	public function __construct() {
32 32
 		$this->id           = 'stripe_checkout';
33
-		$this->method_title = __( 'Stripe Checkout', 'woocommerce-gateway-stripe' );
33
+		$this->method_title = __('Stripe Checkout', 'woocommerce-gateway-stripe');
34 34
 		/* translators: link */
35
-		$this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe' ) );
35
+		$this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout&section=stripe'));
36 36
 		$this->supports           = array(
37 37
 			'products',
38 38
 			'refunds',
@@ -44,20 +44,20 @@  discard block
 block discarded – undo
44 44
 		// Load the settings.
45 45
 		$this->init_settings();
46 46
 
47
-		$main_settings              = get_option( 'woocommerce_stripe_settings' );
48
-		$this->title                = $this->get_option( 'title' );
49
-		$this->description          = $this->get_option( 'description' );
50
-		$this->enabled              = $this->get_option( 'enabled' );
51
-		$this->testmode             = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false;
52
-		$this->secret_key           = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : '';
47
+		$main_settings              = get_option('woocommerce_stripe_settings');
48
+		$this->title                = $this->get_option('title');
49
+		$this->description          = $this->get_option('description');
50
+		$this->enabled              = $this->get_option('enabled');
51
+		$this->testmode             = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false;
52
+		$this->secret_key           = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : '';
53 53
 
54
-		if ( $this->testmode ) {
55
-			$this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : '';
56
-			$this->secret_key      = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : '';
54
+		if ($this->testmode) {
55
+			$this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : '';
56
+			$this->secret_key      = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : '';
57 57
 		}
58 58
 
59
-		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
60
-		add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
59
+		add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
60
+		add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
61 61
 	}
62 62
 
63 63
 	/**
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	 * @return bool
84 84
 	 */
85 85
 	public function is_available() {
86
-		if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) {
86
+		if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) {
87 87
 			return false;
88 88
 		}
89 89
 
@@ -96,16 +96,16 @@  discard block
 block discarded – undo
96 96
 	 * @since 4.6.0
97 97
 	 */
98 98
 	public function init_form_fields() {
99
-		$this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-checkout-settings.php' );
99
+		$this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-checkout-settings.php');
100 100
 	}
101 101
 
102 102
 	public function payment_scripts() {
103
-		if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) {
103
+		if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) {
104 104
 			return;
105 105
 		}
106 106
 
107
-		wp_enqueue_style( 'stripe_styles' );
108
-		wp_enqueue_script( 'woocommerce_stripe' );
107
+		wp_enqueue_style('stripe_styles');
108
+		wp_enqueue_script('woocommerce_stripe');
109 109
 	}
110 110
 
111 111
 	/**
@@ -121,13 +121,13 @@  discard block
 block discarded – undo
121 121
 		// Request session from stripe.
122 122
 		$stripe_session = new WC_Stripe_Session();
123 123
 		$stripe_session->create_session(
124
-			[ 'success_url' => $this->get_return_url() ]
124
+			['success_url' => $this->get_return_url()]
125 125
 		);
126 126
 
127
-		echo '<div id="stripe-checkout-data" data-secret="' . esc_attr( $stripe_session->get_id() ) . '"></div>';
127
+		echo '<div id="stripe-checkout-data" data-secret="' . esc_attr($stripe_session->get_id()) . '"></div>';
128 128
 
129
-		if ( $description ) {
130
-			echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id );
129
+		if ($description) {
130
+			echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id);
131 131
 		}
132 132
 	}
133 133
 }
Please login to merge, or discard this patch.