@@ -1,191 +1,191 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | 6 | $webhook_url = WC_Stripe_Helper::get_webhook_url(); |
7 | 7 | |
8 | -return apply_filters( 'wc_stripe_settings', |
|
8 | +return apply_filters('wc_stripe_settings', |
|
9 | 9 | array( |
10 | 10 | 'enabled' => array( |
11 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
12 | - 'label' => __( 'Enable Stripe', 'woocommerce-gateway-stripe' ), |
|
11 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
12 | + 'label' => __('Enable Stripe', 'woocommerce-gateway-stripe'), |
|
13 | 13 | 'type' => 'checkbox', |
14 | 14 | 'description' => '', |
15 | 15 | 'default' => 'no', |
16 | 16 | ), |
17 | 17 | 'title' => array( |
18 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
18 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
19 | 19 | 'type' => 'text', |
20 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
21 | - 'default' => __( 'Credit Card (Stripe)', 'woocommerce-gateway-stripe' ), |
|
20 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
21 | + 'default' => __('Credit Card (Stripe)', 'woocommerce-gateway-stripe'), |
|
22 | 22 | 'desc_tip' => true, |
23 | 23 | ), |
24 | 24 | 'description' => array( |
25 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
25 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
26 | 26 | 'type' => 'text', |
27 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
28 | - 'default' => __( 'Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe' ), |
|
27 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
28 | + 'default' => __('Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe'), |
|
29 | 29 | 'desc_tip' => true, |
30 | 30 | ), |
31 | 31 | 'webhook' => array( |
32 | - 'title' => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ), |
|
32 | + 'title' => __('Webhook Endpoints', 'woocommerce-gateway-stripe'), |
|
33 | 33 | 'type' => 'title', |
34 | 34 | /* translators: webhook URL */ |
35 | - 'description' => sprintf( __( 'You must add the webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe' ), $webhook_url ), |
|
35 | + 'description' => sprintf(__('You must add the webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe'), $webhook_url), |
|
36 | 36 | ), |
37 | 37 | 'testmode' => array( |
38 | - 'title' => __( 'Test mode', 'woocommerce-gateway-stripe' ), |
|
39 | - 'label' => __( 'Enable Test Mode', 'woocommerce-gateway-stripe' ), |
|
38 | + 'title' => __('Test mode', 'woocommerce-gateway-stripe'), |
|
39 | + 'label' => __('Enable Test Mode', 'woocommerce-gateway-stripe'), |
|
40 | 40 | 'type' => 'checkbox', |
41 | - 'description' => __( 'Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe' ), |
|
41 | + 'description' => __('Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe'), |
|
42 | 42 | 'default' => 'yes', |
43 | 43 | 'desc_tip' => true, |
44 | 44 | ), |
45 | 45 | 'test_publishable_key' => array( |
46 | - 'title' => __( 'Test Publishable Key', 'woocommerce-gateway-stripe' ), |
|
46 | + 'title' => __('Test Publishable Key', 'woocommerce-gateway-stripe'), |
|
47 | 47 | 'type' => 'password', |
48 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
48 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
49 | 49 | 'default' => '', |
50 | 50 | 'desc_tip' => true, |
51 | 51 | ), |
52 | 52 | 'test_secret_key' => array( |
53 | - 'title' => __( 'Test Secret Key', 'woocommerce-gateway-stripe' ), |
|
53 | + 'title' => __('Test Secret Key', 'woocommerce-gateway-stripe'), |
|
54 | 54 | 'type' => 'password', |
55 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
55 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
56 | 56 | 'default' => '', |
57 | 57 | 'desc_tip' => true, |
58 | 58 | ), |
59 | 59 | 'publishable_key' => array( |
60 | - 'title' => __( 'Live Publishable Key', 'woocommerce-gateway-stripe' ), |
|
60 | + 'title' => __('Live Publishable Key', 'woocommerce-gateway-stripe'), |
|
61 | 61 | 'type' => 'password', |
62 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
62 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
63 | 63 | 'default' => '', |
64 | 64 | 'desc_tip' => true, |
65 | 65 | ), |
66 | 66 | 'secret_key' => array( |
67 | - 'title' => __( 'Live Secret Key', 'woocommerce-gateway-stripe' ), |
|
67 | + 'title' => __('Live Secret Key', 'woocommerce-gateway-stripe'), |
|
68 | 68 | 'type' => 'password', |
69 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
69 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
70 | 70 | 'default' => '', |
71 | 71 | 'desc_tip' => true, |
72 | 72 | ), |
73 | 73 | 'inline_cc_form' => array( |
74 | - 'title' => __( 'Inline Credit Card Form', 'woocommerce-gateway-stripe' ), |
|
74 | + 'title' => __('Inline Credit Card Form', 'woocommerce-gateway-stripe'), |
|
75 | 75 | 'type' => 'checkbox', |
76 | - 'description' => __( 'Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe' ), |
|
76 | + 'description' => __('Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe'), |
|
77 | 77 | 'default' => 'no', |
78 | 78 | 'desc_tip' => true, |
79 | 79 | ), |
80 | 80 | 'statement_descriptor' => array( |
81 | - 'title' => __( 'Statement Descriptor', 'woocommerce-gateway-stripe' ), |
|
81 | + 'title' => __('Statement Descriptor', 'woocommerce-gateway-stripe'), |
|
82 | 82 | 'type' => 'text', |
83 | - 'description' => __( 'This may be up to 22 characters. The statement description must contain at least one letter, may not include ><"\' characters, and will appear on your customer\'s statement in capital letters.', 'woocommerce-gateway-stripe' ), |
|
83 | + 'description' => __('This may be up to 22 characters. The statement description must contain at least one letter, may not include ><"\' characters, and will appear on your customer\'s statement in capital letters.', 'woocommerce-gateway-stripe'), |
|
84 | 84 | 'default' => '', |
85 | 85 | 'desc_tip' => true, |
86 | 86 | ), |
87 | 87 | 'capture' => array( |
88 | - 'title' => __( 'Capture', 'woocommerce-gateway-stripe' ), |
|
89 | - 'label' => __( 'Capture charge immediately', 'woocommerce-gateway-stripe' ), |
|
88 | + 'title' => __('Capture', 'woocommerce-gateway-stripe'), |
|
89 | + 'label' => __('Capture charge immediately', 'woocommerce-gateway-stripe'), |
|
90 | 90 | 'type' => 'checkbox', |
91 | - 'description' => __( 'Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe' ), |
|
91 | + 'description' => __('Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe'), |
|
92 | 92 | 'default' => 'yes', |
93 | 93 | 'desc_tip' => true, |
94 | 94 | ), |
95 | 95 | 'three_d_secure' => array( |
96 | - 'title' => __( '3D Secure', 'woocommerce-gateway-stripe' ), |
|
97 | - 'label' => __( 'Require 3D Secure when applicable', 'woocommerce-gateway-stripe' ), |
|
96 | + 'title' => __('3D Secure', 'woocommerce-gateway-stripe'), |
|
97 | + 'label' => __('Require 3D Secure when applicable', 'woocommerce-gateway-stripe'), |
|
98 | 98 | 'type' => 'checkbox', |
99 | - 'description' => __( 'Some payment methods have 3D Secure feature. This is an extra security layer for your store. Choose how to handle payments when 3D Secure is optional. Enabling would require customers to use 3D Secure when optional.', 'woocommerce-gateway-stripe' ), |
|
99 | + 'description' => __('Some payment methods have 3D Secure feature. This is an extra security layer for your store. Choose how to handle payments when 3D Secure is optional. Enabling would require customers to use 3D Secure when optional.', 'woocommerce-gateway-stripe'), |
|
100 | 100 | 'default' => 'no', |
101 | 101 | 'desc_tip' => true, |
102 | 102 | ), |
103 | 103 | 'stripe_checkout' => array( |
104 | - 'title' => __( 'Stripe Checkout', 'woocommerce-gateway-stripe' ), |
|
105 | - 'label' => __( 'Enable Stripe Checkout', 'woocommerce-gateway-stripe' ), |
|
104 | + 'title' => __('Stripe Checkout', 'woocommerce-gateway-stripe'), |
|
105 | + 'label' => __('Enable Stripe Checkout', 'woocommerce-gateway-stripe'), |
|
106 | 106 | 'type' => 'checkbox', |
107 | - 'description' => __( 'If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe' ), |
|
107 | + 'description' => __('If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe'), |
|
108 | 108 | 'default' => 'no', |
109 | 109 | 'desc_tip' => true, |
110 | 110 | ), |
111 | 111 | 'stripe_bitcoin' => array( |
112 | - 'title' => __( 'Bitcoin Currency', 'woocommerce-gateway-stripe' ), |
|
113 | - 'label' => __( 'Enable Bitcoin Currency', 'woocommerce-gateway-stripe' ), |
|
112 | + 'title' => __('Bitcoin Currency', 'woocommerce-gateway-stripe'), |
|
113 | + 'label' => __('Enable Bitcoin Currency', 'woocommerce-gateway-stripe'), |
|
114 | 114 | 'type' => 'checkbox', |
115 | - 'description' => __( 'If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe' ), |
|
115 | + 'description' => __('If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe'), |
|
116 | 116 | 'default' => 'no', |
117 | 117 | 'desc_tip' => true, |
118 | 118 | ), |
119 | 119 | 'stripe_checkout_image' => array( |
120 | - 'title' => __( 'Stripe Checkout Image', 'woocommerce-gateway-stripe' ), |
|
121 | - 'description' => __( 'Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe' ), |
|
120 | + 'title' => __('Stripe Checkout Image', 'woocommerce-gateway-stripe'), |
|
121 | + 'description' => __('Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe'), |
|
122 | 122 | 'type' => 'text', |
123 | 123 | 'default' => '', |
124 | 124 | 'desc_tip' => true, |
125 | 125 | ), |
126 | 126 | 'stripe_checkout_description' => array( |
127 | - 'title' => __( 'Stripe Checkout Description', 'woocommerce-gateway-stripe' ), |
|
127 | + 'title' => __('Stripe Checkout Description', 'woocommerce-gateway-stripe'), |
|
128 | 128 | 'type' => 'text', |
129 | - 'description' => __( 'Shows a description of your store on Stripe Modal Checkout.', 'woocommerce-gateway-stripe' ), |
|
129 | + 'description' => __('Shows a description of your store on Stripe Modal Checkout.', 'woocommerce-gateway-stripe'), |
|
130 | 130 | 'default' => '', |
131 | 131 | 'desc_tip' => true, |
132 | 132 | ), |
133 | 133 | 'payment_request' => array( |
134 | - 'title' => __( 'Payment Request Buttons', 'woocommerce-gateway-stripe' ), |
|
134 | + 'title' => __('Payment Request Buttons', 'woocommerce-gateway-stripe'), |
|
135 | 135 | /* translators: 1) br tag 2) opening anchor tag 3) closing anchor tag */ |
136 | - 'label' => sprintf( __( 'Enable Payment Request Buttons. (Apple Pay/Chrome Payment Request API) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe' ), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>' ), |
|
136 | + 'label' => sprintf(__('Enable Payment Request Buttons. (Apple Pay/Chrome Payment Request API) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe'), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>'), |
|
137 | 137 | 'type' => 'checkbox', |
138 | - 'description' => __( 'If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe' ), |
|
138 | + 'description' => __('If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe'), |
|
139 | 139 | 'default' => 'yes', |
140 | 140 | 'desc_tip' => true, |
141 | 141 | ), |
142 | 142 | 'payment_request_button_type' => array( |
143 | - 'title' => __( 'Payment Request Button Type', 'woocommerce-gateway-stripe' ), |
|
144 | - 'label' => __( 'Button Type', 'woocommerce-gateway-stripe' ), |
|
143 | + 'title' => __('Payment Request Button Type', 'woocommerce-gateway-stripe'), |
|
144 | + 'label' => __('Button Type', 'woocommerce-gateway-stripe'), |
|
145 | 145 | 'type' => 'select', |
146 | - 'description' => __( 'Select the button type you would like to show.', 'woocommerce-gateway-stripe' ), |
|
146 | + 'description' => __('Select the button type you would like to show.', 'woocommerce-gateway-stripe'), |
|
147 | 147 | 'default' => 'buy', |
148 | 148 | 'desc_tip' => true, |
149 | 149 | 'options' => array( |
150 | - 'default' => __( 'Default', 'woocommerce-gateway-stripe' ), |
|
151 | - 'buy' => __( 'Buy', 'woocommerce-gateway-stripe' ), |
|
152 | - 'donate' => __( 'Donate', 'woocommerce-gateway-stripe' ), |
|
150 | + 'default' => __('Default', 'woocommerce-gateway-stripe'), |
|
151 | + 'buy' => __('Buy', 'woocommerce-gateway-stripe'), |
|
152 | + 'donate' => __('Donate', 'woocommerce-gateway-stripe'), |
|
153 | 153 | ), |
154 | 154 | ), |
155 | 155 | 'payment_request_button_theme' => array( |
156 | - 'title' => __( 'Payment Request Button Theme', 'woocommerce-gateway-stripe' ), |
|
157 | - 'label' => __( 'Button Theme', 'woocommerce-gateway-stripe' ), |
|
156 | + 'title' => __('Payment Request Button Theme', 'woocommerce-gateway-stripe'), |
|
157 | + 'label' => __('Button Theme', 'woocommerce-gateway-stripe'), |
|
158 | 158 | 'type' => 'select', |
159 | - 'description' => __( 'Select the button theme you would like to show.', 'woocommerce-gateway-stripe' ), |
|
159 | + 'description' => __('Select the button theme you would like to show.', 'woocommerce-gateway-stripe'), |
|
160 | 160 | 'default' => 'dark', |
161 | 161 | 'desc_tip' => true, |
162 | 162 | 'options' => array( |
163 | - 'dark' => __( 'Dark', 'woocommerce-gateway-stripe' ), |
|
164 | - 'light' => __( 'Light', 'woocommerce-gateway-stripe' ), |
|
165 | - 'light-outline' => __( 'Light-Outline', 'woocommerce-gateway-stripe' ), |
|
163 | + 'dark' => __('Dark', 'woocommerce-gateway-stripe'), |
|
164 | + 'light' => __('Light', 'woocommerce-gateway-stripe'), |
|
165 | + 'light-outline' => __('Light-Outline', 'woocommerce-gateway-stripe'), |
|
166 | 166 | ), |
167 | 167 | ), |
168 | 168 | 'payment_request_button_height' => array( |
169 | - 'title' => __( 'Payment Request Button Height', 'woocommerce-gateway-stripe' ), |
|
170 | - 'label' => __( 'Button Height', 'woocommerce-gateway-stripe' ), |
|
169 | + 'title' => __('Payment Request Button Height', 'woocommerce-gateway-stripe'), |
|
170 | + 'label' => __('Button Height', 'woocommerce-gateway-stripe'), |
|
171 | 171 | 'type' => 'text', |
172 | - 'description' => __( 'Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe' ), |
|
172 | + 'description' => __('Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe'), |
|
173 | 173 | 'default' => '44', |
174 | 174 | 'desc_tip' => true, |
175 | 175 | ), |
176 | 176 | 'saved_cards' => array( |
177 | - 'title' => __( 'Saved Cards', 'woocommerce-gateway-stripe' ), |
|
178 | - 'label' => __( 'Enable Payment via Saved Cards', 'woocommerce-gateway-stripe' ), |
|
177 | + 'title' => __('Saved Cards', 'woocommerce-gateway-stripe'), |
|
178 | + 'label' => __('Enable Payment via Saved Cards', 'woocommerce-gateway-stripe'), |
|
179 | 179 | 'type' => 'checkbox', |
180 | - 'description' => __( 'If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe' ), |
|
180 | + 'description' => __('If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe'), |
|
181 | 181 | 'default' => 'no', |
182 | 182 | 'desc_tip' => true, |
183 | 183 | ), |
184 | 184 | 'logging' => array( |
185 | - 'title' => __( 'Logging', 'woocommerce-gateway-stripe' ), |
|
186 | - 'label' => __( 'Log debug messages', 'woocommerce-gateway-stripe' ), |
|
185 | + 'title' => __('Logging', 'woocommerce-gateway-stripe'), |
|
186 | + 'label' => __('Log debug messages', 'woocommerce-gateway-stripe'), |
|
187 | 187 | 'type' => 'checkbox', |
188 | - 'description' => __( 'Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe' ), |
|
188 | + 'description' => __('Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe'), |
|
189 | 189 | 'default' => 'no', |
190 | 190 | 'desc_tip' => true, |
191 | 191 | ), |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | public function __construct() { |
114 | 114 | $this->retry_interval = 1; |
115 | 115 | $this->id = 'stripe'; |
116 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
116 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
117 | 117 | /* translators: 1) link to Stripe register page 2) link to Stripe api keys page */ |
118 | - $this->method_description = sprintf( __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys' ); |
|
118 | + $this->method_description = sprintf(__('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys'); |
|
119 | 119 | $this->has_fields = true; |
120 | 120 | $this->supports = array( |
121 | 121 | 'products', |
@@ -142,33 +142,33 @@ discard block |
||
142 | 142 | $this->init_settings(); |
143 | 143 | |
144 | 144 | // Get setting values. |
145 | - $this->title = $this->get_option( 'title' ); |
|
146 | - $this->description = $this->get_option( 'description' ); |
|
147 | - $this->enabled = $this->get_option( 'enabled' ); |
|
148 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
149 | - $this->inline_cc_form = 'yes' === $this->get_option( 'inline_cc_form' ); |
|
150 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
151 | - $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) ); |
|
152 | - $this->three_d_secure = 'yes' === $this->get_option( 'three_d_secure' ); |
|
153 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
154 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
155 | - $this->stripe_checkout_description = $this->get_option( 'stripe_checkout_description' ); |
|
156 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
157 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
158 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
159 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
160 | - $this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
161 | - |
|
162 | - if ( $this->stripe_checkout ) { |
|
163 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
145 | + $this->title = $this->get_option('title'); |
|
146 | + $this->description = $this->get_option('description'); |
|
147 | + $this->enabled = $this->get_option('enabled'); |
|
148 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
149 | + $this->inline_cc_form = 'yes' === $this->get_option('inline_cc_form'); |
|
150 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
151 | + $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor')); |
|
152 | + $this->three_d_secure = 'yes' === $this->get_option('three_d_secure'); |
|
153 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
154 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
155 | + $this->stripe_checkout_description = $this->get_option('stripe_checkout_description'); |
|
156 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
157 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
158 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
159 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
160 | + $this->payment_request = 'yes' === $this->get_option('payment_request', 'yes'); |
|
161 | + |
|
162 | + if ($this->stripe_checkout) { |
|
163 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
164 | 164 | } |
165 | 165 | |
166 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
166 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
167 | 167 | |
168 | 168 | // Hooks. |
169 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
170 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
|
171 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
169 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
170 | + add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); |
|
171 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * @return bool |
179 | 179 | */ |
180 | 180 | public function are_keys_set() { |
181 | - if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) { |
|
181 | + if (empty($this->secret_key) || empty($this->publishable_key)) { |
|
182 | 182 | return false; |
183 | 183 | } |
184 | 184 | |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * @since 4.0.2 |
192 | 192 | */ |
193 | 193 | public function is_available() { |
194 | - if ( is_add_payment_method_page() && ! $this->saved_cards ) { |
|
194 | + if (is_add_payment_method_page() && ! $this->saved_cards) { |
|
195 | 195 | return false; |
196 | 196 | } |
197 | 197 | |
@@ -214,24 +214,24 @@ discard block |
||
214 | 214 | $icons_str .= $icons['amex']; |
215 | 215 | $icons_str .= $icons['mastercard']; |
216 | 216 | |
217 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
217 | + if ('USD' === get_woocommerce_currency()) { |
|
218 | 218 | $icons_str .= $icons['discover']; |
219 | 219 | $icons_str .= $icons['jcb']; |
220 | 220 | $icons_str .= $icons['diners']; |
221 | 221 | } |
222 | 222 | |
223 | - if ( $this->bitcoin && $this->stripe_checkout ) { |
|
223 | + if ($this->bitcoin && $this->stripe_checkout) { |
|
224 | 224 | $icons_str .= $icons['bitcoin']; |
225 | 225 | } |
226 | 226 | |
227 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
227 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
231 | 231 | * Initialise Gateway Settings Form Fields |
232 | 232 | */ |
233 | 233 | public function init_form_fields() { |
234 | - $this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' ); |
|
234 | + $this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php'); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
@@ -239,68 +239,68 @@ discard block |
||
239 | 239 | */ |
240 | 240 | public function payment_fields() { |
241 | 241 | $user = wp_get_current_user(); |
242 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
242 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
243 | 243 | $total = WC()->cart->total; |
244 | 244 | $user_email = ''; |
245 | 245 | |
246 | 246 | // If paying from order, we need to get total from order not cart. |
247 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
248 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
247 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
248 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
249 | 249 | $total = $order->get_total(); |
250 | 250 | $user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
251 | 251 | } else { |
252 | - if ( $user->ID ) { |
|
253 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
252 | + if ($user->ID) { |
|
253 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
254 | 254 | $user_email = $user_email ? $user_email : $user->user_email; |
255 | 255 | } |
256 | 256 | } |
257 | 257 | |
258 | - if ( is_add_payment_method_page() ) { |
|
259 | - $pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' ); |
|
260 | - $total = ''; |
|
258 | + if (is_add_payment_method_page()) { |
|
259 | + $pay_button_text = __('Add Card', 'woocommerce-gateway-stripe'); |
|
260 | + $total = ''; |
|
261 | 261 | } else { |
262 | 262 | $pay_button_text = ''; |
263 | 263 | } |
264 | 264 | |
265 | 265 | echo '<div |
266 | 266 | id="stripe-payment-data" |
267 | - data-panel-label="' . esc_attr( $pay_button_text ) . '" |
|
268 | - data-description="'. esc_attr( strip_tags( $this->stripe_checkout_description ) ) . '" |
|
269 | - data-email="' . esc_attr( $user_email ) . '" |
|
270 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
271 | - data-name="' . esc_attr( $this->statement_descriptor ) . '" |
|
272 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
273 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
274 | - data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '" |
|
275 | - data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', $this->get_locale() ) ) . '" |
|
276 | - data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '" |
|
277 | - data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">'; |
|
278 | - |
|
279 | - if ( $this->description ) { |
|
280 | - if ( $this->testmode ) { |
|
267 | + data-panel-label="' . esc_attr($pay_button_text) . '" |
|
268 | + data-description="'. esc_attr(strip_tags($this->stripe_checkout_description)) . '" |
|
269 | + data-email="' . esc_attr($user_email) . '" |
|
270 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
271 | + data-name="' . esc_attr($this->statement_descriptor) . '" |
|
272 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
273 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
274 | + data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '" |
|
275 | + data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', $this->get_locale())) . '" |
|
276 | + data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '" |
|
277 | + data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">'; |
|
278 | + |
|
279 | + if ($this->description) { |
|
280 | + if ($this->testmode) { |
|
281 | 281 | /* translators: link to Stripe testing page */ |
282 | - $this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' ); |
|
283 | - $this->description = trim( $this->description ); |
|
282 | + $this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing'); |
|
283 | + $this->description = trim($this->description); |
|
284 | 284 | } |
285 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
285 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
286 | 286 | } |
287 | 287 | |
288 | - if ( $display_tokenization ) { |
|
288 | + if ($display_tokenization) { |
|
289 | 289 | $this->tokenization_script(); |
290 | 290 | $this->saved_payment_methods(); |
291 | 291 | } |
292 | 292 | |
293 | - if ( ! $this->stripe_checkout ) { |
|
294 | - if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) { |
|
293 | + if ( ! $this->stripe_checkout) { |
|
294 | + if (apply_filters('wc_stripe_use_elements_checkout_form', true)) { |
|
295 | 295 | $this->elements_form(); |
296 | 296 | } else { |
297 | - WC_Stripe_Logger::log( 'DEPRECATED! Since version 4.0. Stripe Elements is used. This legacy credit card form will be removed by version 5.0!' ); |
|
297 | + WC_Stripe_Logger::log('DEPRECATED! Since version 4.0. Stripe Elements is used. This legacy credit card form will be removed by version 5.0!'); |
|
298 | 298 | $this->form(); |
299 | 299 | echo '<div class="stripe-source-errors" role="alert"></div>'; |
300 | 300 | } |
301 | 301 | } |
302 | 302 | |
303 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
303 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
304 | 304 | $this->save_payment_method_checkbox(); |
305 | 305 | } |
306 | 306 | |
@@ -315,12 +315,12 @@ discard block |
||
315 | 315 | */ |
316 | 316 | public function elements_form() { |
317 | 317 | ?> |
318 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
319 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
318 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
319 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
320 | 320 | |
321 | - <?php if ( $this->inline_cc_form ) { ?> |
|
321 | + <?php if ($this->inline_cc_form) { ?> |
|
322 | 322 | <label for="card-element"> |
323 | - <?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?> |
|
323 | + <?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?> |
|
324 | 324 | </label> |
325 | 325 | |
326 | 326 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | </div> |
329 | 329 | <?php } else { ?> |
330 | 330 | <div class="form-row form-row-wide"> |
331 | - <label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
331 | + <label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
332 | 332 | |
333 | 333 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
334 | 334 | <!-- a Stripe Element will be inserted here. --> |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | </div> |
337 | 337 | |
338 | 338 | <div class="form-row form-row-first"> |
339 | - <label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
339 | + <label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
340 | 340 | |
341 | 341 | <div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
342 | 342 | <!-- a Stripe Element will be inserted here. --> |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | </div> |
345 | 345 | |
346 | 346 | <div class="form-row form-row-last"> |
347 | - <label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
347 | + <label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
348 | 348 | <div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
349 | 349 | <!-- a Stripe Element will be inserted here. --> |
350 | 350 | </div> |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | |
355 | 355 | <!-- Used to display form errors --> |
356 | 356 | <div class="stripe-source-errors" role="alert"></div> |
357 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
357 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
358 | 358 | <div class="clear"></div> |
359 | 359 | </fieldset> |
360 | 360 | <?php |
@@ -367,13 +367,13 @@ discard block |
||
367 | 367 | * @version 3.1.0 |
368 | 368 | */ |
369 | 369 | public function admin_scripts() { |
370 | - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
370 | + if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
371 | 371 | return; |
372 | 372 | } |
373 | 373 | |
374 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
374 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
375 | 375 | |
376 | - wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
376 | + wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | /** |
@@ -385,46 +385,46 @@ discard block |
||
385 | 385 | * @version 4.0.0 |
386 | 386 | */ |
387 | 387 | public function payment_scripts() { |
388 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
388 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
389 | 389 | return; |
390 | 390 | } |
391 | 391 | |
392 | 392 | // If Stripe is not enabled bail. |
393 | - if ( 'no' === $this->enabled ) { |
|
393 | + if ('no' === $this->enabled) { |
|
394 | 394 | return; |
395 | 395 | } |
396 | 396 | |
397 | 397 | // If keys are not set bail. |
398 | - if ( ! $this->are_keys_set() ) { |
|
399 | - WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
398 | + if ( ! $this->are_keys_set()) { |
|
399 | + WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
400 | 400 | return; |
401 | 401 | } |
402 | 402 | |
403 | 403 | // If no SSL bail. |
404 | - if ( ! $this->testmode && ! is_ssl() ) { |
|
405 | - WC_Stripe_Logger::log( 'Stripe requires SSL.' ); |
|
404 | + if ( ! $this->testmode && ! is_ssl()) { |
|
405 | + WC_Stripe_Logger::log('Stripe requires SSL.'); |
|
406 | 406 | return; |
407 | 407 | } |
408 | 408 | |
409 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
409 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
410 | 410 | |
411 | - wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' ); |
|
412 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
413 | - wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true ); |
|
414 | - wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true ); |
|
415 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
416 | - wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripev2', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
411 | + wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5'); |
|
412 | + wp_enqueue_style('stripe_paymentfonts'); |
|
413 | + wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true); |
|
414 | + wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true); |
|
415 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
416 | + wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripev2', 'stripe'), WC_STRIPE_VERSION, true); |
|
417 | 417 | |
418 | 418 | $stripe_params = array( |
419 | 419 | 'key' => $this->publishable_key, |
420 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
421 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
420 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
421 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
422 | 422 | ); |
423 | 423 | |
424 | 424 | // If we're on the pay page we need to pass stripe.js the address of the order. |
425 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { |
|
426 | - $order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); |
|
427 | - $order = wc_get_order( $order_id ); |
|
425 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { |
|
426 | + $order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); |
|
427 | + $order = wc_get_order($order_id); |
|
428 | 428 | |
429 | 429 | $stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
430 | 430 | $stripe_params['billing_last_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
@@ -436,39 +436,39 @@ discard block |
||
436 | 436 | $stripe_params['billing_country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
437 | 437 | } |
438 | 438 | |
439 | - $stripe_params['no_prepaid_card_msg'] = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
440 | - $stripe_params['no_sepa_owner_msg'] = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' ); |
|
441 | - $stripe_params['no_sepa_iban_msg'] = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' ); |
|
442 | - $stripe_params['sepa_mandate_notification'] = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' ); |
|
443 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
439 | + $stripe_params['no_prepaid_card_msg'] = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
440 | + $stripe_params['no_sepa_owner_msg'] = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe'); |
|
441 | + $stripe_params['no_sepa_iban_msg'] = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe'); |
|
442 | + $stripe_params['sepa_mandate_notification'] = apply_filters('wc_stripe_sepa_mandate_notification', 'email'); |
|
443 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
444 | 444 | $stripe_params['inline_cc_form'] = $this->inline_cc_form ? 'yes' : 'no'; |
445 | - $stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no'; |
|
446 | - $stripe_params['is_checkout'] = ( is_checkout() && empty( $_GET['pay_for_order'] ) ) ? 'yes' : 'no'; |
|
445 | + $stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no'; |
|
446 | + $stripe_params['is_checkout'] = (is_checkout() && empty($_GET['pay_for_order'])) ? 'yes' : 'no'; |
|
447 | 447 | $stripe_params['return_url'] = $this->get_stripe_return_url(); |
448 | - $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint( '%%endpoint%%' ); |
|
449 | - $stripe_params['stripe_nonce'] = wp_create_nonce( '_wc_stripe_nonce' ); |
|
448 | + $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint('%%endpoint%%'); |
|
449 | + $stripe_params['stripe_nonce'] = wp_create_nonce('_wc_stripe_nonce'); |
|
450 | 450 | $stripe_params['statement_descriptor'] = $this->statement_descriptor; |
451 | - $stripe_params['use_elements'] = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no'; |
|
452 | - $stripe_params['elements_options'] = apply_filters( 'wc_stripe_elements_options', array() ); |
|
451 | + $stripe_params['use_elements'] = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no'; |
|
452 | + $stripe_params['elements_options'] = apply_filters('wc_stripe_elements_options', array()); |
|
453 | 453 | $stripe_params['is_stripe_checkout'] = $this->stripe_checkout ? 'yes' : 'no'; |
454 | - $stripe_params['is_change_payment_page'] = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no'; |
|
455 | - $stripe_params['is_pay_for_order_page'] = isset( $_GET['pay_for_order'] ) ? 'yes' : 'no'; |
|
456 | - $stripe_params['validate_modal_checkout'] = apply_filters( 'wc_stripe_validate_modal_checkout', false ) ? 'yes' : 'no'; |
|
457 | - $stripe_params['elements_styling'] = apply_filters( 'wc_stripe_elements_styling', false ); |
|
458 | - $stripe_params['elements_classes'] = apply_filters( 'wc_stripe_elements_classes', false ); |
|
454 | + $stripe_params['is_change_payment_page'] = isset($_GET['change_payment_method']) ? 'yes' : 'no'; |
|
455 | + $stripe_params['is_pay_for_order_page'] = isset($_GET['pay_for_order']) ? 'yes' : 'no'; |
|
456 | + $stripe_params['validate_modal_checkout'] = apply_filters('wc_stripe_validate_modal_checkout', false) ? 'yes' : 'no'; |
|
457 | + $stripe_params['elements_styling'] = apply_filters('wc_stripe_elements_styling', false); |
|
458 | + $stripe_params['elements_classes'] = apply_filters('wc_stripe_elements_classes', false); |
|
459 | 459 | |
460 | 460 | // merge localized messages to be use in JS |
461 | - $stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() ); |
|
461 | + $stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages()); |
|
462 | 462 | |
463 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
464 | - wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
463 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
464 | + wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
465 | 465 | |
466 | - if ( $this->stripe_checkout ) { |
|
467 | - wp_enqueue_script( 'stripe_checkout' ); |
|
466 | + if ($this->stripe_checkout) { |
|
467 | + wp_enqueue_script('stripe_checkout'); |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | $this->tokenization_script(); |
471 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
471 | + wp_enqueue_script('woocommerce_stripe'); |
|
472 | 472 | } |
473 | 473 | |
474 | 474 | /** |
@@ -484,41 +484,41 @@ discard block |
||
484 | 484 | * |
485 | 485 | * @return array|void |
486 | 486 | */ |
487 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
487 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
488 | 488 | try { |
489 | - $order = wc_get_order( $order_id ); |
|
489 | + $order = wc_get_order($order_id); |
|
490 | 490 | |
491 | 491 | // This comes from the create account checkbox in the checkout page. |
492 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
492 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
493 | 493 | |
494 | - if ( $create_account ) { |
|
494 | + if ($create_account) { |
|
495 | 495 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
496 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
496 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
497 | 497 | $new_stripe_customer->create_customer(); |
498 | 498 | } |
499 | 499 | |
500 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source ); |
|
500 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source); |
|
501 | 501 | $source_object = $prepared_source->source_object; |
502 | 502 | |
503 | 503 | // Check if we don't allow prepaid credit cards. |
504 | - if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) && $this->is_prepaid_card( $source_object ) ) { |
|
505 | - $localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
506 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message ); |
|
504 | + if ( ! apply_filters('wc_stripe_allow_prepaid_card', true) && $this->is_prepaid_card($source_object)) { |
|
505 | + $localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
506 | + throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message); |
|
507 | 507 | } |
508 | 508 | |
509 | - if ( empty( $prepared_source->source ) ) { |
|
510 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
511 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
509 | + if (empty($prepared_source->source)) { |
|
510 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
511 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
512 | 512 | } |
513 | 513 | |
514 | - $this->save_source_to_order( $order, $prepared_source ); |
|
514 | + $this->save_source_to_order($order, $prepared_source); |
|
515 | 515 | |
516 | 516 | // Result from Stripe API request. |
517 | 517 | $response = null; |
518 | 518 | |
519 | - if ( $order->get_total() > 0 ) { |
|
519 | + if ($order->get_total() > 0) { |
|
520 | 520 | // This will throw exception if not valid. |
521 | - $this->validate_minimum_order_amount( $order ); |
|
521 | + $this->validate_minimum_order_amount($order); |
|
522 | 522 | |
523 | 523 | /* |
524 | 524 | * Check if card 3DS is required or optional with 3DS setting. |
@@ -527,105 +527,105 @@ discard block |
||
527 | 527 | * Note that if we need to save source, the original source must be first |
528 | 528 | * attached to a customer in Stripe before it can be charged. |
529 | 529 | */ |
530 | - if ( $this->is_3ds_required( $source_object ) ) { |
|
531 | - $response = $this->create_3ds_source( $order, $source_object ); |
|
530 | + if ($this->is_3ds_required($source_object)) { |
|
531 | + $response = $this->create_3ds_source($order, $source_object); |
|
532 | 532 | |
533 | - if ( ! empty( $response->error ) ) { |
|
533 | + if ( ! empty($response->error)) { |
|
534 | 534 | $localized_message = $response->error->message; |
535 | 535 | |
536 | - $order->add_order_note( $localized_message ); |
|
536 | + $order->add_order_note($localized_message); |
|
537 | 537 | |
538 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
538 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | // Update order meta with 3DS source. |
542 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
543 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
542 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
543 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
544 | 544 | } else { |
545 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
545 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
546 | 546 | $order->save(); |
547 | 547 | } |
548 | 548 | |
549 | - WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' ); |
|
549 | + WC_Stripe_Logger::log('Info: Redirecting to 3DS...'); |
|
550 | 550 | |
551 | 551 | return array( |
552 | 552 | 'result' => 'success', |
553 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
553 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
554 | 554 | ); |
555 | 555 | } |
556 | 556 | |
557 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
557 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
558 | 558 | |
559 | 559 | /* If we're doing a retry and source is chargeable, we need to pass |
560 | 560 | * a different idempotency key and retry for success. |
561 | 561 | */ |
562 | - if ( 1 < $this->retry_interval && ! empty( $source_object ) && 'chargeable' === $source_object->status ) { |
|
563 | - add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 ); |
|
562 | + if (1 < $this->retry_interval && ! empty($source_object) && 'chargeable' === $source_object->status) { |
|
563 | + add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2); |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | // Make the request. |
567 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
567 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source)); |
|
568 | 568 | |
569 | - if ( ! empty( $response->error ) ) { |
|
569 | + if ( ! empty($response->error)) { |
|
570 | 570 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
571 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
572 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
573 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
574 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
571 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
572 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
573 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
574 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
575 | 575 | } else { |
576 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
577 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
576 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
577 | + $order->delete_meta_data('_stripe_customer_id'); |
|
578 | 578 | $order->save(); |
579 | 579 | } |
580 | 580 | |
581 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
582 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) { |
|
581 | + return $this->process_payment($order_id, false, $force_save_source); |
|
582 | + } elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) { |
|
583 | 583 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
584 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
584 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
585 | 585 | $wc_token->delete(); |
586 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
587 | - $order->add_order_note( $localized_message ); |
|
588 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
586 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
587 | + $order->add_order_note($localized_message); |
|
588 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
589 | 589 | } |
590 | 590 | |
591 | 591 | // We want to retry. |
592 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
593 | - if ( $retry ) { |
|
592 | + if ($this->is_retryable_error($response->error)) { |
|
593 | + if ($retry) { |
|
594 | 594 | // Don't do anymore retries after this. |
595 | - if ( 5 <= $this->retry_interval ) { |
|
595 | + if (5 <= $this->retry_interval) { |
|
596 | 596 | |
597 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
597 | + return $this->process_payment($order_id, false, $force_save_source); |
|
598 | 598 | } |
599 | 599 | |
600 | - sleep( $this->retry_interval ); |
|
600 | + sleep($this->retry_interval); |
|
601 | 601 | |
602 | 602 | $this->retry_interval++; |
603 | 603 | |
604 | - return $this->process_payment( $order_id, true, $force_save_source ); |
|
604 | + return $this->process_payment($order_id, true, $force_save_source); |
|
605 | 605 | } else { |
606 | - $localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' ); |
|
607 | - $order->add_order_note( $localized_message ); |
|
608 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
606 | + $localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe'); |
|
607 | + $order->add_order_note($localized_message); |
|
608 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
609 | 609 | } |
610 | 610 | } |
611 | 611 | |
612 | 612 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
613 | 613 | |
614 | - if ( 'card_error' === $response->error->type ) { |
|
615 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
614 | + if ('card_error' === $response->error->type) { |
|
615 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
616 | 616 | } else { |
617 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
617 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
618 | 618 | } |
619 | 619 | |
620 | - $order->add_order_note( $localized_message ); |
|
620 | + $order->add_order_note($localized_message); |
|
621 | 621 | |
622 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
622 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
623 | 623 | } |
624 | 624 | |
625 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
625 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
626 | 626 | |
627 | 627 | // Process valid response. |
628 | - $this->process_response( $response, $order ); |
|
628 | + $this->process_response($response, $order); |
|
629 | 629 | } else { |
630 | 630 | $order->payment_complete(); |
631 | 631 | } |
@@ -636,20 +636,20 @@ discard block |
||
636 | 636 | // Return thank you page redirect. |
637 | 637 | return array( |
638 | 638 | 'result' => 'success', |
639 | - 'redirect' => $this->get_return_url( $order ), |
|
639 | + 'redirect' => $this->get_return_url($order), |
|
640 | 640 | ); |
641 | 641 | |
642 | - } catch ( WC_Stripe_Exception $e ) { |
|
643 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
644 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
642 | + } catch (WC_Stripe_Exception $e) { |
|
643 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
644 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
645 | 645 | |
646 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
646 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
647 | 647 | |
648 | 648 | /* translators: error message */ |
649 | - $order->update_status( 'failed' ); |
|
649 | + $order->update_status('failed'); |
|
650 | 650 | |
651 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
652 | - $this->send_failed_order_email( $order_id ); |
|
651 | + if ($order->has_status(array('pending', 'failed'))) { |
|
652 | + $this->send_failed_order_email($order_id); |
|
653 | 653 | } |
654 | 654 | |
655 | 655 | return array( |
@@ -15,20 +15,20 @@ discard block |
||
15 | 15 | * |
16 | 16 | */ |
17 | 17 | |
18 | -if ( ! defined( 'ABSPATH' ) ) { |
|
18 | +if ( ! defined('ABSPATH')) { |
|
19 | 19 | exit; |
20 | 20 | } |
21 | 21 | |
22 | -if ( ! class_exists( 'WC_Stripe' ) ) : |
|
22 | +if ( ! class_exists('WC_Stripe')) : |
|
23 | 23 | /** |
24 | 24 | * Required minimums and constants |
25 | 25 | */ |
26 | - define( 'WC_STRIPE_VERSION', '4.0.7' ); |
|
27 | - define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' ); |
|
28 | - define( 'WC_STRIPE_MIN_WC_VER', '2.6.0' ); |
|
29 | - define( 'WC_STRIPE_MAIN_FILE', __FILE__ ); |
|
30 | - define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); |
|
31 | - define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); |
|
26 | + define('WC_STRIPE_VERSION', '4.0.7'); |
|
27 | + define('WC_STRIPE_MIN_PHP_VER', '5.6.0'); |
|
28 | + define('WC_STRIPE_MIN_WC_VER', '2.6.0'); |
|
29 | + define('WC_STRIPE_MAIN_FILE', __FILE__); |
|
30 | + define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)))); |
|
31 | + define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__))); |
|
32 | 32 | |
33 | 33 | class WC_Stripe { |
34 | 34 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @return Singleton The *Singleton* instance. |
49 | 49 | */ |
50 | 50 | public static function get_instance() { |
51 | - if ( null === self::$instance ) { |
|
51 | + if (null === self::$instance) { |
|
52 | 52 | self::$instance = new self(); |
53 | 53 | } |
54 | 54 | return self::$instance; |
@@ -81,10 +81,10 @@ discard block |
||
81 | 81 | * *Singleton* via the `new` operator from outside of this class. |
82 | 82 | */ |
83 | 83 | private function __construct() { |
84 | - add_action( 'admin_init', array( $this, 'check_environment' ) ); |
|
85 | - add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 ); |
|
86 | - add_action( 'plugins_loaded', array( $this, 'init' ) ); |
|
87 | - add_action( 'wp_loaded', array( $this, 'hide_notices' ) ); |
|
84 | + add_action('admin_init', array($this, 'check_environment')); |
|
85 | + add_action('admin_notices', array($this, 'admin_notices'), 15); |
|
86 | + add_action('plugins_loaded', array($this, 'init')); |
|
87 | + add_action('wp_loaded', array($this, 'hide_notices')); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -94,44 +94,44 @@ discard block |
||
94 | 94 | * @version 4.0.0 |
95 | 95 | */ |
96 | 96 | public function init() { |
97 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-exception.php' ); |
|
98 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php' ); |
|
99 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php' ); |
|
100 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' ); |
|
97 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-exception.php'); |
|
98 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-logger.php'); |
|
99 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-helper.php'); |
|
100 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php'); |
|
101 | 101 | |
102 | 102 | // Don't hook anything else in the plugin if we're in an incompatible environment. |
103 | - if ( self::get_environment_warning() ) { |
|
103 | + if (self::get_environment_warning()) { |
|
104 | 104 | return; |
105 | 105 | } |
106 | 106 | |
107 | - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
|
108 | - |
|
109 | - require_once( dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php' ); |
|
110 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php' ); |
|
111 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-sepa-payment-token.php' ); |
|
112 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay-registration.php' ); |
|
113 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' ); |
|
114 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php' ); |
|
115 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php' ); |
|
116 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php' ); |
|
117 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php' ); |
|
118 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php' ); |
|
119 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php' ); |
|
120 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php' ); |
|
121 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php' ); |
|
122 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php' ); |
|
123 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-compat.php' ); |
|
124 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-compat.php' ); |
|
125 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php' ); |
|
126 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php' ); |
|
127 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' ); |
|
107 | + load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages'); |
|
108 | + |
|
109 | + require_once(dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php'); |
|
110 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php'); |
|
111 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-sepa-payment-token.php'); |
|
112 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay-registration.php'); |
|
113 | + require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php'); |
|
114 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'); |
|
115 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'); |
|
116 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'); |
|
117 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php'); |
|
118 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php'); |
|
119 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php'); |
|
120 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php'); |
|
121 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php'); |
|
122 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php'); |
|
123 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-compat.php'); |
|
124 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-sepa-compat.php'); |
|
125 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php'); |
|
126 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php'); |
|
127 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php'); |
|
128 | 128 | |
129 | 129 | // REMOVE IN THE FUTURE. |
130 | - require_once( dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php' ); |
|
130 | + require_once(dirname(__FILE__) . '/includes/deprecated/class-wc-stripe-apple-pay.php'); |
|
131 | 131 | |
132 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
133 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
|
134 | - add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) ); |
|
132 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
133 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); |
|
134 | + add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin')); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -141,23 +141,23 @@ discard block |
||
141 | 141 | * @version 4.0.0 |
142 | 142 | */ |
143 | 143 | public function hide_notices() { |
144 | - if ( isset( $_GET['wc-stripe-hide-notice'] ) && isset( $_GET['_wc_stripe_notice_nonce'] ) ) { |
|
145 | - if ( ! wp_verify_nonce( $_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce' ) ) { |
|
146 | - wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe' ) ); |
|
144 | + if (isset($_GET['wc-stripe-hide-notice']) && isset($_GET['_wc_stripe_notice_nonce'])) { |
|
145 | + if ( ! wp_verify_nonce($_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce')) { |
|
146 | + wp_die(__('Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe')); |
|
147 | 147 | } |
148 | 148 | |
149 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
150 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
149 | + if ( ! current_user_can('manage_woocommerce')) { |
|
150 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
151 | 151 | } |
152 | 152 | |
153 | - $notice = wc_clean( $_GET['wc-stripe-hide-notice'] ); |
|
153 | + $notice = wc_clean($_GET['wc-stripe-hide-notice']); |
|
154 | 154 | |
155 | - switch ( $notice ) { |
|
155 | + switch ($notice) { |
|
156 | 156 | case 'ssl': |
157 | - update_option( 'wc_stripe_show_ssl_notice', 'no' ); |
|
157 | + update_option('wc_stripe_show_ssl_notice', 'no'); |
|
158 | 158 | break; |
159 | 159 | case 'keys': |
160 | - update_option( 'wc_stripe_show_keys_notice', 'no' ); |
|
160 | + update_option('wc_stripe_show_keys_notice', 'no'); |
|
161 | 161 | break; |
162 | 162 | } |
163 | 163 | } |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | * @since 1.0.0 |
170 | 170 | * @version 4.0.0 |
171 | 171 | */ |
172 | - public function add_admin_notice( $slug, $class, $message, $dismissible = false ) { |
|
173 | - $this->notices[ $slug ] = array( |
|
172 | + public function add_admin_notice($slug, $class, $message, $dismissible = false) { |
|
173 | + $this->notices[$slug] = array( |
|
174 | 174 | 'class' => $class, |
175 | 175 | 'message' => $message, |
176 | 176 | 'dismissible' => $dismissible, |
@@ -184,21 +184,21 @@ discard block |
||
184 | 184 | * @version 4.0.0 |
185 | 185 | */ |
186 | 186 | public function admin_notices() { |
187 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
187 | + if ( ! current_user_can('manage_woocommerce')) { |
|
188 | 188 | return; |
189 | 189 | } |
190 | 190 | |
191 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
192 | - echo '<div class="' . esc_attr( $notice['class'] ) . '" style="position:relative;">'; |
|
191 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
192 | + echo '<div class="' . esc_attr($notice['class']) . '" style="position:relative;">'; |
|
193 | 193 | |
194 | - if ( $notice['dismissible'] ) { |
|
194 | + if ($notice['dismissible']) { |
|
195 | 195 | ?> |
196 | - <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-stripe-hide-notice', $notice_key ), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce' ) ); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a> |
|
196 | + <a href="<?php echo esc_url(wp_nonce_url(add_query_arg('wc-stripe-hide-notice', $notice_key), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce')); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a> |
|
197 | 197 | <?php |
198 | 198 | } |
199 | 199 | |
200 | 200 | echo '<p>'; |
201 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
201 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
202 | 202 | echo '</p></div>'; |
203 | 203 | } |
204 | 204 | } |
@@ -211,26 +211,26 @@ discard block |
||
211 | 211 | * @version 4.0.0 |
212 | 212 | */ |
213 | 213 | public function get_environment_warning() { |
214 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
214 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
215 | 215 | /* translators: 1) int version 2) int version */ |
216 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
216 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
217 | 217 | |
218 | - return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ); |
|
218 | + return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()); |
|
219 | 219 | } |
220 | 220 | |
221 | - if ( ! defined( 'WC_VERSION' ) ) { |
|
222 | - return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' ); |
|
221 | + if ( ! defined('WC_VERSION')) { |
|
222 | + return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe'); |
|
223 | 223 | } |
224 | 224 | |
225 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
225 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
226 | 226 | /* translators: 1) int version 2) int version */ |
227 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
227 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
228 | 228 | |
229 | - return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ); |
|
229 | + return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION); |
|
230 | 230 | } |
231 | 231 | |
232 | - if ( ! function_exists( 'curl_init' ) ) { |
|
233 | - return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ); |
|
232 | + if ( ! function_exists('curl_init')) { |
|
233 | + return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | return false; |
@@ -244,11 +244,11 @@ discard block |
||
244 | 244 | * @return string Setting link |
245 | 245 | */ |
246 | 246 | public function get_setting_link() { |
247 | - $use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false; |
|
247 | + $use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false; |
|
248 | 248 | |
249 | - $section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' ); |
|
249 | + $section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe'); |
|
250 | 250 | |
251 | - return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); |
|
251 | + return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
@@ -259,65 +259,65 @@ discard block |
||
259 | 259 | * @version 4.0.0 |
260 | 260 | */ |
261 | 261 | public function check_environment() { |
262 | - if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) { |
|
262 | + if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) { |
|
263 | 263 | $this->install(); |
264 | 264 | |
265 | - do_action( 'woocommerce_stripe_updated' ); |
|
265 | + do_action('woocommerce_stripe_updated'); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | $environment_warning = $this->get_environment_warning(); |
269 | 269 | |
270 | - if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
|
271 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
270 | + if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) { |
|
271 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
272 | 272 | } |
273 | 273 | |
274 | - $show_ssl_notice = get_option( 'wc_stripe_show_ssl_notice' ); |
|
275 | - $show_keys_notice = get_option( 'wc_stripe_show_keys_notice' ); |
|
276 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
277 | - $testmode = ( isset( $options['testmode'] ) && 'yes' === $options['testmode'] ) ? true : false; |
|
278 | - $test_pub_key = isset( $options['test_publishable_key'] ) ? $options['test_publishable_key'] : ''; |
|
279 | - $test_secret_key = isset( $options['test_secret_key'] ) ? $options['test_secret_key'] : ''; |
|
280 | - $live_pub_key = isset( $options['publishable_key'] ) ? $options['publishable_key'] : ''; |
|
281 | - $live_secret_key = isset( $options['secret_key'] ) ? $options['secret_key'] : ''; |
|
274 | + $show_ssl_notice = get_option('wc_stripe_show_ssl_notice'); |
|
275 | + $show_keys_notice = get_option('wc_stripe_show_keys_notice'); |
|
276 | + $options = get_option('woocommerce_stripe_settings'); |
|
277 | + $testmode = (isset($options['testmode']) && 'yes' === $options['testmode']) ? true : false; |
|
278 | + $test_pub_key = isset($options['test_publishable_key']) ? $options['test_publishable_key'] : ''; |
|
279 | + $test_secret_key = isset($options['test_secret_key']) ? $options['test_secret_key'] : ''; |
|
280 | + $live_pub_key = isset($options['publishable_key']) ? $options['publishable_key'] : ''; |
|
281 | + $live_secret_key = isset($options['secret_key']) ? $options['secret_key'] : ''; |
|
282 | 282 | |
283 | - if ( isset( $options['enabled'] ) && 'yes' === $options['enabled'] && empty( $show_keys_notice ) ) { |
|
284 | - $secret = WC_Stripe_API::get_secret_key(); |
|
283 | + if (isset($options['enabled']) && 'yes' === $options['enabled'] && empty($show_keys_notice)) { |
|
284 | + $secret = WC_Stripe_API::get_secret_key(); |
|
285 | 285 | |
286 | - if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
|
286 | + if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) { |
|
287 | 287 | $setting_link = $this->get_setting_link(); |
288 | 288 | /* translators: 1) link */ |
289 | - $this->add_admin_notice( 'keys', 'notice notice-warning', sprintf( __( 'Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
289 | + $this->add_admin_notice('keys', 'notice notice-warning', sprintf(__('Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | // Check if keys are entered properly per live/test mode. |
293 | - if ( $testmode ) { |
|
293 | + if ($testmode) { |
|
294 | 294 | if ( |
295 | - ! empty( $test_pub_key ) && ! preg_match( '/^pk_test_/', $test_pub_key ) |
|
296 | - || ( ! empty( $test_secret_key ) && ! preg_match( '/^sk_test_/', $test_secret_key ) |
|
297 | - && ! empty( $test_secret_key ) && ! preg_match( '/^rk_test_/', $test_secret_key ) ) ) |
|
295 | + ! empty($test_pub_key) && ! preg_match('/^pk_test_/', $test_pub_key) |
|
296 | + || ( ! empty($test_secret_key) && ! preg_match('/^sk_test_/', $test_secret_key) |
|
297 | + && ! empty($test_secret_key) && ! preg_match('/^rk_test_/', $test_secret_key)) ) |
|
298 | 298 | { |
299 | 299 | $setting_link = $this->get_setting_link(); |
300 | 300 | /* translators: 1) link */ |
301 | - $this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in test mode however your test keys may not be valid. Test keys start with pk_test and sk_test or rk_test. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
301 | + $this->add_admin_notice('keys', 'notice notice-error', sprintf(__('Stripe is in test mode however your test keys may not be valid. Test keys start with pk_test and sk_test or rk_test. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
302 | 302 | } |
303 | 303 | } else { |
304 | 304 | if ( |
305 | - ! empty( $live_pub_key ) && ! preg_match( '/^pk_live_/', $live_pub_key ) |
|
306 | - || ( ! empty( $live_secret_key ) && ! preg_match( '/^sk_live_/', $live_secret_key ) |
|
307 | - && ! empty( $live_secret_key ) && ! preg_match( '/^rk_live_/', $live_secret_key ) ) ) |
|
305 | + ! empty($live_pub_key) && ! preg_match('/^pk_live_/', $live_pub_key) |
|
306 | + || ( ! empty($live_secret_key) && ! preg_match('/^sk_live_/', $live_secret_key) |
|
307 | + && ! empty($live_secret_key) && ! preg_match('/^rk_live_/', $live_secret_key)) ) |
|
308 | 308 | { |
309 | 309 | $setting_link = $this->get_setting_link(); |
310 | 310 | /* translators: 1) link */ |
311 | - $this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in live mode however your test keys may not be valid. Live keys start with pk_live and sk_live or rk_live. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
311 | + $this->add_admin_notice('keys', 'notice notice-error', sprintf(__('Stripe is in live mode however your test keys may not be valid. Live keys start with pk_live and sk_live or rk_live. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
312 | 312 | } |
313 | 313 | } |
314 | 314 | } |
315 | 315 | |
316 | - if ( empty( $show_ssl_notice ) && isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) { |
|
316 | + if (empty($show_ssl_notice) && isset($options['enabled']) && 'yes' === $options['enabled']) { |
|
317 | 317 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
318 | - if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
318 | + if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
319 | 319 | /* translators: 1) link 2) link */ |
320 | - $this->add_admin_notice( 'ssl', 'notice notice-warning', sprintf( __( 'Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ), 'https://en.wikipedia.org/wiki/Transport_Layer_Security' ), true ); |
|
320 | + $this->add_admin_notice('ssl', 'notice notice-warning', sprintf(__('Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout'), 'https://en.wikipedia.org/wiki/Transport_Layer_Security'), true); |
|
321 | 321 | } |
322 | 322 | } |
323 | 323 | } |
@@ -329,8 +329,8 @@ discard block |
||
329 | 329 | * @version 4.0.0 |
330 | 330 | */ |
331 | 331 | public function update_plugin_version() { |
332 | - delete_option( 'wc_stripe_version' ); |
|
333 | - update_option( 'wc_stripe_version', WC_STRIPE_VERSION ); |
|
332 | + delete_option('wc_stripe_version'); |
|
333 | + update_option('wc_stripe_version', WC_STRIPE_VERSION); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
@@ -340,8 +340,8 @@ discard block |
||
340 | 340 | * @version 3.1.0 |
341 | 341 | */ |
342 | 342 | public function install() { |
343 | - if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) { |
|
344 | - define( 'WC_STRIPE_INSTALLING', true ); |
|
343 | + if ( ! defined('WC_STRIPE_INSTALLING')) { |
|
344 | + define('WC_STRIPE_INSTALLING', true); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | $this->update_plugin_version(); |
@@ -353,13 +353,13 @@ discard block |
||
353 | 353 | * @since 1.0.0 |
354 | 354 | * @version 4.0.0 |
355 | 355 | */ |
356 | - public function plugin_action_links( $links ) { |
|
356 | + public function plugin_action_links($links) { |
|
357 | 357 | $plugin_links = array( |
358 | - '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
359 | - '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
360 | - '<a href="https://woocommerce.com/contact-us/">' . esc_html__( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
358 | + '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
359 | + '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
360 | + '<a href="https://woocommerce.com/contact-us/">' . esc_html__('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
361 | 361 | ); |
362 | - return array_merge( $plugin_links, $links ); |
|
362 | + return array_merge($plugin_links, $links); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
@@ -368,8 +368,8 @@ discard block |
||
368 | 368 | * @since 1.0.0 |
369 | 369 | * @version 4.0.0 |
370 | 370 | */ |
371 | - public function add_gateways( $methods ) { |
|
372 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
371 | + public function add_gateways($methods) { |
|
372 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order') || class_exists('WC_Pre_Orders_Order')) { |
|
373 | 373 | $methods[] = 'WC_Stripe_Compat'; |
374 | 374 | $methods[] = 'WC_Stripe_Sepa_Compat'; |
375 | 375 | } else { |
@@ -394,26 +394,26 @@ discard block |
||
394 | 394 | * @since 4.0.0 |
395 | 395 | * @version 4.0.0 |
396 | 396 | */ |
397 | - public function filter_gateway_order_admin( $sections ) { |
|
398 | - unset( $sections['stripe'] ); |
|
399 | - unset( $sections['stripe_bancontact'] ); |
|
400 | - unset( $sections['stripe_sofort'] ); |
|
401 | - unset( $sections['stripe_giropay'] ); |
|
402 | - unset( $sections['stripe_ideal'] ); |
|
403 | - unset( $sections['stripe_p24'] ); |
|
404 | - unset( $sections['stripe_alipay'] ); |
|
405 | - unset( $sections['stripe_sepa'] ); |
|
406 | - unset( $sections['stripe_bitcoin'] ); |
|
397 | + public function filter_gateway_order_admin($sections) { |
|
398 | + unset($sections['stripe']); |
|
399 | + unset($sections['stripe_bancontact']); |
|
400 | + unset($sections['stripe_sofort']); |
|
401 | + unset($sections['stripe_giropay']); |
|
402 | + unset($sections['stripe_ideal']); |
|
403 | + unset($sections['stripe_p24']); |
|
404 | + unset($sections['stripe_alipay']); |
|
405 | + unset($sections['stripe_sepa']); |
|
406 | + unset($sections['stripe_bitcoin']); |
|
407 | 407 | |
408 | 408 | $sections['stripe'] = 'Stripe'; |
409 | - $sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
410 | - $sections['stripe_sofort'] = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
411 | - $sections['stripe_giropay'] = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
412 | - $sections['stripe_ideal'] = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
413 | - $sections['stripe_p24'] = __( 'Stripe P24', 'woocommerce-gateway-stripe' ); |
|
414 | - $sections['stripe_alipay'] = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
415 | - $sections['stripe_sepa'] = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
416 | - $sections['stripe_bitcoin'] = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' ); |
|
409 | + $sections['stripe_bancontact'] = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
410 | + $sections['stripe_sofort'] = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
411 | + $sections['stripe_giropay'] = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
412 | + $sections['stripe_ideal'] = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
413 | + $sections['stripe_p24'] = __('Stripe P24', 'woocommerce-gateway-stripe'); |
|
414 | + $sections['stripe_alipay'] = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
415 | + $sections['stripe_sepa'] = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
416 | + $sections['stripe_bitcoin'] = __('Stripe Bitcoin', 'woocommerce-gateway-stripe'); |
|
417 | 417 | |
418 | 418 | return $sections; |
419 | 419 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @since 4.0.5 |
22 | 22 | * @param array $error |
23 | 23 | */ |
24 | - public function is_retryable_error( $error ) { |
|
24 | + public function is_retryable_error($error) { |
|
25 | 25 | return ( |
26 | 26 | 'invalid_request_error' === $error->type || |
27 | 27 | 'idempotency_error' === $error->type || |
@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | * Check if this gateway is enabled |
36 | 36 | */ |
37 | 37 | public function is_available() { |
38 | - if ( 'yes' === $this->enabled ) { |
|
39 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
38 | + if ('yes' === $this->enabled) { |
|
39 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
40 | 40 | return false; |
41 | 41 | } |
42 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
42 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
43 | 43 | return false; |
44 | 44 | } |
45 | 45 | return true; |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | * @since 4.0.0 |
55 | 55 | * @version 4.0.0 |
56 | 56 | */ |
57 | - public function add_admin_notice( $slug, $class, $message ) { |
|
58 | - $this->notices[ $slug ] = array( |
|
57 | + public function add_admin_notice($slug, $class, $message) { |
|
58 | + $this->notices[$slug] = array( |
|
59 | 59 | 'class' => $class, |
60 | 60 | 'message' => $message, |
61 | 61 | ); |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | * @version 4.0.0 |
69 | 69 | */ |
70 | 70 | public function remove_admin_notice() { |
71 | - if ( did_action( 'woocommerce_update_options' ) ) { |
|
72 | - remove_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
71 | + if (did_action('woocommerce_update_options')) { |
|
72 | + remove_action('admin_notices', array($this, 'check_environment')); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * @return array |
82 | 82 | */ |
83 | 83 | public function payment_icons() { |
84 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
84 | + return apply_filters('wc_stripe_payment_icons', array( |
|
85 | 85 | 'visa' => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>', |
86 | 86 | 'amex' => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>', |
87 | 87 | 'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>', |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | 'eps' => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>', |
99 | 99 | 'sofort' => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>', |
100 | 100 | 'sepa' => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>', |
101 | - ) ); |
|
101 | + )); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -109,10 +109,10 @@ discard block |
||
109 | 109 | * @version 4.0.0 |
110 | 110 | * @param object $order |
111 | 111 | */ |
112 | - public function validate_minimum_order_amount( $order ) { |
|
113 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
112 | + public function validate_minimum_order_amount($order) { |
|
113 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
114 | 114 | /* translators: 1) dollar amount */ |
115 | - throw new WC_Stripe_Exception( 'Did not meet minimum amount', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
115 | + throw new WC_Stripe_Exception('Did not meet minimum amount', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
@@ -122,14 +122,14 @@ discard block |
||
122 | 122 | * @since 4.0.0 |
123 | 123 | * @version 4.0.0 |
124 | 124 | */ |
125 | - public function get_transaction_url( $order ) { |
|
126 | - if ( $this->testmode ) { |
|
125 | + public function get_transaction_url($order) { |
|
126 | + if ($this->testmode) { |
|
127 | 127 | $this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s'; |
128 | 128 | } else { |
129 | 129 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
130 | 130 | } |
131 | 131 | |
132 | - return parent::get_transaction_url( $order ); |
|
132 | + return parent::get_transaction_url($order); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -138,15 +138,15 @@ discard block |
||
138 | 138 | * @since 4.0.0 |
139 | 139 | * @version 4.0.0 |
140 | 140 | */ |
141 | - public function get_stripe_customer_id( $order ) { |
|
142 | - $customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true ); |
|
141 | + public function get_stripe_customer_id($order) { |
|
142 | + $customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true); |
|
143 | 143 | |
144 | - if ( empty( $customer ) ) { |
|
144 | + if (empty($customer)) { |
|
145 | 145 | // Try to get it via the order. |
146 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
147 | - return get_post_meta( $order->id, '_stripe_customer_id', true ); |
|
146 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
147 | + return get_post_meta($order->id, '_stripe_customer_id', true); |
|
148 | 148 | } else { |
149 | - return $order->get_meta( '_stripe_customer_id', true ); |
|
149 | + return $order->get_meta('_stripe_customer_id', true); |
|
150 | 150 | } |
151 | 151 | } else { |
152 | 152 | return $customer; |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | * @param object $order |
164 | 164 | * @param int $id Stripe session id. |
165 | 165 | */ |
166 | - public function get_stripe_return_url( $order = null, $id = null ) { |
|
167 | - if ( is_object( $order ) ) { |
|
168 | - if ( empty( $id ) ) { |
|
166 | + public function get_stripe_return_url($order = null, $id = null) { |
|
167 | + if (is_object($order)) { |
|
168 | + if (empty($id)) { |
|
169 | 169 | $id = uniqid(); |
170 | 170 | } |
171 | 171 | |
@@ -176,10 +176,10 @@ discard block |
||
176 | 176 | 'order_id' => $order_id, |
177 | 177 | ); |
178 | 178 | |
179 | - return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) ); |
|
179 | + return esc_url_raw(add_query_arg($args, $this->get_return_url($order))); |
|
180 | 180 | } |
181 | 181 | |
182 | - return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) ); |
|
182 | + return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url())); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -187,8 +187,8 @@ discard block |
||
187 | 187 | * @param int $order_id |
188 | 188 | * @return boolean |
189 | 189 | */ |
190 | - public function has_subscription( $order_id ) { |
|
191 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
190 | + public function has_subscription($order_id) { |
|
191 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -200,34 +200,33 @@ discard block |
||
200 | 200 | * @param object $prepared_source |
201 | 201 | * @return array() |
202 | 202 | */ |
203 | - public function generate_payment_request( $order, $prepared_source ) { |
|
204 | - $settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
205 | - $statement_descriptor = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : ''; |
|
206 | - $capture = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false; |
|
203 | + public function generate_payment_request($order, $prepared_source) { |
|
204 | + $settings = get_option('woocommerce_stripe_settings', array()); |
|
205 | + $statement_descriptor = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : ''; |
|
206 | + $capture = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false; |
|
207 | 207 | $post_data = array(); |
208 | - $post_data['currency'] = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() ); |
|
209 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
208 | + $post_data['currency'] = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency()); |
|
209 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']); |
|
210 | 210 | /* translators: 1) blog name 2) order number */ |
211 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
211 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
212 | 212 | $billing_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
213 | 213 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
214 | 214 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
215 | 215 | |
216 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
216 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
217 | 217 | $post_data['receipt_email'] = $billing_email; |
218 | 218 | } |
219 | 219 | |
220 | - switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) { |
|
221 | - case 'stripe': |
|
222 | - if ( ! empty( $statement_descriptor ) ) { |
|
223 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
220 | + switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) { |
|
221 | + case 'stripe' : if ( ! empty($statement_descriptor)) { |
|
222 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
224 | 223 | } |
225 | 224 | |
226 | 225 | $post_data['capture'] = $capture ? 'true' : 'false'; |
227 | 226 | break; |
228 | 227 | case 'stripe_sepa': |
229 | - if ( ! empty( $statement_descriptor ) ) { |
|
230 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
228 | + if ( ! empty($statement_descriptor)) { |
|
229 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
231 | 230 | } |
232 | 231 | break; |
233 | 232 | } |
@@ -235,25 +234,25 @@ discard block |
||
235 | 234 | $post_data['expand[]'] = 'balance_transaction'; |
236 | 235 | |
237 | 236 | $metadata = array( |
238 | - __( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ), |
|
239 | - __( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ), |
|
237 | + __('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name), |
|
238 | + __('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email), |
|
240 | 239 | 'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(), |
241 | 240 | ); |
242 | 241 | |
243 | - if ( $this->has_subscription( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) { |
|
242 | + if ($this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id())) { |
|
244 | 243 | $metadata += array( |
245 | 244 | 'payment_type' => 'recurring', |
246 | - 'site_url' => esc_url( get_site_url() ), |
|
245 | + 'site_url' => esc_url(get_site_url()), |
|
247 | 246 | ); |
248 | 247 | } |
249 | 248 | |
250 | - $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $prepared_source ); |
|
249 | + $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $prepared_source); |
|
251 | 250 | |
252 | - if ( $prepared_source->customer ) { |
|
251 | + if ($prepared_source->customer) { |
|
253 | 252 | $post_data['customer'] = $prepared_source->customer; |
254 | 253 | } |
255 | 254 | |
256 | - if ( $prepared_source->source ) { |
|
255 | + if ($prepared_source->source) { |
|
257 | 256 | $post_data['source'] = $prepared_source->source; |
258 | 257 | } |
259 | 258 | |
@@ -265,79 +264,79 @@ discard block |
||
265 | 264 | * @param WC_Order $order |
266 | 265 | * @param object $source |
267 | 266 | */ |
268 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $prepared_source ); |
|
267 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $prepared_source); |
|
269 | 268 | } |
270 | 269 | |
271 | 270 | /** |
272 | 271 | * Store extra meta data for an order from a Stripe Response. |
273 | 272 | */ |
274 | - public function process_response( $response, $order ) { |
|
275 | - WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) ); |
|
273 | + public function process_response($response, $order) { |
|
274 | + WC_Stripe_Logger::log('Processing response: ' . print_r($response, true)); |
|
276 | 275 | |
277 | 276 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
278 | 277 | |
279 | - $captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no'; |
|
278 | + $captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no'; |
|
280 | 279 | |
281 | 280 | // Store charge data. |
282 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured ); |
|
281 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured); |
|
283 | 282 | |
284 | 283 | // Store other data such as fees. |
285 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
284 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
286 | 285 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
287 | 286 | // values are in the local currency of the Stripe account, not from WC. |
288 | - $fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0; |
|
289 | - $net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0; |
|
290 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee ); |
|
291 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net ); |
|
287 | + $fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0; |
|
288 | + $net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0; |
|
289 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee); |
|
290 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net); |
|
292 | 291 | } |
293 | 292 | |
294 | - if ( 'yes' === $captured ) { |
|
293 | + if ('yes' === $captured) { |
|
295 | 294 | /** |
296 | 295 | * Charge can be captured but in a pending state. Payment methods |
297 | 296 | * that are asynchronous may take couple days to clear. Webhook will |
298 | 297 | * take care of the status changes. |
299 | 298 | */ |
300 | - if ( 'pending' === $response->status ) { |
|
301 | - $order_stock_reduced = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_order_stock_reduced', true ) : $order->get_meta( '_order_stock_reduced', true ); |
|
299 | + if ('pending' === $response->status) { |
|
300 | + $order_stock_reduced = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_order_stock_reduced', true) : $order->get_meta('_order_stock_reduced', true); |
|
302 | 301 | |
303 | - if ( ! $order_stock_reduced ) { |
|
304 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
302 | + if ( ! $order_stock_reduced) { |
|
303 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
305 | 304 | } |
306 | 305 | |
307 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
306 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
308 | 307 | /* translators: transaction id */ |
309 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
308 | + $order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id)); |
|
310 | 309 | } |
311 | 310 | |
312 | - if ( 'succeeded' === $response->status ) { |
|
313 | - $order->payment_complete( $response->id ); |
|
311 | + if ('succeeded' === $response->status) { |
|
312 | + $order->payment_complete($response->id); |
|
314 | 313 | |
315 | 314 | /* translators: transaction id */ |
316 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
317 | - $order->add_order_note( $message ); |
|
315 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
316 | + $order->add_order_note($message); |
|
318 | 317 | } |
319 | 318 | |
320 | - if ( 'failed' === $response->status ) { |
|
321 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
322 | - $order->add_order_note( $localized_message ); |
|
323 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
319 | + if ('failed' === $response->status) { |
|
320 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
321 | + $order->add_order_note($localized_message); |
|
322 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
324 | 323 | } |
325 | 324 | } else { |
326 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
325 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
327 | 326 | |
328 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
329 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
327 | + if ($order->has_status(array('pending', 'failed'))) { |
|
328 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
330 | 329 | } |
331 | 330 | |
332 | 331 | /* translators: transaction id */ |
333 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
332 | + $order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id)); |
|
334 | 333 | } |
335 | 334 | |
336 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
335 | + if (is_callable(array($order, 'save'))) { |
|
337 | 336 | $order->save(); |
338 | 337 | } |
339 | 338 | |
340 | - do_action( 'wc_gateway_stripe_process_response', $response, $order ); |
|
339 | + do_action('wc_gateway_stripe_process_response', $response, $order); |
|
341 | 340 | |
342 | 341 | return $response; |
343 | 342 | } |
@@ -350,10 +349,10 @@ discard block |
||
350 | 349 | * @param int $order_id |
351 | 350 | * @return null |
352 | 351 | */ |
353 | - public function send_failed_order_email( $order_id ) { |
|
352 | + public function send_failed_order_email($order_id) { |
|
354 | 353 | $emails = WC()->mailer()->get_emails(); |
355 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
356 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
354 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
355 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
357 | 356 | } |
358 | 357 | } |
359 | 358 | |
@@ -365,7 +364,7 @@ discard block |
||
365 | 364 | * @param object $order |
366 | 365 | * @return object $details |
367 | 366 | */ |
368 | - public function get_owner_details( $order ) { |
|
367 | + public function get_owner_details($order) { |
|
369 | 368 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
370 | 369 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
371 | 370 | |
@@ -376,8 +375,8 @@ discard block |
||
376 | 375 | |
377 | 376 | $phone = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone(); |
378 | 377 | |
379 | - if ( ! empty( $phone ) ) { |
|
380 | - $details['phone'] = $phone; |
|
378 | + if ( ! empty($phone)) { |
|
379 | + $details['phone'] = $phone; |
|
381 | 380 | } |
382 | 381 | |
383 | 382 | $details['address']['line1'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1(); |
@@ -387,7 +386,7 @@ discard block |
||
387 | 386 | $details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode(); |
388 | 387 | $details['address']['country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
389 | 388 | |
390 | - return (object) apply_filters( 'wc_stripe_owner_details', $details, $order ); |
|
389 | + return (object) apply_filters('wc_stripe_owner_details', $details, $order); |
|
391 | 390 | } |
392 | 391 | |
393 | 392 | /** |
@@ -396,15 +395,15 @@ discard block |
||
396 | 395 | * @since 4.0.3 |
397 | 396 | * @param string $source_id The source ID to get source object for. |
398 | 397 | */ |
399 | - public function get_source_object( $source_id = '' ) { |
|
400 | - if ( empty( $source_id ) ) { |
|
398 | + public function get_source_object($source_id = '') { |
|
399 | + if (empty($source_id)) { |
|
401 | 400 | return ''; |
402 | 401 | } |
403 | 402 | |
404 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id ); |
|
403 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source_id); |
|
405 | 404 | |
406 | - if ( ! empty( $source_object->error ) ) { |
|
407 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message ); |
|
405 | + if ( ! empty($source_object->error)) { |
|
406 | + throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message); |
|
408 | 407 | } |
409 | 408 | |
410 | 409 | return $source_object; |
@@ -417,11 +416,11 @@ discard block |
||
417 | 416 | * @param object $source_object |
418 | 417 | * @return bool |
419 | 418 | */ |
420 | - public function is_3ds_required( $source_object ) { |
|
419 | + public function is_3ds_required($source_object) { |
|
421 | 420 | return ( |
422 | - $source_object && ! empty( $source_object->card ) ) && |
|
423 | - ( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure || |
|
424 | - ( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure ) |
|
421 | + $source_object && ! empty($source_object->card) ) && |
|
422 | + ('card' === $source_object->type && 'required' === $source_object->card->three_d_secure || |
|
423 | + ($this->three_d_secure && 'optional' === $source_object->card->three_d_secure) |
|
425 | 424 | ); |
426 | 425 | } |
427 | 426 | |
@@ -432,8 +431,8 @@ discard block |
||
432 | 431 | * @param object $source_object |
433 | 432 | * @return bool |
434 | 433 | */ |
435 | - public function is_3ds_card( $source_object ) { |
|
436 | - return ( $source_object && 'three_d_secure' === $source_object->type ); |
|
434 | + public function is_3ds_card($source_object) { |
|
435 | + return ($source_object && 'three_d_secure' === $source_object->type); |
|
437 | 436 | } |
438 | 437 | |
439 | 438 | /** |
@@ -443,8 +442,8 @@ discard block |
||
443 | 442 | * @param object $source_object |
444 | 443 | * @return bool |
445 | 444 | */ |
446 | - public function is_prepaid_card( $source_object ) { |
|
447 | - return ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ); |
|
445 | + public function is_prepaid_card($source_object) { |
|
446 | + return ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding); |
|
448 | 447 | } |
449 | 448 | |
450 | 449 | /** |
@@ -454,8 +453,8 @@ discard block |
||
454 | 453 | * @param string $source_id |
455 | 454 | * @return bool |
456 | 455 | */ |
457 | - public function is_type_legacy_card( $source_id ) { |
|
458 | - return ( preg_match( '/^card_/', $source_id ) ); |
|
456 | + public function is_type_legacy_card($source_id) { |
|
457 | + return (preg_match('/^card_/', $source_id)); |
|
459 | 458 | } |
460 | 459 | |
461 | 460 | /** |
@@ -468,22 +467,22 @@ discard block |
||
468 | 467 | * @param string $return_url |
469 | 468 | * @return mixed |
470 | 469 | */ |
471 | - public function create_3ds_source( $order, $source_object, $return_url = '' ) { |
|
470 | + public function create_3ds_source($order, $source_object, $return_url = '') { |
|
472 | 471 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
473 | 472 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
474 | - $return_url = empty( $return_url ) ? $this->get_stripe_return_url( $order ) : $return_url; |
|
473 | + $return_url = empty($return_url) ? $this->get_stripe_return_url($order) : $return_url; |
|
475 | 474 | |
476 | 475 | $post_data = array(); |
477 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
478 | - $post_data['currency'] = strtolower( $currency ); |
|
476 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
477 | + $post_data['currency'] = strtolower($currency); |
|
479 | 478 | $post_data['type'] = 'three_d_secure'; |
480 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
481 | - $post_data['three_d_secure'] = array( 'card' => $source_object->id ); |
|
482 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
479 | + $post_data['owner'] = $this->get_owner_details($order); |
|
480 | + $post_data['three_d_secure'] = array('card' => $source_object->id); |
|
481 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
483 | 482 | |
484 | - WC_Stripe_Logger::log( 'Info: Begin creating 3DS source...' ); |
|
483 | + WC_Stripe_Logger::log('Info: Begin creating 3DS source...'); |
|
485 | 484 | |
486 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_3ds_source', $post_data, $order ), 'sources' ); |
|
485 | + return WC_Stripe_API::request(apply_filters('wc_stripe_3ds_source', $post_data, $order), 'sources'); |
|
487 | 486 | } |
488 | 487 | |
489 | 488 | /** |
@@ -499,61 +498,61 @@ discard block |
||
499 | 498 | * @throws Exception When card was not added or for and invalid card. |
500 | 499 | * @return object |
501 | 500 | */ |
502 | - public function prepare_source( $user_id, $force_save_source = false ) { |
|
503 | - $customer = new WC_Stripe_Customer( $user_id ); |
|
501 | + public function prepare_source($user_id, $force_save_source = false) { |
|
502 | + $customer = new WC_Stripe_Customer($user_id); |
|
504 | 503 | $set_customer = true; |
505 | - $force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer ); |
|
504 | + $force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer); |
|
506 | 505 | $source_object = ''; |
507 | 506 | $source_id = ''; |
508 | 507 | $wc_token_id = false; |
509 | - $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe'; |
|
508 | + $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe'; |
|
510 | 509 | $is_token = false; |
511 | 510 | |
512 | 511 | // New CC info was entered and we have a new source to process. |
513 | - if ( ! empty( $_POST['stripe_source'] ) ) { |
|
514 | - $source_object = self::get_source_object( wc_clean( $_POST['stripe_source'] ) ); |
|
512 | + if ( ! empty($_POST['stripe_source'])) { |
|
513 | + $source_object = self::get_source_object(wc_clean($_POST['stripe_source'])); |
|
515 | 514 | $source_id = $source_object->id; |
516 | 515 | |
517 | 516 | // This checks to see if customer opted to save the payment method to file. |
518 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
517 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
519 | 518 | |
520 | 519 | /** |
521 | 520 | * This is true if the user wants to store the card to their account. |
522 | 521 | * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is |
523 | 522 | * actually reusable. Either that or force_save_source is true. |
524 | 523 | */ |
525 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) { |
|
526 | - $response = $customer->add_source( $source_object->id ); |
|
524 | + if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) { |
|
525 | + $response = $customer->add_source($source_object->id); |
|
527 | 526 | |
528 | - if ( ! empty( $response->error ) ) { |
|
529 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
527 | + if ( ! empty($response->error)) { |
|
528 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
530 | 529 | } |
531 | 530 | } |
532 | - } elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) { |
|
531 | + } elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) { |
|
533 | 532 | // Use an existing token, and then process the payment. |
534 | - $wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ); |
|
535 | - $wc_token = WC_Payment_Tokens::get( $wc_token_id ); |
|
533 | + $wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']); |
|
534 | + $wc_token = WC_Payment_Tokens::get($wc_token_id); |
|
536 | 535 | |
537 | - if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) { |
|
538 | - WC()->session->set( 'refresh_totals', true ); |
|
539 | - throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
536 | + if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) { |
|
537 | + WC()->session->set('refresh_totals', true); |
|
538 | + throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
540 | 539 | } |
541 | 540 | |
542 | 541 | $source_id = $wc_token->get_token(); |
543 | 542 | |
544 | - if ( $this->is_type_legacy_card( $source_id ) ) { |
|
543 | + if ($this->is_type_legacy_card($source_id)) { |
|
545 | 544 | $is_token = true; |
546 | 545 | } |
547 | - } elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) { |
|
548 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
549 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
546 | + } elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) { |
|
547 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
548 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
550 | 549 | |
551 | 550 | // This is true if the user wants to store the card to their account. |
552 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) { |
|
553 | - $response = $customer->add_source( $stripe_token ); |
|
551 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) { |
|
552 | + $response = $customer->add_source($stripe_token); |
|
554 | 553 | |
555 | - if ( ! empty( $response->error ) ) { |
|
556 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
554 | + if ( ! empty($response->error)) { |
|
555 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
557 | 556 | } |
558 | 557 | } else { |
559 | 558 | $set_customer = false; |
@@ -562,14 +561,14 @@ discard block |
||
562 | 561 | } |
563 | 562 | } |
564 | 563 | |
565 | - if ( ! $set_customer ) { |
|
564 | + if ( ! $set_customer) { |
|
566 | 565 | $customer_id = false; |
567 | 566 | } else { |
568 | 567 | $customer_id = $customer->get_id() ? $customer->get_id() : false; |
569 | 568 | } |
570 | 569 | |
571 | - if ( empty( $source_object ) && ! $is_token ) { |
|
572 | - $source_object = self::get_source_object( $source_id ); |
|
570 | + if (empty($source_object) && ! $is_token) { |
|
571 | + $source_object = self::get_source_object($source_id); |
|
573 | 572 | } |
574 | 573 | |
575 | 574 | return (object) array( |
@@ -593,37 +592,37 @@ discard block |
||
593 | 592 | * @param object $order |
594 | 593 | * @return object |
595 | 594 | */ |
596 | - public function prepare_order_source( $order = null ) { |
|
595 | + public function prepare_order_source($order = null) { |
|
597 | 596 | $stripe_customer = new WC_Stripe_Customer(); |
598 | 597 | $stripe_source = false; |
599 | 598 | $token_id = false; |
600 | 599 | |
601 | - if ( $order ) { |
|
600 | + if ($order) { |
|
602 | 601 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
603 | 602 | |
604 | - $stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true ); |
|
603 | + $stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true); |
|
605 | 604 | |
606 | - if ( $stripe_customer_id ) { |
|
607 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
605 | + if ($stripe_customer_id) { |
|
606 | + $stripe_customer->set_id($stripe_customer_id); |
|
608 | 607 | } |
609 | 608 | |
610 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true ); |
|
609 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true); |
|
611 | 610 | |
612 | 611 | // Since 4.0.0, we changed card to source so we need to account for that. |
613 | - if ( empty( $source_id ) ) { |
|
614 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true ); |
|
612 | + if (empty($source_id)) { |
|
613 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true); |
|
615 | 614 | |
616 | 615 | // Take this opportunity to update the key name. |
617 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_source_id', $source_id ) : $order->update_meta_data( '_stripe_source_id', $source_id ); |
|
616 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_source_id', $source_id) : $order->update_meta_data('_stripe_source_id', $source_id); |
|
618 | 617 | |
619 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
618 | + if (is_callable(array($order, 'save'))) { |
|
620 | 619 | $order->save(); |
621 | 620 | } |
622 | 621 | } |
623 | 622 | |
624 | - if ( $source_id ) { |
|
623 | + if ($source_id) { |
|
625 | 624 | $stripe_source = $source_id; |
626 | - } elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
625 | + } elseif (apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
627 | 626 | /* |
628 | 627 | * We can attempt to charge the customer's default source |
629 | 628 | * by sending empty source id. |
@@ -647,27 +646,27 @@ discard block |
||
647 | 646 | * @param WC_Order $order For to which the source applies. |
648 | 647 | * @param stdClass $source Source information. |
649 | 648 | */ |
650 | - public function save_source_to_order( $order, $source ) { |
|
649 | + public function save_source_to_order($order, $source) { |
|
651 | 650 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
652 | 651 | |
653 | 652 | // Store source in the order. |
654 | - if ( $source->customer ) { |
|
655 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
656 | - update_post_meta( $order_id, '_stripe_customer_id', $source->customer ); |
|
653 | + if ($source->customer) { |
|
654 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
655 | + update_post_meta($order_id, '_stripe_customer_id', $source->customer); |
|
657 | 656 | } else { |
658 | - $order->update_meta_data( '_stripe_customer_id', $source->customer ); |
|
657 | + $order->update_meta_data('_stripe_customer_id', $source->customer); |
|
659 | 658 | } |
660 | 659 | } |
661 | 660 | |
662 | - if ( $source->source ) { |
|
663 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
664 | - update_post_meta( $order_id, '_stripe_source_id', $source->source ); |
|
661 | + if ($source->source) { |
|
662 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
663 | + update_post_meta($order_id, '_stripe_source_id', $source->source); |
|
665 | 664 | } else { |
666 | - $order->update_meta_data( '_stripe_source_id', $source->source ); |
|
665 | + $order->update_meta_data('_stripe_source_id', $source->source); |
|
667 | 666 | } |
668 | 667 | } |
669 | 668 | |
670 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
669 | + if (is_callable(array($order, 'save'))) { |
|
671 | 670 | $order->save(); |
672 | 671 | } |
673 | 672 | } |
@@ -681,35 +680,35 @@ discard block |
||
681 | 680 | * @param object $order The order object |
682 | 681 | * @param int $balance_transaction_id |
683 | 682 | */ |
684 | - public function update_fees( $order, $balance_transaction_id ) { |
|
683 | + public function update_fees($order, $balance_transaction_id) { |
|
685 | 684 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
686 | 685 | |
687 | - $balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id ); |
|
686 | + $balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id); |
|
688 | 687 | |
689 | - if ( empty( $balance_transaction->error ) ) { |
|
690 | - if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) { |
|
688 | + if (empty($balance_transaction->error)) { |
|
689 | + if (isset($balance_transaction) && isset($balance_transaction->fee)) { |
|
691 | 690 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
692 | 691 | // values are in the local currency of the Stripe account, not from WC. |
693 | - $fee_refund = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0; |
|
694 | - $net_refund = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0; |
|
692 | + $fee_refund = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0; |
|
693 | + $net_refund = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0; |
|
695 | 694 | |
696 | 695 | // Current data fee & net. |
697 | - $fee_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, self::META_NAME_FEE, true ) : $order->get_meta( self::META_NAME_FEE, true ); |
|
698 | - $net_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, self::META_NAME_NET, true ) : $order->get_meta( self::META_NAME_NET, true ); |
|
696 | + $fee_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, self::META_NAME_FEE, true) : $order->get_meta(self::META_NAME_FEE, true); |
|
697 | + $net_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, self::META_NAME_NET, true) : $order->get_meta(self::META_NAME_NET, true); |
|
699 | 698 | |
700 | 699 | // Calculation. |
701 | 700 | $fee = (float) $fee_current + (float) $fee_refund; |
702 | 701 | $net = (float) $net_current + (float) $net_refund; |
703 | 702 | |
704 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee ); |
|
705 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net ); |
|
703 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee); |
|
704 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net); |
|
706 | 705 | |
707 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
706 | + if (is_callable(array($order, 'save'))) { |
|
708 | 707 | $order->save(); |
709 | 708 | } |
710 | 709 | } |
711 | 710 | } else { |
712 | - WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" ); |
|
711 | + WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}"); |
|
713 | 712 | } |
714 | 713 | } |
715 | 714 | |
@@ -722,33 +721,33 @@ discard block |
||
722 | 721 | * @param float $amount |
723 | 722 | * @return bool |
724 | 723 | */ |
725 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
726 | - $order = wc_get_order( $order_id ); |
|
724 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
725 | + $order = wc_get_order($order_id); |
|
727 | 726 | |
728 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
727 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
729 | 728 | return false; |
730 | 729 | } |
731 | 730 | |
732 | 731 | $request = array(); |
733 | 732 | |
734 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
735 | - $order_currency = get_post_meta( $order_id, '_order_currency', true ); |
|
736 | - $captured = get_post_meta( $order_id, '_stripe_charge_captured', true ); |
|
733 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
734 | + $order_currency = get_post_meta($order_id, '_order_currency', true); |
|
735 | + $captured = get_post_meta($order_id, '_stripe_charge_captured', true); |
|
737 | 736 | } else { |
738 | 737 | $order_currency = $order->get_currency(); |
739 | - $captured = $order->get_meta( '_stripe_charge_captured', true ); |
|
738 | + $captured = $order->get_meta('_stripe_charge_captured', true); |
|
740 | 739 | } |
741 | 740 | |
742 | - if ( ! is_null( $amount ) ) { |
|
743 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency ); |
|
741 | + if ( ! is_null($amount)) { |
|
742 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency); |
|
744 | 743 | } |
745 | 744 | |
746 | 745 | // If order is only authorized, don't pass amount. |
747 | - if ( 'yes' !== $captured ) { |
|
748 | - unset( $request['amount'] ); |
|
746 | + if ('yes' !== $captured) { |
|
747 | + unset($request['amount']); |
|
749 | 748 | } |
750 | 749 | |
751 | - if ( $reason ) { |
|
750 | + if ($reason) { |
|
752 | 751 | $request['metadata'] = array( |
753 | 752 | 'reason' => $reason, |
754 | 753 | ); |
@@ -756,35 +755,35 @@ discard block |
||
756 | 755 | |
757 | 756 | $request['charge'] = $order->get_transaction_id(); |
758 | 757 | |
759 | - WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" ); |
|
758 | + WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}"); |
|
760 | 759 | |
761 | - $request = apply_filters( 'wc_stripe_refund_request', $request, $order ); |
|
760 | + $request = apply_filters('wc_stripe_refund_request', $request, $order); |
|
762 | 761 | |
763 | - $response = WC_Stripe_API::request( $request, 'refunds' ); |
|
762 | + $response = WC_Stripe_API::request($request, 'refunds'); |
|
764 | 763 | |
765 | - if ( ! empty( $response->error ) ) { |
|
766 | - WC_Stripe_Logger::log( 'Error: ' . $response->error->message ); |
|
764 | + if ( ! empty($response->error)) { |
|
765 | + WC_Stripe_Logger::log('Error: ' . $response->error->message); |
|
767 | 766 | |
768 | 767 | return $response; |
769 | 768 | |
770 | - } elseif ( ! empty( $response->id ) ) { |
|
771 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_refund_id', $response->id ) : $order->update_meta_data( '_stripe_refund_id', $response->id ); |
|
769 | + } elseif ( ! empty($response->id)) { |
|
770 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_refund_id', $response->id) : $order->update_meta_data('_stripe_refund_id', $response->id); |
|
772 | 771 | |
773 | - $amount = wc_price( $response->amount / 100 ); |
|
772 | + $amount = wc_price($response->amount / 100); |
|
774 | 773 | |
775 | - if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
776 | - $amount = wc_price( $response->amount ); |
|
774 | + if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) { |
|
775 | + $amount = wc_price($response->amount); |
|
777 | 776 | } |
778 | 777 | |
779 | - if ( isset( $response->balance_transaction ) ) { |
|
780 | - $this->update_fees( $order, $response->balance_transaction ); |
|
778 | + if (isset($response->balance_transaction)) { |
|
779 | + $this->update_fees($order, $response->balance_transaction); |
|
781 | 780 | } |
782 | 781 | |
783 | 782 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
784 | - $refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ) : __( 'Pre-Authorization Released', 'woocommerce-gateway-stripe' ); |
|
783 | + $refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason) : __('Pre-Authorization Released', 'woocommerce-gateway-stripe'); |
|
785 | 784 | |
786 | - $order->add_order_note( $refund_message ); |
|
787 | - WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
785 | + $order->add_order_note($refund_message); |
|
786 | + WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message))); |
|
788 | 787 | |
789 | 788 | return true; |
790 | 789 | } |
@@ -799,44 +798,44 @@ discard block |
||
799 | 798 | */ |
800 | 799 | public function add_payment_method() { |
801 | 800 | $error = false; |
802 | - $error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ); |
|
801 | + $error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe'); |
|
803 | 802 | $source_id = ''; |
804 | 803 | |
805 | - if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
804 | + if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
806 | 805 | $error = true; |
807 | 806 | } |
808 | 807 | |
809 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
808 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
810 | 809 | |
811 | - $source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : ''; |
|
810 | + $source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : ''; |
|
812 | 811 | |
813 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
812 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source); |
|
814 | 813 | |
815 | - if ( isset( $source_object ) ) { |
|
816 | - if ( ! empty( $source_object->error ) ) { |
|
814 | + if (isset($source_object)) { |
|
815 | + if ( ! empty($source_object->error)) { |
|
817 | 816 | $error = true; |
818 | 817 | } |
819 | 818 | |
820 | 819 | $source_id = $source_object->id; |
821 | - } elseif ( isset( $_POST['stripe_token'] ) ) { |
|
822 | - $source_id = wc_clean( $_POST['stripe_token'] ); |
|
820 | + } elseif (isset($_POST['stripe_token'])) { |
|
821 | + $source_id = wc_clean($_POST['stripe_token']); |
|
823 | 822 | } |
824 | 823 | |
825 | - $response = $stripe_customer->add_source( $source_id ); |
|
824 | + $response = $stripe_customer->add_source($source_id); |
|
826 | 825 | |
827 | - if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) { |
|
826 | + if ( ! $response || is_wp_error($response) || ! empty($response->error)) { |
|
828 | 827 | $error = true; |
829 | 828 | } |
830 | 829 | |
831 | - if ( $error ) { |
|
832 | - wc_add_notice( $error_msg, 'error' ); |
|
833 | - WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg ); |
|
830 | + if ($error) { |
|
831 | + wc_add_notice($error_msg, 'error'); |
|
832 | + WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg); |
|
834 | 833 | return; |
835 | 834 | } |
836 | 835 | |
837 | 836 | return array( |
838 | 837 | 'result' => 'success', |
839 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
838 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
840 | 839 | ); |
841 | 840 | } |
842 | 841 | |
@@ -853,10 +852,10 @@ discard block |
||
853 | 852 | * Stripe expects Norwegian to only be passed NO. |
854 | 853 | * But WP has different dialects. |
855 | 854 | */ |
856 | - if ( 'NO' === substr( $locale, 3, 2 ) ) { |
|
855 | + if ('NO' === substr($locale, 3, 2)) { |
|
857 | 856 | $locale = 'no'; |
858 | 857 | } else { |
859 | - $locale = substr( get_locale(), 0, 2 ); |
|
858 | + $locale = substr(get_locale(), 0, 2); |
|
860 | 859 | } |
861 | 860 | |
862 | 861 | return $locale; |
@@ -870,9 +869,9 @@ discard block |
||
870 | 869 | * @param string $idempotency_key |
871 | 870 | * @param array $request |
872 | 871 | */ |
873 | - public function change_idempotency_key( $idempotency_key, $request ) { |
|
874 | - $customer = ! empty( $request['customer'] ) ? $request['customer'] : ''; |
|
875 | - $source = ! empty( $request['source'] ) ? $request['source'] : $customer; |
|
872 | + public function change_idempotency_key($idempotency_key, $request) { |
|
873 | + $customer = ! empty($request['customer']) ? $request['customer'] : ''; |
|
874 | + $source = ! empty($request['source']) ? $request['source'] : $customer; |
|
876 | 875 | $count = $this->retry_interval; |
877 | 876 | |
878 | 877 | return $request['metadata']['order_id'] . '-' . $count . '-' . $source; |
@@ -886,8 +885,8 @@ discard block |
||
886 | 885 | * @since 4.0.6 |
887 | 886 | * @param array $headers |
888 | 887 | */ |
889 | - public function is_original_request( $headers ) { |
|
890 | - if ( $headers['original-request'] === $headers['request-id'] ) { |
|
888 | + public function is_original_request($headers) { |
|
889 | + if ($headers['original-request'] === $headers['request-id']) { |
|
891 | 890 | return true; |
892 | 891 | } |
893 | 892 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 4.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if ( ! defined('ABSPATH')) { |
|
10 | 10 | exit; |
11 | 11 | } |
12 | 12 | |
@@ -71,36 +71,36 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function __construct() { |
73 | 73 | self::$_this = $this; |
74 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
75 | - $this->testmode = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false; |
|
76 | - $this->publishable_key = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : ''; |
|
77 | - $this->secret_key = ! empty( $this->stripe_settings['secret_key'] ) ? $this->stripe_settings['secret_key'] : ''; |
|
78 | - $this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
79 | - $this->total_label = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : ''; |
|
74 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
75 | + $this->testmode = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false; |
|
76 | + $this->publishable_key = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : ''; |
|
77 | + $this->secret_key = ! empty($this->stripe_settings['secret_key']) ? $this->stripe_settings['secret_key'] : ''; |
|
78 | + $this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
79 | + $this->total_label = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : ''; |
|
80 | 80 | |
81 | - if ( $this->testmode ) { |
|
82 | - $this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
83 | - $this->secret_key = ! empty( $this->stripe_settings['test_secret_key'] ) ? $this->stripe_settings['test_secret_key'] : ''; |
|
81 | + if ($this->testmode) { |
|
82 | + $this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
83 | + $this->secret_key = ! empty($this->stripe_settings['test_secret_key']) ? $this->stripe_settings['test_secret_key'] : ''; |
|
84 | 84 | } |
85 | 85 | |
86 | - $this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' ); |
|
86 | + $this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)'); |
|
87 | 87 | |
88 | 88 | // Checks if Stripe Gateway is enabled. |
89 | - if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) { |
|
89 | + if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) { |
|
90 | 90 | return; |
91 | 91 | } |
92 | 92 | |
93 | 93 | // Checks if Payment Request is enabled. |
94 | - if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) { |
|
94 | + if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) { |
|
95 | 95 | return; |
96 | 96 | } |
97 | 97 | |
98 | 98 | // Don't load for change payment method page. |
99 | - if ( isset( $_GET['change_payment_method'] ) ) { |
|
99 | + if (isset($_GET['change_payment_method'])) { |
|
100 | 100 | return; |
101 | 101 | } |
102 | 102 | |
103 | - add_action( 'template_redirect', array( $this, 'set_session' ) ); |
|
103 | + add_action('template_redirect', array($this, 'set_session')); |
|
104 | 104 | $this->init(); |
105 | 105 | } |
106 | 106 | |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @return bool |
112 | 112 | */ |
113 | 113 | public function are_keys_set() { |
114 | - if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) { |
|
114 | + if (empty($this->secret_key) || empty($this->publishable_key)) { |
|
115 | 115 | return false; |
116 | 116 | } |
117 | 117 | |
@@ -135,19 +135,19 @@ discard block |
||
135 | 135 | * @since 4.0.0 |
136 | 136 | */ |
137 | 137 | public function set_session() { |
138 | - if ( ! is_product() ) { |
|
138 | + if ( ! is_product()) { |
|
139 | 139 | return; |
140 | 140 | } |
141 | 141 | |
142 | - if ( ! is_user_logged_in() ) { |
|
142 | + if ( ! is_user_logged_in()) { |
|
143 | 143 | $wc_session = new WC_Session_Handler(); |
144 | 144 | |
145 | - if ( version_compare( WC_VERSION, '3.3', '>=' ) ) { |
|
145 | + if (version_compare(WC_VERSION, '3.3', '>=')) { |
|
146 | 146 | $wc_session->init(); |
147 | 147 | } |
148 | 148 | |
149 | - if ( ! $wc_session->has_session() ) { |
|
150 | - $wc_session->set_customer_session_cookie( true ); |
|
149 | + if ( ! $wc_session->has_session()) { |
|
150 | + $wc_session->set_customer_session_cookie(true); |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 | } |
@@ -159,40 +159,40 @@ discard block |
||
159 | 159 | * @version 4.0.0 |
160 | 160 | */ |
161 | 161 | public function init() { |
162 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
162 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
163 | 163 | |
164 | 164 | /* |
165 | 165 | * In order to display the Payment Request button in the correct position, |
166 | 166 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
167 | 167 | * CSS is used to position the button. |
168 | 168 | */ |
169 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
170 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
171 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
169 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
170 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1); |
|
171 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2); |
|
172 | 172 | } else { |
173 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
174 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
173 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1); |
|
174 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2); |
|
175 | 175 | } |
176 | 176 | |
177 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
178 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
177 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1); |
|
178 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2); |
|
179 | 179 | |
180 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
181 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
180 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1); |
|
181 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2); |
|
182 | 182 | |
183 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
184 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
185 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
186 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
187 | - add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) ); |
|
188 | - add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) ); |
|
189 | - add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) ); |
|
190 | - add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) ); |
|
183 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
184 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
185 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
186 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
187 | + add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart')); |
|
188 | + add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data')); |
|
189 | + add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart')); |
|
190 | + add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors')); |
|
191 | 191 | |
192 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
193 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
192 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
193 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
194 | 194 | |
195 | - add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 ); |
|
195 | + add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @return string |
204 | 204 | */ |
205 | 205 | public function get_button_type() { |
206 | - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
206 | + return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * @return string |
215 | 215 | */ |
216 | 216 | public function get_button_theme() { |
217 | - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
217 | + return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * @return string |
226 | 226 | */ |
227 | 227 | public function get_button_height() { |
228 | - return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64'; |
|
228 | + return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64'; |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
@@ -235,40 +235,40 @@ discard block |
||
235 | 235 | * @version 4.0.0 |
236 | 236 | */ |
237 | 237 | public function get_product_data() { |
238 | - if ( ! is_product() ) { |
|
238 | + if ( ! is_product()) { |
|
239 | 239 | return false; |
240 | 240 | } |
241 | 241 | |
242 | 242 | global $post; |
243 | 243 | |
244 | - $product = wc_get_product( $post->ID ); |
|
244 | + $product = wc_get_product($post->ID); |
|
245 | 245 | |
246 | 246 | $data = array(); |
247 | 247 | $items = array(); |
248 | 248 | |
249 | 249 | $items[] = array( |
250 | 250 | 'label' => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(), |
251 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
251 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
252 | 252 | ); |
253 | 253 | |
254 | - if ( wc_tax_enabled() ) { |
|
254 | + if (wc_tax_enabled()) { |
|
255 | 255 | $items[] = array( |
256 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
256 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
257 | 257 | 'amount' => 0, |
258 | 258 | 'pending' => true, |
259 | 259 | ); |
260 | 260 | } |
261 | 261 | |
262 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
262 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
263 | 263 | $items[] = array( |
264 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
264 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
265 | 265 | 'amount' => 0, |
266 | 266 | 'pending' => true, |
267 | 267 | ); |
268 | 268 | |
269 | - $data['shippingOptions'] = array( |
|
269 | + $data['shippingOptions'] = array( |
|
270 | 270 | 'id' => 'pending', |
271 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
271 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
272 | 272 | 'detail' => '', |
273 | 273 | 'amount' => 0, |
274 | 274 | ); |
@@ -276,41 +276,41 @@ discard block |
||
276 | 276 | |
277 | 277 | $data['displayItems'] = $items; |
278 | 278 | $data['total'] = array( |
279 | - 'label' => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ), |
|
280 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
279 | + 'label' => apply_filters('wc_stripe_payment_request_total_label', $this->total_label), |
|
280 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
281 | 281 | 'pending' => true, |
282 | 282 | ); |
283 | 283 | |
284 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
285 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
286 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
284 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
285 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
286 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
287 | 287 | |
288 | - return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product ); |
|
288 | + return apply_filters('wc_stripe_payment_request_product_data', $data, $product); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
292 | 292 | * Filters the gateway title to reflect Payment Request type |
293 | 293 | * |
294 | 294 | */ |
295 | - public function filter_gateway_title( $title, $id ) { |
|
295 | + public function filter_gateway_title($title, $id) { |
|
296 | 296 | global $post; |
297 | 297 | |
298 | - if ( ! is_object( $post ) ) { |
|
298 | + if ( ! is_object($post)) { |
|
299 | 299 | return $title; |
300 | 300 | } |
301 | 301 | |
302 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
303 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
302 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
303 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
304 | 304 | } else { |
305 | - $order = wc_get_order( $post->ID ); |
|
306 | - $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
305 | + $order = wc_get_order($post->ID); |
|
306 | + $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
307 | 307 | } |
308 | 308 | |
309 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
309 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
310 | 310 | return $method_title; |
311 | 311 | } |
312 | 312 | |
313 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
313 | + if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
314 | 314 | return $method_title; |
315 | 315 | } |
316 | 316 | |
@@ -323,16 +323,16 @@ discard block |
||
323 | 323 | * @since 3.1.4 |
324 | 324 | * @version 4.0.0 |
325 | 325 | */ |
326 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
326 | + public function postal_code_validation($valid, $postcode, $country) { |
|
327 | 327 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
328 | 328 | |
329 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
329 | + if ( ! isset($gateways['stripe'])) { |
|
330 | 330 | return $valid; |
331 | 331 | } |
332 | 332 | |
333 | - $payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : ''; |
|
333 | + $payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : ''; |
|
334 | 334 | |
335 | - if ( 'apple_pay' !== $payment_request_type ) { |
|
335 | + if ('apple_pay' !== $payment_request_type) { |
|
336 | 336 | return $valid; |
337 | 337 | } |
338 | 338 | |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | * the order and not let it go through. The remedy for now is just to remove this validation. |
343 | 343 | * Note that this only works with shipping providers that don't validate full postal codes. |
344 | 344 | */ |
345 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
345 | + if ('GB' === $country || 'CA' === $country) { |
|
346 | 346 | return true; |
347 | 347 | } |
348 | 348 | |
@@ -357,29 +357,29 @@ discard block |
||
357 | 357 | * @param int $order_id |
358 | 358 | * @param array $posted_data The posted data from checkout form. |
359 | 359 | */ |
360 | - public function add_order_meta( $order_id, $posted_data ) { |
|
361 | - if ( empty( $_POST['payment_request_type'] ) ) { |
|
360 | + public function add_order_meta($order_id, $posted_data) { |
|
361 | + if (empty($_POST['payment_request_type'])) { |
|
362 | 362 | return; |
363 | 363 | } |
364 | 364 | |
365 | - $order = wc_get_order( $order_id ); |
|
365 | + $order = wc_get_order($order_id); |
|
366 | 366 | |
367 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
367 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
368 | 368 | |
369 | - if ( 'apple_pay' === $payment_request_type ) { |
|
370 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
371 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
369 | + if ('apple_pay' === $payment_request_type) { |
|
370 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
371 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
372 | 372 | } else { |
373 | - $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
373 | + $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
374 | 374 | $order->save(); |
375 | 375 | } |
376 | 376 | } |
377 | 377 | |
378 | - if ( 'payment_request_api' === $payment_request_type ) { |
|
379 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
380 | - update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' ); |
|
378 | + if ('payment_request_api' === $payment_request_type) { |
|
379 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
380 | + update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)'); |
|
381 | 381 | } else { |
382 | - $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
382 | + $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
383 | 383 | $order->save(); |
384 | 384 | } |
385 | 385 | } |
@@ -393,11 +393,11 @@ discard block |
||
393 | 393 | * @return array |
394 | 394 | */ |
395 | 395 | public function supported_product_types() { |
396 | - return apply_filters( 'wc_stripe_payment_request_supported_types', array( |
|
396 | + return apply_filters('wc_stripe_payment_request_supported_types', array( |
|
397 | 397 | 'simple', |
398 | 398 | 'variable', |
399 | 399 | 'variation', |
400 | - ) ); |
|
400 | + )); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | /** |
@@ -408,15 +408,15 @@ discard block |
||
408 | 408 | * @return bool |
409 | 409 | */ |
410 | 410 | public function allowed_items_in_cart() { |
411 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
412 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
411 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
412 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
413 | 413 | |
414 | - if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
414 | + if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
415 | 415 | return false; |
416 | 416 | } |
417 | 417 | |
418 | 418 | // Pre Orders compatbility where we don't support charge upon release. |
419 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release( WC_Pre_Orders_Cart::get_pre_order_product() ) ) { |
|
419 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product())) { |
|
420 | 420 | return false; |
421 | 421 | } |
422 | 422 | } |
@@ -432,82 +432,82 @@ discard block |
||
432 | 432 | */ |
433 | 433 | public function scripts() { |
434 | 434 | // If keys are not set bail. |
435 | - if ( ! $this->are_keys_set() ) { |
|
436 | - WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
435 | + if ( ! $this->are_keys_set()) { |
|
436 | + WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
437 | 437 | return; |
438 | 438 | } |
439 | 439 | |
440 | 440 | // If no SSL bail. |
441 | - if ( ! $this->testmode && ! is_ssl() ) { |
|
442 | - WC_Stripe_Logger::log( 'Stripe requires SSL.' ); |
|
441 | + if ( ! $this->testmode && ! is_ssl()) { |
|
442 | + WC_Stripe_Logger::log('Stripe requires SSL.'); |
|
443 | 443 | return; |
444 | 444 | } |
445 | 445 | |
446 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
446 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
447 | 447 | return; |
448 | 448 | } |
449 | 449 | |
450 | - if ( is_product() ) { |
|
450 | + if (is_product()) { |
|
451 | 451 | global $post; |
452 | 452 | |
453 | - $product = wc_get_product( $post->ID ); |
|
453 | + $product = wc_get_product($post->ID); |
|
454 | 454 | |
455 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
455 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
456 | 456 | return; |
457 | 457 | } |
458 | 458 | |
459 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
459 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
460 | 460 | return; |
461 | 461 | } |
462 | 462 | } |
463 | 463 | |
464 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
464 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
465 | 465 | |
466 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
467 | - wp_register_script( 'wc_stripe_payment_request', plugins_url( 'assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
466 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
467 | + wp_register_script('wc_stripe_payment_request', plugins_url('assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true); |
|
468 | 468 | |
469 | 469 | wp_localize_script( |
470 | 470 | 'wc_stripe_payment_request', |
471 | 471 | 'wc_stripe_payment_request_params', |
472 | 472 | array( |
473 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
473 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
474 | 474 | 'stripe' => array( |
475 | 475 | 'key' => $this->publishable_key, |
476 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
476 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
477 | 477 | ), |
478 | 478 | 'nonce' => array( |
479 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
480 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
481 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
482 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
483 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
484 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
485 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
486 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
479 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
480 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
481 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
482 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
483 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
484 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
485 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
486 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
487 | 487 | ), |
488 | 488 | 'i18n' => array( |
489 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
489 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
490 | 490 | /* translators: Do not translate the [option] placeholder */ |
491 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
491 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
492 | 492 | ), |
493 | 493 | 'checkout' => array( |
494 | 494 | 'url' => wc_get_checkout_url(), |
495 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
496 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
495 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
496 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
497 | 497 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
498 | 498 | ), |
499 | 499 | 'button' => array( |
500 | 500 | 'type' => $this->get_button_type(), |
501 | 501 | 'theme' => $this->get_button_theme(), |
502 | 502 | 'height' => $this->get_button_height(), |
503 | - 'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US. |
|
503 | + 'locale' => substr(get_locale(), 0, 2), // Default format is en_US. |
|
504 | 504 | ), |
505 | 505 | 'is_product_page' => is_product(), |
506 | 506 | 'product' => $this->get_product_data(), |
507 | 507 | ) |
508 | 508 | ); |
509 | 509 | |
510 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
510 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | /** |
@@ -519,39 +519,39 @@ discard block |
||
519 | 519 | public function display_payment_request_button_html() { |
520 | 520 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
521 | 521 | |
522 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
522 | + if ( ! isset($gateways['stripe'])) { |
|
523 | 523 | return; |
524 | 524 | } |
525 | 525 | |
526 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
526 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
527 | 527 | return; |
528 | 528 | } |
529 | 529 | |
530 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
530 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
531 | 531 | return; |
532 | 532 | } |
533 | 533 | |
534 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
534 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
535 | 535 | return; |
536 | 536 | } |
537 | 537 | |
538 | - if ( is_product() ) { |
|
538 | + if (is_product()) { |
|
539 | 539 | global $post; |
540 | 540 | |
541 | - $product = wc_get_product( $post->ID ); |
|
541 | + $product = wc_get_product($post->ID); |
|
542 | 542 | |
543 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
543 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
544 | 544 | return; |
545 | 545 | } |
546 | 546 | |
547 | 547 | // Pre Orders charge upon release not supported. |
548 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
549 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
548 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
549 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
550 | 550 | return; |
551 | 551 | } |
552 | 552 | } else { |
553 | - if ( ! $this->allowed_items_in_cart() ) { |
|
554 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
553 | + if ( ! $this->allowed_items_in_cart()) { |
|
554 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
555 | 555 | return; |
556 | 556 | } |
557 | 557 | } |
@@ -573,44 +573,44 @@ discard block |
||
573 | 573 | public function display_payment_request_button_separator_html() { |
574 | 574 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
575 | 575 | |
576 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
576 | + if ( ! isset($gateways['stripe'])) { |
|
577 | 577 | return; |
578 | 578 | } |
579 | 579 | |
580 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
580 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
581 | 581 | return; |
582 | 582 | } |
583 | 583 | |
584 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
584 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
585 | 585 | return; |
586 | 586 | } |
587 | 587 | |
588 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
588 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
589 | 589 | return; |
590 | 590 | } |
591 | 591 | |
592 | - if ( is_product() ) { |
|
592 | + if (is_product()) { |
|
593 | 593 | global $post; |
594 | 594 | |
595 | - $product = wc_get_product( $post->ID ); |
|
595 | + $product = wc_get_product($post->ID); |
|
596 | 596 | |
597 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
597 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
598 | 598 | return; |
599 | 599 | } |
600 | 600 | |
601 | 601 | // Pre Orders charge upon release not supported. |
602 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
603 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
602 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
603 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
604 | 604 | return; |
605 | 605 | } |
606 | 606 | } else { |
607 | - if ( ! $this->allowed_items_in_cart() ) { |
|
608 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
607 | + if ( ! $this->allowed_items_in_cart()) { |
|
608 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
609 | 609 | return; |
610 | 610 | } |
611 | 611 | } |
612 | 612 | ?> |
613 | - <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">— <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> —</p> |
|
613 | + <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">— <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> —</p> |
|
614 | 614 | <?php |
615 | 615 | } |
616 | 616 | |
@@ -621,11 +621,11 @@ discard block |
||
621 | 621 | * @version 4.0.0 |
622 | 622 | */ |
623 | 623 | public function ajax_log_errors() { |
624 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
624 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
625 | 625 | |
626 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
626 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
627 | 627 | |
628 | - WC_Stripe_Logger::log( $errors ); |
|
628 | + WC_Stripe_Logger::log($errors); |
|
629 | 629 | |
630 | 630 | exit; |
631 | 631 | } |
@@ -637,7 +637,7 @@ discard block |
||
637 | 637 | * @version 4.0.0 |
638 | 638 | */ |
639 | 639 | public function ajax_clear_cart() { |
640 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
640 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
641 | 641 | |
642 | 642 | WC()->cart->empty_cart(); |
643 | 643 | exit; |
@@ -647,10 +647,10 @@ discard block |
||
647 | 647 | * Get cart details. |
648 | 648 | */ |
649 | 649 | public function ajax_get_cart_details() { |
650 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
650 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
651 | 651 | |
652 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
653 | - define( 'WOOCOMMERCE_CART', true ); |
|
652 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
653 | + define('WOOCOMMERCE_CART', true); |
|
654 | 654 | } |
655 | 655 | |
656 | 656 | WC()->cart->calculate_totals(); |
@@ -661,14 +661,14 @@ discard block |
||
661 | 661 | $data = array( |
662 | 662 | 'shipping_required' => WC()->cart->needs_shipping(), |
663 | 663 | 'order_data' => array( |
664 | - 'currency' => strtolower( $currency ), |
|
665 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
664 | + 'currency' => strtolower($currency), |
|
665 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
666 | 666 | ), |
667 | 667 | ); |
668 | 668 | |
669 | 669 | $data['order_data'] += $this->build_display_items(); |
670 | 670 | |
671 | - wp_send_json( $data ); |
|
671 | + wp_send_json($data); |
|
672 | 672 | } |
673 | 673 | |
674 | 674 | /** |
@@ -679,47 +679,47 @@ discard block |
||
679 | 679 | * @see WC_Shipping::get_packages(). |
680 | 680 | */ |
681 | 681 | public function ajax_get_shipping_options() { |
682 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
682 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
683 | 683 | |
684 | 684 | try { |
685 | 685 | // Set the shipping package. |
686 | - $posted = filter_input_array( INPUT_POST, array( |
|
686 | + $posted = filter_input_array(INPUT_POST, array( |
|
687 | 687 | 'country' => FILTER_SANITIZE_STRING, |
688 | 688 | 'state' => FILTER_SANITIZE_STRING, |
689 | 689 | 'postcode' => FILTER_SANITIZE_STRING, |
690 | 690 | 'city' => FILTER_SANITIZE_STRING, |
691 | 691 | 'address' => FILTER_SANITIZE_STRING, |
692 | 692 | 'address_2' => FILTER_SANITIZE_STRING, |
693 | - ) ); |
|
693 | + )); |
|
694 | 694 | |
695 | - $this->calculate_shipping( $posted ); |
|
695 | + $this->calculate_shipping($posted); |
|
696 | 696 | |
697 | 697 | // Set the shipping options. |
698 | 698 | $data = array(); |
699 | 699 | $packages = WC()->shipping->get_packages(); |
700 | 700 | |
701 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
702 | - foreach ( $packages as $package_key => $package ) { |
|
703 | - if ( empty( $package['rates'] ) ) { |
|
704 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
701 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
702 | + foreach ($packages as $package_key => $package) { |
|
703 | + if (empty($package['rates'])) { |
|
704 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
705 | 705 | } |
706 | 706 | |
707 | - foreach ( $package['rates'] as $key => $rate ) { |
|
707 | + foreach ($package['rates'] as $key => $rate) { |
|
708 | 708 | $data['shipping_options'][] = array( |
709 | 709 | 'id' => $rate->id, |
710 | 710 | 'label' => $rate->label, |
711 | 711 | 'detail' => '', |
712 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
712 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
713 | 713 | ); |
714 | 714 | } |
715 | 715 | } |
716 | 716 | } else { |
717 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
717 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
718 | 718 | } |
719 | 719 | |
720 | - if ( isset( $data[0] ) ) { |
|
720 | + if (isset($data[0])) { |
|
721 | 721 | // Auto select the first shipping method. |
722 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
722 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
723 | 723 | } |
724 | 724 | |
725 | 725 | WC()->cart->calculate_totals(); |
@@ -727,12 +727,12 @@ discard block |
||
727 | 727 | $data += $this->build_display_items(); |
728 | 728 | $data['result'] = 'success'; |
729 | 729 | |
730 | - wp_send_json( $data ); |
|
731 | - } catch ( Exception $e ) { |
|
730 | + wp_send_json($data); |
|
731 | + } catch (Exception $e) { |
|
732 | 732 | $data += $this->build_display_items(); |
733 | 733 | $data['result'] = 'invalid_shipping_address'; |
734 | 734 | |
735 | - wp_send_json( $data ); |
|
735 | + wp_send_json($data); |
|
736 | 736 | } |
737 | 737 | } |
738 | 738 | |
@@ -740,22 +740,22 @@ discard block |
||
740 | 740 | * Update shipping method. |
741 | 741 | */ |
742 | 742 | public function ajax_update_shipping_method() { |
743 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
743 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
744 | 744 | |
745 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
746 | - define( 'WOOCOMMERCE_CART', true ); |
|
745 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
746 | + define('WOOCOMMERCE_CART', true); |
|
747 | 747 | } |
748 | 748 | |
749 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
750 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
749 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
750 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
751 | 751 | |
752 | - if ( is_array( $shipping_method ) ) { |
|
753 | - foreach ( $shipping_method as $i => $value ) { |
|
754 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
752 | + if (is_array($shipping_method)) { |
|
753 | + foreach ($shipping_method as $i => $value) { |
|
754 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
755 | 755 | } |
756 | 756 | } |
757 | 757 | |
758 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
758 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
759 | 759 | |
760 | 760 | WC()->cart->calculate_totals(); |
761 | 761 | |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | $data += $this->build_display_items(); |
764 | 764 | $data['result'] = 'success'; |
765 | 765 | |
766 | - wp_send_json( $data ); |
|
766 | + wp_send_json($data); |
|
767 | 767 | } |
768 | 768 | |
769 | 769 | /** |
@@ -774,31 +774,31 @@ discard block |
||
774 | 774 | * @return array $data |
775 | 775 | */ |
776 | 776 | public function ajax_get_selected_product_data() { |
777 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
777 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
778 | 778 | |
779 | - $product_id = absint( $_POST['product_id'] ); |
|
780 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
779 | + $product_id = absint($_POST['product_id']); |
|
780 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
781 | 781 | |
782 | - $product = wc_get_product( $product_id ); |
|
782 | + $product = wc_get_product($product_id); |
|
783 | 783 | |
784 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
785 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
784 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
785 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
786 | 786 | |
787 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
788 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
787 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
788 | + $variation_id = $product->get_matching_variation($attributes); |
|
789 | 789 | } else { |
790 | - $data_store = WC_Data_Store::load( 'product' ); |
|
791 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
790 | + $data_store = WC_Data_Store::load('product'); |
|
791 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
792 | 792 | } |
793 | 793 | |
794 | - if ( ! empty( $variation_id ) ) { |
|
795 | - $product = wc_get_product( $variation_id ); |
|
794 | + if ( ! empty($variation_id)) { |
|
795 | + $product = wc_get_product($variation_id); |
|
796 | 796 | } |
797 | - } elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
798 | - $product = wc_get_product( $product_id ); |
|
797 | + } elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
798 | + $product = wc_get_product($product_id); |
|
799 | 799 | } |
800 | 800 | |
801 | - $total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ); |
|
801 | + $total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()); |
|
802 | 802 | |
803 | 803 | $quantity_label = 1 < $qty ? ' (x' . $qty . ')' : ''; |
804 | 804 | |
@@ -806,28 +806,28 @@ discard block |
||
806 | 806 | $items = array(); |
807 | 807 | |
808 | 808 | $items[] = array( |
809 | - 'label' => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label, |
|
810 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
809 | + 'label' => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label, |
|
810 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
811 | 811 | ); |
812 | 812 | |
813 | - if ( wc_tax_enabled() ) { |
|
813 | + if (wc_tax_enabled()) { |
|
814 | 814 | $items[] = array( |
815 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
815 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
816 | 816 | 'amount' => 0, |
817 | 817 | 'pending' => true, |
818 | 818 | ); |
819 | 819 | } |
820 | 820 | |
821 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
821 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
822 | 822 | $items[] = array( |
823 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
823 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
824 | 824 | 'amount' => 0, |
825 | 825 | 'pending' => true, |
826 | 826 | ); |
827 | 827 | |
828 | - $data['shippingOptions'] = array( |
|
828 | + $data['shippingOptions'] = array( |
|
829 | 829 | 'id' => 'pending', |
830 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
830 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
831 | 831 | 'detail' => '', |
832 | 832 | 'amount' => 0, |
833 | 833 | ); |
@@ -836,15 +836,15 @@ discard block |
||
836 | 836 | $data['displayItems'] = $items; |
837 | 837 | $data['total'] = array( |
838 | 838 | 'label' => $this->total_label, |
839 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
839 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
840 | 840 | 'pending' => true, |
841 | 841 | ); |
842 | 842 | |
843 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
844 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
845 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
843 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
844 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
845 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
846 | 846 | |
847 | - wp_send_json( $data ); |
|
847 | + wp_send_json($data); |
|
848 | 848 | } |
849 | 849 | |
850 | 850 | /** |
@@ -855,37 +855,37 @@ discard block |
||
855 | 855 | * @return array $data |
856 | 856 | */ |
857 | 857 | public function ajax_add_to_cart() { |
858 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
858 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
859 | 859 | |
860 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
861 | - define( 'WOOCOMMERCE_CART', true ); |
|
860 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
861 | + define('WOOCOMMERCE_CART', true); |
|
862 | 862 | } |
863 | 863 | |
864 | 864 | WC()->shipping->reset_shipping(); |
865 | 865 | |
866 | - $product_id = absint( $_POST['product_id'] ); |
|
867 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
866 | + $product_id = absint($_POST['product_id']); |
|
867 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
868 | 868 | |
869 | - $product = wc_get_product( $product_id ); |
|
869 | + $product = wc_get_product($product_id); |
|
870 | 870 | |
871 | 871 | // First empty the cart to prevent wrong calculation. |
872 | 872 | WC()->cart->empty_cart(); |
873 | 873 | |
874 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
875 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
874 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
875 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
876 | 876 | |
877 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
878 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
877 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
878 | + $variation_id = $product->get_matching_variation($attributes); |
|
879 | 879 | } else { |
880 | - $data_store = WC_Data_Store::load( 'product' ); |
|
881 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
880 | + $data_store = WC_Data_Store::load('product'); |
|
881 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
882 | 882 | } |
883 | 883 | |
884 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
884 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
885 | 885 | } |
886 | 886 | |
887 | - if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
888 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
887 | + if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
888 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
889 | 889 | } |
890 | 890 | |
891 | 891 | WC()->cart->calculate_totals(); |
@@ -894,7 +894,7 @@ discard block |
||
894 | 894 | $data += $this->build_display_items(); |
895 | 895 | $data['result'] = 'success'; |
896 | 896 | |
897 | - wp_send_json( $data ); |
|
897 | + wp_send_json($data); |
|
898 | 898 | } |
899 | 899 | |
900 | 900 | /** |
@@ -907,31 +907,31 @@ discard block |
||
907 | 907 | * @version 4.0.0 |
908 | 908 | */ |
909 | 909 | public function normalize_state() { |
910 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
911 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
912 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
913 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
910 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
911 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
912 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
913 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
914 | 914 | |
915 | - if ( $billing_state && $billing_country ) { |
|
916 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
915 | + if ($billing_state && $billing_country) { |
|
916 | + $valid_states = WC()->countries->get_states($billing_country); |
|
917 | 917 | |
918 | 918 | // Valid states found for country. |
919 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
920 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
921 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
919 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
920 | + foreach ($valid_states as $state_abbr => $state) { |
|
921 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
922 | 922 | $_POST['billing_state'] = $state_abbr; |
923 | 923 | } |
924 | 924 | } |
925 | 925 | } |
926 | 926 | } |
927 | 927 | |
928 | - if ( $shipping_state && $shipping_country ) { |
|
929 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
928 | + if ($shipping_state && $shipping_country) { |
|
929 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
930 | 930 | |
931 | 931 | // Valid states found for country. |
932 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
933 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
934 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
932 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
933 | + foreach ($valid_states as $state_abbr => $state) { |
|
934 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
935 | 935 | $_POST['shipping_state'] = $state_abbr; |
936 | 936 | } |
937 | 937 | } |
@@ -946,19 +946,19 @@ discard block |
||
946 | 946 | * @version 4.0.0 |
947 | 947 | */ |
948 | 948 | public function ajax_create_order() { |
949 | - if ( WC()->cart->is_empty() ) { |
|
950 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
949 | + if (WC()->cart->is_empty()) { |
|
950 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
951 | 951 | } |
952 | 952 | |
953 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
954 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
953 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
954 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
955 | 955 | } |
956 | 956 | |
957 | 957 | $this->normalize_state(); |
958 | 958 | |
959 | 959 | WC()->checkout()->process_checkout(); |
960 | 960 | |
961 | - die( 0 ); |
|
961 | + die(0); |
|
962 | 962 | } |
963 | 963 | |
964 | 964 | /** |
@@ -968,7 +968,7 @@ discard block |
||
968 | 968 | * @version 4.0.0 |
969 | 969 | * @param array $address |
970 | 970 | */ |
971 | - protected function calculate_shipping( $address = array() ) { |
|
971 | + protected function calculate_shipping($address = array()) { |
|
972 | 972 | global $states; |
973 | 973 | |
974 | 974 | $country = $address['country']; |
@@ -985,28 +985,28 @@ discard block |
||
985 | 985 | * In some versions of Chrome, state can be a full name. So we need |
986 | 986 | * to convert that to abbreviation as WC is expecting that. |
987 | 987 | */ |
988 | - if ( 2 < strlen( $state ) ) { |
|
989 | - $state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] ); |
|
988 | + if (2 < strlen($state)) { |
|
989 | + $state = array_search(ucfirst(strtolower($state)), $states[$country]); |
|
990 | 990 | } |
991 | 991 | |
992 | 992 | WC()->shipping->reset_shipping(); |
993 | 993 | |
994 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
995 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
994 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
995 | + $postcode = wc_format_postcode($postcode, $country); |
|
996 | 996 | } |
997 | 997 | |
998 | - if ( $country ) { |
|
999 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
1000 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
998 | + if ($country) { |
|
999 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
1000 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
1001 | 1001 | } else { |
1002 | 1002 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
1003 | 1003 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
1004 | 1004 | } |
1005 | 1005 | |
1006 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
1007 | - WC()->customer->calculated_shipping( true ); |
|
1006 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
1007 | + WC()->customer->calculated_shipping(true); |
|
1008 | 1008 | } else { |
1009 | - WC()->customer->set_calculated_shipping( true ); |
|
1009 | + WC()->customer->set_calculated_shipping(true); |
|
1010 | 1010 | WC()->customer->save(); |
1011 | 1011 | } |
1012 | 1012 | |
@@ -1023,17 +1023,17 @@ discard block |
||
1023 | 1023 | $packages[0]['destination']['address'] = $address_1; |
1024 | 1024 | $packages[0]['destination']['address_2'] = $address_2; |
1025 | 1025 | |
1026 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
1027 | - if ( $item['data']->needs_shipping() ) { |
|
1028 | - if ( isset( $item['line_total'] ) ) { |
|
1026 | + foreach (WC()->cart->get_cart() as $item) { |
|
1027 | + if ($item['data']->needs_shipping()) { |
|
1028 | + if (isset($item['line_total'])) { |
|
1029 | 1029 | $packages[0]['contents_cost'] += $item['line_total']; |
1030 | 1030 | } |
1031 | 1031 | } |
1032 | 1032 | } |
1033 | 1033 | |
1034 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
1034 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
1035 | 1035 | |
1036 | - WC()->shipping->calculate_shipping( $packages ); |
|
1036 | + WC()->shipping->calculate_shipping($packages); |
|
1037 | 1037 | } |
1038 | 1038 | |
1039 | 1039 | /** |
@@ -1042,19 +1042,19 @@ discard block |
||
1042 | 1042 | * @since 3.1.0 |
1043 | 1043 | * @version 4.0.0 |
1044 | 1044 | */ |
1045 | - protected function build_shipping_methods( $shipping_methods ) { |
|
1046 | - if ( empty( $shipping_methods ) ) { |
|
1045 | + protected function build_shipping_methods($shipping_methods) { |
|
1046 | + if (empty($shipping_methods)) { |
|
1047 | 1047 | return array(); |
1048 | 1048 | } |
1049 | 1049 | |
1050 | 1050 | $shipping = array(); |
1051 | 1051 | |
1052 | - foreach ( $shipping_methods as $method ) { |
|
1052 | + foreach ($shipping_methods as $method) { |
|
1053 | 1053 | $shipping[] = array( |
1054 | 1054 | 'id' => $method['id'], |
1055 | 1055 | 'label' => $method['label'], |
1056 | 1056 | 'detail' => '', |
1057 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
1057 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
1058 | 1058 | ); |
1059 | 1059 | } |
1060 | 1060 | |
@@ -1068,69 +1068,69 @@ discard block |
||
1068 | 1068 | * @version 4.0.0 |
1069 | 1069 | */ |
1070 | 1070 | protected function build_display_items() { |
1071 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
1072 | - define( 'WOOCOMMERCE_CART', true ); |
|
1071 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
1072 | + define('WOOCOMMERCE_CART', true); |
|
1073 | 1073 | } |
1074 | 1074 | |
1075 | 1075 | $items = array(); |
1076 | 1076 | $subtotal = 0; |
1077 | 1077 | |
1078 | 1078 | // Default show only subtotal instead of itemization. |
1079 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
1080 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
1079 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
1080 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
1081 | 1081 | $amount = $cart_item['line_subtotal']; |
1082 | - $subtotal += $cart_item['line_subtotal']; |
|
1082 | + $subtotal += $cart_item['line_subtotal']; |
|
1083 | 1083 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
1084 | 1084 | |
1085 | 1085 | $product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
1086 | 1086 | |
1087 | 1087 | $item = array( |
1088 | 1088 | 'label' => $product_name . $quantity_label, |
1089 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
1089 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
1090 | 1090 | ); |
1091 | 1091 | |
1092 | 1092 | $items[] = $item; |
1093 | 1093 | } |
1094 | 1094 | } |
1095 | 1095 | |
1096 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
1097 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
1098 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
1099 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
1100 | - $order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ); |
|
1096 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
1097 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
1098 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
1099 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
1100 | + $order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp); |
|
1101 | 1101 | |
1102 | - if ( wc_tax_enabled() ) { |
|
1102 | + if (wc_tax_enabled()) { |
|
1103 | 1103 | $items[] = array( |
1104 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
1105 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
1104 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
1105 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
1106 | 1106 | ); |
1107 | 1107 | } |
1108 | 1108 | |
1109 | - if ( WC()->cart->needs_shipping() ) { |
|
1109 | + if (WC()->cart->needs_shipping()) { |
|
1110 | 1110 | $items[] = array( |
1111 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
1112 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
1111 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
1112 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
1113 | 1113 | ); |
1114 | 1114 | } |
1115 | 1115 | |
1116 | - if ( WC()->cart->has_discount() ) { |
|
1116 | + if (WC()->cart->has_discount()) { |
|
1117 | 1117 | $items[] = array( |
1118 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
1119 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
1118 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
1119 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
1120 | 1120 | ); |
1121 | 1121 | } |
1122 | 1122 | |
1123 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
1123 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
1124 | 1124 | $cart_fees = WC()->cart->fees; |
1125 | 1125 | } else { |
1126 | 1126 | $cart_fees = WC()->cart->get_fees(); |
1127 | 1127 | } |
1128 | 1128 | |
1129 | 1129 | // Include fees and taxes as display items. |
1130 | - foreach ( $cart_fees as $key => $fee ) { |
|
1130 | + foreach ($cart_fees as $key => $fee) { |
|
1131 | 1131 | $items[] = array( |
1132 | 1132 | 'label' => $fee->name, |
1133 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
1133 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
1134 | 1134 | ); |
1135 | 1135 | } |
1136 | 1136 | |
@@ -1138,7 +1138,7 @@ discard block |
||
1138 | 1138 | 'displayItems' => $items, |
1139 | 1139 | 'total' => array( |
1140 | 1140 | 'label' => $this->total_label, |
1141 | - 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
1141 | + 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
1142 | 1142 | 'pending' => false, |
1143 | 1143 | ), |
1144 | 1144 | ); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -15,23 +15,23 @@ discard block |
||
15 | 15 | public function __construct() { |
16 | 16 | parent::__construct(); |
17 | 17 | |
18 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
19 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
20 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
21 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
22 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
18 | + if (class_exists('WC_Subscriptions_Order')) { |
|
19 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
20 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
21 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
22 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
23 | 23 | |
24 | 24 | // display the credit card used for a subscription in the "My Subscriptions" table |
25 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
25 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
26 | 26 | |
27 | 27 | // allow store managers to manually set Stripe as the payment method on a subscription |
28 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
29 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
30 | - add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
28 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
29 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
30 | + add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
31 | 31 | } |
32 | 32 | |
33 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
34 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) ); |
|
33 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
34 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment')); |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | * @since 4.0.0 |
43 | 43 | * @version 4.0.0 |
44 | 44 | */ |
45 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
46 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
45 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
46 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
47 | 47 | return false; |
48 | 48 | } |
49 | 49 | |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | * @param int $order_id |
56 | 56 | * @return boolean |
57 | 57 | */ |
58 | - public function has_subscription( $order_id ) { |
|
59 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
58 | + public function has_subscription($order_id) { |
|
59 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @return bool |
67 | 67 | */ |
68 | 68 | public function is_subs_change_payment() { |
69 | - return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) ); |
|
69 | + return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method'])); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -74,8 +74,8 @@ discard block |
||
74 | 74 | * @param int $order_id |
75 | 75 | * @return boolean |
76 | 76 | */ |
77 | - public function is_pre_order( $order_id ) { |
|
78 | - return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) ); |
|
77 | + public function is_pre_order($order_id) { |
|
78 | + return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id)); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -84,24 +84,24 @@ discard block |
||
84 | 84 | * @since 4.0.4 |
85 | 85 | * @param int $order_id |
86 | 86 | */ |
87 | - public function change_subs_payment_method( $order_id ) { |
|
87 | + public function change_subs_payment_method($order_id) { |
|
88 | 88 | try { |
89 | - $subscription = wc_get_order( $order_id ); |
|
90 | - $prepared_source = $this->prepare_source( get_current_user_id(), true ); |
|
89 | + $subscription = wc_get_order($order_id); |
|
90 | + $prepared_source = $this->prepare_source(get_current_user_id(), true); |
|
91 | 91 | $source_object = $prepared_source->source_object; |
92 | 92 | |
93 | 93 | // Check if we don't allow prepaid credit cards. |
94 | - if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) && $this->is_prepaid_card( $source_object ) ) { |
|
95 | - $localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
96 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message ); |
|
94 | + if ( ! apply_filters('wc_stripe_allow_prepaid_card', true) && $this->is_prepaid_card($source_object)) { |
|
95 | + $localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
96 | + throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message); |
|
97 | 97 | } |
98 | 98 | |
99 | - if ( empty( $prepared_source->source ) ) { |
|
100 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
101 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
99 | + if (empty($prepared_source->source)) { |
|
100 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
101 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
102 | 102 | } |
103 | 103 | |
104 | - $this->save_source_to_order( $subscription, $prepared_source ); |
|
104 | + $this->save_source_to_order($subscription, $prepared_source); |
|
105 | 105 | |
106 | 106 | /* |
107 | 107 | * Check if card 3DS is required or optional with 3DS setting. |
@@ -110,41 +110,41 @@ discard block |
||
110 | 110 | * Note that if we need to save source, the original source must be first |
111 | 111 | * attached to a customer in Stripe before it can be charged. |
112 | 112 | */ |
113 | - if ( $this->is_3ds_required( $source_object ) ) { |
|
113 | + if ($this->is_3ds_required($source_object)) { |
|
114 | 114 | $order = $subscription->get_parent(); |
115 | - $response = $this->create_3ds_source( $order, $source_object, $subscription->get_view_order_url() ); |
|
115 | + $response = $this->create_3ds_source($order, $source_object, $subscription->get_view_order_url()); |
|
116 | 116 | |
117 | - if ( ! empty( $response->error ) ) { |
|
117 | + if ( ! empty($response->error)) { |
|
118 | 118 | $localized_message = $response->error->message; |
119 | 119 | |
120 | - $order->add_order_note( $localized_message ); |
|
120 | + $order->add_order_note($localized_message); |
|
121 | 121 | |
122 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
122 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | // Update order meta with 3DS source. |
126 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
127 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
126 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
127 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
128 | 128 | } else { |
129 | - $subscription->update_meta_data( '_stripe_source_id', $response->id ); |
|
129 | + $subscription->update_meta_data('_stripe_source_id', $response->id); |
|
130 | 130 | $subscription->save(); |
131 | 131 | } |
132 | 132 | |
133 | - WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' ); |
|
133 | + WC_Stripe_Logger::log('Info: Redirecting to 3DS...'); |
|
134 | 134 | |
135 | 135 | return array( |
136 | 136 | 'result' => 'success', |
137 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
137 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
138 | 138 | ); |
139 | 139 | } |
140 | 140 | |
141 | 141 | return array( |
142 | 142 | 'result' => 'success', |
143 | - 'redirect' => $this->get_return_url( $subscription ), |
|
143 | + 'redirect' => $this->get_return_url($subscription), |
|
144 | 144 | ); |
145 | - } catch ( WC_Stripe_Exception $e ) { |
|
146 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
147 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
145 | + } catch (WC_Stripe_Exception $e) { |
|
146 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
147 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
@@ -153,18 +153,18 @@ discard block |
||
153 | 153 | * @param int $order_id |
154 | 154 | * @return array |
155 | 155 | */ |
156 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
157 | - if ( $this->has_subscription( $order_id ) ) { |
|
158 | - if ( $this->is_subs_change_payment() ) { |
|
159 | - return $this->change_subs_payment_method( $order_id ); |
|
156 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
157 | + if ($this->has_subscription($order_id)) { |
|
158 | + if ($this->is_subs_change_payment()) { |
|
159 | + return $this->change_subs_payment_method($order_id); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | // Regular payment with force customer enabled |
163 | - return parent::process_payment( $order_id, true, true ); |
|
164 | - } elseif ( $this->is_pre_order( $order_id ) ) { |
|
165 | - return $this->process_pre_order( $order_id, $retry, $force_save_source ); |
|
163 | + return parent::process_payment($order_id, true, true); |
|
164 | + } elseif ($this->is_pre_order($order_id)) { |
|
165 | + return $this->process_pre_order($order_id, $retry, $force_save_source); |
|
166 | 166 | } else { |
167 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
167 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
@@ -174,24 +174,24 @@ discard block |
||
174 | 174 | * @since 3.1.0 |
175 | 175 | * @version 4.0.0 |
176 | 176 | */ |
177 | - public function save_source_to_order( $order, $source ) { |
|
178 | - parent::save_source_to_order( $order, $source ); |
|
177 | + public function save_source_to_order($order, $source) { |
|
178 | + parent::save_source_to_order($order, $source); |
|
179 | 179 | |
180 | 180 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
181 | 181 | |
182 | 182 | // Also store it on the subscriptions being purchased or paid for in the order |
183 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
184 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
185 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
186 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
183 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
184 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
185 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
186 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
187 | 187 | } else { |
188 | 188 | $subscriptions = array(); |
189 | 189 | } |
190 | 190 | |
191 | - foreach ( $subscriptions as $subscription ) { |
|
191 | + foreach ($subscriptions as $subscription) { |
|
192 | 192 | $subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id(); |
193 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
194 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
193 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
194 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
195 | 195 | } |
196 | 196 | } |
197 | 197 | |
@@ -204,45 +204,45 @@ discard block |
||
204 | 204 | * @param mixed $renewal_order |
205 | 205 | * @param bool $is_retry Is this a retry process. |
206 | 206 | */ |
207 | - public function process_subscription_payment( $amount = 0.0, $renewal_order, $is_retry = false ) { |
|
208 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
207 | + public function process_subscription_payment($amount = 0.0, $renewal_order, $is_retry = false) { |
|
208 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
209 | 209 | /* translators: minimum amount */ |
210 | - return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
210 | + return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | $order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id(); |
214 | 214 | |
215 | 215 | // Get source from order |
216 | - $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
216 | + $prepared_source = $this->prepare_order_source($renewal_order); |
|
217 | 217 | |
218 | - if ( ! $prepared_source->customer ) { |
|
219 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
218 | + if ( ! $prepared_source->customer) { |
|
219 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
220 | 220 | } |
221 | 221 | |
222 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
222 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
223 | 223 | |
224 | - if ( $is_retry ) { |
|
224 | + if ($is_retry) { |
|
225 | 225 | // Passing empty source with charge customer default. |
226 | 226 | $prepared_source->source = ''; |
227 | 227 | } |
228 | 228 | |
229 | - $request = $this->generate_payment_request( $renewal_order, $prepared_source ); |
|
229 | + $request = $this->generate_payment_request($renewal_order, $prepared_source); |
|
230 | 230 | $request['capture'] = 'true'; |
231 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
232 | - $response = WC_Stripe_API::request( $request ); |
|
231 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
232 | + $response = WC_Stripe_API::request($request); |
|
233 | 233 | |
234 | - if ( ! empty( $response->error ) || is_wp_error( $response ) ) { |
|
235 | - if ( $is_retry ) { |
|
234 | + if ( ! empty($response->error) || is_wp_error($response)) { |
|
235 | + if ($is_retry) { |
|
236 | 236 | /* translators: error message */ |
237 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
237 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | return $response; // Default catch all errors. |
241 | 241 | } |
242 | 242 | |
243 | - $this->process_response( $response, $renewal_order ); |
|
243 | + $this->process_response($response, $renewal_order); |
|
244 | 244 | |
245 | - if ( ! $is_retry ) { |
|
245 | + if ( ! $is_retry) { |
|
246 | 246 | return $response; |
247 | 247 | } |
248 | 248 | } |
@@ -251,21 +251,21 @@ discard block |
||
251 | 251 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
252 | 252 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
253 | 253 | */ |
254 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
255 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
256 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
254 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
255 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
256 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
257 | 257 | // For BW compat will remove in future |
258 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
259 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
258 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
259 | + $this->delete_renewal_meta($resubscribe_order); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
263 | 263 | * Don't transfer Stripe fee/ID meta to renewal orders. |
264 | 264 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
265 | 265 | */ |
266 | - public function delete_renewal_meta( $renewal_order ) { |
|
267 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
|
268 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' ); |
|
266 | + public function delete_renewal_meta($renewal_order) { |
|
267 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee'); |
|
268 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe'); |
|
269 | 269 | return $renewal_order; |
270 | 270 | } |
271 | 271 | |
@@ -275,21 +275,21 @@ discard block |
||
275 | 275 | * @param $amount_to_charge float The amount to charge. |
276 | 276 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
277 | 277 | */ |
278 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
279 | - $response = $this->process_subscription_payment( $amount_to_charge, $renewal_order ); |
|
278 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
279 | + $response = $this->process_subscription_payment($amount_to_charge, $renewal_order); |
|
280 | 280 | |
281 | - if ( is_wp_error( $response ) ) { |
|
281 | + if (is_wp_error($response)) { |
|
282 | 282 | /* translators: error message */ |
283 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
283 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
284 | 284 | } |
285 | 285 | |
286 | - if ( ! empty( $response->error ) ) { |
|
286 | + if ( ! empty($response->error)) { |
|
287 | 287 | // This is a very generic error to listen for but worth a retry before total fail. |
288 | - if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
289 | - $this->process_subscription_payment( $amount_to_charge, $renewal_order, true ); |
|
288 | + if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
289 | + $this->process_subscription_payment($amount_to_charge, $renewal_order, true); |
|
290 | 290 | } else { |
291 | 291 | /* translators: error message */ |
292 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
292 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
293 | 293 | } |
294 | 294 | } |
295 | 295 | } |
@@ -298,20 +298,20 @@ discard block |
||
298 | 298 | * Remove order meta |
299 | 299 | * @param object $order |
300 | 300 | */ |
301 | - public function remove_order_source_before_retry( $order ) { |
|
301 | + public function remove_order_source_before_retry($order) { |
|
302 | 302 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
303 | - delete_post_meta( $order_id, '_stripe_source_id' ); |
|
303 | + delete_post_meta($order_id, '_stripe_source_id'); |
|
304 | 304 | // For BW compat will remove in the future. |
305 | - delete_post_meta( $order_id, '_stripe_card_id' ); |
|
305 | + delete_post_meta($order_id, '_stripe_card_id'); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
309 | 309 | * Remove order meta |
310 | 310 | * @param object $order |
311 | 311 | */ |
312 | - public function remove_order_customer_before_retry( $order ) { |
|
312 | + public function remove_order_customer_before_retry($order) { |
|
313 | 313 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
314 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
314 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -323,14 +323,14 @@ discard block |
||
323 | 323 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
324 | 324 | * @return void |
325 | 325 | */ |
326 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
327 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
328 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
329 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
326 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
327 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
328 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
329 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
330 | 330 | |
331 | 331 | } else { |
332 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
333 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
332 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
333 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
334 | 334 | } |
335 | 335 | } |
336 | 336 | |
@@ -343,21 +343,21 @@ discard block |
||
343 | 343 | * @param WC_Subscription $subscription An instance of a subscription object |
344 | 344 | * @return array |
345 | 345 | */ |
346 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
347 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
346 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
347 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
348 | 348 | |
349 | 349 | // For BW compat will remove in future. |
350 | - if ( empty( $source_id ) ) { |
|
351 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
350 | + if (empty($source_id)) { |
|
351 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
352 | 352 | |
353 | 353 | // Take this opportunity to update the key name. |
354 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id ); |
|
354 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id); |
|
355 | 355 | } |
356 | 356 | |
357 | - $payment_meta[ $this->id ] = array( |
|
357 | + $payment_meta[$this->id] = array( |
|
358 | 358 | 'post_meta' => array( |
359 | 359 | '_stripe_customer_id' => array( |
360 | - 'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
360 | + 'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
361 | 361 | 'label' => 'Stripe Customer ID', |
362 | 362 | ), |
363 | 363 | '_stripe_source_id' => array( |
@@ -380,22 +380,22 @@ discard block |
||
380 | 380 | * @param array $payment_meta associative array of meta data required for automatic payments |
381 | 381 | * @return array |
382 | 382 | */ |
383 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
384 | - if ( $this->id === $payment_method_id ) { |
|
383 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
384 | + if ($this->id === $payment_method_id) { |
|
385 | 385 | |
386 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
387 | - throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); |
|
388 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
389 | - throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
386 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
387 | + throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe')); |
|
388 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
389 | + throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe')); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | if ( |
393 | - ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
394 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) ) |
|
395 | - && ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
396 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) { |
|
393 | + ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
394 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_')) |
|
395 | + && ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
396 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) { |
|
397 | 397 | |
398 | - throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
398 | + throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe')); |
|
399 | 399 | } |
400 | 400 | } |
401 | 401 | } |
@@ -408,92 +408,92 @@ discard block |
||
408 | 408 | * @param WC_Subscription $subscription the subscription details |
409 | 409 | * @return string the subscription payment method |
410 | 410 | */ |
411 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
411 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
412 | 412 | $customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id(); |
413 | 413 | |
414 | 414 | // bail for other payment methods |
415 | - if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
415 | + if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
416 | 416 | return $payment_method_to_display; |
417 | 417 | } |
418 | 418 | |
419 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
419 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
420 | 420 | |
421 | 421 | // For BW compat will remove in future. |
422 | - if ( empty( $stripe_source_id ) ) { |
|
423 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
422 | + if (empty($stripe_source_id)) { |
|
423 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
424 | 424 | |
425 | 425 | // Take this opportunity to update the key name. |
426 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
426 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | $stripe_customer = new WC_Stripe_Customer(); |
430 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
430 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
431 | 431 | |
432 | 432 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
433 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
433 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
434 | 434 | $user_id = $customer_user; |
435 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
436 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
435 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
436 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
437 | 437 | |
438 | 438 | // For BW compat will remove in future. |
439 | - if ( empty( $stripe_source_id ) ) { |
|
440 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
439 | + if (empty($stripe_source_id)) { |
|
440 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
441 | 441 | |
442 | 442 | // Take this opportunity to update the key name. |
443 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
443 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
444 | 444 | } |
445 | 445 | } |
446 | 446 | |
447 | 447 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
448 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
449 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
450 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
448 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
449 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
450 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
451 | 451 | |
452 | 452 | // For BW compat will remove in future. |
453 | - if ( empty( $stripe_source_id ) ) { |
|
454 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
453 | + if (empty($stripe_source_id)) { |
|
454 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
455 | 455 | |
456 | 456 | // Take this opportunity to update the key name. |
457 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id ); |
|
457 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id); |
|
458 | 458 | } |
459 | 459 | } |
460 | 460 | |
461 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
461 | + $stripe_customer->set_id($stripe_customer_id); |
|
462 | 462 | $sources = $stripe_customer->get_sources(); |
463 | 463 | |
464 | - if ( $sources ) { |
|
464 | + if ($sources) { |
|
465 | 465 | $card = false; |
466 | 466 | $found_source = false; |
467 | - foreach ( $sources as $source ) { |
|
468 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
467 | + foreach ($sources as $source) { |
|
468 | + if (isset($source->type) && 'card' === $source->type) { |
|
469 | 469 | $card = $source->card; |
470 | - } elseif ( isset( $source->object ) && 'card' === $source->object ) { |
|
470 | + } elseif (isset($source->object) && 'card' === $source->object) { |
|
471 | 471 | $card = $source; |
472 | 472 | } |
473 | 473 | |
474 | - if ( $source->id === $stripe_source_id ) { |
|
474 | + if ($source->id === $stripe_source_id) { |
|
475 | 475 | $found_source = true; |
476 | 476 | |
477 | - if ( $card ) { |
|
477 | + if ($card) { |
|
478 | 478 | /* translators: 1) card brand 2) last 4 digits */ |
479 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
479 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
480 | 480 | } else { |
481 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
481 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
482 | 482 | } |
483 | 483 | break; |
484 | 484 | } |
485 | 485 | } |
486 | 486 | |
487 | - if ( ! $found_source ) { |
|
488 | - if ( 'card' === $sources[0]->type ) { |
|
487 | + if ( ! $found_source) { |
|
488 | + if ('card' === $sources[0]->type) { |
|
489 | 489 | $card = $sources[0]->card; |
490 | 490 | } |
491 | 491 | |
492 | - if ( $card ) { |
|
492 | + if ($card) { |
|
493 | 493 | /* translators: 1) card brand 2) last 4 digits */ |
494 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
494 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
495 | 495 | } else { |
496 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
496 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
497 | 497 | } |
498 | 498 | } |
499 | 499 | } |
@@ -506,42 +506,42 @@ discard block |
||
506 | 506 | * @param int $order_id |
507 | 507 | * @return array |
508 | 508 | */ |
509 | - public function process_pre_order( $order_id, $retry, $force_save_source ) { |
|
510 | - if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
509 | + public function process_pre_order($order_id, $retry, $force_save_source) { |
|
510 | + if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) { |
|
511 | 511 | try { |
512 | - $order = wc_get_order( $order_id ); |
|
512 | + $order = wc_get_order($order_id); |
|
513 | 513 | |
514 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
514 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
515 | 515 | /* translators: minimum amount */ |
516 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
516 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
517 | 517 | } |
518 | 518 | |
519 | - $prepared_source = $this->prepare_source( get_current_user_id(), true ); |
|
519 | + $prepared_source = $this->prepare_source(get_current_user_id(), true); |
|
520 | 520 | |
521 | 521 | // We need a source on file to continue. |
522 | - if ( empty( $prepared_source->customer ) || empty( $prepared_source->source ) ) { |
|
523 | - throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
522 | + if (empty($prepared_source->customer) || empty($prepared_source->source)) { |
|
523 | + throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
524 | 524 | } |
525 | 525 | |
526 | - $this->save_source_to_order( $order, $prepared_source ); |
|
526 | + $this->save_source_to_order($order, $prepared_source); |
|
527 | 527 | |
528 | 528 | // Remove cart |
529 | 529 | WC()->cart->empty_cart(); |
530 | 530 | |
531 | 531 | // Is pre ordered! |
532 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
532 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
533 | 533 | |
534 | 534 | // Return thank you page redirect |
535 | 535 | return array( |
536 | 536 | 'result' => 'success', |
537 | - 'redirect' => $this->get_return_url( $order ), |
|
537 | + 'redirect' => $this->get_return_url($order), |
|
538 | 538 | ); |
539 | - } catch ( Exception $e ) { |
|
540 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
539 | + } catch (Exception $e) { |
|
540 | + wc_add_notice($e->getMessage(), 'error'); |
|
541 | 541 | return; |
542 | 542 | } |
543 | 543 | } else { |
544 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
544 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
545 | 545 | } |
546 | 546 | } |
547 | 547 | |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | * @param WC_Order $order |
551 | 551 | * @return void |
552 | 552 | */ |
553 | - public function process_pre_order_release_payment( $order ) { |
|
553 | + public function process_pre_order_release_payment($order) { |
|
554 | 554 | try { |
555 | 555 | // Define some callbacks if the first attempt fails. |
556 | 556 | $retry_callbacks = array( |
@@ -558,33 +558,33 @@ discard block |
||
558 | 558 | 'remove_order_customer_before_retry', |
559 | 559 | ); |
560 | 560 | |
561 | - while ( 1 ) { |
|
562 | - $source = $this->prepare_order_source( $order ); |
|
563 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
561 | + while (1) { |
|
562 | + $source = $this->prepare_order_source($order); |
|
563 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
564 | 564 | |
565 | - if ( ! empty( $response->error ) ) { |
|
566 | - if ( 0 === sizeof( $retry_callbacks ) ) { |
|
567 | - throw new Exception( $response->error->message ); |
|
565 | + if ( ! empty($response->error)) { |
|
566 | + if (0 === sizeof($retry_callbacks)) { |
|
567 | + throw new Exception($response->error->message); |
|
568 | 568 | } else { |
569 | - $retry_callback = array_shift( $retry_callbacks ); |
|
570 | - call_user_func( array( $this, $retry_callback ), $order ); |
|
569 | + $retry_callback = array_shift($retry_callbacks); |
|
570 | + call_user_func(array($this, $retry_callback), $order); |
|
571 | 571 | } |
572 | 572 | } else { |
573 | 573 | // Successful |
574 | - $this->process_response( $response, $order ); |
|
574 | + $this->process_response($response, $order); |
|
575 | 575 | break; |
576 | 576 | } |
577 | 577 | } |
578 | - } catch ( Exception $e ) { |
|
578 | + } catch (Exception $e) { |
|
579 | 579 | /* translators: error message */ |
580 | - $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
580 | + $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
581 | 581 | |
582 | 582 | // Mark order as failed if not already set, |
583 | 583 | // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
584 | - if ( ! $order->has_status( 'failed' ) ) { |
|
585 | - $order->update_status( 'failed', $order_note ); |
|
584 | + if ( ! $order->has_status('failed')) { |
|
585 | + $order->update_status('failed', $order_note); |
|
586 | 586 | } else { |
587 | - $order->add_order_note( $order_note ); |
|
587 | + $order->add_order_note($order_note); |
|
588 | 588 | } |
589 | 589 | } |
590 | 590 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -15,24 +15,24 @@ discard block |
||
15 | 15 | public function __construct() { |
16 | 16 | parent::__construct(); |
17 | 17 | |
18 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
19 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
20 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
21 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
22 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
18 | + if (class_exists('WC_Subscriptions_Order')) { |
|
19 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
20 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
21 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
22 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
23 | 23 | |
24 | 24 | // Display the credit card used for a subscription in the "My Subscriptions" table. |
25 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
25 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
26 | 26 | |
27 | 27 | // Allow store managers to manually set Stripe as the payment method on a subscription. |
28 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
29 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
30 | - add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
31 | - add_filter( 'wc_stripe_payment_metadata', array( $this, 'add_subscription_meta_data' ), 10, 2 ); |
|
28 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
29 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
30 | + add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
31 | + add_filter('wc_stripe_payment_metadata', array($this, 'add_subscription_meta_data'), 10, 2); |
|
32 | 32 | } |
33 | 33 | |
34 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
35 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) ); |
|
34 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
35 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment')); |
|
36 | 36 | } |
37 | 37 | } |
38 | 38 | |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | * @since 4.0.0 |
44 | 44 | * @version 4.0.0 |
45 | 45 | */ |
46 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
47 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
46 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
47 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
48 | 48 | return false; |
49 | 49 | } |
50 | 50 | |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | * @param int $order_id |
57 | 57 | * @return boolean |
58 | 58 | */ |
59 | - public function has_subscription( $order_id ) { |
|
60 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
59 | + public function has_subscription($order_id) { |
|
60 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | * @param int $order_id |
66 | 66 | * @return boolean |
67 | 67 | */ |
68 | - protected function is_pre_order( $order_id ) { |
|
69 | - return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) ); |
|
68 | + protected function is_pre_order($order_id) { |
|
69 | + return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id)); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -74,14 +74,14 @@ discard block |
||
74 | 74 | * @param int $order_id |
75 | 75 | * @return array |
76 | 76 | */ |
77 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
78 | - if ( $this->has_subscription( $order_id ) ) { |
|
77 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
78 | + if ($this->has_subscription($order_id)) { |
|
79 | 79 | // Regular payment with force customer enabled. |
80 | - return parent::process_payment( $order_id, true, true ); |
|
81 | - } elseif ( $this->is_pre_order( $order_id ) ) { |
|
82 | - return $this->process_pre_order( $order_id, $retry, $force_save_source ); |
|
80 | + return parent::process_payment($order_id, true, true); |
|
81 | + } elseif ($this->is_pre_order($order_id)) { |
|
82 | + return $this->process_pre_order($order_id, $retry, $force_save_source); |
|
83 | 83 | } else { |
84 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
84 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
@@ -92,14 +92,14 @@ discard block |
||
92 | 92 | * @param array $metadata |
93 | 93 | * @param object $order |
94 | 94 | */ |
95 | - public function add_subscription_meta_data( $metadata, $order ) { |
|
96 | - if ( ! $this->has_subscription( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) { |
|
95 | + public function add_subscription_meta_data($metadata, $order) { |
|
96 | + if ( ! $this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id())) { |
|
97 | 97 | return $metadata; |
98 | 98 | } |
99 | 99 | |
100 | 100 | return $metadata += array( |
101 | 101 | 'payment_type' => 'recurring', |
102 | - 'site_url' => esc_url( get_site_url() ), |
|
102 | + 'site_url' => esc_url(get_site_url()), |
|
103 | 103 | ); |
104 | 104 | } |
105 | 105 | |
@@ -109,24 +109,24 @@ discard block |
||
109 | 109 | * @since 3.1.0 |
110 | 110 | * @version 4.0.0 |
111 | 111 | */ |
112 | - public function save_source_to_order( $order, $source ) { |
|
113 | - parent::save_source_to_order( $order, $source ); |
|
112 | + public function save_source_to_order($order, $source) { |
|
113 | + parent::save_source_to_order($order, $source); |
|
114 | 114 | |
115 | - $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
115 | + $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
116 | 116 | |
117 | 117 | // Also store it on the subscriptions being purchased or paid for in the order. |
118 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
119 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
120 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
121 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
118 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
119 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
120 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
121 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
122 | 122 | } else { |
123 | 123 | $subscriptions = array(); |
124 | 124 | } |
125 | 125 | |
126 | - foreach ( $subscriptions as $subscription ) { |
|
126 | + foreach ($subscriptions as $subscription) { |
|
127 | 127 | $subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id(); |
128 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
129 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
128 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
129 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
@@ -139,45 +139,45 @@ discard block |
||
139 | 139 | * @param mixed $renewal_order |
140 | 140 | * @param bool $is_retry Is this a retry process. |
141 | 141 | */ |
142 | - public function process_subscription_payment( $amount = 0.0, $renewal_order, $is_retry = false ) { |
|
143 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
142 | + public function process_subscription_payment($amount = 0.0, $renewal_order, $is_retry = false) { |
|
143 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
144 | 144 | /* translators: minimum amount */ |
145 | - return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
145 | + return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | $order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id(); |
149 | 149 | |
150 | 150 | // Get source from order. |
151 | - $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
151 | + $prepared_source = $this->prepare_order_source($renewal_order); |
|
152 | 152 | |
153 | - if ( ! $prepared_source->customer ) { |
|
154 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
153 | + if ( ! $prepared_source->customer) { |
|
154 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
155 | 155 | } |
156 | 156 | |
157 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
157 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
158 | 158 | |
159 | - if ( $is_retry ) { |
|
159 | + if ($is_retry) { |
|
160 | 160 | // Passing empty source with charge customer default. |
161 | 161 | $prepared_source->source = ''; |
162 | 162 | } |
163 | 163 | |
164 | - $request = $this->generate_payment_request( $renewal_order, $prepared_source ); |
|
164 | + $request = $this->generate_payment_request($renewal_order, $prepared_source); |
|
165 | 165 | $request['capture'] = 'true'; |
166 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
167 | - $response = WC_Stripe_API::request( $request ); |
|
166 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
167 | + $response = WC_Stripe_API::request($request); |
|
168 | 168 | |
169 | - if ( ! empty( $response->error ) || is_wp_error( $response ) ) { |
|
170 | - if ( $is_retry ) { |
|
169 | + if ( ! empty($response->error) || is_wp_error($response)) { |
|
170 | + if ($is_retry) { |
|
171 | 171 | /* translators: error message */ |
172 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
172 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | return $response; // Default catch all errors. |
176 | 176 | } |
177 | 177 | |
178 | - $this->process_response( $response, $renewal_order ); |
|
178 | + $this->process_response($response, $renewal_order); |
|
179 | 179 | |
180 | - if ( ! $is_retry ) { |
|
180 | + if ( ! $is_retry) { |
|
181 | 181 | return $response; |
182 | 182 | } |
183 | 183 | } |
@@ -186,21 +186,21 @@ discard block |
||
186 | 186 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
187 | 187 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
188 | 188 | */ |
189 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
190 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
191 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
189 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
190 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
191 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
192 | 192 | // For BW compat will remove in future |
193 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
194 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
193 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
194 | + $this->delete_renewal_meta($resubscribe_order); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
198 | 198 | * Don't transfer Stripe fee/ID meta to renewal orders. |
199 | 199 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
200 | 200 | */ |
201 | - public function delete_renewal_meta( $renewal_order ) { |
|
202 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
|
203 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' ); |
|
201 | + public function delete_renewal_meta($renewal_order) { |
|
202 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee'); |
|
203 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe'); |
|
204 | 204 | return $renewal_order; |
205 | 205 | } |
206 | 206 | |
@@ -210,21 +210,21 @@ discard block |
||
210 | 210 | * @param $amount_to_charge float The amount to charge. |
211 | 211 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
212 | 212 | */ |
213 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
214 | - $response = $this->process_subscription_payment( $amount_to_charge, $renewal_order ); |
|
213 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
214 | + $response = $this->process_subscription_payment($amount_to_charge, $renewal_order); |
|
215 | 215 | |
216 | - if ( is_wp_error( $response ) ) { |
|
216 | + if (is_wp_error($response)) { |
|
217 | 217 | /* translators: error message */ |
218 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
218 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
219 | 219 | } |
220 | 220 | |
221 | - if ( ! empty( $response->error ) ) { |
|
221 | + if ( ! empty($response->error)) { |
|
222 | 222 | // This is a very generic error to listen for but worth a retry before total fail. |
223 | - if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
224 | - $this->process_subscription_payment( $amount_to_charge, $renewal_order, true ); |
|
223 | + if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
224 | + $this->process_subscription_payment($amount_to_charge, $renewal_order, true); |
|
225 | 225 | } else { |
226 | 226 | /* translators: error message */ |
227 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
227 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
228 | 228 | } |
229 | 229 | } |
230 | 230 | } |
@@ -233,20 +233,20 @@ discard block |
||
233 | 233 | * Remove order meta |
234 | 234 | * @param object $order |
235 | 235 | */ |
236 | - public function remove_order_source_before_retry( $order ) { |
|
236 | + public function remove_order_source_before_retry($order) { |
|
237 | 237 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
238 | - delete_post_meta( $order_id, '_stripe_source_id' ); |
|
238 | + delete_post_meta($order_id, '_stripe_source_id'); |
|
239 | 239 | // For BW compat will remove in the future. |
240 | - delete_post_meta( $order_id, '_stripe_card_id' ); |
|
240 | + delete_post_meta($order_id, '_stripe_card_id'); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
244 | 244 | * Remove order meta |
245 | 245 | * @param object $order |
246 | 246 | */ |
247 | - public function remove_order_customer_before_retry( $order ) { |
|
247 | + public function remove_order_customer_before_retry($order) { |
|
248 | 248 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
249 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
249 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
@@ -258,14 +258,14 @@ discard block |
||
258 | 258 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
259 | 259 | * @return void |
260 | 260 | */ |
261 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
262 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
263 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
264 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
261 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
262 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
263 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
264 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
265 | 265 | |
266 | 266 | } else { |
267 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
268 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
267 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
268 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
269 | 269 | } |
270 | 270 | } |
271 | 271 | |
@@ -278,21 +278,21 @@ discard block |
||
278 | 278 | * @param WC_Subscription $subscription An instance of a subscription object |
279 | 279 | * @return array |
280 | 280 | */ |
281 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
282 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
281 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
282 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
283 | 283 | |
284 | 284 | // For BW compat will remove in future. |
285 | - if ( empty( $source_id ) ) { |
|
286 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
285 | + if (empty($source_id)) { |
|
286 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
287 | 287 | |
288 | 288 | // Take this opportunity to update the key name. |
289 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id ); |
|
289 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id); |
|
290 | 290 | } |
291 | 291 | |
292 | - $payment_meta[ $this->id ] = array( |
|
292 | + $payment_meta[$this->id] = array( |
|
293 | 293 | 'post_meta' => array( |
294 | 294 | '_stripe_customer_id' => array( |
295 | - 'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
295 | + 'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
296 | 296 | 'label' => 'Stripe Customer ID', |
297 | 297 | ), |
298 | 298 | '_stripe_source_id' => array( |
@@ -313,22 +313,22 @@ discard block |
||
313 | 313 | * @param array $payment_meta associative array of meta data required for automatic payments |
314 | 314 | * @return array |
315 | 315 | */ |
316 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
317 | - if ( $this->id === $payment_method_id ) { |
|
316 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
317 | + if ($this->id === $payment_method_id) { |
|
318 | 318 | |
319 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
320 | - throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); |
|
321 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
322 | - throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
319 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
320 | + throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe')); |
|
321 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
322 | + throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe')); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | if ( |
326 | - ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
327 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) ) |
|
328 | - && ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
329 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) { |
|
326 | + ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
327 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_')) |
|
328 | + && ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
329 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) { |
|
330 | 330 | |
331 | - throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
331 | + throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe')); |
|
332 | 332 | } |
333 | 333 | } |
334 | 334 | } |
@@ -341,67 +341,67 @@ discard block |
||
341 | 341 | * @param WC_Subscription $subscription the subscription details |
342 | 342 | * @return string the subscription payment method |
343 | 343 | */ |
344 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
344 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
345 | 345 | $customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id(); |
346 | 346 | |
347 | 347 | // bail for other payment methods |
348 | - if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
348 | + if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
349 | 349 | return $payment_method_to_display; |
350 | 350 | } |
351 | 351 | |
352 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
352 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
353 | 353 | |
354 | 354 | // For BW compat will remove in future. |
355 | - if ( empty( $stripe_source_id ) ) { |
|
356 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
355 | + if (empty($stripe_source_id)) { |
|
356 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
357 | 357 | |
358 | 358 | // Take this opportunity to update the key name. |
359 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
359 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | $stripe_customer = new WC_Stripe_Customer(); |
363 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
363 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
364 | 364 | |
365 | 365 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
366 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
366 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
367 | 367 | $user_id = $customer_user; |
368 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
369 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
368 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
369 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
370 | 370 | |
371 | 371 | // For BW compat will remove in future. |
372 | - if ( empty( $stripe_source_id ) ) { |
|
373 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
372 | + if (empty($stripe_source_id)) { |
|
373 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
374 | 374 | |
375 | 375 | // Take this opportunity to update the key name. |
376 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
376 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
377 | 377 | } |
378 | 378 | } |
379 | 379 | |
380 | 380 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
381 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
382 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
383 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
381 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
382 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
383 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
384 | 384 | |
385 | 385 | // For BW compat will remove in future. |
386 | - if ( empty( $stripe_source_id ) ) { |
|
387 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
386 | + if (empty($stripe_source_id)) { |
|
387 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
388 | 388 | |
389 | 389 | // Take this opportunity to update the key name. |
390 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id ); |
|
390 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id); |
|
391 | 391 | } |
392 | 392 | } |
393 | 393 | |
394 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
394 | + $stripe_customer->set_id($stripe_customer_id); |
|
395 | 395 | $sources = $stripe_customer->get_sources(); |
396 | 396 | |
397 | - if ( $sources ) { |
|
398 | - foreach ( $sources as $source ) { |
|
399 | - if ( $source->id === $stripe_source_id ) { |
|
400 | - if ( $source->sepa_debit ) { |
|
397 | + if ($sources) { |
|
398 | + foreach ($sources as $source) { |
|
399 | + if ($source->id === $stripe_source_id) { |
|
400 | + if ($source->sepa_debit) { |
|
401 | 401 | /* translators: 1) last 4 digits of SEPA Direct Debit */ |
402 | - $payment_method_to_display = sprintf( __( 'Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe' ), $source->sepa_debit->last4 ); |
|
402 | + $payment_method_to_display = sprintf(__('Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe'), $source->sepa_debit->last4); |
|
403 | 403 | } else { |
404 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
404 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
405 | 405 | } |
406 | 406 | break; |
407 | 407 | } |
@@ -416,42 +416,42 @@ discard block |
||
416 | 416 | * @param int $order_id |
417 | 417 | * @return array |
418 | 418 | */ |
419 | - public function process_pre_order( $order_id, $retry, $force_save_source ) { |
|
420 | - if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
419 | + public function process_pre_order($order_id, $retry, $force_save_source) { |
|
420 | + if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) { |
|
421 | 421 | try { |
422 | - $order = wc_get_order( $order_id ); |
|
422 | + $order = wc_get_order($order_id); |
|
423 | 423 | |
424 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
424 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
425 | 425 | /* translators: minimum amount */ |
426 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
426 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
427 | 427 | } |
428 | 428 | |
429 | - $prepared_source = $this->prepare_source( get_current_user_id(), true ); |
|
429 | + $prepared_source = $this->prepare_source(get_current_user_id(), true); |
|
430 | 430 | |
431 | 431 | // We need a source on file to continue. |
432 | - if ( empty( $prepared_source->customer ) || empty( $prepared_source->source ) ) { |
|
433 | - throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
432 | + if (empty($prepared_source->customer) || empty($prepared_source->source)) { |
|
433 | + throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
434 | 434 | } |
435 | 435 | |
436 | - $this->save_source_to_order( $order, $prepared_source ); |
|
436 | + $this->save_source_to_order($order, $prepared_source); |
|
437 | 437 | |
438 | 438 | // Remove cart |
439 | 439 | WC()->cart->empty_cart(); |
440 | 440 | |
441 | 441 | // Is pre ordered! |
442 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
442 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
443 | 443 | |
444 | 444 | // Return thank you page redirect |
445 | 445 | return array( |
446 | 446 | 'result' => 'success', |
447 | - 'redirect' => $this->get_return_url( $order ), |
|
447 | + 'redirect' => $this->get_return_url($order), |
|
448 | 448 | ); |
449 | - } catch ( Exception $e ) { |
|
450 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
449 | + } catch (Exception $e) { |
|
450 | + wc_add_notice($e->getMessage(), 'error'); |
|
451 | 451 | return; |
452 | 452 | } |
453 | 453 | } else { |
454 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
454 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
455 | 455 | } |
456 | 456 | } |
457 | 457 | |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | * @param WC_Order $order |
461 | 461 | * @return void |
462 | 462 | */ |
463 | - public function process_pre_order_release_payment( $order ) { |
|
463 | + public function process_pre_order_release_payment($order) { |
|
464 | 464 | try { |
465 | 465 | // Define some callbacks if the first attempt fails. |
466 | 466 | $retry_callbacks = array( |
@@ -468,33 +468,33 @@ discard block |
||
468 | 468 | 'remove_order_customer_before_retry', |
469 | 469 | ); |
470 | 470 | |
471 | - while ( 1 ) { |
|
472 | - $source = $this->prepare_order_source( $order ); |
|
473 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
471 | + while (1) { |
|
472 | + $source = $this->prepare_order_source($order); |
|
473 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
474 | 474 | |
475 | - if ( ! empty( $response->error ) ) { |
|
476 | - if ( 0 === sizeof( $retry_callbacks ) ) { |
|
477 | - throw new Exception( $response->error->message ); |
|
475 | + if ( ! empty($response->error)) { |
|
476 | + if (0 === sizeof($retry_callbacks)) { |
|
477 | + throw new Exception($response->error->message); |
|
478 | 478 | } else { |
479 | - $retry_callback = array_shift( $retry_callbacks ); |
|
480 | - call_user_func( array( $this, $retry_callback ), $order ); |
|
479 | + $retry_callback = array_shift($retry_callbacks); |
|
480 | + call_user_func(array($this, $retry_callback), $order); |
|
481 | 481 | } |
482 | 482 | } else { |
483 | 483 | // Successful |
484 | - $this->process_response( $response, $order ); |
|
484 | + $this->process_response($response, $order); |
|
485 | 485 | break; |
486 | 486 | } |
487 | 487 | } |
488 | - } catch ( Exception $e ) { |
|
488 | + } catch (Exception $e) { |
|
489 | 489 | /* translators: error message */ |
490 | - $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
490 | + $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
491 | 491 | |
492 | 492 | // Mark order as failed if not already set, |
493 | 493 | // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
494 | - if ( ! $order->has_status( 'failed' ) ) { |
|
495 | - $order->update_status( 'failed', $order_note ); |
|
494 | + if ( ! $order->has_status('failed')) { |
|
495 | + $order->update_status('failed', $order_note); |
|
496 | 496 | } else { |
497 | - $order->add_order_note( $order_note ); |
|
497 | + $order->add_order_note($order_note); |
|
498 | 498 | } |
499 | 499 | } |
500 | 500 | } |