Completed
Pull Request — master (#1015)
by Radoslav
01:42
created
includes/compat/class-wc-stripe-pre-orders-compat.php 1 patch
Spacing   +44 added lines, -44 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
 
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 	public $saved_cards;
12 12
 
13 13
 	public function __construct() {
14
-		$this->saved_cards = WC_Stripe_Helper::get_settings( 'stripe', 'saved_cards' );
14
+		$this->saved_cards = WC_Stripe_Helper::get_settings('stripe', 'saved_cards');
15 15
 	}
16 16
 
17 17
 	/**
@@ -19,68 +19,68 @@  discard block
 block discarded – undo
19 19
 	 * @param  int  $order_id
20 20
 	 * @return boolean
21 21
 	 */
22
-	public function is_pre_order( $order_id ) {
23
-		return WC_Pre_Orders_Order::order_contains_pre_order( $order_id );
22
+	public function is_pre_order($order_id) {
23
+		return WC_Pre_Orders_Order::order_contains_pre_order($order_id);
24 24
 	}
25 25
 
26 26
 	/**
27 27
 	 * Remove order meta
28 28
 	 * @param object $order
29 29
 	 */
30
-	public function remove_order_source_before_retry( $order ) {
31
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
32
-		delete_post_meta( $order_id, '_stripe_source_id' );
30
+	public function remove_order_source_before_retry($order) {
31
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
32
+		delete_post_meta($order_id, '_stripe_source_id');
33 33
 		// For BW compat will remove in the future.
34
-		delete_post_meta( $order_id, '_stripe_card_id' );
34
+		delete_post_meta($order_id, '_stripe_card_id');
35 35
 	}
36 36
 
37 37
 	/**
38 38
 	 * Remove order meta
39 39
 	 * @param  object $order
40 40
 	 */
41
-	public function remove_order_customer_before_retry( $order ) {
42
-		$order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id();
43
-		delete_post_meta( $order_id, '_stripe_customer_id' );
41
+	public function remove_order_customer_before_retry($order) {
42
+		$order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id();
43
+		delete_post_meta($order_id, '_stripe_customer_id');
44 44
 	}
45 45
 
46 46
 	/**
47 47
 	 * Process the pre-order when pay upon release is used.
48 48
 	 * @param int $order_id
49 49
 	 */
50
-	public function process_pre_order( $order_id ) {
50
+	public function process_pre_order($order_id) {
51 51
 		try {
52
-			$order = wc_get_order( $order_id );
52
+			$order = wc_get_order($order_id);
53 53
 
54 54
 			// This will throw exception if not valid.
55
-			$this->validate_minimum_order_amount( $order );
55
+			$this->validate_minimum_order_amount($order);
56 56
 
57
-			$prepared_source = $this->prepare_source( get_current_user_id(), true );
57
+			$prepared_source = $this->prepare_source(get_current_user_id(), true);
58 58
 
59 59
 			// We need a source on file to continue.
60
-			if ( empty( $prepared_source->customer ) || empty( $prepared_source->source ) ) {
61
-				throw new WC_Stripe_Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
60
+			if (empty($prepared_source->customer) || empty($prepared_source->source)) {
61
+				throw new WC_Stripe_Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe'));
62 62
 			}
63 63
 
64
-			$this->save_source_to_order( $order, $prepared_source );
64
+			$this->save_source_to_order($order, $prepared_source);
65 65
 
66 66
 			// Remove cart
67 67
 			WC()->cart->empty_cart();
68 68
 
69 69
 			// Is pre ordered!
70
-			WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
70
+			WC_Pre_Orders_Order::mark_order_as_pre_ordered($order);
71 71
 
72 72
 			// Return thank you page redirect
73 73
 			return array(
74 74
 				'result'   => 'success',
75
-				'redirect' => $this->get_return_url( $order ),
75
+				'redirect' => $this->get_return_url($order),
76 76
 			);
77
-		} catch ( WC_Stripe_Exception $e ) {
78
-			wc_add_notice( $e->getLocalizedMessage(), 'error' );
79
-			WC_Stripe_Logger::log( 'Pre Orders Error: ' . $e->getMessage() );
77
+		} catch (WC_Stripe_Exception $e) {
78
+			wc_add_notice($e->getLocalizedMessage(), 'error');
79
+			WC_Stripe_Logger::log('Pre Orders Error: ' . $e->getMessage());
80 80
 
81 81
 			return array(
82 82
 				'result'   => 'success',
83
-				'redirect' => $order->get_checkout_payment_url( true ),
83
+				'redirect' => $order->get_checkout_payment_url(true),
84 84
 			);
85 85
 		}
86 86
 	}
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
 	 * @param WC_Order $order
91 91
 	 * @return void
92 92
 	 */
93
-	public function process_pre_order_release_payment( $order ) {
94
-		add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 );
93
+	public function process_pre_order_release_payment($order) {
94
+		add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2);
95 95
 
96 96
 		try {
97 97
 			// Define some callbacks if the first attempt fails.
@@ -100,37 +100,37 @@  discard block
 block discarded – undo
100 100
 				'remove_order_customer_before_retry',
101 101
 			);
102 102
 
103
-			while ( 1 ) {
104
-				$source   = $this->prepare_order_source( $order );
105
-				$response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) );
103
+			while (1) {
104
+				$source   = $this->prepare_order_source($order);
105
+				$response = WC_Stripe_API::request($this->generate_payment_request($order, $source));
106 106
 
107
-				if ( ! empty( $response->error ) ) {
108
-					if ( 0 === sizeof( $retry_callbacks ) ) {
109
-						throw new Exception( $response->error->message );
107
+				if ( ! empty($response->error)) {
108
+					if (0 === sizeof($retry_callbacks)) {
109
+						throw new Exception($response->error->message);
110 110
 					} else {
111
-						$retry_callback = array_shift( $retry_callbacks );
112
-						call_user_func( array( $this, $retry_callback ), $order );
111
+						$retry_callback = array_shift($retry_callbacks);
112
+						call_user_func(array($this, $retry_callback), $order);
113 113
 					}
114 114
 				} else {
115 115
 					// Successful
116
-					$this->process_response( $response, $order );
116
+					$this->process_response($response, $order);
117 117
 					break;
118 118
 				}
119 119
 			}
120
-		} catch ( Exception $e ) {
120
+		} catch (Exception $e) {
121 121
 			/* translators: error message */
122
-			$order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() );
122
+			$order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage());
123 123
 
124 124
 			// Mark order as failed if not already set,
125 125
 			// otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
126
-			if ( ! $order->has_status( 'failed' ) ) {
127
-				$order->update_status( 'failed', $order_note );
126
+			if ( ! $order->has_status('failed')) {
127
+				$order->update_status('failed', $order_note);
128 128
 			} else {
129
-				$order->add_order_note( $order_note );
129
+				$order->add_order_note($order_note);
130 130
 			}
131 131
 		}
132 132
 
133
-		remove_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 );
133
+		remove_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2);
134 134
 	}
135 135
 
136 136
 	/**
@@ -142,9 +142,9 @@  discard block
 block discarded – undo
142 142
 	 * @param array  $request         All of the request's parameters.
143 143
 	 * @return string                 An idempotency key, which includes both the customer, and the source.
144 144
 	 */
145
-	public function change_idempotency_key( $idempotency_key, $request ) {
146
-		$customer = ! empty( $request['customer'] ) ? $request['customer'] : '';
147
-		$source   = ! empty( $request['source'] ) ? $request['source'] : $customer;
145
+	public function change_idempotency_key($idempotency_key, $request) {
146
+		$customer = ! empty($request['customer']) ? $request['customer'] : '';
147
+		$source   = ! empty($request['source']) ? $request['source'] : $customer;
148 148
 
149 149
 		return $request['metadata']['order_id'] . '-' . $source . '-' . $customer;
150 150
 	}
Please login to merge, or discard this patch.