@@ -1,138 +1,138 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | -return apply_filters( 'wc_stripe_settings', |
|
6 | +return apply_filters('wc_stripe_settings', |
|
7 | 7 | array( |
8 | 8 | 'enabled' => array( |
9 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
10 | - 'label' => __( 'Enable Stripe', 'woocommerce-gateway-stripe' ), |
|
9 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
10 | + 'label' => __('Enable Stripe', 'woocommerce-gateway-stripe'), |
|
11 | 11 | 'type' => 'checkbox', |
12 | 12 | 'description' => '', |
13 | 13 | 'default' => 'no' |
14 | 14 | ), |
15 | 15 | 'title' => array( |
16 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
16 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
17 | 17 | 'type' => 'text', |
18 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
19 | - 'default' => __( 'Credit Card (Stripe)', 'woocommerce-gateway-stripe' ), |
|
18 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
19 | + 'default' => __('Credit Card (Stripe)', 'woocommerce-gateway-stripe'), |
|
20 | 20 | 'desc_tip' => true, |
21 | 21 | ), |
22 | 22 | 'description' => array( |
23 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
23 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
24 | 24 | 'type' => 'text', |
25 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
26 | - 'default' => __( 'Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe'), |
|
25 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
26 | + 'default' => __('Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe'), |
|
27 | 27 | 'desc_tip' => true, |
28 | 28 | ), |
29 | 29 | 'testmode' => array( |
30 | - 'title' => __( 'Test mode', 'woocommerce-gateway-stripe' ), |
|
31 | - 'label' => __( 'Enable Test Mode', 'woocommerce-gateway-stripe' ), |
|
30 | + 'title' => __('Test mode', 'woocommerce-gateway-stripe'), |
|
31 | + 'label' => __('Enable Test Mode', 'woocommerce-gateway-stripe'), |
|
32 | 32 | 'type' => 'checkbox', |
33 | - 'description' => __( 'Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe' ), |
|
33 | + 'description' => __('Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe'), |
|
34 | 34 | 'default' => 'yes', |
35 | 35 | 'desc_tip' => true, |
36 | 36 | ), |
37 | 37 | 'secret_key' => array( |
38 | - 'title' => __( 'Live Secret Key', 'woocommerce-gateway-stripe' ), |
|
38 | + 'title' => __('Live Secret Key', 'woocommerce-gateway-stripe'), |
|
39 | 39 | 'type' => 'text', |
40 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
40 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
41 | 41 | 'default' => '', |
42 | 42 | 'desc_tip' => true, |
43 | 43 | ), |
44 | 44 | 'publishable_key' => array( |
45 | - 'title' => __( 'Live Publishable Key', 'woocommerce-gateway-stripe' ), |
|
45 | + 'title' => __('Live Publishable Key', 'woocommerce-gateway-stripe'), |
|
46 | 46 | 'type' => 'text', |
47 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
47 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
48 | 48 | 'default' => '', |
49 | 49 | 'desc_tip' => true, |
50 | 50 | ), |
51 | 51 | 'test_secret_key' => array( |
52 | - 'title' => __( 'Test Secret Key', 'woocommerce-gateway-stripe' ), |
|
52 | + 'title' => __('Test Secret Key', 'woocommerce-gateway-stripe'), |
|
53 | 53 | 'type' => 'text', |
54 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
54 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
55 | 55 | 'default' => '', |
56 | 56 | 'desc_tip' => true, |
57 | 57 | ), |
58 | 58 | 'test_publishable_key' => array( |
59 | - 'title' => __( 'Test Publishable Key', 'woocommerce-gateway-stripe' ), |
|
59 | + 'title' => __('Test Publishable Key', 'woocommerce-gateway-stripe'), |
|
60 | 60 | 'type' => 'text', |
61 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
61 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
62 | 62 | 'default' => '', |
63 | 63 | 'desc_tip' => true, |
64 | 64 | ), |
65 | 65 | 'capture' => array( |
66 | - 'title' => __( 'Capture', 'woocommerce-gateway-stripe' ), |
|
67 | - 'label' => __( 'Capture charge immediately', 'woocommerce-gateway-stripe' ), |
|
66 | + 'title' => __('Capture', 'woocommerce-gateway-stripe'), |
|
67 | + 'label' => __('Capture charge immediately', 'woocommerce-gateway-stripe'), |
|
68 | 68 | 'type' => 'checkbox', |
69 | - 'description' => __( 'Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe' ), |
|
69 | + 'description' => __('Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe'), |
|
70 | 70 | 'default' => 'yes', |
71 | 71 | 'desc_tip' => true, |
72 | 72 | ), |
73 | 73 | 'stripe_checkout' => array( |
74 | - 'title' => __( 'Stripe Checkout', 'woocommerce-gateway-stripe' ), |
|
75 | - 'label' => __( 'Enable Stripe Checkout', 'woocommerce-gateway-stripe' ), |
|
74 | + 'title' => __('Stripe Checkout', 'woocommerce-gateway-stripe'), |
|
75 | + 'label' => __('Enable Stripe Checkout', 'woocommerce-gateway-stripe'), |
|
76 | 76 | 'type' => 'checkbox', |
77 | - 'description' => __( 'If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe' ), |
|
77 | + 'description' => __('If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe'), |
|
78 | 78 | 'default' => 'no', |
79 | 79 | 'desc_tip' => true, |
80 | 80 | ), |
81 | 81 | 'stripe_checkout_locale' => array( |
82 | - 'title' => __( 'Stripe Checkout locale', 'woocommerce-gateway-stripe' ), |
|
82 | + 'title' => __('Stripe Checkout locale', 'woocommerce-gateway-stripe'), |
|
83 | 83 | 'type' => 'select', |
84 | 84 | 'class' => 'wc-enhanced-select', |
85 | - 'description' => __( 'Language to display in Stripe Checkout modal. Specify Auto to display Checkout in the user\'s preferred language, if available. English will be used by default.', 'woocommerce-gateway-stripe' ), |
|
85 | + 'description' => __('Language to display in Stripe Checkout modal. Specify Auto to display Checkout in the user\'s preferred language, if available. English will be used by default.', 'woocommerce-gateway-stripe'), |
|
86 | 86 | 'default' => 'en', |
87 | 87 | 'desc_tip' => true, |
88 | 88 | 'options' => array( |
89 | - 'auto' => __( 'Auto', 'woocommerce-gateway-stripe' ), |
|
90 | - 'zh' => __( 'Simplified Chinese', 'woocommerce-gateway-stripe' ), |
|
91 | - 'nl' => __( 'Dutch', 'woocommerce-gateway-stripe' ), |
|
92 | - 'en' => __( 'English', 'woocommerce-gateway-stripe' ), |
|
93 | - 'fr' => __( 'French', 'woocommerce-gateway-stripe' ), |
|
94 | - 'de' => __( 'German', 'woocommerce-gateway-stripe' ), |
|
95 | - 'it' => __( 'Italian', 'woocommerce-gateway-stripe' ), |
|
96 | - 'ja' => __( 'Japanese', 'woocommerce-gateway-stripe' ), |
|
97 | - 'es' => __( 'Spanish', 'woocommerce-gateway-stripe' ), |
|
89 | + 'auto' => __('Auto', 'woocommerce-gateway-stripe'), |
|
90 | + 'zh' => __('Simplified Chinese', 'woocommerce-gateway-stripe'), |
|
91 | + 'nl' => __('Dutch', 'woocommerce-gateway-stripe'), |
|
92 | + 'en' => __('English', 'woocommerce-gateway-stripe'), |
|
93 | + 'fr' => __('French', 'woocommerce-gateway-stripe'), |
|
94 | + 'de' => __('German', 'woocommerce-gateway-stripe'), |
|
95 | + 'it' => __('Italian', 'woocommerce-gateway-stripe'), |
|
96 | + 'ja' => __('Japanese', 'woocommerce-gateway-stripe'), |
|
97 | + 'es' => __('Spanish', 'woocommerce-gateway-stripe'), |
|
98 | 98 | ), |
99 | 99 | ), |
100 | 100 | 'stripe_bitcoin' => array( |
101 | - 'title' => __( 'Bitcoin Currency', 'woocommerce-gateway-stripe' ), |
|
102 | - 'label' => __( 'Enable Bitcoin Currency', 'woocommerce-gateway-stripe' ), |
|
101 | + 'title' => __('Bitcoin Currency', 'woocommerce-gateway-stripe'), |
|
102 | + 'label' => __('Enable Bitcoin Currency', 'woocommerce-gateway-stripe'), |
|
103 | 103 | 'type' => 'checkbox', |
104 | - 'description' => __( 'If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe' ), |
|
104 | + 'description' => __('If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe'), |
|
105 | 105 | 'default' => 'no', |
106 | 106 | 'desc_tip' => true, |
107 | 107 | ), |
108 | 108 | 'stripe_checkout_image' => array( |
109 | - 'title' => __( 'Stripe Checkout Image', 'woocommerce-gateway-stripe' ), |
|
110 | - 'description' => __( 'Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe' ), |
|
109 | + 'title' => __('Stripe Checkout Image', 'woocommerce-gateway-stripe'), |
|
110 | + 'description' => __('Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe'), |
|
111 | 111 | 'type' => 'text', |
112 | 112 | 'default' => '', |
113 | 113 | 'desc_tip' => true, |
114 | 114 | ), |
115 | 115 | 'request_payment_api' => array( |
116 | - 'title' => __( 'RequestPayment API', 'woocommerce-gateway-stripe' ), |
|
117 | - 'label' => __( 'Enable RequestPayment API', 'woocommerce-gateway-stripe' ), |
|
116 | + 'title' => __('RequestPayment API', 'woocommerce-gateway-stripe'), |
|
117 | + 'label' => __('Enable RequestPayment API', 'woocommerce-gateway-stripe'), |
|
118 | 118 | 'type' => 'checkbox', |
119 | - 'description' => __( 'If enabled, users will be able to pay using the RequestPayment API if avaiable in the browser.', 'woocommerce-gateway-stripe' ), |
|
119 | + 'description' => __('If enabled, users will be able to pay using the RequestPayment API if avaiable in the browser.', 'woocommerce-gateway-stripe'), |
|
120 | 120 | 'default' => 'no', |
121 | 121 | 'desc_tip' => true, |
122 | 122 | ), |
123 | 123 | 'saved_cards' => array( |
124 | - 'title' => __( 'Saved Cards', 'woocommerce-gateway-stripe' ), |
|
125 | - 'label' => __( 'Enable Payment via Saved Cards', 'woocommerce-gateway-stripe' ), |
|
124 | + 'title' => __('Saved Cards', 'woocommerce-gateway-stripe'), |
|
125 | + 'label' => __('Enable Payment via Saved Cards', 'woocommerce-gateway-stripe'), |
|
126 | 126 | 'type' => 'checkbox', |
127 | - 'description' => __( 'If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe' ), |
|
127 | + 'description' => __('If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe'), |
|
128 | 128 | 'default' => 'no', |
129 | 129 | 'desc_tip' => true, |
130 | 130 | ), |
131 | 131 | 'logging' => array( |
132 | - 'title' => __( 'Logging', 'woocommerce-gateway-stripe' ), |
|
133 | - 'label' => __( 'Log debug messages', 'woocommerce-gateway-stripe' ), |
|
132 | + 'title' => __('Logging', 'woocommerce-gateway-stripe'), |
|
133 | + 'label' => __('Log debug messages', 'woocommerce-gateway-stripe'), |
|
134 | 134 | 'type' => 'checkbox', |
135 | - 'description' => __( 'Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe' ), |
|
135 | + 'description' => __('Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe'), |
|
136 | 136 | 'default' => 'no', |
137 | 137 | 'desc_tip' => true, |
138 | 138 | ), |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @version 3.1.0 |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if ( ! defined('ABSPATH')) { |
|
11 | 11 | exit; |
12 | 12 | } |
13 | 13 | |
@@ -20,12 +20,12 @@ discard block |
||
20 | 20 | * Initialize class actions. |
21 | 21 | */ |
22 | 22 | public function __construct() { |
23 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
23 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
24 | 24 | |
25 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
26 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
27 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
28 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
25 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
26 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
27 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
28 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -34,10 +34,10 @@ discard block |
||
34 | 34 | * @return bool |
35 | 35 | */ |
36 | 36 | protected function is_activated() { |
37 | - $options = get_option( 'woocommerce_stripe_settings', array() ); |
|
38 | - $enabled = isset( $options['enabled'] ) && 'yes' === $options['enabled']; |
|
39 | - $stripe_checkout = isset( $options['stripe_checkout'] ) && 'yes' !== $options['stripe_checkout']; |
|
40 | - $request_payment_api = isset( $options['request_payment_api'] ) && 'yes' === $options['request_payment_api']; |
|
37 | + $options = get_option('woocommerce_stripe_settings', array()); |
|
38 | + $enabled = isset($options['enabled']) && 'yes' === $options['enabled']; |
|
39 | + $stripe_checkout = isset($options['stripe_checkout']) && 'yes' !== $options['stripe_checkout']; |
|
40 | + $request_payment_api = isset($options['request_payment_api']) && 'yes' === $options['request_payment_api']; |
|
41 | 41 | |
42 | 42 | return $enabled && $stripe_checkout && $request_payment_api && is_ssl(); |
43 | 43 | } |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | * @return string |
49 | 49 | */ |
50 | 50 | protected function get_publishable_key() { |
51 | - $options = get_option( 'woocommerce_stripe_settings', array() ); |
|
51 | + $options = get_option('woocommerce_stripe_settings', array()); |
|
52 | 52 | |
53 | - if ( empty( $options ) ) { |
|
53 | + if (empty($options)) { |
|
54 | 54 | return ''; |
55 | 55 | } |
56 | 56 | |
@@ -62,38 +62,38 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function scripts() { |
64 | 64 | // Load PaymentRequest only on cart for now. |
65 | - if ( ! is_cart() ) { |
|
65 | + if ( ! is_cart()) { |
|
66 | 66 | return; |
67 | 67 | } |
68 | 68 | |
69 | - if ( ! $this->is_activated() ) { |
|
69 | + if ( ! $this->is_activated()) { |
|
70 | 70 | return; |
71 | 71 | } |
72 | 72 | |
73 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
73 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
74 | 74 | |
75 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
76 | - wp_enqueue_script( 'wc-stripe-payment-request', plugins_url( 'assets/js/payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
75 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
76 | + wp_enqueue_script('wc-stripe-payment-request', plugins_url('assets/js/payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true); |
|
77 | 77 | |
78 | 78 | wp_localize_script( |
79 | 79 | 'wc-stripe-payment-request', |
80 | 80 | 'wcStripePaymentRequestParams', |
81 | 81 | array( |
82 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
82 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
83 | 83 | 'stripe' => array( |
84 | 84 | 'key' => $this->get_publishable_key(), |
85 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
85 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
86 | 86 | ), |
87 | 87 | 'nonce' => array( |
88 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
89 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
90 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
91 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
88 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
89 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
90 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
91 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
92 | 92 | ), |
93 | 93 | 'i18n' => array( |
94 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
94 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
95 | 95 | /* translators: Do not translate the [option] placeholder */ |
96 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
96 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
97 | 97 | ), |
98 | 98 | ) |
99 | 99 | ); |
@@ -103,10 +103,10 @@ discard block |
||
103 | 103 | * Get cart details. |
104 | 104 | */ |
105 | 105 | public function ajax_get_cart_details() { |
106 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
106 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
107 | 107 | |
108 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
109 | - define( 'WOOCOMMERCE_CART', true ); |
|
108 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
109 | + define('WOOCOMMERCE_CART', true); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | WC()->cart->calculate_totals(); |
@@ -118,16 +118,16 @@ discard block |
||
118 | 118 | 'shipping_required' => WC()->cart->needs_shipping(), |
119 | 119 | 'order_data' => array( |
120 | 120 | 'total' => array( |
121 | - 'label' => __( 'Total', 'woocommerce-gateway-stripe' ), |
|
121 | + 'label' => __('Total', 'woocommerce-gateway-stripe'), |
|
122 | 122 | 'amount' => array( |
123 | - 'value' => max( 0, apply_filters( 'woocommerce_calculated_total', round( WC()->cart->cart_contents_total + WC()->cart->fee_total, WC()->cart->dp ), WC()->cart ) ), |
|
123 | + 'value' => max(0, apply_filters('woocommerce_calculated_total', round(WC()->cart->cart_contents_total + WC()->cart->fee_total, WC()->cart->dp), WC()->cart)), |
|
124 | 124 | 'currency' => $currency, |
125 | 125 | ), |
126 | 126 | ), |
127 | 127 | ), |
128 | 128 | ); |
129 | 129 | |
130 | - wp_send_json( $data ); |
|
130 | + wp_send_json($data); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -138,17 +138,17 @@ discard block |
||
138 | 138 | * @see WC_Shipping::get_packages(). |
139 | 139 | */ |
140 | 140 | public function ajax_get_shipping_options() { |
141 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
141 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
142 | 142 | |
143 | 143 | // Set the shipping package. |
144 | - $posted = filter_input_array( INPUT_POST, array( |
|
144 | + $posted = filter_input_array(INPUT_POST, array( |
|
145 | 145 | 'country' => FILTER_SANITIZE_ENCODED, |
146 | 146 | 'state' => FILTER_SANITIZE_STRING, |
147 | 147 | 'postcode' => FILTER_SANITIZE_ENCODED, |
148 | 148 | 'city' => FILTER_SANITIZE_STRING, |
149 | 149 | 'address' => FILTER_SANITIZE_STRING, |
150 | 150 | 'address_2' => FILTER_SANITIZE_STRING, |
151 | - ) ); |
|
151 | + )); |
|
152 | 152 | $packages = array(); |
153 | 153 | |
154 | 154 | $packages[0]['contents'] = WC()->cart->get_cart(); |
@@ -162,23 +162,23 @@ discard block |
||
162 | 162 | $packages[0]['destination']['address'] = $posted['address']; |
163 | 163 | $packages[0]['destination']['address_2'] = $posted['address_2']; |
164 | 164 | |
165 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
166 | - if ( $item['data']->needs_shipping() ) { |
|
167 | - if ( isset( $item['line_total'] ) ) { |
|
165 | + foreach (WC()->cart->get_cart() as $item) { |
|
166 | + if ($item['data']->needs_shipping()) { |
|
167 | + if (isset($item['line_total'])) { |
|
168 | 168 | $packages[0]['contents_cost'] += $item['line_total']; |
169 | 169 | } |
170 | 170 | } |
171 | 171 | } |
172 | 172 | |
173 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
173 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
174 | 174 | |
175 | - WC()->shipping->calculate_shipping( $packages ); |
|
175 | + WC()->shipping->calculate_shipping($packages); |
|
176 | 176 | |
177 | 177 | // Set the shipping options. |
178 | 178 | $currency = get_woocommerce_currency(); |
179 | 179 | $data = array(); |
180 | - foreach ( WC()->shipping->get_packages() as $package_key => $package ) { |
|
181 | - foreach ( $package['rates'] as $key => $rate ) { |
|
180 | + foreach (WC()->shipping->get_packages() as $package_key => $package) { |
|
181 | + foreach ($package['rates'] as $key => $rate) { |
|
182 | 182 | $data[] = array( |
183 | 183 | 'id' => $rate->id, |
184 | 184 | 'label' => $rate->label, |
@@ -192,45 +192,45 @@ discard block |
||
192 | 192 | } |
193 | 193 | |
194 | 194 | // Auto select when have only one shipping method available. |
195 | - if ( 1 === count( $data ) ) { |
|
195 | + if (1 === count($data)) { |
|
196 | 196 | $data[0]['selected'] = true; |
197 | 197 | } |
198 | 198 | |
199 | - wp_send_json( $data ); |
|
199 | + wp_send_json($data); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
203 | 203 | * Update shipping method. |
204 | 204 | */ |
205 | 205 | public function ajax_update_shipping_method() { |
206 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
206 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
207 | 207 | |
208 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
209 | - define( 'WOOCOMMERCE_CART', true ); |
|
208 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
209 | + define('WOOCOMMERCE_CART', true); |
|
210 | 210 | } |
211 | 211 | |
212 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
213 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
212 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
213 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
214 | 214 | |
215 | - if ( is_array( $shipping_method ) ) { |
|
216 | - foreach ( $shipping_method as $i => $value ) { |
|
217 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
215 | + if (is_array($shipping_method)) { |
|
216 | + foreach ($shipping_method as $i => $value) { |
|
217 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
218 | 218 | } |
219 | 219 | } |
220 | 220 | |
221 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
221 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
222 | 222 | |
223 | 223 | WC()->cart->calculate_totals(); |
224 | 224 | |
225 | 225 | // Send back the new cart total. |
226 | 226 | $currency = get_woocommerce_currency(); |
227 | - $tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) ); |
|
227 | + $tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp)); |
|
228 | 228 | $data = array( |
229 | 229 | 'total' => WC()->cart->total, |
230 | 230 | ); |
231 | 231 | |
232 | 232 | // Include fees and taxes as displayItems. |
233 | - foreach ( WC()->cart->fees as $key => $fee ) { |
|
233 | + foreach (WC()->cart->fees as $key => $fee) { |
|
234 | 234 | $data['items'][] = array( |
235 | 235 | 'label' => $fee->name, |
236 | 236 | 'amount' => array( |
@@ -239,9 +239,9 @@ discard block |
||
239 | 239 | ), |
240 | 240 | ); |
241 | 241 | } |
242 | - if ( 0 < $tax_total ) { |
|
242 | + if (0 < $tax_total) { |
|
243 | 243 | $data['items'][] = array( |
244 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
244 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
245 | 245 | 'amount' => array( |
246 | 246 | 'currency' => $currency, |
247 | 247 | 'value' => $tax_total, |
@@ -249,24 +249,24 @@ discard block |
||
249 | 249 | ); |
250 | 250 | } |
251 | 251 | |
252 | - wp_send_json( $data ); |
|
252 | + wp_send_json($data); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
256 | 256 | * Create order. |
257 | 257 | */ |
258 | 258 | public function ajax_create_order() { |
259 | - if ( WC()->cart->is_empty() ) { |
|
260 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
259 | + if (WC()->cart->is_empty()) { |
|
260 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
261 | 261 | } |
262 | 262 | |
263 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
264 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
263 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
264 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | WC()->checkout()->process_checkout(); |
268 | 268 | |
269 | - die( 0 ); |
|
269 | + die(0); |
|
270 | 270 | } |
271 | 271 | } |
272 | 272 |
@@ -25,20 +25,20 @@ discard block |
||
25 | 25 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
26 | 26 | */ |
27 | 27 | |
28 | -if ( ! defined( 'ABSPATH' ) ) { |
|
28 | +if ( ! defined('ABSPATH')) { |
|
29 | 29 | exit; |
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
33 | 33 | * Required minimums and constants |
34 | 34 | */ |
35 | -define( 'WC_STRIPE_VERSION', '3.0.6' ); |
|
36 | -define( 'WC_STRIPE_MIN_PHP_VER', '5.3.0' ); |
|
37 | -define( 'WC_STRIPE_MIN_WC_VER', '2.5.0' ); |
|
38 | -define( 'WC_STRIPE_MAIN_FILE', __FILE__ ); |
|
39 | -define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); |
|
35 | +define('WC_STRIPE_VERSION', '3.0.6'); |
|
36 | +define('WC_STRIPE_MIN_PHP_VER', '5.3.0'); |
|
37 | +define('WC_STRIPE_MIN_WC_VER', '2.5.0'); |
|
38 | +define('WC_STRIPE_MAIN_FILE', __FILE__); |
|
39 | +define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)))); |
|
40 | 40 | |
41 | -if ( ! class_exists( 'WC_Stripe' ) ) : |
|
41 | +if ( ! class_exists('WC_Stripe')) : |
|
42 | 42 | |
43 | 43 | class WC_Stripe { |
44 | 44 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @return Singleton The *Singleton* instance. |
59 | 59 | */ |
60 | 60 | public static function get_instance() { |
61 | - if ( null === self::$instance ) { |
|
61 | + if (null === self::$instance) { |
|
62 | 62 | self::$instance = new self(); |
63 | 63 | } |
64 | 64 | return self::$instance; |
@@ -107,9 +107,9 @@ discard block |
||
107 | 107 | * *Singleton* via the `new` operator from outside of this class. |
108 | 108 | */ |
109 | 109 | protected function __construct() { |
110 | - add_action( 'admin_init', array( $this, 'check_environment' ) ); |
|
111 | - add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 ); |
|
112 | - add_action( 'plugins_loaded', array( $this, 'init' ) ); |
|
110 | + add_action('admin_init', array($this, 'check_environment')); |
|
111 | + add_action('admin_notices', array($this, 'admin_notices'), 15); |
|
112 | + add_action('plugins_loaded', array($this, 'init')); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -117,33 +117,33 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function init() { |
119 | 119 | // Don't hook anything else in the plugin if we're in an incompatible environment |
120 | - if ( self::get_environment_warning() ) { |
|
120 | + if (self::get_environment_warning()) { |
|
121 | 121 | return; |
122 | 122 | } |
123 | 123 | |
124 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' ); |
|
125 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' ); |
|
124 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php'); |
|
125 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php'); |
|
126 | 126 | |
127 | 127 | // Init the gateway itself |
128 | 128 | $this->init_gateways(); |
129 | 129 | |
130 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
|
131 | - add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) ); |
|
132 | - add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) ); |
|
133 | - add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) ); |
|
134 | - add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) ); |
|
135 | - add_filter( 'woocommerce_get_customer_payment_tokens', array( $this, 'woocommerce_get_customer_payment_tokens' ), 10, 3 ); |
|
136 | - add_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 ); |
|
137 | - add_action( 'woocommerce_payment_token_set_default', array( $this, 'woocommerce_payment_token_set_default' ) ); |
|
130 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); |
|
131 | + add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment')); |
|
132 | + add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment')); |
|
133 | + add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment')); |
|
134 | + add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment')); |
|
135 | + add_filter('woocommerce_get_customer_payment_tokens', array($this, 'woocommerce_get_customer_payment_tokens'), 10, 3); |
|
136 | + add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2); |
|
137 | + add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default')); |
|
138 | 138 | |
139 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-request.php' ); |
|
139 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-request.php'); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
143 | 143 | * Allow this class and other classes to add slug keyed notices (to avoid duplication) |
144 | 144 | */ |
145 | - public function add_admin_notice( $slug, $class, $message ) { |
|
146 | - $this->notices[ $slug ] = array( |
|
145 | + public function add_admin_notice($slug, $class, $message) { |
|
146 | + $this->notices[$slug] = array( |
|
147 | 147 | 'class' => $class, |
148 | 148 | 'message' => $message |
149 | 149 | ); |
@@ -156,21 +156,21 @@ discard block |
||
156 | 156 | public function check_environment() { |
157 | 157 | $environment_warning = self::get_environment_warning(); |
158 | 158 | |
159 | - if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
|
160 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
159 | + if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) { |
|
160 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | // Check if secret key present. Otherwise prompt, via notice, to go to |
164 | 164 | // setting. |
165 | - if ( ! class_exists( 'WC_Stripe_API' ) ) { |
|
166 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' ); |
|
165 | + if ( ! class_exists('WC_Stripe_API')) { |
|
166 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php'); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | $secret = WC_Stripe_API::get_secret_key(); |
170 | 170 | |
171 | - if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
|
171 | + if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) { |
|
172 | 172 | $setting_link = $this->get_setting_link(); |
173 | - $this->add_admin_notice( 'prompt_connect', 'notice notice-warning', sprintf( __( 'Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ) ); |
|
173 | + $this->add_admin_notice('prompt_connect', 'notice notice-warning', sprintf(__('Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link)); |
|
174 | 174 | } |
175 | 175 | } |
176 | 176 | |
@@ -179,24 +179,24 @@ discard block |
||
179 | 179 | * found or false if the environment has no problems. |
180 | 180 | */ |
181 | 181 | static function get_environment_warning() { |
182 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
183 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe', 'woocommerce-gateway-stripe' ); |
|
182 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
183 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe', 'woocommerce-gateway-stripe'); |
|
184 | 184 | |
185 | - return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ); |
|
185 | + return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()); |
|
186 | 186 | } |
187 | 187 | |
188 | - if ( ! defined( 'WC_VERSION' ) ) { |
|
189 | - return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' ); |
|
188 | + if ( ! defined('WC_VERSION')) { |
|
189 | + return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe'); |
|
190 | 190 | } |
191 | 191 | |
192 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
193 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe', 'woocommerce-gateway-stripe' ); |
|
192 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
193 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe', 'woocommerce-gateway-stripe'); |
|
194 | 194 | |
195 | - return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ); |
|
195 | + return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION); |
|
196 | 196 | } |
197 | 197 | |
198 | - if ( ! function_exists( 'curl_init' ) ) { |
|
199 | - return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ); |
|
198 | + if ( ! function_exists('curl_init')) { |
|
199 | + return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | return false; |
@@ -207,15 +207,15 @@ discard block |
||
207 | 207 | * |
208 | 208 | * @since 1.0.0 |
209 | 209 | */ |
210 | - public function plugin_action_links( $links ) { |
|
210 | + public function plugin_action_links($links) { |
|
211 | 211 | $setting_link = $this->get_setting_link(); |
212 | 212 | |
213 | 213 | $plugin_links = array( |
214 | - '<a href="' . $setting_link . '">' . __( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
215 | - '<a href="https://docs.woothemes.com/document/stripe/">' . __( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
216 | - '<a href="http://support.woothemes.com/">' . __( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
214 | + '<a href="' . $setting_link . '">' . __('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
215 | + '<a href="https://docs.woothemes.com/document/stripe/">' . __('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
216 | + '<a href="http://support.woothemes.com/">' . __('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
217 | 217 | ); |
218 | - return array_merge( $plugin_links, $links ); |
|
218 | + return array_merge($plugin_links, $links); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -226,20 +226,20 @@ discard block |
||
226 | 226 | * @return string Setting link |
227 | 227 | */ |
228 | 228 | public function get_setting_link() { |
229 | - $use_id_as_section = version_compare( WC()->version, '2.6', '>=' ); |
|
229 | + $use_id_as_section = version_compare(WC()->version, '2.6', '>='); |
|
230 | 230 | |
231 | - $section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' ); |
|
231 | + $section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe'); |
|
232 | 232 | |
233 | - return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); |
|
233 | + return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
237 | 237 | * Display any notices we've collected thus far (e.g. for connection, disconnection) |
238 | 238 | */ |
239 | 239 | public function admin_notices() { |
240 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
241 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
242 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
240 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
241 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
242 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
243 | 243 | echo "</p></div>"; |
244 | 244 | } |
245 | 245 | } |
@@ -250,27 +250,27 @@ discard block |
||
250 | 250 | * @since 1.0.0 |
251 | 251 | */ |
252 | 252 | public function init_gateways() { |
253 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) { |
|
253 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) { |
|
254 | 254 | $this->subscription_support_enabled = true; |
255 | 255 | } |
256 | 256 | |
257 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
257 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
258 | 258 | $this->pre_order_enabled = true; |
259 | 259 | } |
260 | 260 | |
261 | - if ( ! class_exists( 'WC_Payment_Gateway' ) ) { |
|
261 | + if ( ! class_exists('WC_Payment_Gateway')) { |
|
262 | 262 | return; |
263 | 263 | } |
264 | 264 | |
265 | - if ( class_exists( 'WC_Payment_Gateway_CC' ) ) { |
|
266 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' ); |
|
265 | + if (class_exists('WC_Payment_Gateway_CC')) { |
|
266 | + include_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php'); |
|
267 | 267 | } else { |
268 | - include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe.php' ); |
|
269 | - include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php' ); |
|
268 | + include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe.php'); |
|
269 | + include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php'); |
|
270 | 270 | } |
271 | 271 | |
272 | - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
|
273 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
272 | + load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages'); |
|
273 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
274 | 274 | |
275 | 275 | $load_addons = ( |
276 | 276 | $this->subscription_support_enabled |
@@ -278,8 +278,8 @@ discard block |
||
278 | 278 | $this->pre_order_enabled |
279 | 279 | ); |
280 | 280 | |
281 | - if ( $load_addons ) { |
|
282 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe-addons.php' ); |
|
281 | + if ($load_addons) { |
|
282 | + require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe-addons.php'); |
|
283 | 283 | } |
284 | 284 | } |
285 | 285 | |
@@ -288,8 +288,8 @@ discard block |
||
288 | 288 | * |
289 | 289 | * @since 1.0.0 |
290 | 290 | */ |
291 | - public function add_gateways( $methods ) { |
|
292 | - if ( $this->subscription_support_enabled || $this->pre_order_enabled ) { |
|
291 | + public function add_gateways($methods) { |
|
292 | + if ($this->subscription_support_enabled || $this->pre_order_enabled) { |
|
293 | 293 | $methods[] = 'WC_Gateway_Stripe_Addons'; |
294 | 294 | } else { |
295 | 295 | $methods[] = 'WC_Gateway_Stripe'; |
@@ -302,35 +302,35 @@ discard block |
||
302 | 302 | * |
303 | 303 | * @param int $order_id |
304 | 304 | */ |
305 | - public function capture_payment( $order_id ) { |
|
306 | - $order = wc_get_order( $order_id ); |
|
305 | + public function capture_payment($order_id) { |
|
306 | + $order = wc_get_order($order_id); |
|
307 | 307 | |
308 | - if ( 'stripe' === $order->payment_method ) { |
|
309 | - $charge = get_post_meta( $order_id, '_stripe_charge_id', true ); |
|
310 | - $captured = get_post_meta( $order_id, '_stripe_charge_captured', true ); |
|
308 | + if ('stripe' === $order->payment_method) { |
|
309 | + $charge = get_post_meta($order_id, '_stripe_charge_id', true); |
|
310 | + $captured = get_post_meta($order_id, '_stripe_charge_captured', true); |
|
311 | 311 | |
312 | - if ( $charge && 'no' === $captured ) { |
|
313 | - $result = WC_Stripe_API::request( array( |
|
312 | + if ($charge && 'no' === $captured) { |
|
313 | + $result = WC_Stripe_API::request(array( |
|
314 | 314 | 'amount' => $order->get_total() * 100, |
315 | 315 | 'expand[]' => 'balance_transaction' |
316 | - ), 'charges/' . $charge . '/capture' ); |
|
316 | + ), 'charges/' . $charge . '/capture'); |
|
317 | 317 | |
318 | - if ( is_wp_error( $result ) ) { |
|
319 | - $order->add_order_note( __( 'Unable to capture charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() ); |
|
318 | + if (is_wp_error($result)) { |
|
319 | + $order->add_order_note(__('Unable to capture charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message()); |
|
320 | 320 | } else { |
321 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
322 | - update_post_meta( $order->id, '_stripe_charge_captured', 'yes' ); |
|
321 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
322 | + update_post_meta($order->id, '_stripe_charge_captured', 'yes'); |
|
323 | 323 | |
324 | 324 | // Store other data such as fees |
325 | - update_post_meta( $order->id, 'Stripe Payment ID', $result->id ); |
|
325 | + update_post_meta($order->id, 'Stripe Payment ID', $result->id); |
|
326 | 326 | |
327 | - if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) { |
|
327 | + if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) { |
|
328 | 328 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
329 | 329 | // values are in the local currency of the Stripe account, not from WC. |
330 | - $fee = ! empty( $result->balance_transaction->fee ) ? number_format( $result->balance_transaction->fee / 100, 2, '.', '' ) : 0; |
|
331 | - $net = ! empty( $result->balance_transaction->net ) ? number_format( $result->balance_transaction->net / 100, 2, '.', '' ) : 0; |
|
332 | - update_post_meta( $order->id, 'Stripe Fee', $fee ); |
|
333 | - update_post_meta( $order->id, 'Net Revenue From Stripe', $net ); |
|
330 | + $fee = ! empty($result->balance_transaction->fee) ? number_format($result->balance_transaction->fee / 100, 2, '.', '') : 0; |
|
331 | + $net = ! empty($result->balance_transaction->net) ? number_format($result->balance_transaction->net / 100, 2, '.', '') : 0; |
|
332 | + update_post_meta($order->id, 'Stripe Fee', $fee); |
|
333 | + update_post_meta($order->id, 'Net Revenue From Stripe', $net); |
|
334 | 334 | } |
335 | 335 | } |
336 | 336 | } |
@@ -342,23 +342,23 @@ discard block |
||
342 | 342 | * |
343 | 343 | * @param int $order_id |
344 | 344 | */ |
345 | - public function cancel_payment( $order_id ) { |
|
346 | - $order = wc_get_order( $order_id ); |
|
345 | + public function cancel_payment($order_id) { |
|
346 | + $order = wc_get_order($order_id); |
|
347 | 347 | |
348 | - if ( 'stripe' === $order->payment_method ) { |
|
349 | - $charge = get_post_meta( $order_id, '_stripe_charge_id', true ); |
|
348 | + if ('stripe' === $order->payment_method) { |
|
349 | + $charge = get_post_meta($order_id, '_stripe_charge_id', true); |
|
350 | 350 | |
351 | - if ( $charge ) { |
|
352 | - $result = WC_Stripe_API::request( array( |
|
351 | + if ($charge) { |
|
352 | + $result = WC_Stripe_API::request(array( |
|
353 | 353 | 'amount' => $order->get_total() * 100, |
354 | - ), 'charges/' . $charge . '/refund' ); |
|
354 | + ), 'charges/' . $charge . '/refund'); |
|
355 | 355 | |
356 | - if ( is_wp_error( $result ) ) { |
|
357 | - $order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() ); |
|
356 | + if (is_wp_error($result)) { |
|
357 | + $order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message()); |
|
358 | 358 | } else { |
359 | - $order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
360 | - delete_post_meta( $order->id, '_stripe_charge_captured' ); |
|
361 | - delete_post_meta( $order->id, '_stripe_charge_id' ); |
|
359 | + $order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
360 | + delete_post_meta($order->id, '_stripe_charge_captured'); |
|
361 | + delete_post_meta($order->id, '_stripe_charge_id'); |
|
362 | 362 | } |
363 | 363 | } |
364 | 364 | } |
@@ -369,28 +369,28 @@ discard block |
||
369 | 369 | * @param array $tokens |
370 | 370 | * @return array |
371 | 371 | */ |
372 | - public function woocommerce_get_customer_payment_tokens( $tokens, $customer_id, $gateway_id ) { |
|
373 | - if ( is_user_logged_in() && 'stripe' === $gateway_id && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
374 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
372 | + public function woocommerce_get_customer_payment_tokens($tokens, $customer_id, $gateway_id) { |
|
373 | + if (is_user_logged_in() && 'stripe' === $gateway_id && class_exists('WC_Payment_Token_CC')) { |
|
374 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
375 | 375 | $stripe_cards = $stripe_customer->get_cards(); |
376 | 376 | $stored_tokens = array(); |
377 | 377 | |
378 | - foreach ( $tokens as $token ) { |
|
378 | + foreach ($tokens as $token) { |
|
379 | 379 | $stored_tokens[] = $token->get_token(); |
380 | 380 | } |
381 | 381 | |
382 | - foreach ( $stripe_cards as $card ) { |
|
383 | - if ( ! in_array( $card->id, $stored_tokens ) ) { |
|
382 | + foreach ($stripe_cards as $card) { |
|
383 | + if ( ! in_array($card->id, $stored_tokens)) { |
|
384 | 384 | $token = new WC_Payment_Token_CC(); |
385 | - $token->set_token( $card->id ); |
|
386 | - $token->set_gateway_id( 'stripe' ); |
|
387 | - $token->set_card_type( strtolower( $card->brand ) ); |
|
388 | - $token->set_last4( $card->last4 ); |
|
389 | - $token->set_expiry_month( $card->exp_month ); |
|
390 | - $token->set_expiry_year( $card->exp_year ); |
|
391 | - $token->set_user_id( $customer_id ); |
|
385 | + $token->set_token($card->id); |
|
386 | + $token->set_gateway_id('stripe'); |
|
387 | + $token->set_card_type(strtolower($card->brand)); |
|
388 | + $token->set_last4($card->last4); |
|
389 | + $token->set_expiry_month($card->exp_month); |
|
390 | + $token->set_expiry_year($card->exp_year); |
|
391 | + $token->set_user_id($customer_id); |
|
392 | 392 | $token->save(); |
393 | - $tokens[ $token->get_id() ] = $token; |
|
393 | + $tokens[$token->get_id()] = $token; |
|
394 | 394 | } |
395 | 395 | } |
396 | 396 | } |
@@ -400,21 +400,21 @@ discard block |
||
400 | 400 | /** |
401 | 401 | * Delete token from Stripe |
402 | 402 | */ |
403 | - public function woocommerce_payment_token_deleted( $token_id, $token ) { |
|
404 | - if ( 'stripe' === $token->get_gateway_id() ) { |
|
405 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
406 | - $stripe_customer->delete_card( $token->get_token() ); |
|
403 | + public function woocommerce_payment_token_deleted($token_id, $token) { |
|
404 | + if ('stripe' === $token->get_gateway_id()) { |
|
405 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
406 | + $stripe_customer->delete_card($token->get_token()); |
|
407 | 407 | } |
408 | 408 | } |
409 | 409 | |
410 | 410 | /** |
411 | 411 | * Set as default in Stripe |
412 | 412 | */ |
413 | - public function woocommerce_payment_token_set_default( $token_id ) { |
|
414 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
415 | - if ( 'stripe' === $token->get_gateway_id() ) { |
|
416 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
417 | - $stripe_customer->set_default_card( $token->get_token() ); |
|
413 | + public function woocommerce_payment_token_set_default($token_id) { |
|
414 | + $token = WC_Payment_Tokens::get($token_id); |
|
415 | + if ('stripe' === $token->get_gateway_id()) { |
|
416 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
417 | + $stripe_customer->set_default_card($token->get_token()); |
|
418 | 418 | } |
419 | 419 | } |
420 | 420 | |
@@ -426,15 +426,15 @@ discard block |
||
426 | 426 | * And fits on your back? |
427 | 427 | * It's log, log, log |
428 | 428 | */ |
429 | - public static function log( $message ) { |
|
430 | - if ( empty( self::$log ) ) { |
|
429 | + public static function log($message) { |
|
430 | + if (empty(self::$log)) { |
|
431 | 431 | self::$log = new WC_Logger(); |
432 | 432 | } |
433 | 433 | |
434 | - self::$log->add( 'woocommerce-gateway-stripe', $message ); |
|
434 | + self::$log->add('woocommerce-gateway-stripe', $message); |
|
435 | 435 | |
436 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
437 | - error_log( $message ); |
|
436 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
437 | + error_log($message); |
|
438 | 438 | } |
439 | 439 | } |
440 | 440 | } |