@@ -1,10 +1,10 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; // Exit if accessed directly |
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | // if uninstall not called from WordPress exit |
| 7 | -if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
|
| 7 | +if ( ! defined('WP_UNINSTALL_PLUGIN')) { |
|
| 8 | 8 | exit; |
| 9 | 9 | } |
| 10 | 10 | |
@@ -13,20 +13,20 @@ discard block |
||
| 13 | 13 | * wp-config.php. This is to prevent data loss when deleting the plugin from the backend |
| 14 | 14 | * and to ensure only the site owner can perform this action. |
| 15 | 15 | */ |
| 16 | -if ( defined( 'WC_REMOVE_ALL_DATA' ) && true === WC_REMOVE_ALL_DATA ) { |
|
| 16 | +if (defined('WC_REMOVE_ALL_DATA') && true === WC_REMOVE_ALL_DATA) { |
|
| 17 | 17 | // Delete options. |
| 18 | - delete_option( 'woocommerce_stripe_settings' ); |
|
| 19 | - delete_option( 'wc_stripe_show_request_api_notice' ); |
|
| 20 | - delete_option( 'wc_stripe_show_apple_pay_notice' ); |
|
| 21 | - delete_option( 'wc_stripe_show_ssl_notice' ); |
|
| 22 | - delete_option( 'wc_stripe_show_keys_notice' ); |
|
| 23 | - delete_option( 'wc_stripe_version' ); |
|
| 24 | - delete_option( 'woocommerce_stripe_bancontact_settings' ); |
|
| 25 | - delete_option( 'woocommerce_stripe_alipay_settings' ); |
|
| 26 | - delete_option( 'woocommerce_stripe_bitcoin_settings' ); |
|
| 27 | - delete_option( 'woocommerce_stripe_ideal_settings' ); |
|
| 28 | - delete_option( 'woocommerce_stripe_p24_settings' ); |
|
| 29 | - delete_option( 'woocommerce_stripe_giropay_settings' ); |
|
| 30 | - delete_option( 'woocommerce_stripe_sepa_settings' ); |
|
| 31 | - delete_option( 'woocommerce_stripe_sofort_settings' ); |
|
| 18 | + delete_option('woocommerce_stripe_settings'); |
|
| 19 | + delete_option('wc_stripe_show_request_api_notice'); |
|
| 20 | + delete_option('wc_stripe_show_apple_pay_notice'); |
|
| 21 | + delete_option('wc_stripe_show_ssl_notice'); |
|
| 22 | + delete_option('wc_stripe_show_keys_notice'); |
|
| 23 | + delete_option('wc_stripe_version'); |
|
| 24 | + delete_option('woocommerce_stripe_bancontact_settings'); |
|
| 25 | + delete_option('woocommerce_stripe_alipay_settings'); |
|
| 26 | + delete_option('woocommerce_stripe_bitcoin_settings'); |
|
| 27 | + delete_option('woocommerce_stripe_ideal_settings'); |
|
| 28 | + delete_option('woocommerce_stripe_p24_settings'); |
|
| 29 | + delete_option('woocommerce_stripe_giropay_settings'); |
|
| 30 | + delete_option('woocommerce_stripe_sepa_settings'); |
|
| 31 | + delete_option('woocommerce_stripe_sofort_settings'); |
|
| 32 | 32 | } |
@@ -134,7 +134,6 @@ discard block |
||
| 134 | 134 | * process_subscription_payment function. |
| 135 | 135 | * @param mixed $order |
| 136 | 136 | * @param int $amount (default: 0) |
| 137 | - * @param string $stripe_token (default: '') |
|
| 138 | 137 | * @param bool initial_payment |
| 139 | 138 | */ |
| 140 | 139 | public function process_subscription_payment( $order = '', $amount = 0 ) { |
@@ -186,7 +185,7 @@ discard block |
||
| 186 | 185 | |
| 187 | 186 | /** |
| 188 | 187 | * Don't transfer Stripe fee/ID meta to renewal orders. |
| 189 | - * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
|
| 188 | + * @param integer $renewal_order |
|
| 190 | 189 | */ |
| 191 | 190 | public function delete_renewal_meta( $renewal_order ) { |
| 192 | 191 | delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
@@ -406,6 +405,8 @@ discard block |
||
| 406 | 405 | /** |
| 407 | 406 | * Process the pre-order |
| 408 | 407 | * @param int $order_id |
| 408 | + * @param boolean $retry |
|
| 409 | + * @param boolean $force_save_source |
|
| 409 | 410 | * @return array |
| 410 | 411 | */ |
| 411 | 412 | public function process_pre_order( $order_id, $retry, $force_save_source ) { |
@@ -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( $order->get_id() ) ) { |
|
| 95 | + public function add_subscription_meta_data($metadata, $order) { |
|
| 96 | + if ( ! $this->has_subscription($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( $order, $source ) { |
|
| 113 | - parent::save_source( $order, $source ); |
|
| 112 | + public function save_source($order, $source) { |
|
| 113 | + parent::save_source($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 | |
@@ -137,37 +137,37 @@ discard block |
||
| 137 | 137 | * @param string $stripe_token (default: '') |
| 138 | 138 | * @param bool initial_payment |
| 139 | 139 | */ |
| 140 | - public function process_subscription_payment( $order = '', $amount = 0 ) { |
|
| 141 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 140 | + public function process_subscription_payment($order = '', $amount = 0) { |
|
| 141 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 142 | 142 | /* translators: minimum amount */ |
| 143 | - 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 ) ) ); |
|
| 143 | + 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))); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | $customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 147 | 147 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 148 | 148 | |
| 149 | 149 | // Get source from order |
| 150 | - $prepared_source = $this->prepare_order_source( $order ); |
|
| 150 | + $prepared_source = $this->prepare_order_source($order); |
|
| 151 | 151 | |
| 152 | 152 | // Or fail :( |
| 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 | 159 | // Make the request |
| 160 | - $request = $this->generate_payment_request( $order, $prepared_source ); |
|
| 160 | + $request = $this->generate_payment_request($order, $prepared_source); |
|
| 161 | 161 | $request['capture'] = 'true'; |
| 162 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
| 163 | - $response = WC_Stripe_API::request( $request ); |
|
| 162 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
| 163 | + $response = WC_Stripe_API::request($request); |
|
| 164 | 164 | |
| 165 | 165 | // Process valid response |
| 166 | - if ( ! empty( $response->error ) ) { |
|
| 166 | + if ( ! empty($response->error)) { |
|
| 167 | 167 | return $response; // Default catch all errors. |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - $this->process_response( $response, $order ); |
|
| 170 | + $this->process_response($response, $order); |
|
| 171 | 171 | |
| 172 | 172 | return $response; |
| 173 | 173 | } |
@@ -176,21 +176,21 @@ discard block |
||
| 176 | 176 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
| 177 | 177 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 178 | 178 | */ |
| 179 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
| 180 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
| 181 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
| 179 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
| 180 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
| 181 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
| 182 | 182 | // For BW compat will remove in future |
| 183 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
| 184 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
| 183 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
| 184 | + $this->delete_renewal_meta($resubscribe_order); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
| 188 | 188 | * Don't transfer Stripe fee/ID meta to renewal orders. |
| 189 | 189 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 190 | 190 | */ |
| 191 | - public function delete_renewal_meta( $renewal_order ) { |
|
| 192 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
|
| 193 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' ); |
|
| 191 | + public function delete_renewal_meta($renewal_order) { |
|
| 192 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee'); |
|
| 193 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe'); |
|
| 194 | 194 | return $renewal_order; |
| 195 | 195 | } |
| 196 | 196 | |
@@ -200,17 +200,17 @@ discard block |
||
| 200 | 200 | * @param $amount_to_charge float The amount to charge. |
| 201 | 201 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
| 202 | 202 | */ |
| 203 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
| 204 | - $response = $this->process_subscription_payment( $renewal_order, $amount_to_charge ); |
|
| 203 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
| 204 | + $response = $this->process_subscription_payment($renewal_order, $amount_to_charge); |
|
| 205 | 205 | |
| 206 | - if ( is_wp_error( $response ) ) { |
|
| 206 | + if (is_wp_error($response)) { |
|
| 207 | 207 | /* translators: error message */ |
| 208 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
| 208 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - if ( ! empty( $response->error ) ) { |
|
| 211 | + if ( ! empty($response->error)) { |
|
| 212 | 212 | /* translators: error message */ |
| 213 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
| 213 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | 216 | |
@@ -218,20 +218,20 @@ discard block |
||
| 218 | 218 | * Remove order meta |
| 219 | 219 | * @param object $order |
| 220 | 220 | */ |
| 221 | - public function remove_order_source_before_retry( $order ) { |
|
| 221 | + public function remove_order_source_before_retry($order) { |
|
| 222 | 222 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 223 | - delete_post_meta( $order_id, '_stripe_source_id' ); |
|
| 223 | + delete_post_meta($order_id, '_stripe_source_id'); |
|
| 224 | 224 | // For BW compat will remove in the future. |
| 225 | - delete_post_meta( $order_id, '_stripe_card_id' ); |
|
| 225 | + delete_post_meta($order_id, '_stripe_card_id'); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
| 229 | 229 | * Remove order meta |
| 230 | 230 | * @param object $order |
| 231 | 231 | */ |
| 232 | - public function remove_order_customer_before_retry( $order ) { |
|
| 232 | + public function remove_order_customer_before_retry($order) { |
|
| 233 | 233 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 234 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
| 234 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -243,14 +243,14 @@ discard block |
||
| 243 | 243 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
| 244 | 244 | * @return void |
| 245 | 245 | */ |
| 246 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
| 247 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 248 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
| 249 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
| 246 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
| 247 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 248 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
| 249 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
| 250 | 250 | |
| 251 | 251 | } else { |
| 252 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
| 253 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
| 252 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
| 253 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | |
@@ -263,21 +263,21 @@ discard block |
||
| 263 | 263 | * @param WC_Subscription $subscription An instance of a subscription object |
| 264 | 264 | * @return array |
| 265 | 265 | */ |
| 266 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
| 267 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
| 266 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
| 267 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
| 268 | 268 | |
| 269 | 269 | // For BW compat will remove in future. |
| 270 | - if ( empty( $source_id ) ) { |
|
| 271 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 270 | + if (empty($source_id)) { |
|
| 271 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 272 | 272 | |
| 273 | 273 | // Take this opportunity to update the key name. |
| 274 | - 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 ); |
|
| 274 | + 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); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - $payment_meta[ $this->id ] = array( |
|
| 277 | + $payment_meta[$this->id] = array( |
|
| 278 | 278 | 'post_meta' => array( |
| 279 | 279 | '_stripe_customer_id' => array( |
| 280 | - 'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
| 280 | + 'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
| 281 | 281 | 'label' => 'Stripe Customer ID', |
| 282 | 282 | ), |
| 283 | 283 | '_stripe_source_id' => array( |
@@ -298,17 +298,17 @@ discard block |
||
| 298 | 298 | * @param array $payment_meta associative array of meta data required for automatic payments |
| 299 | 299 | * @return array |
| 300 | 300 | */ |
| 301 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
| 302 | - if ( $this->id === $payment_method_id ) { |
|
| 301 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
| 302 | + if ($this->id === $payment_method_id) { |
|
| 303 | 303 | |
| 304 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
| 305 | - throw new Exception( 'A "_stripe_customer_id" value is required.' ); |
|
| 306 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
| 307 | - throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' ); |
|
| 304 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
| 305 | + throw new Exception('A "_stripe_customer_id" value is required.'); |
|
| 306 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
| 307 | + throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".'); |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - if ( ! isset( $payment_meta['post_meta']['_stripe_source_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) ) { |
|
| 311 | - throw new Exception( 'A "_stripe_source_id" value is required.' ); |
|
| 310 | + if ( ! isset($payment_meta['post_meta']['_stripe_source_id']['value']) || empty($payment_meta['post_meta']['_stripe_source_id']['value'])) { |
|
| 311 | + throw new Exception('A "_stripe_source_id" value is required.'); |
|
| 312 | 312 | } |
| 313 | 313 | } |
| 314 | 314 | } |
@@ -321,89 +321,89 @@ discard block |
||
| 321 | 321 | * @param WC_Subscription $subscription the subscription details |
| 322 | 322 | * @return string the subscription payment method |
| 323 | 323 | */ |
| 324 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
| 324 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
| 325 | 325 | $customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id(); |
| 326 | 326 | |
| 327 | 327 | // bail for other payment methods |
| 328 | - if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
| 328 | + if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
| 329 | 329 | return $payment_method_to_display; |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
| 332 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
| 333 | 333 | |
| 334 | 334 | // For BW compat will remove in future. |
| 335 | - if ( empty( $stripe_source_id ) ) { |
|
| 336 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 335 | + if (empty($stripe_source_id)) { |
|
| 336 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 337 | 337 | |
| 338 | 338 | // Take this opportunity to update the key name. |
| 339 | - 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 ); |
|
| 339 | + 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); |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | $stripe_customer = new WC_Stripe_Customer(); |
| 343 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
| 343 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
| 344 | 344 | |
| 345 | 345 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
| 346 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
| 346 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
| 347 | 347 | $user_id = $customer_user; |
| 348 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
| 349 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
| 348 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
| 349 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
| 350 | 350 | |
| 351 | 351 | // For BW compat will remove in future. |
| 352 | - if ( empty( $stripe_source_id ) ) { |
|
| 353 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
| 352 | + if (empty($stripe_source_id)) { |
|
| 353 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
| 354 | 354 | |
| 355 | 355 | // Take this opportunity to update the key name. |
| 356 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
| 356 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
| 357 | 357 | } |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
| 361 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
| 362 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
| 363 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
| 361 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
| 362 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
| 363 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
| 364 | 364 | |
| 365 | 365 | // For BW compat will remove in future. |
| 366 | - if ( empty( $stripe_source_id ) ) { |
|
| 367 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
| 366 | + if (empty($stripe_source_id)) { |
|
| 367 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
| 368 | 368 | |
| 369 | 369 | // Take this opportunity to update the key name. |
| 370 | - 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 ); |
|
| 370 | + 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); |
|
| 371 | 371 | } |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
| 374 | + $stripe_customer->set_id($stripe_customer_id); |
|
| 375 | 375 | $sources = $stripe_customer->get_sources(); |
| 376 | 376 | |
| 377 | - if ( $sources ) { |
|
| 377 | + if ($sources) { |
|
| 378 | 378 | $found_source = false; |
| 379 | - foreach ( $sources as $source ) { |
|
| 380 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
| 379 | + foreach ($sources as $source) { |
|
| 380 | + if (isset($source->type) && 'card' === $source->type) { |
|
| 381 | 381 | $card = $source->card; |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | - if ( $source->id === $stripe_source_id ) { |
|
| 384 | + if ($source->id === $stripe_source_id) { |
|
| 385 | 385 | $found_source = true; |
| 386 | 386 | |
| 387 | - if ( $card ) { |
|
| 387 | + if ($card) { |
|
| 388 | 388 | /* translators: 1) card brand 2) last 4 digits */ |
| 389 | - $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 ); |
|
| 389 | + $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); |
|
| 390 | 390 | } else { |
| 391 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
| 391 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
| 392 | 392 | } |
| 393 | 393 | break; |
| 394 | 394 | } |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | - if ( ! $found_source ) { |
|
| 398 | - if ( 'card' === $sources[0]->type ) { |
|
| 397 | + if ( ! $found_source) { |
|
| 398 | + if ('card' === $sources[0]->type) { |
|
| 399 | 399 | $card = $sources[0]->card; |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | - if ( $card ) { |
|
| 402 | + if ($card) { |
|
| 403 | 403 | /* translators: 1) card brand 2) last 4 digits */ |
| 404 | - $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 ); |
|
| 404 | + $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); |
|
| 405 | 405 | } else { |
| 406 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
| 406 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
| 407 | 407 | } |
| 408 | 408 | } |
| 409 | 409 | } |
@@ -416,43 +416,43 @@ 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 | - $source = $this->prepare_source( get_current_user_id(), true ); |
|
| 429 | + $source = $this->prepare_source(get_current_user_id(), true); |
|
| 430 | 430 | |
| 431 | 431 | // We need a source on file to continue. |
| 432 | - if ( empty( $source->customer ) || empty( $source->source ) ) { |
|
| 433 | - throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
| 432 | + if (empty($source->customer) || empty($source->source)) { |
|
| 433 | + throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | // Store source to order meta |
| 437 | - $this->save_source( $order, $source ); |
|
| 437 | + $this->save_source($order, $source); |
|
| 438 | 438 | |
| 439 | 439 | // Remove cart |
| 440 | 440 | WC()->cart->empty_cart(); |
| 441 | 441 | |
| 442 | 442 | // Is pre ordered! |
| 443 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
| 443 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
| 444 | 444 | |
| 445 | 445 | // Return thank you page redirect |
| 446 | 446 | return array( |
| 447 | 447 | 'result' => 'success', |
| 448 | - 'redirect' => $this->get_return_url( $order ), |
|
| 448 | + 'redirect' => $this->get_return_url($order), |
|
| 449 | 449 | ); |
| 450 | - } catch ( Exception $e ) { |
|
| 451 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 450 | + } catch (Exception $e) { |
|
| 451 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 452 | 452 | return; |
| 453 | 453 | } |
| 454 | 454 | } else { |
| 455 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
| 455 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
| 456 | 456 | } |
| 457 | 457 | } |
| 458 | 458 | |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | * @param WC_Order $order |
| 462 | 462 | * @return void |
| 463 | 463 | */ |
| 464 | - public function process_pre_order_release_payment( $order ) { |
|
| 464 | + public function process_pre_order_release_payment($order) { |
|
| 465 | 465 | try { |
| 466 | 466 | // Define some callbacks if the first attempt fails. |
| 467 | 467 | $retry_callbacks = array( |
@@ -469,33 +469,33 @@ discard block |
||
| 469 | 469 | 'remove_order_customer_before_retry', |
| 470 | 470 | ); |
| 471 | 471 | |
| 472 | - while ( 1 ) { |
|
| 473 | - $source = $this->prepare_order_source( $order ); |
|
| 474 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
| 472 | + while (1) { |
|
| 473 | + $source = $this->prepare_order_source($order); |
|
| 474 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
| 475 | 475 | |
| 476 | - if ( ! empty( $response->error ) ) { |
|
| 477 | - if ( 0 === sizeof( $retry_callbacks ) ) { |
|
| 478 | - throw new Exception( $response->error->message ); |
|
| 476 | + if ( ! empty($response->error)) { |
|
| 477 | + if (0 === sizeof($retry_callbacks)) { |
|
| 478 | + throw new Exception($response->error->message); |
|
| 479 | 479 | } else { |
| 480 | - $retry_callback = array_shift( $retry_callbacks ); |
|
| 481 | - call_user_func( array( $this, $retry_callback ), $order ); |
|
| 480 | + $retry_callback = array_shift($retry_callbacks); |
|
| 481 | + call_user_func(array($this, $retry_callback), $order); |
|
| 482 | 482 | } |
| 483 | 483 | } else { |
| 484 | 484 | // Successful |
| 485 | - $this->process_response( $response, $order ); |
|
| 485 | + $this->process_response($response, $order); |
|
| 486 | 486 | break; |
| 487 | 487 | } |
| 488 | 488 | } |
| 489 | - } catch ( Exception $e ) { |
|
| 489 | + } catch (Exception $e) { |
|
| 490 | 490 | /* translators: error message */ |
| 491 | - $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
| 491 | + $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
| 492 | 492 | |
| 493 | 493 | // Mark order as failed if not already set, |
| 494 | 494 | // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
| 495 | - if ( ! $order->has_status( 'failed' ) ) { |
|
| 496 | - $order->update_status( 'failed', $order_note ); |
|
| 495 | + if ( ! $order->has_status('failed')) { |
|
| 496 | + $order->update_status('failed', $order_note); |
|
| 497 | 497 | } else { |
| 498 | - $order->add_order_note( $order_note ); |
|
| 498 | + $order->add_order_note($order_note); |
|
| 499 | 499 | } |
| 500 | 500 | } |
| 501 | 501 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @since 3.1.0 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 9 | +if ( ! defined('ABSPATH')) { |
|
| 10 | 10 | exit; |
| 11 | 11 | } |
| 12 | 12 | |
@@ -42,30 +42,30 @@ discard block |
||
| 42 | 42 | * @version 4.0.0 |
| 43 | 43 | */ |
| 44 | 44 | public function __construct() { |
| 45 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
| 45 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
| 46 | 46 | $this->publishable_key = $this->get_publishable_key(); |
| 47 | - $this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
| 48 | - $this->total_label = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : ''; |
|
| 47 | + $this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
| 48 | + $this->total_label = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : ''; |
|
| 49 | 49 | |
| 50 | 50 | // If both site title and statement descriptor is not set. Fallback. |
| 51 | - if ( empty( $this->total_label ) ) { |
|
| 51 | + if (empty($this->total_label)) { |
|
| 52 | 52 | $this->total_label = $_SERVER['SERVER_NAME']; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - $this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' ); |
|
| 55 | + $this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)'); |
|
| 56 | 56 | |
| 57 | 57 | // Checks if Stripe Gateway is enabled. |
| 58 | - if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) { |
|
| 58 | + if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) { |
|
| 59 | 59 | return; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | // Checks if Payment Request is enabled. |
| 63 | - if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) { |
|
| 63 | + if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) { |
|
| 64 | 64 | return; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | // Don't load for change payment method page. |
| 68 | - if ( isset( $_GET['change_payment_method'] ) ) { |
|
| 68 | + if (isset($_GET['change_payment_method'])) { |
|
| 69 | 69 | return; |
| 70 | 70 | } |
| 71 | 71 | |
@@ -79,43 +79,43 @@ discard block |
||
| 79 | 79 | * @version 4.0.0 |
| 80 | 80 | */ |
| 81 | 81 | protected function init() { |
| 82 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
| 83 | - add_action( 'wp', array( $this, 'set_session' ) ); |
|
| 82 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
| 83 | + add_action('wp', array($this, 'set_session')); |
|
| 84 | 84 | |
| 85 | 85 | /* |
| 86 | 86 | * In order to display the Payment Request button in the correct position, |
| 87 | 87 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
| 88 | 88 | * CSS is used to position the button. |
| 89 | 89 | */ |
| 90 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 91 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 92 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 90 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 91 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1); |
|
| 92 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 93 | 93 | } else { |
| 94 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 95 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 94 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1); |
|
| 95 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 99 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 98 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1); |
|
| 99 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 100 | 100 | |
| 101 | - if ( apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
| 102 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 103 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 101 | + if (apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
| 102 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1); |
|
| 103 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
| 107 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
| 108 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
| 109 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
| 110 | - add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) ); |
|
| 111 | - add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) ); |
|
| 112 | - add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) ); |
|
| 113 | - add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) ); |
|
| 106 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
| 107 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
| 108 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
| 109 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
| 110 | + add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart')); |
|
| 111 | + add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data')); |
|
| 112 | + add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart')); |
|
| 113 | + add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors')); |
|
| 114 | 114 | |
| 115 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
| 116 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
| 115 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
| 116 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
| 117 | 117 | |
| 118 | - add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 3 ); |
|
| 118 | + add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 3); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -125,11 +125,11 @@ discard block |
||
| 125 | 125 | * @since 4.0.0 |
| 126 | 126 | */ |
| 127 | 127 | public function set_session() { |
| 128 | - if ( ! is_user_logged_in() ) { |
|
| 128 | + if ( ! is_user_logged_in()) { |
|
| 129 | 129 | $wc_session = new WC_Session_Handler(); |
| 130 | 130 | |
| 131 | - if ( ! $wc_session->has_session() ) { |
|
| 132 | - $wc_session->set_customer_session_cookie( true ); |
|
| 131 | + if ( ! $wc_session->has_session()) { |
|
| 132 | + $wc_session->set_customer_session_cookie(true); |
|
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | } |
@@ -140,15 +140,15 @@ discard block |
||
| 140 | 140 | * @return string |
| 141 | 141 | */ |
| 142 | 142 | protected function get_publishable_key() { |
| 143 | - if ( empty( $this->stripe_settings ) ) { |
|
| 143 | + if (empty($this->stripe_settings)) { |
|
| 144 | 144 | return ''; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - if ( empty( $this->stripe_settings['testmode'] ) ) { |
|
| 147 | + if (empty($this->stripe_settings['testmode'])) { |
|
| 148 | 148 | return ''; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - if ( empty( $this->stripe_settings['test_publishable_key'] ) ) { |
|
| 151 | + if (empty($this->stripe_settings['test_publishable_key'])) { |
|
| 152 | 152 | return ''; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | * @return string |
| 164 | 164 | */ |
| 165 | 165 | public function get_button_type() { |
| 166 | - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
| 166 | + return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * @return string |
| 175 | 175 | */ |
| 176 | 176 | public function get_button_theme() { |
| 177 | - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
| 177 | + return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | * @return string |
| 186 | 186 | */ |
| 187 | 187 | public function get_button_height() { |
| 188 | - return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64'; |
|
| 188 | + return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64'; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -195,40 +195,40 @@ discard block |
||
| 195 | 195 | * @version 4.0.0 |
| 196 | 196 | */ |
| 197 | 197 | public function get_product_data() { |
| 198 | - if ( ! is_product() ) { |
|
| 198 | + if ( ! is_product()) { |
|
| 199 | 199 | return false; |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | global $post; |
| 203 | 203 | |
| 204 | - $product = wc_get_product( $post->ID ); |
|
| 204 | + $product = wc_get_product($post->ID); |
|
| 205 | 205 | |
| 206 | 206 | $data = array(); |
| 207 | 207 | $items = array(); |
| 208 | 208 | |
| 209 | 209 | $items[] = array( |
| 210 | 210 | 'label' => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(), |
| 211 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
| 211 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
| 212 | 212 | ); |
| 213 | 213 | |
| 214 | - if ( wc_tax_enabled() ) { |
|
| 214 | + if (wc_tax_enabled()) { |
|
| 215 | 215 | $items[] = array( |
| 216 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 216 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 217 | 217 | 'amount' => 0, |
| 218 | 218 | 'pending' => true, |
| 219 | 219 | ); |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
| 222 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
| 223 | 223 | $items[] = array( |
| 224 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
| 224 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
| 225 | 225 | 'amount' => 0, |
| 226 | 226 | 'pending' => true, |
| 227 | 227 | ); |
| 228 | 228 | |
| 229 | - $data['shippingOptions'] = array( |
|
| 229 | + $data['shippingOptions'] = array( |
|
| 230 | 230 | 'id' => 'pending', |
| 231 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
| 231 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
| 232 | 232 | 'detail' => '', |
| 233 | 233 | 'amount' => 0, |
| 234 | 234 | ); |
@@ -237,13 +237,13 @@ discard block |
||
| 237 | 237 | $data['displayItems'] = $items; |
| 238 | 238 | $data['total'] = array( |
| 239 | 239 | 'label' => $this->total_label, |
| 240 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
| 240 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
| 241 | 241 | 'pending' => true, |
| 242 | 242 | ); |
| 243 | 243 | |
| 244 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
| 245 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
| 246 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
| 244 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
| 245 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
| 246 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
| 247 | 247 | |
| 248 | 248 | return $data; |
| 249 | 249 | } |
@@ -252,25 +252,25 @@ discard block |
||
| 252 | 252 | * Filters the gateway title to reflect Payment Request type |
| 253 | 253 | * |
| 254 | 254 | */ |
| 255 | - public function filter_gateway_title( $title, $id ) { |
|
| 255 | + public function filter_gateway_title($title, $id) { |
|
| 256 | 256 | global $post; |
| 257 | 257 | |
| 258 | - if ( ! is_object( $post ) ) { |
|
| 258 | + if ( ! is_object($post)) { |
|
| 259 | 259 | return $title; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 263 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
| 262 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 263 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
| 264 | 264 | } else { |
| 265 | - $order = wc_get_order( $post->ID ); |
|
| 266 | - $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
| 265 | + $order = wc_get_order($post->ID); |
|
| 266 | + $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
| 269 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
| 270 | 270 | return $method_title; |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
| 273 | + if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
| 274 | 274 | return $method_title; |
| 275 | 275 | } |
| 276 | 276 | |
@@ -283,10 +283,10 @@ discard block |
||
| 283 | 283 | * @since 3.1.4 |
| 284 | 284 | * @version 4.0.0 |
| 285 | 285 | */ |
| 286 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
| 286 | + public function postal_code_validation($valid, $postcode, $country) { |
|
| 287 | 287 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 288 | 288 | |
| 289 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
| 289 | + if ( ! isset($gateways['stripe'])) { |
|
| 290 | 290 | return $valid; |
| 291 | 291 | } |
| 292 | 292 | |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | * the order and not let it go through. The remedy for now is just to remove this validation. |
| 297 | 297 | * Note that this only works with shipping providers that don't validate full postal codes. |
| 298 | 298 | */ |
| 299 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
| 299 | + if ('GB' === $country || 'CA' === $country) { |
|
| 300 | 300 | return true; |
| 301 | 301 | } |
| 302 | 302 | |
@@ -312,27 +312,27 @@ discard block |
||
| 312 | 312 | * @param array $posted_data The posted data from checkout form. |
| 313 | 313 | * @param object $order |
| 314 | 314 | */ |
| 315 | - public function add_order_meta( $order_id, $posted_data, $order ) { |
|
| 316 | - if ( empty( $_POST['payment_request_type'] ) ) { |
|
| 315 | + public function add_order_meta($order_id, $posted_data, $order) { |
|
| 316 | + if (empty($_POST['payment_request_type'])) { |
|
| 317 | 317 | return; |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
| 320 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
| 321 | 321 | |
| 322 | - if ( 'apple_pay' === $payment_request_type ) { |
|
| 323 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 324 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
| 322 | + if ('apple_pay' === $payment_request_type) { |
|
| 323 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 324 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
| 325 | 325 | } else { |
| 326 | - $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
| 326 | + $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
| 327 | 327 | $order->save(); |
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - if ( 'payment_request_api' === $payment_request_type ) { |
|
| 332 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 333 | - update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' ); |
|
| 331 | + if ('payment_request_api' === $payment_request_type) { |
|
| 332 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 333 | + update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)'); |
|
| 334 | 334 | } else { |
| 335 | - $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
| 335 | + $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
| 336 | 336 | $order->save(); |
| 337 | 337 | } |
| 338 | 338 | } |
@@ -346,11 +346,11 @@ discard block |
||
| 346 | 346 | * @return array |
| 347 | 347 | */ |
| 348 | 348 | public function supported_product_types() { |
| 349 | - return apply_filters( 'wc_stripe_payment_request_supported_types', array( |
|
| 349 | + return apply_filters('wc_stripe_payment_request_supported_types', array( |
|
| 350 | 350 | 'simple', |
| 351 | 351 | 'variable', |
| 352 | 352 | 'variation', |
| 353 | - ) ); |
|
| 353 | + )); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | /** |
@@ -361,15 +361,15 @@ discard block |
||
| 361 | 361 | * @return bool |
| 362 | 362 | */ |
| 363 | 363 | public function allowed_items_in_cart() { |
| 364 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
| 365 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
| 364 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
| 365 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
| 366 | 366 | |
| 367 | - if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
| 367 | + if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
| 368 | 368 | return false; |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | // Pre Orders compatbility where we don't support charge upon release. |
| 372 | - 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() ) ) { |
|
| 372 | + 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())) { |
|
| 373 | 373 | return false; |
| 374 | 374 | } |
| 375 | 375 | } |
@@ -384,71 +384,71 @@ discard block |
||
| 384 | 384 | * @version 4.0.0 |
| 385 | 385 | */ |
| 386 | 386 | public function scripts() { |
| 387 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 387 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
| 388 | 388 | return; |
| 389 | 389 | } |
| 390 | 390 | |
| 391 | - if ( is_product() ) { |
|
| 391 | + if (is_product()) { |
|
| 392 | 392 | global $post; |
| 393 | 393 | |
| 394 | - $product = wc_get_product( $post->ID ); |
|
| 394 | + $product = wc_get_product($post->ID); |
|
| 395 | 395 | |
| 396 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 396 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 397 | 397 | return; |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
| 400 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
| 401 | 401 | return; |
| 402 | 402 | } |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 405 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 406 | 406 | |
| 407 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
| 408 | - 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 ); |
|
| 407 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
| 408 | + 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); |
|
| 409 | 409 | |
| 410 | 410 | wp_localize_script( |
| 411 | 411 | 'wc_stripe_payment_request', |
| 412 | 412 | 'wc_stripe_payment_request_params', |
| 413 | 413 | array( |
| 414 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
| 414 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
| 415 | 415 | 'stripe' => array( |
| 416 | 416 | 'key' => $this->get_publishable_key(), |
| 417 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
| 417 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
| 418 | 418 | ), |
| 419 | 419 | 'nonce' => array( |
| 420 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
| 421 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
| 422 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
| 423 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
| 424 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
| 425 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
| 426 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
| 427 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
| 420 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
| 421 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
| 422 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
| 423 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
| 424 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
| 425 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
| 426 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
| 427 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
| 428 | 428 | ), |
| 429 | 429 | 'i18n' => array( |
| 430 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
| 430 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
| 431 | 431 | /* translators: Do not translate the [option] placeholder */ |
| 432 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
| 432 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
| 433 | 433 | ), |
| 434 | 434 | 'checkout' => array( |
| 435 | 435 | 'url' => wc_get_checkout_url(), |
| 436 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
| 437 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 436 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
| 437 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 438 | 438 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
| 439 | 439 | ), |
| 440 | 440 | 'button' => array( |
| 441 | 441 | 'type' => $this->get_button_type(), |
| 442 | 442 | 'theme' => $this->get_button_theme(), |
| 443 | 443 | 'height' => $this->get_button_height(), |
| 444 | - 'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US. |
|
| 444 | + 'locale' => substr(get_locale(), 0, 2), // Default format is en_US. |
|
| 445 | 445 | ), |
| 446 | 446 | 'is_product_page' => is_product(), |
| 447 | 447 | 'product' => $this->get_product_data(), |
| 448 | 448 | ) |
| 449 | 449 | ); |
| 450 | 450 | |
| 451 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
| 451 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | /** |
@@ -460,35 +460,35 @@ discard block |
||
| 460 | 460 | public function display_payment_request_button_html() { |
| 461 | 461 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 462 | 462 | |
| 463 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
| 463 | + if ( ! isset($gateways['stripe'])) { |
|
| 464 | 464 | return; |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 467 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
| 468 | 468 | return; |
| 469 | 469 | } |
| 470 | 470 | |
| 471 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
| 471 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
| 472 | 472 | return; |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | - if ( is_product() ) { |
|
| 475 | + if (is_product()) { |
|
| 476 | 476 | global $post; |
| 477 | 477 | |
| 478 | - $product = wc_get_product( $post->ID ); |
|
| 478 | + $product = wc_get_product($post->ID); |
|
| 479 | 479 | |
| 480 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 480 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 481 | 481 | return; |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | // Pre Orders charge upon release not supported. |
| 485 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
| 486 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
| 485 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
| 486 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
| 487 | 487 | return; |
| 488 | 488 | } |
| 489 | 489 | } else { |
| 490 | - if ( ! $this->allowed_items_in_cart() ) { |
|
| 491 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
| 490 | + if ( ! $this->allowed_items_in_cart()) { |
|
| 491 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
| 492 | 492 | return; |
| 493 | 493 | } |
| 494 | 494 | } |
@@ -510,40 +510,40 @@ discard block |
||
| 510 | 510 | public function display_payment_request_button_separator_html() { |
| 511 | 511 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 512 | 512 | |
| 513 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
| 513 | + if ( ! isset($gateways['stripe'])) { |
|
| 514 | 514 | return; |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 517 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
| 518 | 518 | return; |
| 519 | 519 | } |
| 520 | 520 | |
| 521 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
| 521 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
| 522 | 522 | return; |
| 523 | 523 | } |
| 524 | 524 | |
| 525 | - if ( is_product() ) { |
|
| 525 | + if (is_product()) { |
|
| 526 | 526 | global $post; |
| 527 | 527 | |
| 528 | - $product = wc_get_product( $post->ID ); |
|
| 528 | + $product = wc_get_product($post->ID); |
|
| 529 | 529 | |
| 530 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 530 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 531 | 531 | return; |
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | // Pre Orders charge upon release not supported. |
| 535 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
| 536 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
| 535 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
| 536 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
| 537 | 537 | return; |
| 538 | 538 | } |
| 539 | 539 | } else { |
| 540 | - if ( ! $this->allowed_items_in_cart() ) { |
|
| 541 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
| 540 | + if ( ! $this->allowed_items_in_cart()) { |
|
| 541 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
| 542 | 542 | return; |
| 543 | 543 | } |
| 544 | 544 | } |
| 545 | 545 | ?> |
| 546 | - <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> |
|
| 546 | + <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> |
|
| 547 | 547 | <?php |
| 548 | 548 | } |
| 549 | 549 | |
@@ -554,11 +554,11 @@ discard block |
||
| 554 | 554 | * @version 4.0.0 |
| 555 | 555 | */ |
| 556 | 556 | public function ajax_log_errors() { |
| 557 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
| 557 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
| 558 | 558 | |
| 559 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
| 559 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
| 560 | 560 | |
| 561 | - WC_Stripe_Logger::log( $errors ); |
|
| 561 | + WC_Stripe_Logger::log($errors); |
|
| 562 | 562 | |
| 563 | 563 | exit; |
| 564 | 564 | } |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | * @version 4.0.0 |
| 571 | 571 | */ |
| 572 | 572 | public function ajax_clear_cart() { |
| 573 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
| 573 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
| 574 | 574 | |
| 575 | 575 | WC()->cart->empty_cart(); |
| 576 | 576 | exit; |
@@ -580,10 +580,10 @@ discard block |
||
| 580 | 580 | * Get cart details. |
| 581 | 581 | */ |
| 582 | 582 | public function ajax_get_cart_details() { |
| 583 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
| 583 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
| 584 | 584 | |
| 585 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 586 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 585 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 586 | + define('WOOCOMMERCE_CART', true); |
|
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | WC()->cart->calculate_totals(); |
@@ -594,14 +594,14 @@ discard block |
||
| 594 | 594 | $data = array( |
| 595 | 595 | 'shipping_required' => WC()->cart->needs_shipping(), |
| 596 | 596 | 'order_data' => array( |
| 597 | - 'currency' => strtolower( $currency ), |
|
| 598 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 597 | + 'currency' => strtolower($currency), |
|
| 598 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 599 | 599 | ), |
| 600 | 600 | ); |
| 601 | 601 | |
| 602 | 602 | $data['order_data'] += $this->build_display_items(); |
| 603 | 603 | |
| 604 | - wp_send_json( $data ); |
|
| 604 | + wp_send_json($data); |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | /** |
@@ -612,47 +612,47 @@ discard block |
||
| 612 | 612 | * @see WC_Shipping::get_packages(). |
| 613 | 613 | */ |
| 614 | 614 | public function ajax_get_shipping_options() { |
| 615 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
| 615 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
| 616 | 616 | |
| 617 | 617 | try { |
| 618 | 618 | // Set the shipping package. |
| 619 | - $posted = filter_input_array( INPUT_POST, array( |
|
| 619 | + $posted = filter_input_array(INPUT_POST, array( |
|
| 620 | 620 | 'country' => FILTER_SANITIZE_STRING, |
| 621 | 621 | 'state' => FILTER_SANITIZE_STRING, |
| 622 | 622 | 'postcode' => FILTER_SANITIZE_STRING, |
| 623 | 623 | 'city' => FILTER_SANITIZE_STRING, |
| 624 | 624 | 'address' => FILTER_SANITIZE_STRING, |
| 625 | 625 | 'address_2' => FILTER_SANITIZE_STRING, |
| 626 | - ) ); |
|
| 626 | + )); |
|
| 627 | 627 | |
| 628 | - $this->calculate_shipping( $posted ); |
|
| 628 | + $this->calculate_shipping($posted); |
|
| 629 | 629 | |
| 630 | 630 | // Set the shipping options. |
| 631 | 631 | $data = array(); |
| 632 | 632 | $packages = WC()->shipping->get_packages(); |
| 633 | 633 | |
| 634 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
| 635 | - foreach ( $packages as $package_key => $package ) { |
|
| 636 | - if ( empty( $package['rates'] ) ) { |
|
| 637 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 634 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
| 635 | + foreach ($packages as $package_key => $package) { |
|
| 636 | + if (empty($package['rates'])) { |
|
| 637 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 638 | 638 | } |
| 639 | 639 | |
| 640 | - foreach ( $package['rates'] as $key => $rate ) { |
|
| 640 | + foreach ($package['rates'] as $key => $rate) { |
|
| 641 | 641 | $data['shipping_options'][] = array( |
| 642 | 642 | 'id' => $rate->id, |
| 643 | 643 | 'label' => $rate->label, |
| 644 | 644 | 'detail' => '', |
| 645 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
| 645 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
| 646 | 646 | ); |
| 647 | 647 | } |
| 648 | 648 | } |
| 649 | 649 | } else { |
| 650 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 650 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 651 | 651 | } |
| 652 | 652 | |
| 653 | - if ( isset( $data[0] ) ) { |
|
| 653 | + if (isset($data[0])) { |
|
| 654 | 654 | // Auto select the first shipping method. |
| 655 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
| 655 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | WC()->cart->calculate_totals(); |
@@ -660,12 +660,12 @@ discard block |
||
| 660 | 660 | $data += $this->build_display_items(); |
| 661 | 661 | $data['result'] = 'success'; |
| 662 | 662 | |
| 663 | - wp_send_json( $data ); |
|
| 664 | - } catch ( Exception $e ) { |
|
| 663 | + wp_send_json($data); |
|
| 664 | + } catch (Exception $e) { |
|
| 665 | 665 | $data += $this->build_display_items(); |
| 666 | 666 | $data['result'] = 'invalid_shipping_address'; |
| 667 | 667 | |
| 668 | - wp_send_json( $data ); |
|
| 668 | + wp_send_json($data); |
|
| 669 | 669 | } |
| 670 | 670 | } |
| 671 | 671 | |
@@ -673,22 +673,22 @@ discard block |
||
| 673 | 673 | * Update shipping method. |
| 674 | 674 | */ |
| 675 | 675 | public function ajax_update_shipping_method() { |
| 676 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
| 676 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
| 677 | 677 | |
| 678 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 679 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 678 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 679 | + define('WOOCOMMERCE_CART', true); |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
| 683 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
| 682 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
| 683 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
| 684 | 684 | |
| 685 | - if ( is_array( $shipping_method ) ) { |
|
| 686 | - foreach ( $shipping_method as $i => $value ) { |
|
| 687 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
| 685 | + if (is_array($shipping_method)) { |
|
| 686 | + foreach ($shipping_method as $i => $value) { |
|
| 687 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
| 688 | 688 | } |
| 689 | 689 | } |
| 690 | 690 | |
| 691 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
| 691 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
| 692 | 692 | |
| 693 | 693 | WC()->cart->calculate_totals(); |
| 694 | 694 | |
@@ -696,7 +696,7 @@ discard block |
||
| 696 | 696 | $data += $this->build_display_items(); |
| 697 | 697 | $data['result'] = 'success'; |
| 698 | 698 | |
| 699 | - wp_send_json( $data ); |
|
| 699 | + wp_send_json($data); |
|
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | /** |
@@ -707,31 +707,31 @@ discard block |
||
| 707 | 707 | * @return array $data |
| 708 | 708 | */ |
| 709 | 709 | public function ajax_get_selected_product_data() { |
| 710 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
| 710 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
| 711 | 711 | |
| 712 | - $product_id = absint( $_POST['product_id'] ); |
|
| 713 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
| 712 | + $product_id = absint($_POST['product_id']); |
|
| 713 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
| 714 | 714 | |
| 715 | - $product = wc_get_product( $product_id ); |
|
| 715 | + $product = wc_get_product($product_id); |
|
| 716 | 716 | |
| 717 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
| 718 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
| 717 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
| 718 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
| 719 | 719 | |
| 720 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 721 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
| 720 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 721 | + $variation_id = $product->get_matching_variation($attributes); |
|
| 722 | 722 | } else { |
| 723 | - $data_store = WC_Data_Store::load( 'product' ); |
|
| 724 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
| 723 | + $data_store = WC_Data_Store::load('product'); |
|
| 724 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
| 725 | 725 | } |
| 726 | 726 | |
| 727 | - if ( ! empty( $variation_id ) ) { |
|
| 728 | - $product = wc_get_product( $variation_id ); |
|
| 727 | + if ( ! empty($variation_id)) { |
|
| 728 | + $product = wc_get_product($variation_id); |
|
| 729 | 729 | } |
| 730 | - } elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
| 731 | - $product = wc_get_product( $product_id ); |
|
| 730 | + } elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
| 731 | + $product = wc_get_product($product_id); |
|
| 732 | 732 | } |
| 733 | 733 | |
| 734 | - $total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ); |
|
| 734 | + $total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()); |
|
| 735 | 735 | |
| 736 | 736 | $quantity_label = 1 < $qty ? ' (x' . $qty . ')' : ''; |
| 737 | 737 | |
@@ -739,28 +739,28 @@ discard block |
||
| 739 | 739 | $items = array(); |
| 740 | 740 | |
| 741 | 741 | $items[] = array( |
| 742 | - 'label' => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label, |
|
| 743 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
| 742 | + 'label' => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label, |
|
| 743 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
| 744 | 744 | ); |
| 745 | 745 | |
| 746 | - if ( wc_tax_enabled() ) { |
|
| 746 | + if (wc_tax_enabled()) { |
|
| 747 | 747 | $items[] = array( |
| 748 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 748 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 749 | 749 | 'amount' => 0, |
| 750 | 750 | 'pending' => true, |
| 751 | 751 | ); |
| 752 | 752 | } |
| 753 | 753 | |
| 754 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
| 754 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
| 755 | 755 | $items[] = array( |
| 756 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
| 756 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
| 757 | 757 | 'amount' => 0, |
| 758 | 758 | 'pending' => true, |
| 759 | 759 | ); |
| 760 | 760 | |
| 761 | - $data['shippingOptions'] = array( |
|
| 761 | + $data['shippingOptions'] = array( |
|
| 762 | 762 | 'id' => 'pending', |
| 763 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
| 763 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
| 764 | 764 | 'detail' => '', |
| 765 | 765 | 'amount' => 0, |
| 766 | 766 | ); |
@@ -769,15 +769,15 @@ discard block |
||
| 769 | 769 | $data['displayItems'] = $items; |
| 770 | 770 | $data['total'] = array( |
| 771 | 771 | 'label' => $this->total_label, |
| 772 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
| 772 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
| 773 | 773 | 'pending' => true, |
| 774 | 774 | ); |
| 775 | 775 | |
| 776 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
| 777 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
| 778 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
| 776 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
| 777 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
| 778 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
| 779 | 779 | |
| 780 | - wp_send_json( $data ); |
|
| 780 | + wp_send_json($data); |
|
| 781 | 781 | } |
| 782 | 782 | |
| 783 | 783 | /** |
@@ -788,37 +788,37 @@ discard block |
||
| 788 | 788 | * @return array $data |
| 789 | 789 | */ |
| 790 | 790 | public function ajax_add_to_cart() { |
| 791 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
| 791 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
| 792 | 792 | |
| 793 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 794 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 793 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 794 | + define('WOOCOMMERCE_CART', true); |
|
| 795 | 795 | } |
| 796 | 796 | |
| 797 | 797 | WC()->shipping->reset_shipping(); |
| 798 | 798 | |
| 799 | - $product_id = absint( $_POST['product_id'] ); |
|
| 800 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
| 799 | + $product_id = absint($_POST['product_id']); |
|
| 800 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
| 801 | 801 | |
| 802 | - $product = wc_get_product( $product_id ); |
|
| 802 | + $product = wc_get_product($product_id); |
|
| 803 | 803 | |
| 804 | 804 | // First empty the cart to prevent wrong calculation. |
| 805 | 805 | WC()->cart->empty_cart(); |
| 806 | 806 | |
| 807 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
| 808 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
| 807 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
| 808 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
| 809 | 809 | |
| 810 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 811 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
| 810 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 811 | + $variation_id = $product->get_matching_variation($attributes); |
|
| 812 | 812 | } else { |
| 813 | - $data_store = WC_Data_Store::load( 'product' ); |
|
| 814 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
| 813 | + $data_store = WC_Data_Store::load('product'); |
|
| 814 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
| 815 | 815 | } |
| 816 | 816 | |
| 817 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
| 817 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
| 818 | 818 | } |
| 819 | 819 | |
| 820 | - if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
| 821 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
| 820 | + if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
| 821 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | WC()->cart->calculate_totals(); |
@@ -827,7 +827,7 @@ discard block |
||
| 827 | 827 | $data += $this->build_display_items(); |
| 828 | 828 | $data['result'] = 'success'; |
| 829 | 829 | |
| 830 | - wp_send_json( $data ); |
|
| 830 | + wp_send_json($data); |
|
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | /** |
@@ -840,31 +840,31 @@ discard block |
||
| 840 | 840 | * @version 4.0.0 |
| 841 | 841 | */ |
| 842 | 842 | public function normalize_state() { |
| 843 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
| 844 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
| 845 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
| 846 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
| 843 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
| 844 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
| 845 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
| 846 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
| 847 | 847 | |
| 848 | - if ( $billing_state && $billing_country ) { |
|
| 849 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
| 848 | + if ($billing_state && $billing_country) { |
|
| 849 | + $valid_states = WC()->countries->get_states($billing_country); |
|
| 850 | 850 | |
| 851 | 851 | // Valid states found for country. |
| 852 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
| 853 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
| 854 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
| 852 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
| 853 | + foreach ($valid_states as $state_abbr => $state) { |
|
| 854 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
| 855 | 855 | $_POST['billing_state'] = $state_abbr; |
| 856 | 856 | } |
| 857 | 857 | } |
| 858 | 858 | } |
| 859 | 859 | } |
| 860 | 860 | |
| 861 | - if ( $shipping_state && $shipping_country ) { |
|
| 862 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
| 861 | + if ($shipping_state && $shipping_country) { |
|
| 862 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
| 863 | 863 | |
| 864 | 864 | // Valid states found for country. |
| 865 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
| 866 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
| 867 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
| 865 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
| 866 | + foreach ($valid_states as $state_abbr => $state) { |
|
| 867 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
| 868 | 868 | $_POST['shipping_state'] = $state_abbr; |
| 869 | 869 | } |
| 870 | 870 | } |
@@ -879,19 +879,19 @@ discard block |
||
| 879 | 879 | * @version 4.0.0 |
| 880 | 880 | */ |
| 881 | 881 | public function ajax_create_order() { |
| 882 | - if ( WC()->cart->is_empty() ) { |
|
| 883 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
| 882 | + if (WC()->cart->is_empty()) { |
|
| 883 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
| 884 | 884 | } |
| 885 | 885 | |
| 886 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
| 887 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
| 886 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
| 887 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
| 888 | 888 | } |
| 889 | 889 | |
| 890 | 890 | $this->normalize_state(); |
| 891 | 891 | |
| 892 | 892 | WC()->checkout()->process_checkout(); |
| 893 | 893 | |
| 894 | - die( 0 ); |
|
| 894 | + die(0); |
|
| 895 | 895 | } |
| 896 | 896 | |
| 897 | 897 | /** |
@@ -901,7 +901,7 @@ discard block |
||
| 901 | 901 | * @version 4.0.0 |
| 902 | 902 | * @param array $address |
| 903 | 903 | */ |
| 904 | - protected function calculate_shipping( $address = array() ) { |
|
| 904 | + protected function calculate_shipping($address = array()) { |
|
| 905 | 905 | global $states; |
| 906 | 906 | |
| 907 | 907 | $country = $address['country']; |
@@ -918,28 +918,28 @@ discard block |
||
| 918 | 918 | * In some versions of Chrome, state can be a full name. So we need |
| 919 | 919 | * to convert that to abbreviation as WC is expecting that. |
| 920 | 920 | */ |
| 921 | - if ( 2 < strlen( $state ) ) { |
|
| 922 | - $state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] ); |
|
| 921 | + if (2 < strlen($state)) { |
|
| 922 | + $state = array_search(ucfirst(strtolower($state)), $states[$country]); |
|
| 923 | 923 | } |
| 924 | 924 | |
| 925 | 925 | WC()->shipping->reset_shipping(); |
| 926 | 926 | |
| 927 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
| 928 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
| 927 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
| 928 | + $postcode = wc_format_postcode($postcode, $country); |
|
| 929 | 929 | } |
| 930 | 930 | |
| 931 | - if ( $country ) { |
|
| 932 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
| 933 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
| 931 | + if ($country) { |
|
| 932 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
| 933 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
| 934 | 934 | } else { |
| 935 | 935 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
| 936 | 936 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
| 937 | 937 | } |
| 938 | 938 | |
| 939 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 940 | - WC()->customer->calculated_shipping( true ); |
|
| 939 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 940 | + WC()->customer->calculated_shipping(true); |
|
| 941 | 941 | } else { |
| 942 | - WC()->customer->set_calculated_shipping( true ); |
|
| 942 | + WC()->customer->set_calculated_shipping(true); |
|
| 943 | 943 | WC()->customer->save(); |
| 944 | 944 | } |
| 945 | 945 | |
@@ -956,17 +956,17 @@ discard block |
||
| 956 | 956 | $packages[0]['destination']['address'] = $address_1; |
| 957 | 957 | $packages[0]['destination']['address_2'] = $address_2; |
| 958 | 958 | |
| 959 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
| 960 | - if ( $item['data']->needs_shipping() ) { |
|
| 961 | - if ( isset( $item['line_total'] ) ) { |
|
| 959 | + foreach (WC()->cart->get_cart() as $item) { |
|
| 960 | + if ($item['data']->needs_shipping()) { |
|
| 961 | + if (isset($item['line_total'])) { |
|
| 962 | 962 | $packages[0]['contents_cost'] += $item['line_total']; |
| 963 | 963 | } |
| 964 | 964 | } |
| 965 | 965 | } |
| 966 | 966 | |
| 967 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
| 967 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
| 968 | 968 | |
| 969 | - WC()->shipping->calculate_shipping( $packages ); |
|
| 969 | + WC()->shipping->calculate_shipping($packages); |
|
| 970 | 970 | } |
| 971 | 971 | |
| 972 | 972 | /** |
@@ -975,19 +975,19 @@ discard block |
||
| 975 | 975 | * @since 3.1.0 |
| 976 | 976 | * @version 4.0.0 |
| 977 | 977 | */ |
| 978 | - protected function build_shipping_methods( $shipping_methods ) { |
|
| 979 | - if ( empty( $shipping_methods ) ) { |
|
| 978 | + protected function build_shipping_methods($shipping_methods) { |
|
| 979 | + if (empty($shipping_methods)) { |
|
| 980 | 980 | return array(); |
| 981 | 981 | } |
| 982 | 982 | |
| 983 | 983 | $shipping = array(); |
| 984 | 984 | |
| 985 | - foreach ( $shipping_methods as $method ) { |
|
| 985 | + foreach ($shipping_methods as $method) { |
|
| 986 | 986 | $shipping[] = array( |
| 987 | 987 | 'id' => $method['id'], |
| 988 | 988 | 'label' => $method['label'], |
| 989 | 989 | 'detail' => '', |
| 990 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
| 990 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
| 991 | 991 | ); |
| 992 | 992 | } |
| 993 | 993 | |
@@ -1001,69 +1001,69 @@ discard block |
||
| 1001 | 1001 | * @version 4.0.0 |
| 1002 | 1002 | */ |
| 1003 | 1003 | protected function build_display_items() { |
| 1004 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 1005 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 1004 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 1005 | + define('WOOCOMMERCE_CART', true); |
|
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | 1008 | $items = array(); |
| 1009 | 1009 | $subtotal = 0; |
| 1010 | 1010 | |
| 1011 | 1011 | // Default show only subtotal instead of itemization. |
| 1012 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
| 1013 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
| 1012 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
| 1013 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
| 1014 | 1014 | $amount = $cart_item['line_subtotal']; |
| 1015 | - $subtotal += $cart_item['line_subtotal']; |
|
| 1015 | + $subtotal += $cart_item['line_subtotal']; |
|
| 1016 | 1016 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
| 1017 | 1017 | |
| 1018 | 1018 | $product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
| 1019 | 1019 | |
| 1020 | 1020 | $item = array( |
| 1021 | 1021 | 'label' => $product_name . $quantity_label, |
| 1022 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
| 1022 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
| 1023 | 1023 | ); |
| 1024 | 1024 | |
| 1025 | 1025 | $items[] = $item; |
| 1026 | 1026 | } |
| 1027 | 1027 | } |
| 1028 | 1028 | |
| 1029 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
| 1030 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
| 1031 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
| 1032 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
| 1033 | - $order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ); |
|
| 1029 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
| 1030 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
| 1031 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
| 1032 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
| 1033 | + $order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp); |
|
| 1034 | 1034 | |
| 1035 | - if ( wc_tax_enabled() ) { |
|
| 1035 | + if (wc_tax_enabled()) { |
|
| 1036 | 1036 | $items[] = array( |
| 1037 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
| 1038 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
| 1037 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
| 1038 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
| 1039 | 1039 | ); |
| 1040 | 1040 | } |
| 1041 | 1041 | |
| 1042 | - if ( WC()->cart->needs_shipping() ) { |
|
| 1042 | + if (WC()->cart->needs_shipping()) { |
|
| 1043 | 1043 | $items[] = array( |
| 1044 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
| 1045 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
| 1044 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
| 1045 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
| 1046 | 1046 | ); |
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | - if ( WC()->cart->has_discount() ) { |
|
| 1049 | + if (WC()->cart->has_discount()) { |
|
| 1050 | 1050 | $items[] = array( |
| 1051 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
| 1052 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
| 1051 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
| 1052 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
| 1053 | 1053 | ); |
| 1054 | 1054 | } |
| 1055 | 1055 | |
| 1056 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
| 1056 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
| 1057 | 1057 | $cart_fees = WC()->cart->fees; |
| 1058 | 1058 | } else { |
| 1059 | 1059 | $cart_fees = WC()->cart->get_fees(); |
| 1060 | 1060 | } |
| 1061 | 1061 | |
| 1062 | 1062 | // Include fees and taxes as display items. |
| 1063 | - foreach ( $cart_fees as $key => $fee ) { |
|
| 1063 | + foreach ($cart_fees as $key => $fee) { |
|
| 1064 | 1064 | $items[] = array( |
| 1065 | 1065 | 'label' => $fee->name, |
| 1066 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
| 1066 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
| 1067 | 1067 | ); |
| 1068 | 1068 | } |
| 1069 | 1069 | |
@@ -1071,7 +1071,7 @@ discard block |
||
| 1071 | 1071 | 'displayItems' => $items, |
| 1072 | 1072 | 'total' => array( |
| 1073 | 1073 | 'label' => $this->total_label, |
| 1074 | - 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
| 1074 | + 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
| 1075 | 1075 | 'pending' => false, |
| 1076 | 1076 | ), |
| 1077 | 1077 | ); |
@@ -1,12 +1,12 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * DEPRECATED DO NOT USE!! |
| 8 | 8 | */ |
| 9 | -if ( ! class_exists( 'WC_Stripe_Apple_Pay' ) ) { |
|
| 9 | +if ( ! class_exists('WC_Stripe_Apple_Pay')) { |
|
| 10 | 10 | class WC_Stripe_Apple_Pay { |
| 11 | 11 | /** |
| 12 | 12 | * This Instance. |
@@ -20,15 +20,15 @@ discard block |
||
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | public static function instance() { |
| 23 | - WC_Stripe_Logger::log( "DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance." ); |
|
| 23 | + WC_Stripe_Logger::log("DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance."); |
|
| 24 | 24 | return self::$_this; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - public function __get( $var ) { |
|
| 27 | + public function __get($var) { |
|
| 28 | 28 | return null; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - public function __call( $name, $arguments ) { |
|
| 31 | + public function __call($name, $arguments) { |
|
| 32 | 32 | return null; |
| 33 | 33 | } |
| 34 | 34 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -119,9 +119,9 @@ discard block |
||
| 119 | 119 | */ |
| 120 | 120 | public function __construct() { |
| 121 | 121 | $this->id = 'stripe'; |
| 122 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
| 122 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
| 123 | 123 | /* translators: 1) link to Stripe register page 2) link to Stripe api keys page */ |
| 124 | - $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' ); |
|
| 124 | + $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'); |
|
| 125 | 125 | $this->has_fields = true; |
| 126 | 126 | $this->supports = array( |
| 127 | 127 | 'products', |
@@ -148,38 +148,38 @@ discard block |
||
| 148 | 148 | $this->init_settings(); |
| 149 | 149 | |
| 150 | 150 | // Get setting values. |
| 151 | - $this->title = $this->get_option( 'title' ); |
|
| 152 | - $this->description = $this->get_option( 'description' ); |
|
| 153 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 154 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
| 155 | - $this->inline_cc_form = 'yes' === $this->get_option( 'inline_cc_form' ); |
|
| 156 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
| 157 | - $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) ); |
|
| 158 | - $this->three_d_secure = 'yes' === $this->get_option( 'three_d_secure' ); |
|
| 159 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
| 160 | - $this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' ); |
|
| 161 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
| 162 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
| 163 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
| 164 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
| 165 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
| 166 | - $this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
| 167 | - $this->apple_pay_domain_set = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' ); |
|
| 151 | + $this->title = $this->get_option('title'); |
|
| 152 | + $this->description = $this->get_option('description'); |
|
| 153 | + $this->enabled = $this->get_option('enabled'); |
|
| 154 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
| 155 | + $this->inline_cc_form = 'yes' === $this->get_option('inline_cc_form'); |
|
| 156 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
| 157 | + $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor')); |
|
| 158 | + $this->three_d_secure = 'yes' === $this->get_option('three_d_secure'); |
|
| 159 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
| 160 | + $this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale'); |
|
| 161 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
| 162 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
| 163 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
| 164 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
| 165 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
| 166 | + $this->payment_request = 'yes' === $this->get_option('payment_request', 'yes'); |
|
| 167 | + $this->apple_pay_domain_set = 'yes' === $this->get_option('apple_pay_domain_set', 'no'); |
|
| 168 | 168 | $this->apple_pay_verify_notice = ''; |
| 169 | 169 | |
| 170 | - if ( $this->stripe_checkout ) { |
|
| 171 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
| 170 | + if ($this->stripe_checkout) { |
|
| 171 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
| 174 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
| 175 | 175 | |
| 176 | 176 | $this->init_apple_pay(); |
| 177 | 177 | |
| 178 | 178 | // Hooks. |
| 179 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 180 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
|
| 181 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
| 182 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 179 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 180 | + add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); |
|
| 181 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
| 182 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -198,17 +198,17 @@ discard block |
||
| 198 | 198 | $icons_str .= $icons['amex']; |
| 199 | 199 | $icons_str .= $icons['mastercard']; |
| 200 | 200 | |
| 201 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
| 201 | + if ('USD' === get_woocommerce_currency()) { |
|
| 202 | 202 | $icons_str .= $icons['discover']; |
| 203 | 203 | $icons_str .= $icons['jcb']; |
| 204 | 204 | $icons_str .= $icons['diners']; |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - if ( $this->bitcoin && $this->stripe_checkout ) { |
|
| 207 | + if ($this->bitcoin && $this->stripe_checkout) { |
|
| 208 | 208 | $icons_str .= $icons['bitcoin']; |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 211 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -220,9 +220,9 @@ discard block |
||
| 220 | 220 | public function init_apple_pay() { |
| 221 | 221 | if ( |
| 222 | 222 | is_admin() && |
| 223 | - isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && |
|
| 224 | - isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] && |
|
| 225 | - isset( $_GET['section'] ) && 'stripe' === $_GET['section'] && |
|
| 223 | + isset($_GET['page']) && 'wc-settings' === $_GET['page'] && |
|
| 224 | + isset($_GET['tab']) && 'checkout' === $_GET['tab'] && |
|
| 225 | + isset($_GET['section']) && 'stripe' === $_GET['section'] && |
|
| 226 | 226 | $this->payment_request |
| 227 | 227 | ) { |
| 228 | 228 | $this->process_apple_pay_verification(); |
@@ -236,9 +236,9 @@ discard block |
||
| 236 | 236 | * @version 3.1.0 |
| 237 | 237 | * @param string $secret_key |
| 238 | 238 | */ |
| 239 | - private function register_apple_pay_domain( $secret_key = '' ) { |
|
| 240 | - if ( empty( $secret_key ) ) { |
|
| 241 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
| 239 | + private function register_apple_pay_domain($secret_key = '') { |
|
| 240 | + if (empty($secret_key)) { |
|
| 241 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -252,23 +252,23 @@ discard block |
||
| 252 | 252 | 'Authorization' => 'Bearer ' . $secret_key, |
| 253 | 253 | ); |
| 254 | 254 | |
| 255 | - $response = wp_remote_post( $endpoint, array( |
|
| 255 | + $response = wp_remote_post($endpoint, array( |
|
| 256 | 256 | 'headers' => $headers, |
| 257 | - 'body' => http_build_query( $data ), |
|
| 258 | - ) ); |
|
| 257 | + 'body' => http_build_query($data), |
|
| 258 | + )); |
|
| 259 | 259 | |
| 260 | - if ( is_wp_error( $response ) ) { |
|
| 260 | + if (is_wp_error($response)) { |
|
| 261 | 261 | /* translators: error message */ |
| 262 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
| 262 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - if ( 200 !== $response['response']['code'] ) { |
|
| 266 | - $parsed_response = json_decode( $response['body'] ); |
|
| 265 | + if (200 !== $response['response']['code']) { |
|
| 266 | + $parsed_response = json_decode($response['body']); |
|
| 267 | 267 | |
| 268 | 268 | $this->apple_pay_verify_notice = $parsed_response->error->message; |
| 269 | 269 | |
| 270 | 270 | /* translators: error message */ |
| 271 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) ); |
|
| 271 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message)); |
|
| 272 | 272 | } |
| 273 | 273 | } |
| 274 | 274 | |
@@ -279,48 +279,48 @@ discard block |
||
| 279 | 279 | * @version 3.1.0 |
| 280 | 280 | */ |
| 281 | 281 | public function process_apple_pay_verification() { |
| 282 | - $gateway_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
| 282 | + $gateway_settings = get_option('woocommerce_stripe_settings', array()); |
|
| 283 | 283 | |
| 284 | 284 | try { |
| 285 | - $path = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] ); |
|
| 285 | + $path = untrailingslashit($_SERVER['DOCUMENT_ROOT']); |
|
| 286 | 286 | $dir = '.well-known'; |
| 287 | 287 | $file = 'apple-developer-merchantid-domain-association'; |
| 288 | 288 | $fullpath = $path . '/' . $dir . '/' . $file; |
| 289 | 289 | |
| 290 | - if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) { |
|
| 290 | + if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) { |
|
| 291 | 291 | return; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - if ( ! file_exists( $path . '/' . $dir ) ) { |
|
| 295 | - if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) { |
|
| 296 | - throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
| 294 | + if ( ! file_exists($path . '/' . $dir)) { |
|
| 295 | + if ( ! @mkdir($path . '/' . $dir, 0755)) { |
|
| 296 | + throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe')); |
|
| 297 | 297 | } |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - if ( ! file_exists( $fullpath ) ) { |
|
| 301 | - if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { |
|
| 302 | - throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
| 300 | + if ( ! file_exists($fullpath)) { |
|
| 301 | + if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { |
|
| 302 | + throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe')); |
|
| 303 | 303 | } |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | // At this point then the domain association folder and file should be available. |
| 307 | 307 | // Proceed to verify/and or verify again. |
| 308 | - $this->register_apple_pay_domain( $this->secret_key ); |
|
| 308 | + $this->register_apple_pay_domain($this->secret_key); |
|
| 309 | 309 | |
| 310 | 310 | // No errors to this point, verification success! |
| 311 | 311 | $gateway_settings['apple_pay_domain_set'] = 'yes'; |
| 312 | 312 | $this->apple_pay_domain_set = true; |
| 313 | 313 | |
| 314 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
| 314 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
| 315 | 315 | |
| 316 | - WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' ); |
|
| 316 | + WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!'); |
|
| 317 | 317 | |
| 318 | - } catch ( Exception $e ) { |
|
| 318 | + } catch (Exception $e) { |
|
| 319 | 319 | $gateway_settings['apple_pay_domain_set'] = 'no'; |
| 320 | 320 | |
| 321 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
| 321 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
| 322 | 322 | |
| 323 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 323 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 324 | 324 | } |
| 325 | 325 | } |
| 326 | 326 | |
@@ -328,11 +328,11 @@ discard block |
||
| 328 | 328 | * Check if SSL is enabled and notify the user |
| 329 | 329 | */ |
| 330 | 330 | public function admin_notices() { |
| 331 | - if ( 'no' === $this->enabled ) { |
|
| 331 | + if ('no' === $this->enabled) { |
|
| 332 | 332 | return; |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | - if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) { |
|
| 335 | + if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) { |
|
| 336 | 336 | $allowed_html = array( |
| 337 | 337 | 'a' => array( |
| 338 | 338 | 'href' => array(), |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | ), |
| 341 | 341 | ); |
| 342 | 342 | |
| 343 | - echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>'; |
|
| 343 | + echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>'; |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | /** |
@@ -348,9 +348,9 @@ discard block |
||
| 348 | 348 | * when setting screen is displayed. So if domain verification is not set, |
| 349 | 349 | * something went wrong so lets notify user. |
| 350 | 350 | */ |
| 351 | - if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) { |
|
| 351 | + if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) { |
|
| 352 | 352 | /* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */ |
| 353 | - echo '<div class="error stripe-apple-pay-message"><p>' . sprintf( __( 'Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>'; |
|
| 353 | + echo '<div class="error stripe-apple-pay-message"><p>' . sprintf(__('Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', '</a>') . '</p></div>'; |
|
| 354 | 354 | } |
| 355 | 355 | } |
| 356 | 356 | |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | * Initialise Gateway Settings Form Fields |
| 359 | 359 | */ |
| 360 | 360 | public function init_form_fields() { |
| 361 | - $this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' ); |
|
| 361 | + $this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php'); |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | /** |
@@ -366,59 +366,59 @@ discard block |
||
| 366 | 366 | */ |
| 367 | 367 | public function payment_fields() { |
| 368 | 368 | $user = wp_get_current_user(); |
| 369 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
| 369 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
| 370 | 370 | $total = WC()->cart->total; |
| 371 | 371 | $user_email = ''; |
| 372 | 372 | |
| 373 | 373 | // If paying from order, we need to get total from order not cart. |
| 374 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 375 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 374 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 375 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 376 | 376 | $total = $order->get_total(); |
| 377 | 377 | $user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
| 378 | 378 | } else { |
| 379 | - if ( $user->ID ) { |
|
| 380 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
| 379 | + if ($user->ID) { |
|
| 380 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
| 381 | 381 | $user_email = $user_email ? $user_email : $user->user_email; |
| 382 | 382 | } |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | - if ( is_add_payment_method_page() ) { |
|
| 386 | - $pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' ); |
|
| 387 | - $total = ''; |
|
| 385 | + if (is_add_payment_method_page()) { |
|
| 386 | + $pay_button_text = __('Add Card', 'woocommerce-gateway-stripe'); |
|
| 387 | + $total = ''; |
|
| 388 | 388 | } else { |
| 389 | 389 | $pay_button_text = ''; |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | echo '<div |
| 393 | 393 | id="stripe-payment-data" |
| 394 | - data-panel-label="' . esc_attr( $pay_button_text ) . '" |
|
| 394 | + data-panel-label="' . esc_attr($pay_button_text) . '" |
|
| 395 | 395 | data-description="" |
| 396 | - data-email="' . esc_attr( $user_email ) . '" |
|
| 397 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 398 | - data-name="' . esc_attr( $this->statement_descriptor ) . '" |
|
| 399 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
| 400 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
| 401 | - data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '" |
|
| 402 | - data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '" |
|
| 403 | - data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '" |
|
| 404 | - data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">'; |
|
| 405 | - |
|
| 406 | - if ( $this->description ) { |
|
| 407 | - if ( $this->testmode ) { |
|
| 396 | + data-email="' . esc_attr($user_email) . '" |
|
| 397 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 398 | + data-name="' . esc_attr($this->statement_descriptor) . '" |
|
| 399 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
| 400 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
| 401 | + data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '" |
|
| 402 | + data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '" |
|
| 403 | + data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '" |
|
| 404 | + data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">'; |
|
| 405 | + |
|
| 406 | + if ($this->description) { |
|
| 407 | + if ($this->testmode) { |
|
| 408 | 408 | /* translators: link to Stripe testing page */ |
| 409 | - $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' ); |
|
| 410 | - $this->description = trim( $this->description ); |
|
| 409 | + $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'); |
|
| 410 | + $this->description = trim($this->description); |
|
| 411 | 411 | } |
| 412 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 412 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | - if ( $display_tokenization ) { |
|
| 415 | + if ($display_tokenization) { |
|
| 416 | 416 | $this->tokenization_script(); |
| 417 | 417 | $this->saved_payment_methods(); |
| 418 | 418 | } |
| 419 | 419 | |
| 420 | - if ( ! $this->stripe_checkout ) { |
|
| 421 | - if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) { |
|
| 420 | + if ( ! $this->stripe_checkout) { |
|
| 421 | + if (apply_filters('wc_stripe_use_elements_checkout_form', true)) { |
|
| 422 | 422 | $this->elements_form(); |
| 423 | 423 | } else { |
| 424 | 424 | $this->form(); |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | } |
| 427 | 427 | } |
| 428 | 428 | |
| 429 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
| 429 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
| 430 | 430 | $this->save_payment_method_checkbox(); |
| 431 | 431 | } |
| 432 | 432 | |
@@ -441,13 +441,13 @@ discard block |
||
| 441 | 441 | */ |
| 442 | 442 | public function elements_form() { |
| 443 | 443 | ?> |
| 444 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
| 445 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
| 444 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
| 445 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
| 446 | 446 | <label for="card-element"> |
| 447 | - <?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?> |
|
| 447 | + <?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?> |
|
| 448 | 448 | </label> |
| 449 | 449 | |
| 450 | - <?php if ( $this->inline_cc_form ) { ?> |
|
| 450 | + <?php if ($this->inline_cc_form) { ?> |
|
| 451 | 451 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
| 452 | 452 | <!-- a Stripe Element will be inserted here. --> |
| 453 | 453 | </div> |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | |
| 467 | 467 | <!-- Used to display form errors --> |
| 468 | 468 | <div class="stripe-source-errors" role="alert"></div> |
| 469 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
| 469 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
| 470 | 470 | <div class="clear"></div> |
| 471 | 471 | </fieldset> |
| 472 | 472 | <?php |
@@ -479,13 +479,13 @@ discard block |
||
| 479 | 479 | * @version 3.1.0 |
| 480 | 480 | */ |
| 481 | 481 | public function admin_scripts() { |
| 482 | - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
| 482 | + if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
| 483 | 483 | return; |
| 484 | 484 | } |
| 485 | 485 | |
| 486 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 486 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 487 | 487 | |
| 488 | - wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
| 488 | + wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | /** |
@@ -497,29 +497,29 @@ discard block |
||
| 497 | 497 | * @version 4.0.0 |
| 498 | 498 | */ |
| 499 | 499 | public function payment_scripts() { |
| 500 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
| 500 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
| 501 | 501 | return; |
| 502 | 502 | } |
| 503 | 503 | |
| 504 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 504 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 505 | 505 | |
| 506 | - wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' ); |
|
| 507 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 508 | - wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true ); |
|
| 509 | - wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true ); |
|
| 510 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
| 511 | - 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 ); |
|
| 506 | + wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5'); |
|
| 507 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 508 | + wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true); |
|
| 509 | + wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true); |
|
| 510 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
| 511 | + 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); |
|
| 512 | 512 | |
| 513 | 513 | $stripe_params = array( |
| 514 | 514 | 'key' => $this->publishable_key, |
| 515 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
| 516 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
| 515 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
| 516 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
| 517 | 517 | ); |
| 518 | 518 | |
| 519 | 519 | // If we're on the pay page we need to pass stripe.js the address of the order. |
| 520 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { |
|
| 521 | - $order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); |
|
| 522 | - $order = wc_get_order( $order_id ); |
|
| 520 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { |
|
| 521 | + $order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); |
|
| 522 | + $order = wc_get_order($order_id); |
|
| 523 | 523 | |
| 524 | 524 | $stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
| 525 | 525 | $stripe_params['billing_last_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
@@ -531,37 +531,37 @@ discard block |
||
| 531 | 531 | $stripe_params['billing_country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
| 532 | 532 | } |
| 533 | 533 | |
| 534 | - $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' ); |
|
| 535 | - $stripe_params['no_bank_country_msg'] = __( 'Please select a country for your bank.', 'woocommerce-gateway-stripe' ); |
|
| 536 | - $stripe_params['no_sepa_owner_msg'] = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' ); |
|
| 537 | - $stripe_params['no_sepa_iban_msg'] = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' ); |
|
| 538 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
| 534 | + $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'); |
|
| 535 | + $stripe_params['no_bank_country_msg'] = __('Please select a country for your bank.', 'woocommerce-gateway-stripe'); |
|
| 536 | + $stripe_params['no_sepa_owner_msg'] = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe'); |
|
| 537 | + $stripe_params['no_sepa_iban_msg'] = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe'); |
|
| 538 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
| 539 | 539 | $stripe_params['inline_cc_form'] = $this->inline_cc_form ? 'yes' : 'no'; |
| 540 | - $stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no'; |
|
| 541 | - $stripe_params['is_checkout'] = ( is_checkout() && empty( $_GET['pay_for_order'] ) ); |
|
| 540 | + $stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no'; |
|
| 541 | + $stripe_params['is_checkout'] = (is_checkout() && empty($_GET['pay_for_order'])); |
|
| 542 | 542 | $stripe_params['return_url'] = $this->get_stripe_return_url(); |
| 543 | - $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint( '%%endpoint%%' ); |
|
| 544 | - $stripe_params['stripe_nonce'] = wp_create_nonce( '_wc_stripe_nonce' ); |
|
| 543 | + $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint('%%endpoint%%'); |
|
| 544 | + $stripe_params['stripe_nonce'] = wp_create_nonce('_wc_stripe_nonce'); |
|
| 545 | 545 | $stripe_params['statement_descriptor'] = $this->statement_descriptor; |
| 546 | - $stripe_params['use_elements'] = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no'; |
|
| 546 | + $stripe_params['use_elements'] = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no'; |
|
| 547 | 547 | $stripe_params['is_stripe_checkout'] = $this->stripe_checkout ? 'yes' : 'no'; |
| 548 | - $stripe_params['is_change_payment_page'] = ( isset( $_GET['pay_for_order'] ) || isset( $_GET['change_payment_method'] ) ) ? 'yes' : 'no'; |
|
| 548 | + $stripe_params['is_change_payment_page'] = (isset($_GET['pay_for_order']) || isset($_GET['change_payment_method'])) ? 'yes' : 'no'; |
|
| 549 | 549 | $stripe_params['is_add_payment_method_page'] = is_add_payment_method_page() ? 'yes' : 'no'; |
| 550 | - $stripe_params['elements_styling'] = apply_filters( 'wc_stripe_elements_styling', false ); |
|
| 551 | - $stripe_params['elements_classes'] = apply_filters( 'wc_stripe_elements_classes', false ); |
|
| 550 | + $stripe_params['elements_styling'] = apply_filters('wc_stripe_elements_styling', false); |
|
| 551 | + $stripe_params['elements_classes'] = apply_filters('wc_stripe_elements_classes', false); |
|
| 552 | 552 | |
| 553 | 553 | // merge localized messages to be use in JS |
| 554 | - $stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() ); |
|
| 554 | + $stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages()); |
|
| 555 | 555 | |
| 556 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
| 557 | - wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
| 556 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
| 557 | + wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
| 558 | 558 | |
| 559 | - if ( $this->stripe_checkout ) { |
|
| 560 | - wp_enqueue_script( 'stripe_checkout' ); |
|
| 559 | + if ($this->stripe_checkout) { |
|
| 560 | + wp_enqueue_script('stripe_checkout'); |
|
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | $this->tokenization_script(); |
| 564 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 564 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | /** |
@@ -573,22 +573,22 @@ discard block |
||
| 573 | 573 | * @param object $source_object |
| 574 | 574 | * @return mixed |
| 575 | 575 | */ |
| 576 | - public function create_3ds_source( $order, $source_object ) { |
|
| 576 | + public function create_3ds_source($order, $source_object) { |
|
| 577 | 577 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 578 | 578 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 579 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 579 | + $return_url = $this->get_stripe_return_url($order); |
|
| 580 | 580 | |
| 581 | 581 | $post_data = array(); |
| 582 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 583 | - $post_data['currency'] = strtolower( $currency ); |
|
| 582 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 583 | + $post_data['currency'] = strtolower($currency); |
|
| 584 | 584 | $post_data['type'] = 'three_d_secure'; |
| 585 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 586 | - $post_data['three_d_secure'] = array( 'card' => $source_object->id ); |
|
| 587 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 585 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 586 | + $post_data['three_d_secure'] = array('card' => $source_object->id); |
|
| 587 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 588 | 588 | |
| 589 | - WC_Stripe_Logger::log( 'Info: Begin creating 3DS source' ); |
|
| 589 | + WC_Stripe_Logger::log('Info: Begin creating 3DS source'); |
|
| 590 | 590 | |
| 591 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
| 591 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
| 592 | 592 | } |
| 593 | 593 | |
| 594 | 594 | /** |
@@ -604,46 +604,46 @@ discard block |
||
| 604 | 604 | * |
| 605 | 605 | * @return array|void |
| 606 | 606 | */ |
| 607 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 607 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 608 | 608 | try { |
| 609 | - $order = wc_get_order( $order_id ); |
|
| 610 | - $source_object = ! empty( $_POST['stripe_source'] ) ? json_decode( wc_clean( stripslashes( $_POST['stripe_source'] ) ) ) : false; |
|
| 609 | + $order = wc_get_order($order_id); |
|
| 610 | + $source_object = ! empty($_POST['stripe_source']) ? json_decode(wc_clean(stripslashes($_POST['stripe_source']))) : false; |
|
| 611 | 611 | |
| 612 | 612 | // This comes from the create account checkbox in the checkout page. |
| 613 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 613 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 614 | 614 | |
| 615 | - if ( $create_account ) { |
|
| 615 | + if ($create_account) { |
|
| 616 | 616 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 617 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 617 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 618 | 618 | $new_stripe_customer->create_customer(); |
| 619 | 619 | } |
| 620 | 620 | |
| 621 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source ); |
|
| 621 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source); |
|
| 622 | 622 | |
| 623 | 623 | // Check if we don't allow prepaid credit cards. |
| 624 | - if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) { |
|
| 625 | - $stripe_checkout_object = ! empty( $_POST['stripe_checkout_object'] ) ? json_decode( wc_clean( stripslashes( $_POST['stripe_checkout_object'] ) ) ) : false; |
|
| 624 | + if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) { |
|
| 625 | + $stripe_checkout_object = ! empty($_POST['stripe_checkout_object']) ? json_decode(wc_clean(stripslashes($_POST['stripe_checkout_object']))) : false; |
|
| 626 | 626 | |
| 627 | - if ( $stripe_checkout_object && 'token' === $stripe_checkout_object->object && 'prepaid' === $stripe_checkout_object->card->funding ) { |
|
| 628 | - $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' ); |
|
| 629 | - throw new WC_Stripe_Exception( print_r( $stripe_checkout_object, true ), $localized_message ); |
|
| 627 | + if ($stripe_checkout_object && 'token' === $stripe_checkout_object->object && 'prepaid' === $stripe_checkout_object->card->funding) { |
|
| 628 | + $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'); |
|
| 629 | + throw new WC_Stripe_Exception(print_r($stripe_checkout_object, true), $localized_message); |
|
| 630 | 630 | } |
| 631 | 631 | } |
| 632 | 632 | |
| 633 | - if ( empty( $prepared_source->source ) ) { |
|
| 634 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
| 635 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
| 633 | + if (empty($prepared_source->source)) { |
|
| 634 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
| 635 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | // Store source to order meta. |
| 639 | - $this->save_source( $order, $prepared_source ); |
|
| 639 | + $this->save_source($order, $prepared_source); |
|
| 640 | 640 | |
| 641 | 641 | // Result from Stripe API request. |
| 642 | 642 | $response = null; |
| 643 | 643 | |
| 644 | - if ( $order->get_total() > 0 ) { |
|
| 644 | + if ($order->get_total() > 0) { |
|
| 645 | 645 | // This will throw exception if not valid. |
| 646 | - $this->validate_minimum_order_amount( $order ); |
|
| 646 | + $this->validate_minimum_order_amount($order); |
|
| 647 | 647 | |
| 648 | 648 | /** |
| 649 | 649 | * Check if card 3DS is required or optional with 3DS setting. |
@@ -652,83 +652,83 @@ discard block |
||
| 652 | 652 | * Note that if we need to save source, the original source must be first |
| 653 | 653 | * attached to a customer in Stripe before it can be charged. |
| 654 | 654 | */ |
| 655 | - if ( $source_object && ( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure ) ) ) { |
|
| 655 | + if ($source_object && ('card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ($this->three_d_secure && 'optional' === $source_object->card->three_d_secure))) { |
|
| 656 | 656 | |
| 657 | - $response = $this->create_3ds_source( $order, $source_object ); |
|
| 657 | + $response = $this->create_3ds_source($order, $source_object); |
|
| 658 | 658 | |
| 659 | - if ( ! empty( $response->error ) ) { |
|
| 659 | + if ( ! empty($response->error)) { |
|
| 660 | 660 | $localized_message = $response->error->message; |
| 661 | 661 | |
| 662 | - $order->add_order_note( $localized_message ); |
|
| 662 | + $order->add_order_note($localized_message); |
|
| 663 | 663 | |
| 664 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 664 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 665 | 665 | } |
| 666 | 666 | |
| 667 | 667 | // Update order meta with 3DS source. |
| 668 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 669 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 668 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 669 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 670 | 670 | } else { |
| 671 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 671 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 672 | 672 | $order->save(); |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | - WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' ); |
|
| 675 | + WC_Stripe_Logger::log('Info: Redirecting to 3DS...'); |
|
| 676 | 676 | |
| 677 | 677 | return array( |
| 678 | 678 | 'result' => 'success', |
| 679 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 679 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 680 | 680 | ); |
| 681 | 681 | } |
| 682 | 682 | |
| 683 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
| 683 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
| 684 | 684 | |
| 685 | 685 | // Make the request. |
| 686 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
| 686 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source)); |
|
| 687 | 687 | |
| 688 | - if ( ! empty( $response->error ) ) { |
|
| 688 | + if ( ! empty($response->error)) { |
|
| 689 | 689 | // If it is an API error such connection or server, let's retry. |
| 690 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
| 691 | - if ( $retry ) { |
|
| 692 | - sleep( 5 ); |
|
| 693 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
| 690 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
| 691 | + if ($retry) { |
|
| 692 | + sleep(5); |
|
| 693 | + return $this->process_payment($order_id, false, $force_save_source); |
|
| 694 | 694 | } else { |
| 695 | 695 | $localized_message = 'API connection error and retries exhausted.'; |
| 696 | - $order->add_order_note( $localized_message ); |
|
| 697 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 696 | + $order->add_order_note($localized_message); |
|
| 697 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 698 | 698 | } |
| 699 | 699 | } |
| 700 | 700 | |
| 701 | 701 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
| 702 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
| 703 | - delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' ); |
|
| 702 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
| 703 | + delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id'); |
|
| 704 | 704 | |
| 705 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
| 706 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) { |
|
| 705 | + return $this->process_payment($order_id, false, $force_save_source); |
|
| 706 | + } elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) { |
|
| 707 | 707 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
| 708 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
| 708 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
| 709 | 709 | $wc_token->delete(); |
| 710 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
| 711 | - $order->add_order_note( $localized_message ); |
|
| 712 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 710 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
| 711 | + $order->add_order_note($localized_message); |
|
| 712 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
| 716 | 716 | |
| 717 | - if ( 'card_error' === $response->error->type ) { |
|
| 718 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 717 | + if ('card_error' === $response->error->type) { |
|
| 718 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
| 719 | 719 | } else { |
| 720 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 720 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
| 721 | 721 | } |
| 722 | 722 | |
| 723 | - $order->add_order_note( $localized_message ); |
|
| 723 | + $order->add_order_note($localized_message); |
|
| 724 | 724 | |
| 725 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 725 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 726 | 726 | } |
| 727 | 727 | |
| 728 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
| 728 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
| 729 | 729 | |
| 730 | 730 | // Process valid response. |
| 731 | - $this->process_response( $response, $order ); |
|
| 731 | + $this->process_response($response, $order); |
|
| 732 | 732 | } else { |
| 733 | 733 | $order->payment_complete(); |
| 734 | 734 | } |
@@ -739,17 +739,17 @@ discard block |
||
| 739 | 739 | // Return thank you page redirect. |
| 740 | 740 | return array( |
| 741 | 741 | 'result' => 'success', |
| 742 | - 'redirect' => $this->get_return_url( $order ), |
|
| 742 | + 'redirect' => $this->get_return_url($order), |
|
| 743 | 743 | ); |
| 744 | 744 | |
| 745 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 746 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 747 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 745 | + } catch (WC_Stripe_Exception $e) { |
|
| 746 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 747 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 748 | 748 | |
| 749 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 749 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 750 | 750 | |
| 751 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 752 | - $this->send_failed_order_email( $order_id ); |
|
| 751 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 752 | + $this->send_failed_order_email($order_id); |
|
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | return array( |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | * @since 4.0.2 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 10 | +if ( ! defined('ABSPATH')) { |
|
| 11 | 11 | exit; // Exit if accessed directly |
| 12 | 12 | } |
| 13 | 13 | |
@@ -23,9 +23,9 @@ discard block |
||
| 23 | 23 | * @param string $error_message Full response |
| 24 | 24 | * @param string $localized_message user-friendly translated error message |
| 25 | 25 | */ |
| 26 | - public function __construct( $error_message = '', $localized_message = '' ) { |
|
| 26 | + public function __construct($error_message = '', $localized_message = '') { |
|
| 27 | 27 | $this->localized_message = $localized_message; |
| 28 | - parent::__construct( $error_message ); |
|
| 28 | + parent::__construct($error_message); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | * @version 4.0.0 |
| 18 | 18 | */ |
| 19 | 19 | public function __construct() { |
| 20 | - add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) ); |
|
| 20 | + add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook')); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -27,24 +27,24 @@ discard block |
||
| 27 | 27 | * @version 4.0.0 |
| 28 | 28 | */ |
| 29 | 29 | public function check_for_webhook() { |
| 30 | - if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) |
|
| 31 | - || ! isset( $_GET['wc-api'] ) |
|
| 32 | - || ( 'wc_stripe' !== $_GET['wc-api'] ) |
|
| 30 | + if (('POST' !== $_SERVER['REQUEST_METHOD']) |
|
| 31 | + || ! isset($_GET['wc-api']) |
|
| 32 | + || ('wc_stripe' !== $_GET['wc-api']) |
|
| 33 | 33 | ) { |
| 34 | 34 | return; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - $request_body = file_get_contents( 'php://input' ); |
|
| 38 | - $request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER ); |
|
| 37 | + $request_body = file_get_contents('php://input'); |
|
| 38 | + $request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER); |
|
| 39 | 39 | |
| 40 | 40 | // Validate it to make sure it is legit. |
| 41 | - if ( $this->is_valid_request( $request_headers, $request_body ) ) { |
|
| 42 | - $this->process_webhook( $request_body ); |
|
| 43 | - status_header( 200 ); |
|
| 41 | + if ($this->is_valid_request($request_headers, $request_body)) { |
|
| 42 | + $this->process_webhook($request_body); |
|
| 43 | + status_header(200); |
|
| 44 | 44 | exit; |
| 45 | 45 | } else { |
| 46 | - WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) ); |
|
| 47 | - status_header( 400 ); |
|
| 46 | + WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true)); |
|
| 47 | + status_header(400); |
|
| 48 | 48 | exit; |
| 49 | 49 | } |
| 50 | 50 | } |
@@ -59,12 +59,12 @@ discard block |
||
| 59 | 59 | * @param string $request_body The request body from Stripe. |
| 60 | 60 | * @return bool |
| 61 | 61 | */ |
| 62 | - public function is_valid_request( $request_headers = null, $request_body = null ) { |
|
| 63 | - if ( null === $request_headers || null === $request_body ) { |
|
| 62 | + public function is_valid_request($request_headers = null, $request_body = null) { |
|
| 63 | + if (null === $request_headers || null === $request_body) { |
|
| 64 | 64 | return false; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) { |
|
| 67 | + if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) { |
|
| 68 | 68 | return false; |
| 69 | 69 | } |
| 70 | 70 | |
@@ -80,11 +80,11 @@ discard block |
||
| 80 | 80 | * @version 4.0.0 |
| 81 | 81 | */ |
| 82 | 82 | public function get_request_headers() { |
| 83 | - if ( ! function_exists( 'getallheaders' ) ) { |
|
| 83 | + if ( ! function_exists('getallheaders')) { |
|
| 84 | 84 | $headers = []; |
| 85 | - foreach ( $_SERVER as $name => $value ) { |
|
| 86 | - if ( 'HTTP_' === substr( $name, 0, 5 ) ) { |
|
| 87 | - $headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value; |
|
| 85 | + foreach ($_SERVER as $name => $value) { |
|
| 86 | + if ('HTTP_' === substr($name, 0, 5)) { |
|
| 87 | + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | |
@@ -103,30 +103,30 @@ discard block |
||
| 103 | 103 | * @param object $notification |
| 104 | 104 | * @param bool $retry |
| 105 | 105 | */ |
| 106 | - public function process_webhook_payment( $notification, $retry = true ) { |
|
| 106 | + public function process_webhook_payment($notification, $retry = true) { |
|
| 107 | 107 | // The following 2 payment methods are synchronous so does not need to be handle via webhook. |
| 108 | - if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type ) { |
|
| 108 | + if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type) { |
|
| 109 | 109 | return; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - $order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id ); |
|
| 112 | + $order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id); |
|
| 113 | 113 | |
| 114 | - if ( ! $order ) { |
|
| 115 | - WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id ); |
|
| 114 | + if ( ! $order) { |
|
| 115 | + WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id); |
|
| 116 | 116 | return; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 120 | 120 | $source_id = $notification->data->object->id; |
| 121 | 121 | |
| 122 | - $is_pending_receiver = ( 'receiver' === $notification->data->object->flow ); |
|
| 122 | + $is_pending_receiver = ('receiver' === $notification->data->object->flow); |
|
| 123 | 123 | |
| 124 | 124 | try { |
| 125 | - if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() ) { |
|
| 125 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status()) { |
|
| 126 | 126 | return; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - if ( 'on-hold' === $order->get_status() && ! $is_pending_receiver ) { |
|
| 129 | + if ('on-hold' === $order->get_status() && ! $is_pending_receiver) { |
|
| 130 | 130 | return; |
| 131 | 131 | } |
| 132 | 132 | |
@@ -134,73 +134,73 @@ discard block |
||
| 134 | 134 | $response = null; |
| 135 | 135 | |
| 136 | 136 | // This will throw exception if not valid. |
| 137 | - $this->validate_minimum_order_amount( $order ); |
|
| 137 | + $this->validate_minimum_order_amount($order); |
|
| 138 | 138 | |
| 139 | - WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
| 139 | + WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
| 140 | 140 | |
| 141 | 141 | // Prep source object. |
| 142 | 142 | $source_object = new stdClass(); |
| 143 | 143 | $source_object->token_id = ''; |
| 144 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
| 144 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
| 145 | 145 | $source_object->source = $source_id; |
| 146 | 146 | |
| 147 | 147 | // Make the request. |
| 148 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) ); |
|
| 148 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object)); |
|
| 149 | 149 | |
| 150 | - if ( ! empty( $response->error ) ) { |
|
| 150 | + if ( ! empty($response->error)) { |
|
| 151 | 151 | // If it is an API error such connection or server, let's retry. |
| 152 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
| 153 | - if ( $retry ) { |
|
| 154 | - sleep( 5 ); |
|
| 155 | - return $this->process_payment( $order_id, false ); |
|
| 152 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
| 153 | + if ($retry) { |
|
| 154 | + sleep(5); |
|
| 155 | + return $this->process_payment($order_id, false); |
|
| 156 | 156 | } else { |
| 157 | 157 | $localized_message = 'API connection error and retries exhausted.'; |
| 158 | - $order->add_order_note( $localized_message ); |
|
| 159 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 158 | + $order->add_order_note($localized_message); |
|
| 159 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
| 164 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
| 165 | - delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' ); |
|
| 164 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
| 165 | + delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id'); |
|
| 166 | 166 | |
| 167 | - return $this->process_payment( $order_id, false ); |
|
| 167 | + return $this->process_payment($order_id, false); |
|
| 168 | 168 | |
| 169 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) { |
|
| 169 | + } elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) { |
|
| 170 | 170 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
| 171 | - $wc_token = WC_Payment_Tokens::get( $source_object->token_id ); |
|
| 171 | + $wc_token = WC_Payment_Tokens::get($source_object->token_id); |
|
| 172 | 172 | $wc_token->delete(); |
| 173 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
| 174 | - $order->add_order_note( $message ); |
|
| 175 | - throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
| 173 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
| 174 | + $order->add_order_note($message); |
|
| 175 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
| 179 | 179 | |
| 180 | - if ( 'card_error' === $response->error->type ) { |
|
| 181 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 180 | + if ('card_error' === $response->error->type) { |
|
| 181 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
| 182 | 182 | } else { |
| 183 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 183 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - $order->add_order_note( $localized_message ); |
|
| 186 | + $order->add_order_note($localized_message); |
|
| 187 | 187 | |
| 188 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 188 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order ); |
|
| 191 | + do_action('wc_gateway_stripe_process_webhook_payment', $response, $order); |
|
| 192 | 192 | |
| 193 | - $this->process_response( $response, $order ); |
|
| 193 | + $this->process_response($response, $order); |
|
| 194 | 194 | |
| 195 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 196 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 195 | + } catch (WC_Stripe_Exception $e) { |
|
| 196 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 197 | 197 | |
| 198 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $e, $order ); |
|
| 198 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $e, $order); |
|
| 199 | 199 | |
| 200 | - $statuses = array( 'pending', 'failed' ); |
|
| 200 | + $statuses = array('pending', 'failed'); |
|
| 201 | 201 | |
| 202 | - if ( $order->has_status( $statuses ) ) { |
|
| 203 | - $this->send_failed_order_email( $order_id ); |
|
| 202 | + if ($order->has_status($statuses)) { |
|
| 203 | + $this->send_failed_order_email($order_id); |
|
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | 206 | } |
@@ -214,18 +214,18 @@ discard block |
||
| 214 | 214 | * @version 4.0.0 |
| 215 | 215 | * @param object $notification |
| 216 | 216 | */ |
| 217 | - public function process_webhook_dispute( $notification ) { |
|
| 218 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
| 217 | + public function process_webhook_dispute($notification) { |
|
| 218 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
| 219 | 219 | |
| 220 | - if ( ! $order ) { |
|
| 221 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
| 220 | + if ( ! $order) { |
|
| 221 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
| 222 | 222 | return; |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - $order->update_status( 'on-hold', __( 'A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe' ) ); |
|
| 225 | + $order->update_status('on-hold', __('A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe')); |
|
| 226 | 226 | |
| 227 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
| 228 | - $this->send_failed_order_email( $order_id ); |
|
| 227 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
| 228 | + $this->send_failed_order_email($order_id); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -236,41 +236,41 @@ discard block |
||
| 236 | 236 | * @version 4.0.0 |
| 237 | 237 | * @param object $notification |
| 238 | 238 | */ |
| 239 | - public function process_webhook_capture( $notification ) { |
|
| 240 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
| 239 | + public function process_webhook_capture($notification) { |
|
| 240 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
| 241 | 241 | |
| 242 | - if ( ! $order ) { |
|
| 243 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
| 242 | + if ( ! $order) { |
|
| 243 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
| 244 | 244 | return; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 248 | 248 | |
| 249 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
| 250 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
| 251 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
| 249 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
| 250 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
| 251 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
| 252 | 252 | |
| 253 | - if ( $charge && 'no' === $captured ) { |
|
| 254 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
| 253 | + if ($charge && 'no' === $captured) { |
|
| 254 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
| 255 | 255 | |
| 256 | 256 | // Store other data such as fees |
| 257 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
| 257 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
| 258 | 258 | |
| 259 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
| 260 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
| 259 | + if (isset($notification->data->object->balance_transaction)) { |
|
| 260 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 263 | + if (is_callable(array($order, 'save'))) { |
|
| 264 | 264 | $order->save(); |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | /* translators: transaction id */ |
| 268 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
| 268 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
| 269 | 269 | |
| 270 | 270 | // Check and see if capture is partial. |
| 271 | - if ( $this->is_partial_capture( $notification ) ) { |
|
| 272 | - $order->set_total( $this->get_partial_amount_to_charge( $notification ) ); |
|
| 273 | - $order->add_note( __( 'This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe' ) ); |
|
| 271 | + if ($this->is_partial_capture($notification)) { |
|
| 272 | + $order->set_total($this->get_partial_amount_to_charge($notification)); |
|
| 273 | + $order->add_note(__('This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe')); |
|
| 274 | 274 | $order->save(); |
| 275 | 275 | } |
| 276 | 276 | } |
@@ -285,38 +285,38 @@ discard block |
||
| 285 | 285 | * @version 4.0.0 |
| 286 | 286 | * @param object $notification |
| 287 | 287 | */ |
| 288 | - public function process_webhook_charge_succeeded( $notification ) { |
|
| 288 | + public function process_webhook_charge_succeeded($notification) { |
|
| 289 | 289 | // The following payment methods are synchronous so does not need to be handle via webhook. |
| 290 | - if ( ( isset( $notification->data->object->source->type ) && 'card' === $notification->data->object->source->type ) || ( isset( $notification->data->object->source->type ) && 'three_d_secure' === $notification->data->object->source->type ) ) { |
|
| 290 | + if ((isset($notification->data->object->source->type) && 'card' === $notification->data->object->source->type) || (isset($notification->data->object->source->type) && 'three_d_secure' === $notification->data->object->source->type)) { |
|
| 291 | 291 | return; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
| 294 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
| 295 | 295 | |
| 296 | - if ( ! $order ) { |
|
| 297 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
| 296 | + if ( ! $order) { |
|
| 297 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
| 298 | 298 | return; |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 302 | 302 | |
| 303 | - if ( 'on-hold' !== $order->get_status() ) { |
|
| 303 | + if ('on-hold' !== $order->get_status()) { |
|
| 304 | 304 | return; |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | // Store other data such as fees |
| 308 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
| 308 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
| 309 | 309 | |
| 310 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
| 311 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
| 310 | + if (isset($notification->data->object->balance_transaction)) { |
|
| 311 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 314 | + if (is_callable(array($order, 'save'))) { |
|
| 315 | 315 | $order->save(); |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | /* translators: transaction id */ |
| 319 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
| 319 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | /** |
@@ -327,23 +327,23 @@ discard block |
||
| 327 | 327 | * @version 4.0.0 |
| 328 | 328 | * @param object $notification |
| 329 | 329 | */ |
| 330 | - public function process_webhook_charge_failed( $notification ) { |
|
| 331 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
| 330 | + public function process_webhook_charge_failed($notification) { |
|
| 331 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
| 332 | 332 | |
| 333 | - if ( ! $order ) { |
|
| 334 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
| 333 | + if ( ! $order) { |
|
| 334 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
| 335 | 335 | return; |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 339 | 339 | |
| 340 | - if ( 'on-hold' !== $order->get_status() ) { |
|
| 340 | + if ('on-hold' !== $order->get_status()) { |
|
| 341 | 341 | return; |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - $order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) ); |
|
| 344 | + $order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe')); |
|
| 345 | 345 | |
| 346 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
| 346 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /** |
@@ -354,23 +354,23 @@ discard block |
||
| 354 | 354 | * @version 4.0.0 |
| 355 | 355 | * @param object $notification |
| 356 | 356 | */ |
| 357 | - public function process_webhook_source_canceled( $notification ) { |
|
| 358 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
| 357 | + public function process_webhook_source_canceled($notification) { |
|
| 358 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
| 359 | 359 | |
| 360 | - if ( ! $order ) { |
|
| 361 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
| 360 | + if ( ! $order) { |
|
| 361 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
| 362 | 362 | return; |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 366 | 366 | |
| 367 | - if ( 'on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status() ) { |
|
| 367 | + if ('on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status()) { |
|
| 368 | 368 | return; |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | - $order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) ); |
|
| 371 | + $order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe')); |
|
| 372 | 372 | |
| 373 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
| 373 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | /** |
@@ -381,31 +381,31 @@ discard block |
||
| 381 | 381 | * @version 4.0.0 |
| 382 | 382 | * @param object $notification |
| 383 | 383 | */ |
| 384 | - public function process_webhook_refund( $notification ) { |
|
| 385 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
| 384 | + public function process_webhook_refund($notification) { |
|
| 385 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
| 386 | 386 | |
| 387 | - if ( ! $order ) { |
|
| 388 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
| 387 | + if ( ! $order) { |
|
| 388 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
| 389 | 389 | return; |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 393 | 393 | |
| 394 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
| 395 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
| 396 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
| 394 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
| 395 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
| 396 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
| 397 | 397 | |
| 398 | 398 | // Only refund captured charge. |
| 399 | - if ( $charge && 'yes' === $captured ) { |
|
| 399 | + if ($charge && 'yes' === $captured) { |
|
| 400 | 400 | // Create the refund. |
| 401 | - $refund = wc_create_refund( array( |
|
| 401 | + $refund = wc_create_refund(array( |
|
| 402 | 402 | 'order_id' => $order_id, |
| 403 | - 'amount' => $this->get_refund_amount( $notification ), |
|
| 404 | - 'reason' => __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ), |
|
| 405 | - ) ); |
|
| 403 | + 'amount' => $this->get_refund_amount($notification), |
|
| 404 | + 'reason' => __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe'), |
|
| 405 | + )); |
|
| 406 | 406 | |
| 407 | - if ( is_wp_error( $refund ) ) { |
|
| 408 | - WC_Stripe_Logger::log( $refund->get_error_message() ); |
|
| 407 | + if (is_wp_error($refund)) { |
|
| 408 | + WC_Stripe_Logger::log($refund->get_error_message()); |
|
| 409 | 409 | } |
| 410 | 410 | } |
| 411 | 411 | } |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | * @version 4.0.0 |
| 419 | 419 | * @param object $notification |
| 420 | 420 | */ |
| 421 | - public function is_partial_capture( $notification ) { |
|
| 421 | + public function is_partial_capture($notification) { |
|
| 422 | 422 | return 0 < $notification->data->object->amount_refunded; |
| 423 | 423 | } |
| 424 | 424 | |
@@ -429,11 +429,11 @@ discard block |
||
| 429 | 429 | * @version 4.0.0 |
| 430 | 430 | * @param object $notification |
| 431 | 431 | */ |
| 432 | - public function get_refund_amount( $notification ) { |
|
| 433 | - if ( $this->is_partial_capture( $notification ) ) { |
|
| 432 | + public function get_refund_amount($notification) { |
|
| 433 | + if ($this->is_partial_capture($notification)) { |
|
| 434 | 434 | $amount = $notification->data->object->amount_refunded / 100; |
| 435 | 435 | |
| 436 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
| 436 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
| 437 | 437 | $amount = $notification->data->object->amount_refunded; |
| 438 | 438 | } |
| 439 | 439 | |
@@ -450,12 +450,12 @@ discard block |
||
| 450 | 450 | * @version 4.0.0 |
| 451 | 451 | * @param object $notification |
| 452 | 452 | */ |
| 453 | - public function get_partial_amount_to_charge( $notification ) { |
|
| 454 | - if ( $this->is_partial_capture( $notification ) ) { |
|
| 455 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100; |
|
| 453 | + public function get_partial_amount_to_charge($notification) { |
|
| 454 | + if ($this->is_partial_capture($notification)) { |
|
| 455 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100; |
|
| 456 | 456 | |
| 457 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
| 458 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ); |
|
| 457 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
| 458 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded); |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | return $amount; |
@@ -471,36 +471,36 @@ discard block |
||
| 471 | 471 | * @version 4.0.0 |
| 472 | 472 | * @param string $request_body |
| 473 | 473 | */ |
| 474 | - public function process_webhook( $request_body ) { |
|
| 475 | - $notification = json_decode( $request_body ); |
|
| 474 | + public function process_webhook($request_body) { |
|
| 475 | + $notification = json_decode($request_body); |
|
| 476 | 476 | |
| 477 | - switch ( $notification->type ) { |
|
| 477 | + switch ($notification->type) { |
|
| 478 | 478 | case 'source.chargeable': |
| 479 | - $this->process_webhook_payment( $notification ); |
|
| 479 | + $this->process_webhook_payment($notification); |
|
| 480 | 480 | break; |
| 481 | 481 | |
| 482 | 482 | case 'source.canceled': |
| 483 | - $this->process_webhook_source_canceled( $notification ); |
|
| 483 | + $this->process_webhook_source_canceled($notification); |
|
| 484 | 484 | break; |
| 485 | 485 | |
| 486 | 486 | case 'charge.succeeded': |
| 487 | - $this->process_webhook_charge_succeeded( $notification ); |
|
| 487 | + $this->process_webhook_charge_succeeded($notification); |
|
| 488 | 488 | break; |
| 489 | 489 | |
| 490 | 490 | case 'charge.failed': |
| 491 | - $this->process_webhook_charge_failed( $notification ); |
|
| 491 | + $this->process_webhook_charge_failed($notification); |
|
| 492 | 492 | break; |
| 493 | 493 | |
| 494 | 494 | case 'charge.captured': |
| 495 | - $this->process_webhook_capture( $notification ); |
|
| 495 | + $this->process_webhook_capture($notification); |
|
| 496 | 496 | break; |
| 497 | 497 | |
| 498 | 498 | case 'charge.dispute.created': |
| 499 | - $this->process_webhook_dispute( $notification ); |
|
| 499 | + $this->process_webhook_dispute($notification); |
|
| 500 | 500 | break; |
| 501 | 501 | |
| 502 | 502 | case 'charge.refunded': |
| 503 | - $this->process_webhook_refund( $notification ); |
|
| 503 | + $this->process_webhook_refund($notification); |
|
| 504 | 504 | break; |
| 505 | 505 | |
| 506 | 506 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function __construct() { |
| 59 | 59 | $this->id = 'stripe_ideal'; |
| 60 | - $this->method_title = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
| 60 | + $this->method_title = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
| 61 | 61 | /* translators: link */ |
| 62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
| 62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
| 63 | 63 | $this->supports = array( |
| 64 | 64 | 'products', |
| 65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
| 71 | 71 | // Load the settings. |
| 72 | 72 | $this->init_settings(); |
| 73 | 73 | |
| 74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
| 75 | - $this->title = $this->get_option( 'title' ); |
|
| 76 | - $this->description = $this->get_option( 'description' ); |
|
| 77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
| 79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
| 80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
| 81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
| 82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | - |
|
| 84 | - if ( $this->testmode ) { |
|
| 85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
| 74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
| 75 | + $this->title = $this->get_option('title'); |
|
| 76 | + $this->description = $this->get_option('description'); |
|
| 77 | + $this->enabled = $this->get_option('enabled'); |
|
| 78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
| 79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
| 80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
| 81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
| 82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | + |
|
| 84 | + if ($this->testmode) { |
|
| 85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
| 91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
| 92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
| 91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
| 92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
| 99 | 99 | * @version 4.0.0 |
| 100 | 100 | */ |
| 101 | 101 | public function check_environment() { |
| 102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $environment_warning = $this->get_environment_warning(); |
| 107 | 107 | |
| 108 | - if ( $environment_warning ) { |
|
| 109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
| 108 | + if ($environment_warning) { |
|
| 109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
| 114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
| 114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 115 | 115 | echo '</p></div>'; |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | * @version 4.0.0 |
| 125 | 125 | */ |
| 126 | 126 | public function get_environment_warning() { |
| 127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 128 | - $message = __( 'iDeal is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
| 127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 128 | + $message = __('iDeal is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
| 129 | 129 | |
| 130 | 130 | return $message; |
| 131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
| 141 | 141 | * @return array |
| 142 | 142 | */ |
| 143 | 143 | public function get_supported_currency() { |
| 144 | - return apply_filters( 'wc_stripe_ideal_supported_currencies', array( |
|
| 144 | + return apply_filters('wc_stripe_ideal_supported_currencies', array( |
|
| 145 | 145 | 'EUR', |
| 146 | - ) ); |
|
| 146 | + )); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @return bool |
| 155 | 155 | */ |
| 156 | 156 | public function is_available() { |
| 157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 158 | 158 | return false; |
| 159 | 159 | } |
| 160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | $icons_str .= $icons['ideal']; |
| 177 | 177 | |
| 178 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 178 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -186,19 +186,19 @@ discard block |
||
| 186 | 186 | * @access public |
| 187 | 187 | */ |
| 188 | 188 | public function payment_scripts() { |
| 189 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 189 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 190 | 190 | return; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 194 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 193 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 194 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
| 198 | 198 | * Initialize Gateway Settings Form Fields. |
| 199 | 199 | */ |
| 200 | 200 | public function init_form_fields() { |
| 201 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php' ); |
|
| 201 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php'); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -209,25 +209,25 @@ discard block |
||
| 209 | 209 | $total = WC()->cart->total; |
| 210 | 210 | |
| 211 | 211 | // If paying from order, we need to get total from order not cart. |
| 212 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 213 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 212 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 213 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 214 | 214 | $total = $order->get_total(); |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - if ( is_add_payment_method_page() ) { |
|
| 218 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 219 | - $total = ''; |
|
| 217 | + if (is_add_payment_method_page()) { |
|
| 218 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 219 | + $total = ''; |
|
| 220 | 220 | } else { |
| 221 | 221 | $pay_button_text = ''; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | echo '<div |
| 225 | 225 | id="stripe-ideal-payment-data" |
| 226 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 227 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 226 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 227 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 228 | 228 | |
| 229 | - if ( $this->description ) { |
|
| 230 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 229 | + if ($this->description) { |
|
| 230 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | echo '</div>'; |
@@ -241,24 +241,24 @@ discard block |
||
| 241 | 241 | * @param object $order |
| 242 | 242 | * @return mixed |
| 243 | 243 | */ |
| 244 | - public function create_source( $order ) { |
|
| 244 | + public function create_source($order) { |
|
| 245 | 245 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 246 | 246 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 247 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 247 | + $return_url = $this->get_stripe_return_url($order); |
|
| 248 | 248 | $post_data = array(); |
| 249 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 250 | - $post_data['currency'] = strtolower( $currency ); |
|
| 249 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 250 | + $post_data['currency'] = strtolower($currency); |
|
| 251 | 251 | $post_data['type'] = 'ideal'; |
| 252 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 253 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 252 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 253 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 254 | 254 | |
| 255 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
| 256 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
| 255 | + if ( ! empty($this->statement_descriptor)) { |
|
| 256 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - WC_Stripe_Logger::log( 'Info: Begin creating iDeal source' ); |
|
| 259 | + WC_Stripe_Logger::log('Info: Begin creating iDeal source'); |
|
| 260 | 260 | |
| 261 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
| 261 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -272,51 +272,51 @@ discard block |
||
| 272 | 272 | * |
| 273 | 273 | * @return array|void |
| 274 | 274 | */ |
| 275 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 275 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 276 | 276 | try { |
| 277 | - $order = wc_get_order( $order_id ); |
|
| 277 | + $order = wc_get_order($order_id); |
|
| 278 | 278 | |
| 279 | 279 | // This will throw exception if not valid. |
| 280 | - $this->validate_minimum_order_amount( $order ); |
|
| 280 | + $this->validate_minimum_order_amount($order); |
|
| 281 | 281 | |
| 282 | 282 | // This comes from the create account checkbox in the checkout page. |
| 283 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 283 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 284 | 284 | |
| 285 | - if ( $create_account ) { |
|
| 285 | + if ($create_account) { |
|
| 286 | 286 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 287 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 287 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 288 | 288 | $new_stripe_customer->create_customer(); |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - $response = $this->create_source( $order ); |
|
| 291 | + $response = $this->create_source($order); |
|
| 292 | 292 | |
| 293 | - if ( ! empty( $response->error ) ) { |
|
| 294 | - $order->add_order_note( $response->error->message ); |
|
| 293 | + if ( ! empty($response->error)) { |
|
| 294 | + $order->add_order_note($response->error->message); |
|
| 295 | 295 | |
| 296 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 296 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 300 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 299 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 300 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 301 | 301 | } else { |
| 302 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 302 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 303 | 303 | $order->save(); |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - WC_Stripe_Logger::log( 'Info: Redirecting to iDeal...' ); |
|
| 306 | + WC_Stripe_Logger::log('Info: Redirecting to iDeal...'); |
|
| 307 | 307 | |
| 308 | 308 | return array( |
| 309 | 309 | 'result' => 'success', |
| 310 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 310 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 311 | 311 | ); |
| 312 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 313 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 314 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 312 | + } catch (WC_Stripe_Exception $e) { |
|
| 313 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 314 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 315 | 315 | |
| 316 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 316 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 317 | 317 | |
| 318 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 319 | - $this->send_failed_order_email( $order_id ); |
|
| 318 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 319 | + $this->send_failed_order_email($order_id); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function __construct() { |
| 59 | 59 | $this->id = 'stripe_bancontact'; |
| 60 | - $this->method_title = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
| 60 | + $this->method_title = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
| 61 | 61 | /* translators: link */ |
| 62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
| 62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
| 63 | 63 | $this->supports = array( |
| 64 | 64 | 'products', |
| 65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
| 71 | 71 | // Load the settings. |
| 72 | 72 | $this->init_settings(); |
| 73 | 73 | |
| 74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
| 75 | - $this->title = $this->get_option( 'title' ); |
|
| 76 | - $this->description = $this->get_option( 'description' ); |
|
| 77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
| 79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
| 80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
| 81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
| 82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | - |
|
| 84 | - if ( $this->testmode ) { |
|
| 85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
| 74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
| 75 | + $this->title = $this->get_option('title'); |
|
| 76 | + $this->description = $this->get_option('description'); |
|
| 77 | + $this->enabled = $this->get_option('enabled'); |
|
| 78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
| 79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
| 80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
| 81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
| 82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | + |
|
| 84 | + if ($this->testmode) { |
|
| 85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
| 91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
| 92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
| 91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
| 92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
| 99 | 99 | * @version 4.0.0 |
| 100 | 100 | */ |
| 101 | 101 | public function check_environment() { |
| 102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $environment_warning = $this->get_environment_warning(); |
| 107 | 107 | |
| 108 | - if ( $environment_warning ) { |
|
| 109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
| 108 | + if ($environment_warning) { |
|
| 109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
| 114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
| 114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 115 | 115 | echo '</p></div>'; |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | * @version 4.0.0 |
| 125 | 125 | */ |
| 126 | 126 | public function get_environment_warning() { |
| 127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 128 | - $message = __( 'Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
| 127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 128 | + $message = __('Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
| 129 | 129 | |
| 130 | 130 | return $message; |
| 131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
| 141 | 141 | * @return array |
| 142 | 142 | */ |
| 143 | 143 | public function get_supported_currency() { |
| 144 | - return apply_filters( 'wc_stripe_bancontact_supported_currencies', array( |
|
| 144 | + return apply_filters('wc_stripe_bancontact_supported_currencies', array( |
|
| 145 | 145 | 'EUR', |
| 146 | - ) ); |
|
| 146 | + )); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @return bool |
| 155 | 155 | */ |
| 156 | 156 | public function is_available() { |
| 157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 158 | 158 | return false; |
| 159 | 159 | } |
| 160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | $icons_str .= $icons['bancontact']; |
| 177 | 177 | |
| 178 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 178 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -186,19 +186,19 @@ discard block |
||
| 186 | 186 | * @access public |
| 187 | 187 | */ |
| 188 | 188 | public function payment_scripts() { |
| 189 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 189 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 190 | 190 | return; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 194 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 193 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 194 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
| 198 | 198 | * Initialize Gateway Settings Form Fields. |
| 199 | 199 | */ |
| 200 | 200 | public function init_form_fields() { |
| 201 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php' ); |
|
| 201 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php'); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -209,25 +209,25 @@ discard block |
||
| 209 | 209 | $total = WC()->cart->total; |
| 210 | 210 | |
| 211 | 211 | // If paying from order, we need to get total from order not cart. |
| 212 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 213 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 212 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 213 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 214 | 214 | $total = $order->get_total(); |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - if ( is_add_payment_method_page() ) { |
|
| 218 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 219 | - $total = ''; |
|
| 217 | + if (is_add_payment_method_page()) { |
|
| 218 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 219 | + $total = ''; |
|
| 220 | 220 | } else { |
| 221 | 221 | $pay_button_text = ''; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | echo '<div |
| 225 | 225 | id="stripe-bancontact-payment-data" |
| 226 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 227 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 226 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 227 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 228 | 228 | |
| 229 | - if ( $this->description ) { |
|
| 230 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 229 | + if ($this->description) { |
|
| 230 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | echo '</div>'; |
@@ -241,24 +241,24 @@ discard block |
||
| 241 | 241 | * @param object $order |
| 242 | 242 | * @return mixed |
| 243 | 243 | */ |
| 244 | - public function create_source( $order ) { |
|
| 244 | + public function create_source($order) { |
|
| 245 | 245 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 246 | 246 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 247 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 247 | + $return_url = $this->get_stripe_return_url($order); |
|
| 248 | 248 | $post_data = array(); |
| 249 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 250 | - $post_data['currency'] = strtolower( $currency ); |
|
| 249 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 250 | + $post_data['currency'] = strtolower($currency); |
|
| 251 | 251 | $post_data['type'] = 'bancontact'; |
| 252 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 253 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 252 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 253 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 254 | 254 | |
| 255 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
| 256 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
| 255 | + if ( ! empty($this->statement_descriptor)) { |
|
| 256 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - WC_Stripe_Logger::log( 'Info: Begin creating Bancontact source' ); |
|
| 259 | + WC_Stripe_Logger::log('Info: Begin creating Bancontact source'); |
|
| 260 | 260 | |
| 261 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
| 261 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -272,51 +272,51 @@ discard block |
||
| 272 | 272 | * |
| 273 | 273 | * @return array|void |
| 274 | 274 | */ |
| 275 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 275 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 276 | 276 | try { |
| 277 | - $order = wc_get_order( $order_id ); |
|
| 277 | + $order = wc_get_order($order_id); |
|
| 278 | 278 | |
| 279 | 279 | // This will throw exception if not valid. |
| 280 | - $this->validate_minimum_order_amount( $order ); |
|
| 280 | + $this->validate_minimum_order_amount($order); |
|
| 281 | 281 | |
| 282 | 282 | // This comes from the create account checkbox in the checkout page. |
| 283 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 283 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 284 | 284 | |
| 285 | - if ( $create_account ) { |
|
| 285 | + if ($create_account) { |
|
| 286 | 286 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 287 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 287 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 288 | 288 | $new_stripe_customer->create_customer(); |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - $response = $this->create_source( $order ); |
|
| 291 | + $response = $this->create_source($order); |
|
| 292 | 292 | |
| 293 | - if ( ! empty( $response->error ) ) { |
|
| 294 | - $order->add_order_note( $response->error->message ); |
|
| 293 | + if ( ! empty($response->error)) { |
|
| 294 | + $order->add_order_note($response->error->message); |
|
| 295 | 295 | |
| 296 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 296 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 300 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 299 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 300 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 301 | 301 | } else { |
| 302 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 302 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 303 | 303 | $order->save(); |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - WC_Stripe_Logger::log( 'Info: Redirecting to Bancontact...' ); |
|
| 306 | + WC_Stripe_Logger::log('Info: Redirecting to Bancontact...'); |
|
| 307 | 307 | |
| 308 | 308 | return array( |
| 309 | 309 | 'result' => 'success', |
| 310 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 310 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 311 | 311 | ); |
| 312 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 313 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 314 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 312 | + } catch (WC_Stripe_Exception $e) { |
|
| 313 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 314 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 315 | 315 | |
| 316 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 316 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 317 | 317 | |
| 318 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 319 | - $this->send_failed_order_email( $order_id ); |
|
| 318 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 319 | + $this->send_failed_order_email($order_id); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | return array( |