@@ -1,177 +1,177 @@ |
||
| 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 | 'test_secret_key' => array( |
| 38 | - 'title' => __( 'Test Secret Key', 'woocommerce-gateway-stripe' ), |
|
| 38 | + 'title' => __('Test 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 | 'test_publishable_key' => array( |
| 45 | - 'title' => __( 'Test Publishable Key', 'woocommerce-gateway-stripe' ), |
|
| 45 | + 'title' => __('Test 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 | 'secret_key' => array( |
| 52 | - 'title' => __( 'Live Secret Key', 'woocommerce-gateway-stripe' ), |
|
| 52 | + 'title' => __('Live 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 | 'publishable_key' => array( |
| 59 | - 'title' => __( 'Live Publishable Key', 'woocommerce-gateway-stripe' ), |
|
| 59 | + 'title' => __('Live 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 | 'statement_descriptor' => array( |
| 66 | - 'title' => __( 'Statement Descriptor', 'woocommerce-gateway-stripe' ), |
|
| 66 | + 'title' => __('Statement Descriptor', 'woocommerce-gateway-stripe'), |
|
| 67 | 67 | 'type' => 'text', |
| 68 | - 'description' => __( 'Extra information about a charge. This will appear on your customer’s credit card statement.', 'woocommerce-gateway-stripe' ), |
|
| 68 | + 'description' => __('Extra information about a charge. This will appear on your customer’s credit card statement.', 'woocommerce-gateway-stripe'), |
|
| 69 | 69 | 'default' => '', |
| 70 | 70 | 'desc_tip' => true, |
| 71 | 71 | ), |
| 72 | 72 | 'capture' => array( |
| 73 | - 'title' => __( 'Capture', 'woocommerce-gateway-stripe' ), |
|
| 74 | - 'label' => __( 'Capture charge immediately', 'woocommerce-gateway-stripe' ), |
|
| 73 | + 'title' => __('Capture', 'woocommerce-gateway-stripe'), |
|
| 74 | + 'label' => __('Capture charge immediately', 'woocommerce-gateway-stripe'), |
|
| 75 | 75 | 'type' => 'checkbox', |
| 76 | - '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' ), |
|
| 76 | + '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'), |
|
| 77 | 77 | 'default' => 'yes', |
| 78 | 78 | 'desc_tip' => true, |
| 79 | 79 | ), |
| 80 | 80 | 'stripe_checkout' => array( |
| 81 | - 'title' => __( 'Stripe Checkout', 'woocommerce-gateway-stripe' ), |
|
| 82 | - 'label' => __( 'Enable Stripe Checkout', 'woocommerce-gateway-stripe' ), |
|
| 81 | + 'title' => __('Stripe Checkout', 'woocommerce-gateway-stripe'), |
|
| 82 | + 'label' => __('Enable Stripe Checkout', 'woocommerce-gateway-stripe'), |
|
| 83 | 83 | 'type' => 'checkbox', |
| 84 | - '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' ), |
|
| 84 | + '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'), |
|
| 85 | 85 | 'default' => 'no', |
| 86 | 86 | 'desc_tip' => true, |
| 87 | 87 | ), |
| 88 | 88 | 'allow_remember_me' => array( |
| 89 | - 'title' => __( 'Allow Remember Me', 'woocommerce-gateway-stripe' ), |
|
| 90 | - 'label' => __( 'Enable Remember Me', 'woocommerce-gateway-stripe' ), |
|
| 89 | + 'title' => __('Allow Remember Me', 'woocommerce-gateway-stripe'), |
|
| 90 | + 'label' => __('Enable Remember Me', 'woocommerce-gateway-stripe'), |
|
| 91 | 91 | 'type' => 'checkbox', |
| 92 | - 'description' => __( 'If enabled, this option shows a "Remember Me" checkbox which when checked by the customer will persist their details.', 'woocommerce-gateway-stripe' ), |
|
| 92 | + 'description' => __('If enabled, this option shows a "Remember Me" checkbox which when checked by the customer will persist their details.', 'woocommerce-gateway-stripe'), |
|
| 93 | 93 | 'default' => 'yes', |
| 94 | 94 | 'desc_tip' => true, |
| 95 | 95 | ), |
| 96 | 96 | 'stripe_checkout_locale' => array( |
| 97 | - 'title' => __( 'Stripe Checkout locale', 'woocommerce-gateway-stripe' ), |
|
| 97 | + 'title' => __('Stripe Checkout locale', 'woocommerce-gateway-stripe'), |
|
| 98 | 98 | 'type' => 'select', |
| 99 | 99 | 'class' => 'wc-enhanced-select', |
| 100 | - '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' ), |
|
| 100 | + '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'), |
|
| 101 | 101 | 'default' => 'en', |
| 102 | 102 | 'desc_tip' => true, |
| 103 | 103 | 'options' => array( |
| 104 | - 'auto' => __( 'Auto', 'woocommerce-gateway-stripe' ), |
|
| 105 | - 'zh' => __( 'Simplified Chinese', 'woocommerce-gateway-stripe' ), |
|
| 106 | - 'da' => __( 'Danish', 'woocommerce-gateway-stripe' ), |
|
| 107 | - 'nl' => __( 'Dutch', 'woocommerce-gateway-stripe' ), |
|
| 108 | - 'en' => __( 'English', 'woocommerce-gateway-stripe' ), |
|
| 109 | - 'fi' => __( 'Finnish', 'woocommerce-gateway-stripe' ), |
|
| 110 | - 'fr' => __( 'French', 'woocommerce-gateway-stripe' ), |
|
| 111 | - 'de' => __( 'German', 'woocommerce-gateway-stripe' ), |
|
| 112 | - 'it' => __( 'Italian', 'woocommerce-gateway-stripe' ), |
|
| 113 | - 'ja' => __( 'Japanese', 'woocommerce-gateway-stripe' ), |
|
| 114 | - 'no' => __( 'Norwegian', 'woocommerce-gateway-stripe' ), |
|
| 115 | - 'es' => __( 'Spanish', 'woocommerce-gateway-stripe' ), |
|
| 116 | - 'sv' => __( 'Swedish', 'woocommerce-gateway-stripe' ), |
|
| 104 | + 'auto' => __('Auto', 'woocommerce-gateway-stripe'), |
|
| 105 | + 'zh' => __('Simplified Chinese', 'woocommerce-gateway-stripe'), |
|
| 106 | + 'da' => __('Danish', 'woocommerce-gateway-stripe'), |
|
| 107 | + 'nl' => __('Dutch', 'woocommerce-gateway-stripe'), |
|
| 108 | + 'en' => __('English', 'woocommerce-gateway-stripe'), |
|
| 109 | + 'fi' => __('Finnish', 'woocommerce-gateway-stripe'), |
|
| 110 | + 'fr' => __('French', 'woocommerce-gateway-stripe'), |
|
| 111 | + 'de' => __('German', 'woocommerce-gateway-stripe'), |
|
| 112 | + 'it' => __('Italian', 'woocommerce-gateway-stripe'), |
|
| 113 | + 'ja' => __('Japanese', 'woocommerce-gateway-stripe'), |
|
| 114 | + 'no' => __('Norwegian', 'woocommerce-gateway-stripe'), |
|
| 115 | + 'es' => __('Spanish', 'woocommerce-gateway-stripe'), |
|
| 116 | + 'sv' => __('Swedish', 'woocommerce-gateway-stripe'), |
|
| 117 | 117 | ), |
| 118 | 118 | ), |
| 119 | 119 | 'stripe_bitcoin' => array( |
| 120 | - 'title' => __( 'Bitcoin Currency', 'woocommerce-gateway-stripe' ), |
|
| 121 | - 'label' => __( 'Enable Bitcoin Currency', 'woocommerce-gateway-stripe' ), |
|
| 120 | + 'title' => __('Bitcoin Currency', 'woocommerce-gateway-stripe'), |
|
| 121 | + 'label' => __('Enable Bitcoin Currency', 'woocommerce-gateway-stripe'), |
|
| 122 | 122 | 'type' => 'checkbox', |
| 123 | - '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' ), |
|
| 123 | + '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'), |
|
| 124 | 124 | 'default' => 'no', |
| 125 | 125 | 'desc_tip' => true, |
| 126 | 126 | ), |
| 127 | 127 | 'stripe_checkout_image' => array( |
| 128 | - 'title' => __( 'Stripe Checkout Image', 'woocommerce-gateway-stripe' ), |
|
| 129 | - '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' ), |
|
| 128 | + 'title' => __('Stripe Checkout Image', 'woocommerce-gateway-stripe'), |
|
| 129 | + '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'), |
|
| 130 | 130 | 'type' => 'text', |
| 131 | 131 | 'default' => '', |
| 132 | 132 | 'desc_tip' => true, |
| 133 | 133 | ), |
| 134 | 134 | 'request_payment_api' => array( |
| 135 | - 'title' => __( 'Payment Request API', 'woocommerce-gateway-stripe' ), |
|
| 136 | - 'label' => __( 'Enable Payment Request API', 'woocommerce-gateway-stripe' ), |
|
| 135 | + 'title' => __('Payment Request API', 'woocommerce-gateway-stripe'), |
|
| 136 | + 'label' => __('Enable Payment Request API', 'woocommerce-gateway-stripe'), |
|
| 137 | 137 | 'type' => 'checkbox', |
| 138 | - 'description' => __( 'If enabled, users will be able to pay using the Payment Request API if supported by the browser.', 'woocommerce-gateway-stripe' ), |
|
| 138 | + 'description' => __('If enabled, users will be able to pay using the Payment Request API if supported by the browser.', 'woocommerce-gateway-stripe'), |
|
| 139 | 139 | 'default' => 'no', |
| 140 | 140 | 'desc_tip' => true, |
| 141 | 141 | ), |
| 142 | 142 | 'apple_pay' => array( |
| 143 | - 'title' => __( 'Apple Pay', 'woocommerce-gateway-stripe' ), |
|
| 144 | - 'label' => __( 'Enable Apple Pay', 'woocommerce-gateway-stripe' ), |
|
| 143 | + 'title' => __('Apple Pay', 'woocommerce-gateway-stripe'), |
|
| 144 | + 'label' => __('Enable Apple Pay', 'woocommerce-gateway-stripe'), |
|
| 145 | 145 | 'type' => 'checkbox', |
| 146 | - 'description' => __( 'If enabled, users will be able to pay with Apple Pay.', 'woocommerce-gateway-stripe' ), |
|
| 146 | + 'description' => __('If enabled, users will be able to pay with Apple Pay.', 'woocommerce-gateway-stripe'), |
|
| 147 | 147 | 'default' => 'no', |
| 148 | 148 | 'desc_tip' => true, |
| 149 | 149 | ), |
| 150 | 150 | 'apple_pay_button' => array( |
| 151 | - 'title' => __( 'Apple Pay Button Style', 'woocommerce-gateway-stripe' ), |
|
| 152 | - 'label' => __( 'Button Style', 'woocommerce-gateway-stripe' ), |
|
| 151 | + 'title' => __('Apple Pay Button Style', 'woocommerce-gateway-stripe'), |
|
| 152 | + 'label' => __('Button Style', 'woocommerce-gateway-stripe'), |
|
| 153 | 153 | 'type' => 'select', |
| 154 | - 'description' => __( 'Select the button style you would like to show.', 'woocommerce-gateway-stripe' ), |
|
| 154 | + 'description' => __('Select the button style you would like to show.', 'woocommerce-gateway-stripe'), |
|
| 155 | 155 | 'default' => 'black', |
| 156 | 156 | 'desc_tip' => true, |
| 157 | 157 | 'options' => array( |
| 158 | - 'black' => __( 'Black', 'woocommerce-gateway-stripe' ), |
|
| 159 | - 'white' => __( 'White', 'woocommerce-gateway-stripe' ), |
|
| 158 | + 'black' => __('Black', 'woocommerce-gateway-stripe'), |
|
| 159 | + 'white' => __('White', 'woocommerce-gateway-stripe'), |
|
| 160 | 160 | ), |
| 161 | 161 | ), |
| 162 | 162 | 'saved_cards' => array( |
| 163 | - 'title' => __( 'Saved Cards', 'woocommerce-gateway-stripe' ), |
|
| 164 | - 'label' => __( 'Enable Payment via Saved Cards', 'woocommerce-gateway-stripe' ), |
|
| 163 | + 'title' => __('Saved Cards', 'woocommerce-gateway-stripe'), |
|
| 164 | + 'label' => __('Enable Payment via Saved Cards', 'woocommerce-gateway-stripe'), |
|
| 165 | 165 | 'type' => 'checkbox', |
| 166 | - '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' ), |
|
| 166 | + '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'), |
|
| 167 | 167 | 'default' => 'no', |
| 168 | 168 | 'desc_tip' => true, |
| 169 | 169 | ), |
| 170 | 170 | 'logging' => array( |
| 171 | - 'title' => __( 'Logging', 'woocommerce-gateway-stripe' ), |
|
| 172 | - 'label' => __( 'Log debug messages', 'woocommerce-gateway-stripe' ), |
|
| 171 | + 'title' => __('Logging', 'woocommerce-gateway-stripe'), |
|
| 172 | + 'label' => __('Log debug messages', 'woocommerce-gateway-stripe'), |
|
| 173 | 173 | 'type' => 'checkbox', |
| 174 | - 'description' => __( 'Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe' ), |
|
| 174 | + 'description' => __('Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe'), |
|
| 175 | 175 | 'default' => 'no', |
| 176 | 176 | 'desc_tip' => true, |
| 177 | 177 | ), |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -113,8 +113,8 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | public function __construct() { |
| 115 | 115 | $this->id = 'stripe'; |
| 116 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
| 117 | - $this->method_description = __( 'Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe' ); |
|
| 116 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
| 117 | + $this->method_description = __('Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe'); |
|
| 118 | 118 | $this->has_fields = true; |
| 119 | 119 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
| 120 | 120 | $this->supports = array( |
@@ -142,39 +142,39 @@ discard block |
||
| 142 | 142 | $this->init_settings(); |
| 143 | 143 | |
| 144 | 144 | // Get setting values. |
| 145 | - $this->title = $this->get_option( 'title' ); |
|
| 146 | - $this->description = $this->get_option( 'description' ); |
|
| 147 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 148 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
| 149 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
| 150 | - $this->statement_descriptor = $this->get_option( 'statement_descriptor', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) ); |
|
| 151 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
| 152 | - $this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' ); |
|
| 153 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
| 154 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
| 155 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
| 156 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
| 157 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
| 158 | - $this->apple_pay = 'yes' === $this->get_option( 'apple_pay' ); |
|
| 159 | - $this->apple_pay_button = $this->get_option( 'apple_pay_button', 'black' ); |
|
| 160 | - $this->logging = 'yes' === $this->get_option( 'logging' ); |
|
| 161 | - $this->allow_remember_me = 'yes' === $this->get_option( 'allow_remember_me', 'no' ); |
|
| 162 | - |
|
| 163 | - if ( $this->stripe_checkout ) { |
|
| 164 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - if ( $this->testmode ) { |
|
| 168 | - $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">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' ); |
|
| 169 | - $this->description = trim( $this->description ); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
| 145 | + $this->title = $this->get_option('title'); |
|
| 146 | + $this->description = $this->get_option('description'); |
|
| 147 | + $this->enabled = $this->get_option('enabled'); |
|
| 148 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
| 149 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
| 150 | + $this->statement_descriptor = $this->get_option('statement_descriptor', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)); |
|
| 151 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
| 152 | + $this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale'); |
|
| 153 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
| 154 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
| 155 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
| 156 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
| 157 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
| 158 | + $this->apple_pay = 'yes' === $this->get_option('apple_pay'); |
|
| 159 | + $this->apple_pay_button = $this->get_option('apple_pay_button', 'black'); |
|
| 160 | + $this->logging = 'yes' === $this->get_option('logging'); |
|
| 161 | + $this->allow_remember_me = 'yes' === $this->get_option('allow_remember_me', 'no'); |
|
| 162 | + |
|
| 163 | + if ($this->stripe_checkout) { |
|
| 164 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + if ($this->testmode) { |
|
| 168 | + $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">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing'); |
|
| 169 | + $this->description = trim($this->description); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
| 173 | 173 | |
| 174 | 174 | // Hooks. |
| 175 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 176 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
| 177 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 175 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 176 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
| 177 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -184,24 +184,24 @@ discard block |
||
| 184 | 184 | * @return string |
| 185 | 185 | */ |
| 186 | 186 | public function get_icon() { |
| 187 | - $ext = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png'; |
|
| 188 | - $style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : ''; |
|
| 187 | + $ext = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png'; |
|
| 188 | + $style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : ''; |
|
| 189 | 189 | |
| 190 | - $icon = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
| 191 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
| 192 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
| 190 | + $icon = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
| 191 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
| 192 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
| 193 | 193 | |
| 194 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
| 195 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
| 196 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
| 197 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
| 194 | + if ('USD' === get_woocommerce_currency()) { |
|
| 195 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
| 196 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
| 197 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - if ( $this->bitcoin && $this->stripe_checkout ) { |
|
| 201 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="24" ' . $style . ' />'; |
|
| 200 | + if ($this->bitcoin && $this->stripe_checkout) { |
|
| 201 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="24" ' . $style . ' />'; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id ); |
|
| 204 | + return apply_filters('woocommerce_gateway_icon', $icon, $this->id); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -212,11 +212,11 @@ discard block |
||
| 212 | 212 | * |
| 213 | 213 | * @return float|int |
| 214 | 214 | */ |
| 215 | - public function get_stripe_amount( $total, $currency = '' ) { |
|
| 216 | - if ( ! $currency ) { |
|
| 215 | + public function get_stripe_amount($total, $currency = '') { |
|
| 216 | + if ( ! $currency) { |
|
| 217 | 217 | $currency = get_woocommerce_currency(); |
| 218 | 218 | } |
| 219 | - switch ( strtoupper( $currency ) ) { |
|
| 219 | + switch (strtoupper($currency)) { |
|
| 220 | 220 | // Zero decimal currencies. |
| 221 | 221 | case 'BIF' : |
| 222 | 222 | case 'CLP' : |
@@ -233,10 +233,10 @@ discard block |
||
| 233 | 233 | case 'XAF' : |
| 234 | 234 | case 'XOF' : |
| 235 | 235 | case 'XPF' : |
| 236 | - $total = absint( $total ); |
|
| 236 | + $total = absint($total); |
|
| 237 | 237 | break; |
| 238 | 238 | default : |
| 239 | - $total = round( $total, 2 ) * 100; // In cents. |
|
| 239 | + $total = round($total, 2) * 100; // In cents. |
|
| 240 | 240 | break; |
| 241 | 241 | } |
| 242 | 242 | return $total; |
@@ -246,13 +246,13 @@ discard block |
||
| 246 | 246 | * Check if SSL is enabled and notify the user |
| 247 | 247 | */ |
| 248 | 248 | public function admin_notices() { |
| 249 | - if ( 'no' === $this->enabled ) { |
|
| 249 | + if ('no' === $this->enabled) { |
|
| 250 | 250 | return; |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
| 254 | - if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
| 255 | - echo '<div class="error stripe-ssl-message"><p>' . sprintf( __( 'Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ) ) . '</p></div>'; |
|
| 254 | + if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
| 255 | + echo '<div class="error stripe-ssl-message"><p>' . sprintf(__('Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout')) . '</p></div>'; |
|
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | |
@@ -260,11 +260,11 @@ discard block |
||
| 260 | 260 | * Check if this gateway is enabled |
| 261 | 261 | */ |
| 262 | 262 | public function is_available() { |
| 263 | - if ( 'yes' === $this->enabled ) { |
|
| 264 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
| 263 | + if ('yes' === $this->enabled) { |
|
| 264 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
| 265 | 265 | return false; |
| 266 | 266 | } |
| 267 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
| 267 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
| 268 | 268 | return false; |
| 269 | 269 | } |
| 270 | 270 | return true; |
@@ -276,9 +276,9 @@ discard block |
||
| 276 | 276 | * Initialise Gateway Settings Form Fields |
| 277 | 277 | */ |
| 278 | 278 | public function init_form_fields() { |
| 279 | - $this->form_fields = include( 'settings-stripe.php' ); |
|
| 279 | + $this->form_fields = include('settings-stripe.php'); |
|
| 280 | 280 | |
| 281 | - wc_enqueue_js( " |
|
| 281 | + wc_enqueue_js(" |
|
| 282 | 282 | jQuery( function( $ ) { |
| 283 | 283 | $( document.body ).on( 'change', '#woocommerce_stripe_testmode', function() { |
| 284 | 284 | var test_secret_key = $( '#woocommerce_stripe_test_secret_key' ).parents( 'tr' ).eq( 0 ), |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | var value = $( this ).val(); |
| 324 | 324 | |
| 325 | 325 | if ( value.indexOf( '_test_' ) >= 0 ) { |
| 326 | - $( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __( 'This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe' ) . "</span>' ); |
|
| 326 | + $( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __('This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe') . "</span>' ); |
|
| 327 | 327 | } else { |
| 328 | 328 | $( this ).css( 'border-color', '' ); |
| 329 | 329 | $( '.stripe-error-description', $( this ).parent() ).remove(); |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | var value = $( this ).val(); |
| 335 | 335 | |
| 336 | 336 | if ( value.indexOf( '_live_' ) >= 0 ) { |
| 337 | - $( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __( 'This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe' ) . "</span>' ); |
|
| 337 | + $( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __('This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe') . "</span>' ); |
|
| 338 | 338 | } else { |
| 339 | 339 | $( this ).css( 'border-color', '' ); |
| 340 | 340 | $( '.stripe-error-description', $( this ).parent() ).remove(); |
@@ -349,54 +349,54 @@ discard block |
||
| 349 | 349 | */ |
| 350 | 350 | public function payment_fields() { |
| 351 | 351 | $user = wp_get_current_user(); |
| 352 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
| 352 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
| 353 | 353 | $total = WC()->cart->total; |
| 354 | 354 | |
| 355 | 355 | // If paying from order, we need to get total from order not cart. |
| 356 | - if ( isset( $_GET['pay_for_order'] ) && isset( $_GET['key'] ) ) { |
|
| 357 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 356 | + if (isset($_GET['pay_for_order']) && isset($_GET['key'])) { |
|
| 357 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 358 | 358 | $total = $order->get_total(); |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | - if ( $user->ID ) { |
|
| 362 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
| 361 | + if ($user->ID) { |
|
| 362 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
| 363 | 363 | $user_email = $user_email ? $user_email : $user->user_email; |
| 364 | 364 | } else { |
| 365 | 365 | $user_email = ''; |
| 366 | 366 | } |
| 367 | 367 | |
| 368 | - if ( is_add_payment_method_page() ) { |
|
| 369 | - $pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' ); |
|
| 368 | + if (is_add_payment_method_page()) { |
|
| 369 | + $pay_button_text = __('Add Card', 'woocommerce-gateway-stripe'); |
|
| 370 | 370 | } else { |
| 371 | 371 | $pay_button_text = ''; |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | echo '<div |
| 375 | 375 | id="stripe-payment-data" |
| 376 | - data-panel-label="' . esc_attr( $pay_button_text ) . '" |
|
| 376 | + data-panel-label="' . esc_attr($pay_button_text) . '" |
|
| 377 | 377 | data-description="" |
| 378 | - data-email="' . esc_attr( $user_email ) . '" |
|
| 379 | - data-amount="' . esc_attr( $this->get_stripe_amount( $total ) ) . '" |
|
| 380 | - data-name="' . esc_attr( $this->statement_descriptor ) . '" |
|
| 381 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
| 382 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
| 383 | - data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '" |
|
| 384 | - data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '" |
|
| 385 | - data-allow-remember-me="' . esc_attr( $this->allow_remember_me ? 'true' : 'false' ) . '">'; |
|
| 378 | + data-email="' . esc_attr($user_email) . '" |
|
| 379 | + data-amount="' . esc_attr($this->get_stripe_amount($total)) . '" |
|
| 380 | + data-name="' . esc_attr($this->statement_descriptor) . '" |
|
| 381 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
| 382 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
| 383 | + data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '" |
|
| 384 | + data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '" |
|
| 385 | + data-allow-remember-me="' . esc_attr($this->allow_remember_me ? 'true' : 'false') . '">'; |
|
| 386 | 386 | |
| 387 | - if ( $this->description ) { |
|
| 388 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 387 | + if ($this->description) { |
|
| 388 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | - if ( $display_tokenization ) { |
|
| 391 | + if ($display_tokenization) { |
|
| 392 | 392 | $this->tokenization_script(); |
| 393 | 393 | $this->saved_payment_methods(); |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | - if ( ! $this->stripe_checkout ) { |
|
| 396 | + if ( ! $this->stripe_checkout) { |
|
| 397 | 397 | $this->form(); |
| 398 | 398 | |
| 399 | - if ( $display_tokenization ) { |
|
| 399 | + if ($display_tokenization) { |
|
| 400 | 400 | $this->save_payment_method_checkbox(); |
| 401 | 401 | } |
| 402 | 402 | } |
@@ -412,20 +412,20 @@ discard block |
||
| 412 | 412 | * @return array |
| 413 | 413 | */ |
| 414 | 414 | public function get_localized_messages() { |
| 415 | - return apply_filters( 'wc_stripe_localized_messages', array( |
|
| 416 | - 'invalid_number' => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ), |
|
| 417 | - 'invalid_expiry_month' => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ), |
|
| 418 | - 'invalid_expiry_year' => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ), |
|
| 419 | - 'invalid_cvc' => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ), |
|
| 420 | - 'incorrect_number' => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ), |
|
| 421 | - 'expired_card' => __( 'The card has expired.', 'woocommerce-gateway-stripe' ), |
|
| 422 | - 'incorrect_cvc' => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ), |
|
| 423 | - 'incorrect_zip' => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ), |
|
| 424 | - 'card_declined' => __( 'The card was declined.', 'woocommerce-gateway-stripe' ), |
|
| 425 | - 'missing' => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ), |
|
| 426 | - 'processing_error' => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ), |
|
| 427 | - 'invalid_request_error' => __( 'Could not find payment information.', 'woocommerce-gateway-stripe' ), |
|
| 428 | - ) ); |
|
| 415 | + return apply_filters('wc_stripe_localized_messages', array( |
|
| 416 | + 'invalid_number' => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'), |
|
| 417 | + 'invalid_expiry_month' => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'), |
|
| 418 | + 'invalid_expiry_year' => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'), |
|
| 419 | + 'invalid_cvc' => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'), |
|
| 420 | + 'incorrect_number' => __('The card number is incorrect.', 'woocommerce-gateway-stripe'), |
|
| 421 | + 'expired_card' => __('The card has expired.', 'woocommerce-gateway-stripe'), |
|
| 422 | + 'incorrect_cvc' => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'), |
|
| 423 | + 'incorrect_zip' => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'), |
|
| 424 | + 'card_declined' => __('The card was declined.', 'woocommerce-gateway-stripe'), |
|
| 425 | + 'missing' => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'), |
|
| 426 | + 'processing_error' => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'), |
|
| 427 | + 'invalid_request_error' => __('Could not find payment information.', 'woocommerce-gateway-stripe'), |
|
| 428 | + )); |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | /** |
@@ -436,30 +436,30 @@ discard block |
||
| 436 | 436 | * @access public |
| 437 | 437 | */ |
| 438 | 438 | public function payment_scripts() { |
| 439 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 439 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
| 440 | 440 | return; |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 443 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 444 | 444 | |
| 445 | - if ( $this->stripe_checkout ) { |
|
| 446 | - wp_enqueue_script( 'stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true ); |
|
| 447 | - wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe_checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 445 | + if ($this->stripe_checkout) { |
|
| 446 | + wp_enqueue_script('stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true); |
|
| 447 | + wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe_checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true); |
|
| 448 | 448 | } else { |
| 449 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
| 450 | - wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 449 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
| 450 | + wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true); |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | $stripe_params = array( |
| 454 | 454 | 'key' => $this->publishable_key, |
| 455 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
| 456 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
| 455 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
| 456 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
| 457 | 457 | ); |
| 458 | 458 | |
| 459 | 459 | // If we're on the pay page we need to pass stripe.js the address of the order. |
| 460 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { |
|
| 461 | - $order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); |
|
| 462 | - $order = wc_get_order( $order_id ); |
|
| 460 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { |
|
| 461 | + $order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); |
|
| 462 | + $order = wc_get_order($order_id); |
|
| 463 | 463 | |
| 464 | 464 | $stripe_params['billing_first_name'] = $order->billing_first_name; |
| 465 | 465 | $stripe_params['billing_last_name'] = $order->billing_last_name; |
@@ -471,14 +471,14 @@ discard block |
||
| 471 | 471 | $stripe_params['billing_country'] = $order->billing_country; |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | - $stripe_params['no_prepaid_card_msg'] = __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ); |
|
| 475 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
| 476 | - $stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no'; |
|
| 474 | + $stripe_params['no_prepaid_card_msg'] = __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'); |
|
| 475 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
| 476 | + $stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no'; |
|
| 477 | 477 | |
| 478 | 478 | // merge localized messages to be use in JS |
| 479 | - $stripe_params = array_merge( $stripe_params, $this->get_localized_messages() ); |
|
| 479 | + $stripe_params = array_merge($stripe_params, $this->get_localized_messages()); |
|
| 480 | 480 | |
| 481 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
| 481 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | /** |
@@ -487,24 +487,24 @@ discard block |
||
| 487 | 487 | * @param object $source |
| 488 | 488 | * @return array() |
| 489 | 489 | */ |
| 490 | - protected function generate_payment_request( $order, $source ) { |
|
| 490 | + protected function generate_payment_request($order, $source) { |
|
| 491 | 491 | $post_data = array(); |
| 492 | - $post_data['currency'] = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() ); |
|
| 493 | - $post_data['amount'] = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
| 494 | - $post_data['description'] = sprintf( __( '%s - Order %s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() ); |
|
| 492 | + $post_data['currency'] = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency()); |
|
| 493 | + $post_data['amount'] = $this->get_stripe_amount($order->get_total(), $post_data['currency']); |
|
| 494 | + $post_data['description'] = sprintf(__('%s - Order %s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number()); |
|
| 495 | 495 | $post_data['capture'] = $this->capture ? 'true' : 'false'; |
| 496 | 496 | |
| 497 | - if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
| 497 | + if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
| 498 | 498 | $post_data['receipt_email'] = $order->billing_email; |
| 499 | 499 | } |
| 500 | 500 | |
| 501 | - $post_data['expand[]'] = 'balance_transaction'; |
|
| 501 | + $post_data['expand[]'] = 'balance_transaction'; |
|
| 502 | 502 | |
| 503 | - if ( $source->customer ) { |
|
| 503 | + if ($source->customer) { |
|
| 504 | 504 | $post_data['customer'] = $source->customer; |
| 505 | 505 | } |
| 506 | 506 | |
| 507 | - if ( $source->source ) { |
|
| 507 | + if ($source->source) { |
|
| 508 | 508 | $post_data['source'] = $source->source; |
| 509 | 509 | } |
| 510 | 510 | |
@@ -516,7 +516,7 @@ discard block |
||
| 516 | 516 | * @param WC_Order $order |
| 517 | 517 | * @param object $source |
| 518 | 518 | */ |
| 519 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source ); |
|
| 519 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source); |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | /** |
@@ -528,22 +528,22 @@ discard block |
||
| 528 | 528 | * @throws Exception When card was not added or for and invalid card. |
| 529 | 529 | * @return object |
| 530 | 530 | */ |
| 531 | - protected function get_source( $user_id, $force_customer = false ) { |
|
| 532 | - $stripe_customer = new WC_Stripe_Customer( $user_id ); |
|
| 531 | + protected function get_source($user_id, $force_customer = false) { |
|
| 532 | + $stripe_customer = new WC_Stripe_Customer($user_id); |
|
| 533 | 533 | $stripe_source = false; |
| 534 | 534 | $token_id = false; |
| 535 | 535 | |
| 536 | 536 | // New CC info was entered and we have a new token to process |
| 537 | - if ( isset( $_POST['stripe_token'] ) ) { |
|
| 538 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
| 539 | - $maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] ); |
|
| 537 | + if (isset($_POST['stripe_token'])) { |
|
| 538 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
| 539 | + $maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']); |
|
| 540 | 540 | |
| 541 | 541 | // This is true if the user wants to store the card to their account. |
| 542 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) { |
|
| 543 | - $stripe_source = $stripe_customer->add_card( $stripe_token ); |
|
| 542 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) { |
|
| 543 | + $stripe_source = $stripe_customer->add_card($stripe_token); |
|
| 544 | 544 | |
| 545 | - if ( is_wp_error( $stripe_source ) ) { |
|
| 546 | - throw new Exception( $stripe_source->get_error_message() ); |
|
| 545 | + if (is_wp_error($stripe_source)) { |
|
| 546 | + throw new Exception($stripe_source->get_error_message()); |
|
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | } else { |
@@ -554,13 +554,13 @@ discard block |
||
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | // Use an existing token, and then process the payment |
| 557 | - elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) { |
|
| 558 | - $token_id = wc_clean( $_POST['wc-stripe-payment-token'] ); |
|
| 559 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
| 557 | + elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) { |
|
| 558 | + $token_id = wc_clean($_POST['wc-stripe-payment-token']); |
|
| 559 | + $token = WC_Payment_Tokens::get($token_id); |
|
| 560 | 560 | |
| 561 | - if ( ! $token || $token->get_user_id() !== get_current_user_id() ) { |
|
| 562 | - WC()->session->set( 'refresh_totals', true ); |
|
| 563 | - throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
| 561 | + if ( ! $token || $token->get_user_id() !== get_current_user_id()) { |
|
| 562 | + WC()->session->set('refresh_totals', true); |
|
| 563 | + throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | $stripe_source = $token->get_token(); |
@@ -584,16 +584,16 @@ discard block |
||
| 584 | 584 | * @param object $order |
| 585 | 585 | * @return object |
| 586 | 586 | */ |
| 587 | - protected function get_order_source( $order = null ) { |
|
| 587 | + protected function get_order_source($order = null) { |
|
| 588 | 588 | $stripe_customer = new WC_Stripe_Customer(); |
| 589 | 589 | $stripe_source = false; |
| 590 | 590 | $token_id = false; |
| 591 | 591 | |
| 592 | - if ( $order ) { |
|
| 593 | - if ( $meta_value = get_post_meta( $order->id, '_stripe_customer_id', true ) ) { |
|
| 594 | - $stripe_customer->set_id( $meta_value ); |
|
| 592 | + if ($order) { |
|
| 593 | + if ($meta_value = get_post_meta($order->id, '_stripe_customer_id', true)) { |
|
| 594 | + $stripe_customer->set_id($meta_value); |
|
| 595 | 595 | } |
| 596 | - if ( $meta_value = get_post_meta( $order->id, '_stripe_card_id', true ) ) { |
|
| 596 | + if ($meta_value = get_post_meta($order->id, '_stripe_card_id', true)) { |
|
| 597 | 597 | $stripe_source = $meta_value; |
| 598 | 598 | } |
| 599 | 599 | } |
@@ -616,50 +616,50 @@ discard block |
||
| 616 | 616 | * |
| 617 | 617 | * @return array|void |
| 618 | 618 | */ |
| 619 | - public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
| 619 | + public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
| 620 | 620 | try { |
| 621 | - $order = wc_get_order( $order_id ); |
|
| 622 | - $source = $this->get_source( get_current_user_id(), $force_customer ); |
|
| 621 | + $order = wc_get_order($order_id); |
|
| 622 | + $source = $this->get_source(get_current_user_id(), $force_customer); |
|
| 623 | 623 | |
| 624 | - if ( empty( $source->source ) && empty( $source->customer ) ) { |
|
| 625 | - $error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' ); |
|
| 626 | - $error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' ); |
|
| 627 | - throw new Exception( $error_msg ); |
|
| 624 | + if (empty($source->source) && empty($source->customer)) { |
|
| 625 | + $error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe'); |
|
| 626 | + $error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe'); |
|
| 627 | + throw new Exception($error_msg); |
|
| 628 | 628 | } |
| 629 | 629 | |
| 630 | 630 | // Store source to order meta. |
| 631 | - $this->save_source( $order, $source ); |
|
| 631 | + $this->save_source($order, $source); |
|
| 632 | 632 | |
| 633 | 633 | // Handle payment. |
| 634 | - if ( $order->get_total() > 0 ) { |
|
| 634 | + if ($order->get_total() > 0) { |
|
| 635 | 635 | |
| 636 | - if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) { |
|
| 637 | - 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::get_minimum_amount() / 100 ) ) ); |
|
| 636 | + if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) { |
|
| 637 | + 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::get_minimum_amount() / 100))); |
|
| 638 | 638 | } |
| 639 | 639 | |
| 640 | - WC_Stripe::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
| 640 | + WC_Stripe::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
| 641 | 641 | |
| 642 | 642 | // Make the request. |
| 643 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
| 643 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
| 644 | 644 | |
| 645 | - if ( is_wp_error( $response ) ) { |
|
| 645 | + if (is_wp_error($response)) { |
|
| 646 | 646 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
| 647 | - if ( 'customer' === $response->get_error_code() && $retry ) { |
|
| 648 | - delete_user_meta( get_current_user_id(), '_stripe_customer_id' ); |
|
| 649 | - return $this->process_payment( $order_id, false, $force_customer ); |
|
| 647 | + if ('customer' === $response->get_error_code() && $retry) { |
|
| 648 | + delete_user_meta(get_current_user_id(), '_stripe_customer_id'); |
|
| 649 | + return $this->process_payment($order_id, false, $force_customer); |
|
| 650 | 650 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
| 651 | - } elseif ( 'source' === $response->get_error_code() && $source->token_id ) { |
|
| 652 | - $token = WC_Payment_Tokens::get( $source->token_id ); |
|
| 651 | + } elseif ('source' === $response->get_error_code() && $source->token_id) { |
|
| 652 | + $token = WC_Payment_Tokens::get($source->token_id); |
|
| 653 | 653 | $token->delete(); |
| 654 | - throw new Exception( __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ) ); |
|
| 654 | + throw new Exception(__('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe')); |
|
| 655 | 655 | } |
| 656 | 656 | $localized_messages = $this->get_localized_messages(); |
| 657 | 657 | |
| 658 | - throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) ); |
|
| 658 | + throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message())); |
|
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | // Process valid response. |
| 662 | - $this->process_response( $response, $order ); |
|
| 662 | + $this->process_response($response, $order); |
|
| 663 | 663 | } else { |
| 664 | 664 | $order->payment_complete(); |
| 665 | 665 | } |
@@ -667,23 +667,23 @@ discard block |
||
| 667 | 667 | // Remove cart. |
| 668 | 668 | WC()->cart->empty_cart(); |
| 669 | 669 | |
| 670 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
| 670 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
| 671 | 671 | |
| 672 | 672 | // Return thank you page redirect. |
| 673 | 673 | return array( |
| 674 | 674 | 'result' => 'success', |
| 675 | - 'redirect' => $this->get_return_url( $order ) |
|
| 675 | + 'redirect' => $this->get_return_url($order) |
|
| 676 | 676 | ); |
| 677 | 677 | |
| 678 | - } catch ( Exception $e ) { |
|
| 679 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 680 | - WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
| 678 | + } catch (Exception $e) { |
|
| 679 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 680 | + WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
| 681 | 681 | |
| 682 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 683 | - $this->send_failed_order_email( $order_id ); |
|
| 682 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 683 | + $this->send_failed_order_email($order_id); |
|
| 684 | 684 | } |
| 685 | 685 | |
| 686 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 686 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 687 | 687 | |
| 688 | 688 | return array( |
| 689 | 689 | 'result' => 'fail', |
@@ -698,52 +698,52 @@ discard block |
||
| 698 | 698 | * @param WC_Order $order For to which the source applies. |
| 699 | 699 | * @param stdClass $source Source information. |
| 700 | 700 | */ |
| 701 | - protected function save_source( $order, $source ) { |
|
| 701 | + protected function save_source($order, $source) { |
|
| 702 | 702 | // Store source in the order. |
| 703 | - if ( $source->customer ) { |
|
| 704 | - update_post_meta( $order->id, '_stripe_customer_id', $source->customer ); |
|
| 703 | + if ($source->customer) { |
|
| 704 | + update_post_meta($order->id, '_stripe_customer_id', $source->customer); |
|
| 705 | 705 | } |
| 706 | - if ( $source->source ) { |
|
| 707 | - update_post_meta( $order->id, '_stripe_card_id', $source->source ); |
|
| 706 | + if ($source->source) { |
|
| 707 | + update_post_meta($order->id, '_stripe_card_id', $source->source); |
|
| 708 | 708 | } |
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | /** |
| 712 | 712 | * Store extra meta data for an order from a Stripe Response. |
| 713 | 713 | */ |
| 714 | - public function process_response( $response, $order ) { |
|
| 715 | - WC_Stripe::log( "Processing response: " . print_r( $response, true ) ); |
|
| 714 | + public function process_response($response, $order) { |
|
| 715 | + WC_Stripe::log("Processing response: " . print_r($response, true)); |
|
| 716 | 716 | |
| 717 | 717 | // Store charge data |
| 718 | - update_post_meta( $order->id, '_stripe_charge_id', $response->id ); |
|
| 719 | - update_post_meta( $order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' ); |
|
| 718 | + update_post_meta($order->id, '_stripe_charge_id', $response->id); |
|
| 719 | + update_post_meta($order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no'); |
|
| 720 | 720 | |
| 721 | 721 | // Store other data such as fees |
| 722 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
| 722 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
| 723 | 723 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
| 724 | 724 | // values are in the local currency of the Stripe account, not from WC. |
| 725 | - $fee = ! empty( $response->balance_transaction->fee ) ? number_format( $response->balance_transaction->fee / 100, 2, '.', '' ) : 0; |
|
| 726 | - $net = ! empty( $response->balance_transaction->net ) ? number_format( $response->balance_transaction->net / 100, 2, '.', '' ) : 0; |
|
| 727 | - update_post_meta( $order->id, 'Stripe Fee', $fee ); |
|
| 728 | - update_post_meta( $order->id, 'Net Revenue From Stripe', $net ); |
|
| 725 | + $fee = ! empty($response->balance_transaction->fee) ? number_format($response->balance_transaction->fee / 100, 2, '.', '') : 0; |
|
| 726 | + $net = ! empty($response->balance_transaction->net) ? number_format($response->balance_transaction->net / 100, 2, '.', '') : 0; |
|
| 727 | + update_post_meta($order->id, 'Stripe Fee', $fee); |
|
| 728 | + update_post_meta($order->id, 'Net Revenue From Stripe', $net); |
|
| 729 | 729 | } |
| 730 | 730 | |
| 731 | - if ( $response->captured ) { |
|
| 732 | - $order->payment_complete( $response->id ); |
|
| 731 | + if ($response->captured) { |
|
| 732 | + $order->payment_complete($response->id); |
|
| 733 | 733 | |
| 734 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
| 735 | - $order->add_order_note( $message ); |
|
| 736 | - WC_Stripe::log( 'Success: ' . $message ); |
|
| 734 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
| 735 | + $order->add_order_note($message); |
|
| 736 | + WC_Stripe::log('Success: ' . $message); |
|
| 737 | 737 | |
| 738 | 738 | } else { |
| 739 | - add_post_meta( $order->id, '_transaction_id', $response->id, true ); |
|
| 739 | + add_post_meta($order->id, '_transaction_id', $response->id, true); |
|
| 740 | 740 | |
| 741 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 741 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 742 | 742 | $order->reduce_order_stock(); |
| 743 | 743 | } |
| 744 | 744 | |
| 745 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
| 746 | - WC_Stripe::log( "Successful auth: $response->id" ); |
|
| 745 | + $order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id)); |
|
| 746 | + WC_Stripe::log("Successful auth: $response->id"); |
|
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | return $response; |
@@ -755,32 +755,32 @@ discard block |
||
| 755 | 755 | * @since 3.0.0 |
| 756 | 756 | */ |
| 757 | 757 | public function add_payment_method() { |
| 758 | - if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
| 759 | - wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' ); |
|
| 758 | + if (empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
| 759 | + wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error'); |
|
| 760 | 760 | return; |
| 761 | 761 | } |
| 762 | 762 | |
| 763 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 764 | - $card = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) ); |
|
| 763 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 764 | + $card = $stripe_customer->add_card(wc_clean($_POST['stripe_token'])); |
|
| 765 | 765 | |
| 766 | - if ( is_wp_error( $card ) ) { |
|
| 766 | + if (is_wp_error($card)) { |
|
| 767 | 767 | $localized_messages = $this->get_localized_messages(); |
| 768 | - $error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ); |
|
| 768 | + $error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe'); |
|
| 769 | 769 | |
| 770 | 770 | // loop through the errors to find matching localized message |
| 771 | - foreach ( $card->errors as $error => $msg ) { |
|
| 772 | - if ( isset( $localized_messages[ $error ] ) ) { |
|
| 773 | - $error_msg = $localized_messages[ $error ]; |
|
| 771 | + foreach ($card->errors as $error => $msg) { |
|
| 772 | + if (isset($localized_messages[$error])) { |
|
| 773 | + $error_msg = $localized_messages[$error]; |
|
| 774 | 774 | } |
| 775 | 775 | } |
| 776 | 776 | |
| 777 | - wc_add_notice( $error_msg, 'error' ); |
|
| 777 | + wc_add_notice($error_msg, 'error'); |
|
| 778 | 778 | return; |
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | return array( |
| 782 | 782 | 'result' => 'success', |
| 783 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
| 783 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
| 784 | 784 | ); |
| 785 | 785 | } |
| 786 | 786 | |
@@ -790,36 +790,36 @@ discard block |
||
| 790 | 790 | * @param float $amount |
| 791 | 791 | * @return bool |
| 792 | 792 | */ |
| 793 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
| 794 | - $order = wc_get_order( $order_id ); |
|
| 793 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
| 794 | + $order = wc_get_order($order_id); |
|
| 795 | 795 | |
| 796 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
| 796 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
| 797 | 797 | return false; |
| 798 | 798 | } |
| 799 | 799 | |
| 800 | 800 | $body = array(); |
| 801 | 801 | |
| 802 | - if ( ! is_null( $amount ) ) { |
|
| 803 | - $body['amount'] = $this->get_stripe_amount( $amount ); |
|
| 802 | + if ( ! is_null($amount)) { |
|
| 803 | + $body['amount'] = $this->get_stripe_amount($amount); |
|
| 804 | 804 | } |
| 805 | 805 | |
| 806 | - if ( $reason ) { |
|
| 806 | + if ($reason) { |
|
| 807 | 807 | $body['metadata'] = array( |
| 808 | 808 | 'reason' => $reason, |
| 809 | 809 | ); |
| 810 | 810 | } |
| 811 | 811 | |
| 812 | - WC_Stripe::log( "Info: Beginning refund for order $order_id for the amount of {$amount}" ); |
|
| 812 | + WC_Stripe::log("Info: Beginning refund for order $order_id for the amount of {$amount}"); |
|
| 813 | 813 | |
| 814 | - $response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' ); |
|
| 814 | + $response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds'); |
|
| 815 | 815 | |
| 816 | - if ( is_wp_error( $response ) ) { |
|
| 817 | - WC_Stripe::log( "Error: " . $response->get_error_message() ); |
|
| 816 | + if (is_wp_error($response)) { |
|
| 817 | + WC_Stripe::log("Error: " . $response->get_error_message()); |
|
| 818 | 818 | return $response; |
| 819 | - } elseif ( ! empty( $response->id ) ) { |
|
| 820 | - $refund_message = sprintf( __( 'Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason ); |
|
| 821 | - $order->add_order_note( $refund_message ); |
|
| 822 | - WC_Stripe::log( "Success: " . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
| 819 | + } elseif ( ! empty($response->id)) { |
|
| 820 | + $refund_message = sprintf(__('Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason); |
|
| 821 | + $order->add_order_note($refund_message); |
|
| 822 | + WC_Stripe::log("Success: " . html_entity_decode(strip_tags($refund_message))); |
|
| 823 | 823 | return true; |
| 824 | 824 | } |
| 825 | 825 | } |
@@ -832,10 +832,10 @@ discard block |
||
| 832 | 832 | * @param int $order_id |
| 833 | 833 | * @return null |
| 834 | 834 | */ |
| 835 | - public function send_failed_order_email( $order_id ) { |
|
| 835 | + public function send_failed_order_email($order_id) { |
|
| 836 | 836 | $emails = WC()->mailer()->get_emails(); |
| 837 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
| 838 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
| 837 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
| 838 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
| 839 | 839 | } |
| 840 | 840 | } |
| 841 | 841 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -47,9 +47,9 @@ discard block |
||
| 47 | 47 | public function __construct() { |
| 48 | 48 | self::$_this = $this; |
| 49 | 49 | |
| 50 | - $this->_gateway_settings = get_option( 'woocommerce_stripe_settings', '' ); |
|
| 50 | + $this->_gateway_settings = get_option('woocommerce_stripe_settings', ''); |
|
| 51 | 51 | |
| 52 | - $this->statement_descriptor = ! empty( $this->_gateway_settings['statement_descriptor'] ) ? $this->_gateway_settings['statement_descriptor'] : wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); |
|
| 52 | + $this->statement_descriptor = ! empty($this->_gateway_settings['statement_descriptor']) ? $this->_gateway_settings['statement_descriptor'] : wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 53 | 53 | |
| 54 | 54 | $this->init(); |
| 55 | 55 | } |
@@ -66,26 +66,26 @@ discard block |
||
| 66 | 66 | * @version 3.1.0 |
| 67 | 67 | */ |
| 68 | 68 | public function init() { |
| 69 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 70 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_button' ), 20 ); |
|
| 71 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_button' ) ); |
|
| 72 | - add_action( 'wc_ajax_wc_stripe_apple_pay', array( $this, 'process_apple_pay' ) ); |
|
| 73 | - add_action( 'wc_ajax_wc_stripe_generate_apple_pay_cart', array( $this, 'generate_apple_pay_cart' ) ); |
|
| 74 | - add_action( 'wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array( $this, 'get_shipping_methods' ) ); |
|
| 75 | - add_action( 'wc_ajax_wc_stripe_apple_pay_update_shipping_method', array( $this, 'update_shipping_method' ) ); |
|
| 76 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
| 69 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 70 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_button'), 20); |
|
| 71 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_button')); |
|
| 72 | + add_action('wc_ajax_wc_stripe_apple_pay', array($this, 'process_apple_pay')); |
|
| 73 | + add_action('wc_ajax_wc_stripe_generate_apple_pay_cart', array($this, 'generate_apple_pay_cart')); |
|
| 74 | + add_action('wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array($this, 'get_shipping_methods')); |
|
| 75 | + add_action('wc_ajax_wc_stripe_apple_pay_update_shipping_method', array($this, 'update_shipping_method')); |
|
| 76 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
| 80 | 80 | * Filters the gateway title to reflect Apple Pay. |
| 81 | 81 | * |
| 82 | 82 | */ |
| 83 | - public function filter_gateway_title( $title, $id ) { |
|
| 83 | + public function filter_gateway_title($title, $id) { |
|
| 84 | 84 | global $post; |
| 85 | 85 | |
| 86 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
| 86 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
| 87 | 87 | |
| 88 | - if ( 'stripe' === $id && ! empty( $method_title ) ) { |
|
| 88 | + if ('stripe' === $id && ! empty($method_title)) { |
|
| 89 | 89 | return $method_title; |
| 90 | 90 | } |
| 91 | 91 | |
@@ -99,38 +99,38 @@ discard block |
||
| 99 | 99 | * @version 3.1.0 |
| 100 | 100 | */ |
| 101 | 101 | public function payment_scripts() { |
| 102 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 102 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - if ( ! $this->is_supported_product_type() ) { |
|
| 106 | + if ( ! $this->is_supported_product_type()) { |
|
| 107 | 107 | return; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 110 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 111 | 111 | |
| 112 | - wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
| 112 | + wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
| 113 | 113 | |
| 114 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
| 115 | - wp_enqueue_script( 'woocommerce_stripe_apple_pay', plugins_url( 'assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 114 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
| 115 | + wp_enqueue_script('woocommerce_stripe_apple_pay', plugins_url('assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true); |
|
| 116 | 116 | |
| 117 | 117 | $publishable_key = 'yes' === $this->_gateway_settings['testmode'] ? $this->_gateway_settings['test_publishable_key'] : $this->_gateway_settings['publishable_key']; |
| 118 | 118 | |
| 119 | 119 | $stripe_params = array( |
| 120 | 120 | 'key' => $publishable_key, |
| 121 | 121 | 'currency_code' => get_woocommerce_currency(), |
| 122 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 122 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 123 | 123 | 'label' => $this->statement_descriptor, |
| 124 | - 'ajaxurl' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
| 125 | - 'stripe_apple_pay_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ), |
|
| 126 | - 'stripe_apple_pay_cart_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ), |
|
| 127 | - 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ), |
|
| 128 | - 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ), |
|
| 124 | + 'ajaxurl' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
| 125 | + 'stripe_apple_pay_nonce' => wp_create_nonce('_wc_stripe_apple_pay_nonce'), |
|
| 126 | + 'stripe_apple_pay_cart_nonce' => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'), |
|
| 127 | + 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'), |
|
| 128 | + 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'), |
|
| 129 | 129 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
| 130 | 130 | 'is_cart_page' => is_cart() ? 'yes' : 'no', |
| 131 | 131 | ); |
| 132 | 132 | |
| 133 | - wp_localize_script( 'woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters( 'wc_stripe_apple_pay_params', $stripe_params ) ); |
|
| 133 | + wp_localize_script('woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters('wc_stripe_apple_pay_params', $stripe_params)); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -138,8 +138,8 @@ discard block |
||
| 138 | 138 | * |
| 139 | 139 | */ |
| 140 | 140 | public function is_supported_product_type() { |
| 141 | - foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 142 | - if ( 'subscription' === $values['data']->product_type ) { |
|
| 141 | + foreach (WC()->cart->get_cart() as $cart_item_key => $values) { |
|
| 142 | + if ('subscription' === $values['data']->product_type) { |
|
| 143 | 143 | return false; |
| 144 | 144 | } |
| 145 | 145 | } |
@@ -162,19 +162,19 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | if ( |
| 164 | 164 | 'yes' !== $this->_gateway_settings['apple_pay'] |
| 165 | - || ! isset( $gateways['stripe'] ) |
|
| 165 | + || ! isset($gateways['stripe']) |
|
| 166 | 166 | ) { |
| 167 | 167 | return; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - if ( ! $this->is_supported_product_type() ) { |
|
| 170 | + if ( ! $this->is_supported_product_type()) { |
|
| 171 | 171 | return; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - $apple_pay_button = ! empty( $this->_gateway_settings['apple_pay_button'] ) ? $this->_gateway_settings['apple_pay_button'] : 'black'; |
|
| 175 | - $country = strtolower( substr( get_option( 'woocommerce_default_country' ), 0, 2 ) ); |
|
| 174 | + $apple_pay_button = ! empty($this->_gateway_settings['apple_pay_button']) ? $this->_gateway_settings['apple_pay_button'] : 'black'; |
|
| 175 | + $country = strtolower(substr(get_option('woocommerce_default_country'), 0, 2)); |
|
| 176 | 176 | ?> |
| 177 | - <button class="apple-pay-button" lang="<?php echo esc_attr( $country ); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr( $apple_pay_button ); ?>;"></button> |
|
| 177 | + <button class="apple-pay-button" lang="<?php echo esc_attr($country); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr($apple_pay_button); ?>;"></button> |
|
| 178 | 178 | <?php |
| 179 | 179 | } |
| 180 | 180 | |
@@ -185,11 +185,11 @@ discard block |
||
| 185 | 185 | * @version 3.1.0 |
| 186 | 186 | */ |
| 187 | 187 | public function generate_apple_pay_cart() { |
| 188 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
| 189 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 188 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
| 189 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 192 | + wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -199,29 +199,29 @@ discard block |
||
| 199 | 199 | * @version 3.1.0 |
| 200 | 200 | * @param array $address |
| 201 | 201 | */ |
| 202 | - public function calculate_shipping( $address = array() ) { |
|
| 203 | - $country = strtoupper( $address['countryCode'] ); |
|
| 204 | - $state = strtoupper( $address['administrativeArea'] ); |
|
| 202 | + public function calculate_shipping($address = array()) { |
|
| 203 | + $country = strtoupper($address['countryCode']); |
|
| 204 | + $state = strtoupper($address['administrativeArea']); |
|
| 205 | 205 | $postcode = $address['postalCode']; |
| 206 | 206 | $city = $address['locality']; |
| 207 | 207 | |
| 208 | 208 | WC()->shipping->reset_shipping(); |
| 209 | 209 | |
| 210 | - if ( $postcode && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
| 211 | - throw new Exception( __( 'Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
| 212 | - } elseif ( $postcode ) { |
|
| 213 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
| 210 | + if ($postcode && ! WC_Validation::is_postcode($postcode, $country)) { |
|
| 211 | + throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe')); |
|
| 212 | + } elseif ($postcode) { |
|
| 213 | + $postcode = wc_format_postcode($postcode, $country); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - if ( $country ) { |
|
| 217 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
| 218 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
| 216 | + if ($country) { |
|
| 217 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
| 218 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
| 219 | 219 | } else { |
| 220 | 220 | WC()->customer->set_to_base(); |
| 221 | 221 | WC()->customer->set_shipping_to_base(); |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - WC()->customer->calculated_shipping( true ); |
|
| 224 | + WC()->customer->calculated_shipping(true); |
|
| 225 | 225 | |
| 226 | 226 | /** |
| 227 | 227 | * Set the shipping package. |
@@ -243,17 +243,17 @@ discard block |
||
| 243 | 243 | $packages[0]['destination']['postcode'] = $postcode; |
| 244 | 244 | $packages[0]['destination']['city'] = $city; |
| 245 | 245 | |
| 246 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
| 247 | - if ( $item['data']->needs_shipping() ) { |
|
| 248 | - if ( isset( $item['line_total'] ) ) { |
|
| 246 | + foreach (WC()->cart->get_cart() as $item) { |
|
| 247 | + if ($item['data']->needs_shipping()) { |
|
| 248 | + if (isset($item['line_total'])) { |
|
| 249 | 249 | $packages[0]['contents_cost'] += $item['line_total']; |
| 250 | 250 | } |
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
| 254 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
| 255 | 255 | |
| 256 | - WC()->shipping->calculate_shipping( $packages ); |
|
| 256 | + WC()->shipping->calculate_shipping($packages); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -263,30 +263,30 @@ discard block |
||
| 263 | 263 | * @version 3.1.0 |
| 264 | 264 | */ |
| 265 | 265 | public function get_shipping_methods() { |
| 266 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce' ) ) { |
|
| 267 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 266 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce')) { |
|
| 267 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 271 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 270 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 271 | + define('WOOCOMMERCE_CART', true); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | try { |
| 275 | - $address = array_map( 'wc_clean', $_POST['address'] ); |
|
| 275 | + $address = array_map('wc_clean', $_POST['address']); |
|
| 276 | 276 | |
| 277 | - $this->calculate_shipping( $address ); |
|
| 277 | + $this->calculate_shipping($address); |
|
| 278 | 278 | |
| 279 | 279 | // Set the shipping options. |
| 280 | 280 | $currency = get_woocommerce_currency(); |
| 281 | 281 | $data = array(); |
| 282 | 282 | |
| 283 | - if ( ! empty( WC()->shipping->get_packages() ) && WC()->customer->has_calculated_shipping() ) { |
|
| 284 | - foreach ( WC()->shipping->get_packages() as $package_key => $package ) { |
|
| 285 | - if ( empty( $package['rates'] ) ) { |
|
| 286 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 283 | + if ( ! empty(WC()->shipping->get_packages()) && WC()->customer->has_calculated_shipping()) { |
|
| 284 | + foreach (WC()->shipping->get_packages() as $package_key => $package) { |
|
| 285 | + if (empty($package['rates'])) { |
|
| 286 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | - foreach ( $package['rates'] as $key => $rate ) { |
|
| 289 | + foreach ($package['rates'] as $key => $rate) { |
|
| 290 | 290 | $data[] = array( |
| 291 | 291 | 'id' => $rate->id, |
| 292 | 292 | 'label' => $rate->label, |
@@ -300,16 +300,16 @@ discard block |
||
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | // Auto select the first shipping method. |
| 303 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
| 303 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
| 304 | 304 | |
| 305 | 305 | WC()->cart->calculate_totals(); |
| 306 | 306 | |
| 307 | - wp_send_json( array( 'success' => 'true', 'shipping_methods' => $this->build_shipping_methods( $data ), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 307 | + wp_send_json(array('success' => 'true', 'shipping_methods' => $this->build_shipping_methods($data), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 308 | 308 | } else { |
| 309 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 309 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 310 | 310 | } |
| 311 | - } catch( Exception $e ) { |
|
| 312 | - wp_send_json( array( 'success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 311 | + } catch (Exception $e) { |
|
| 312 | + wp_send_json(array('success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 313 | 313 | } |
| 314 | 314 | } |
| 315 | 315 | |
@@ -320,29 +320,29 @@ discard block |
||
| 320 | 320 | * @version 3.1.0 |
| 321 | 321 | */ |
| 322 | 322 | public function update_shipping_method() { |
| 323 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 324 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 323 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 324 | + define('WOOCOMMERCE_CART', true); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce' ) ) { |
|
| 328 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 327 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce')) { |
|
| 328 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - $selected_shipping_method = array_map( 'wc_clean', $_POST['selected_shipping_method'] ); |
|
| 331 | + $selected_shipping_method = array_map('wc_clean', $_POST['selected_shipping_method']); |
|
| 332 | 332 | |
| 333 | - WC()->session->set( 'chosen_shipping_methods', array( $selected_shipping_method['identifier'] ) ); |
|
| 333 | + WC()->session->set('chosen_shipping_methods', array($selected_shipping_method['identifier'])); |
|
| 334 | 334 | |
| 335 | 335 | WC()->cart->calculate_totals(); |
| 336 | 336 | |
| 337 | 337 | // Send back the new cart total. |
| 338 | 338 | $currency = get_woocommerce_currency(); |
| 339 | - $tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) ); |
|
| 339 | + $tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp)); |
|
| 340 | 340 | $data = array( |
| 341 | 341 | 'total' => WC()->cart->total, |
| 342 | 342 | ); |
| 343 | 343 | |
| 344 | 344 | // Include fees and taxes as displayItems. |
| 345 | - foreach ( WC()->cart->fees as $key => $fee ) { |
|
| 345 | + foreach (WC()->cart->fees as $key => $fee) { |
|
| 346 | 346 | $data['items'][] = array( |
| 347 | 347 | 'label' => $fee->name, |
| 348 | 348 | 'amount' => array( |
@@ -351,9 +351,9 @@ discard block |
||
| 351 | 351 | ), |
| 352 | 352 | ); |
| 353 | 353 | } |
| 354 | - if ( 0 < $tax_total ) { |
|
| 354 | + if (0 < $tax_total) { |
|
| 355 | 355 | $data['items'][] = array( |
| 356 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 356 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 357 | 357 | 'amount' => array( |
| 358 | 358 | 'currency' => $currency, |
| 359 | 359 | 'value' => $tax_total, |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | ); |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | - wp_send_json( array( 'success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 364 | + wp_send_json(array('success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | /** |
@@ -372,35 +372,35 @@ discard block |
||
| 372 | 372 | * @version 3.1.0 |
| 373 | 373 | */ |
| 374 | 374 | public function process_apple_pay() { |
| 375 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) { |
|
| 376 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 375 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) { |
|
| 376 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | try { |
| 380 | - $result = array_map( 'wc_clean', $_POST['result'] ); |
|
| 380 | + $result = array_map('wc_clean', $_POST['result']); |
|
| 381 | 381 | |
| 382 | - $order = $this->create_order( $result ); |
|
| 382 | + $order = $this->create_order($result); |
|
| 383 | 383 | |
| 384 | 384 | // Handle payment. |
| 385 | - if ( $order->get_total() > 0 ) { |
|
| 385 | + if ($order->get_total() > 0) { |
|
| 386 | 386 | |
| 387 | - if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) { |
|
| 388 | - 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::get_minimum_amount() / 100 ) ) ); |
|
| 387 | + if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) { |
|
| 388 | + 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::get_minimum_amount() / 100))); |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | - WC_Stripe::log( "Info: Begin processing payment for order $order->id for the amount of {$order->get_total()}" ); |
|
| 391 | + WC_Stripe::log("Info: Begin processing payment for order $order->id for the amount of {$order->get_total()}"); |
|
| 392 | 392 | |
| 393 | 393 | // Make the request. |
| 394 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) ); |
|
| 394 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id'])); |
|
| 395 | 395 | |
| 396 | - if ( is_wp_error( $response ) ) { |
|
| 396 | + if (is_wp_error($response)) { |
|
| 397 | 397 | $localized_messages = $this->get_localized_messages(); |
| 398 | 398 | |
| 399 | - throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) ); |
|
| 399 | + throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message())); |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | // Process valid response. |
| 403 | - $this->process_response( $response, $order ); |
|
| 403 | + $this->process_response($response, $order); |
|
| 404 | 404 | } else { |
| 405 | 405 | $order->payment_complete(); |
| 406 | 406 | } |
@@ -408,24 +408,24 @@ discard block |
||
| 408 | 408 | // Remove cart. |
| 409 | 409 | WC()->cart->empty_cart(); |
| 410 | 410 | |
| 411 | - update_post_meta( $order->id, '_customer_user', get_current_user_id() ); |
|
| 412 | - update_post_meta( $order->id, '_payment_method_title', __( 'Apple Pay (Stripe)', 'woocommerce-gateway-stripe' ) ); |
|
| 411 | + update_post_meta($order->id, '_customer_user', get_current_user_id()); |
|
| 412 | + update_post_meta($order->id, '_payment_method_title', __('Apple Pay (Stripe)', 'woocommerce-gateway-stripe')); |
|
| 413 | 413 | |
| 414 | 414 | // Return thank you page redirect. |
| 415 | - wp_send_json( array( |
|
| 415 | + wp_send_json(array( |
|
| 416 | 416 | 'success' => 'true', |
| 417 | - 'redirect' => $this->get_return_url( $order ), |
|
| 418 | - ) ); |
|
| 417 | + 'redirect' => $this->get_return_url($order), |
|
| 418 | + )); |
|
| 419 | 419 | |
| 420 | - } catch ( Exception $e ) { |
|
| 421 | - WC()->session->set( 'refresh_totals', true ); |
|
| 422 | - WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
| 420 | + } catch (Exception $e) { |
|
| 421 | + WC()->session->set('refresh_totals', true); |
|
| 422 | + WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
| 423 | 423 | |
| 424 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 425 | - $this->send_failed_order_email( $order->id ); |
|
| 424 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 425 | + $this->send_failed_order_email($order->id); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | - wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) ); |
|
| 428 | + wp_send_json(array('success' => 'false', 'msg' => $e->getMessage())); |
|
| 429 | 429 | } |
| 430 | 430 | } |
| 431 | 431 | |
@@ -435,14 +435,14 @@ discard block |
||
| 435 | 435 | * @param string $source token |
| 436 | 436 | * @return array() |
| 437 | 437 | */ |
| 438 | - protected function generate_payment_request( $order, $source ) { |
|
| 438 | + protected function generate_payment_request($order, $source) { |
|
| 439 | 439 | $post_data = array(); |
| 440 | - $post_data['currency'] = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() ); |
|
| 441 | - $post_data['amount'] = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
| 442 | - $post_data['description'] = sprintf( __( '%s - Order %s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() ); |
|
| 440 | + $post_data['currency'] = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency()); |
|
| 441 | + $post_data['amount'] = $this->get_stripe_amount($order->get_total(), $post_data['currency']); |
|
| 442 | + $post_data['description'] = sprintf(__('%s - Order %s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number()); |
|
| 443 | 443 | $post_data['capture'] = 'yes' === $this->_gateway_settings['capture'] ? 'true' : 'false'; |
| 444 | 444 | |
| 445 | - if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
| 445 | + if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
| 446 | 446 | $post_data['receipt_email'] = $order->billing_email; |
| 447 | 447 | } |
| 448 | 448 | |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | * @param WC_Order $order |
| 458 | 458 | * @param object $source |
| 459 | 459 | */ |
| 460 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order ); |
|
| 460 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order); |
|
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | /** |
@@ -466,14 +466,14 @@ discard block |
||
| 466 | 466 | * @since 3.1.0 |
| 467 | 467 | * @version 3.1.0 |
| 468 | 468 | */ |
| 469 | - public function build_shipping_methods( $shipping_methods ) { |
|
| 470 | - if ( empty( $shipping_methods ) ) { |
|
| 469 | + public function build_shipping_methods($shipping_methods) { |
|
| 470 | + if (empty($shipping_methods)) { |
|
| 471 | 471 | return array(); |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | $shipping = array(); |
| 475 | 475 | |
| 476 | - foreach( $shipping_methods as $method ) { |
|
| 476 | + foreach ($shipping_methods as $method) { |
|
| 477 | 477 | $shipping[] = array( |
| 478 | 478 | 'label' => $method['label'], |
| 479 | 479 | 'detail' => '', |
@@ -492,53 +492,53 @@ discard block |
||
| 492 | 492 | * @version 3.1.0 |
| 493 | 493 | */ |
| 494 | 494 | public function build_line_items() { |
| 495 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 496 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 495 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 496 | + define('WOOCOMMERCE_CART', true); |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | - $decimals = apply_filters( 'wc_stripe_apple_pay_decimals', 2 ); |
|
| 499 | + $decimals = apply_filters('wc_stripe_apple_pay_decimals', 2); |
|
| 500 | 500 | |
| 501 | 501 | $items = array(); |
| 502 | 502 | |
| 503 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 504 | - $amount = wc_format_decimal( $values['line_subtotal'], $decimals ); |
|
| 503 | + foreach (WC()->cart->get_cart() as $cart_item_key => $values) { |
|
| 504 | + $amount = wc_format_decimal($values['line_subtotal'], $decimals); |
|
| 505 | 505 | $quantity_label = 1 < $values['quantity'] ? ' (x' . $values['quantity'] . ')' : ''; |
| 506 | 506 | |
| 507 | 507 | $item = array( |
| 508 | 508 | 'type' => 'final', |
| 509 | 509 | 'label' => $values['data']->post->post_title . $quantity_label, |
| 510 | - 'amount' => wc_format_decimal( $amount, $decimals ), |
|
| 510 | + 'amount' => wc_format_decimal($amount, $decimals), |
|
| 511 | 511 | ); |
| 512 | 512 | |
| 513 | 513 | $items[] = $item; |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), $decimals ); |
|
| 517 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals ); |
|
| 518 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, $decimals ); |
|
| 519 | - $item_total = wc_format_decimal( WC()->cart->cart_contents_total, $decimals ) + $discounts; |
|
| 520 | - $order_total = wc_format_decimal( $item_total + $tax + $shipping, $decimals ); |
|
| 516 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), $decimals); |
|
| 517 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals); |
|
| 518 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, $decimals); |
|
| 519 | + $item_total = wc_format_decimal(WC()->cart->cart_contents_total, $decimals) + $discounts; |
|
| 520 | + $order_total = wc_format_decimal($item_total + $tax + $shipping, $decimals); |
|
| 521 | 521 | |
| 522 | - if ( wc_tax_enabled() ) { |
|
| 522 | + if (wc_tax_enabled()) { |
|
| 523 | 523 | $items[] = array( |
| 524 | 524 | 'type' => 'final', |
| 525 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 525 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 526 | 526 | 'amount' => $tax, |
| 527 | 527 | ); |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | - if ( WC()->cart->needs_shipping() ) { |
|
| 530 | + if (WC()->cart->needs_shipping()) { |
|
| 531 | 531 | $items[] = array( |
| 532 | 532 | 'type' => 'final', |
| 533 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
| 533 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
| 534 | 534 | 'amount' => $shipping, |
| 535 | 535 | ); |
| 536 | 536 | } |
| 537 | 537 | |
| 538 | - if ( WC()->cart->has_discount() ) { |
|
| 538 | + if (WC()->cart->has_discount()) { |
|
| 539 | 539 | $items[] = array( |
| 540 | 540 | 'type' => 'final', |
| 541 | - 'label' => __( 'Discount', 'woocommerce-gateway-stripe' ), |
|
| 541 | + 'label' => __('Discount', 'woocommerce-gateway-stripe'), |
|
| 542 | 542 | 'amount' => $discounts, |
| 543 | 543 | ); |
| 544 | 544 | } |
@@ -554,24 +554,24 @@ discard block |
||
| 554 | 554 | * @param array $data |
| 555 | 555 | * @return object $order |
| 556 | 556 | */ |
| 557 | - public function create_order( $data = array() ) { |
|
| 558 | - if ( empty( $data ) ) { |
|
| 559 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) ); |
|
| 557 | + public function create_order($data = array()) { |
|
| 558 | + if (empty($data)) { |
|
| 559 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520)); |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | $order = wc_create_order(); |
| 563 | 563 | |
| 564 | - if ( is_wp_error( $order ) ) { |
|
| 565 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) ); |
|
| 566 | - } elseif ( false === $order ) { |
|
| 567 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) ); |
|
| 564 | + if (is_wp_error($order)) { |
|
| 565 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520)); |
|
| 566 | + } elseif (false === $order) { |
|
| 567 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521)); |
|
| 568 | 568 | } else { |
| 569 | 569 | $order_id = $order->id; |
| 570 | - do_action( 'woocommerce_new_order', $order_id ); |
|
| 570 | + do_action('woocommerce_new_order', $order_id); |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | // Store the line items to the new/resumed order |
| 574 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 574 | + foreach (WC()->cart->get_cart() as $cart_item_key => $values) { |
|
| 575 | 575 | $item_id = $order->add_product( |
| 576 | 576 | $values['data'], |
| 577 | 577 | $values['quantity'], |
@@ -587,47 +587,47 @@ discard block |
||
| 587 | 587 | ) |
| 588 | 588 | ); |
| 589 | 589 | |
| 590 | - if ( ! $item_id ) { |
|
| 591 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) ); |
|
| 590 | + if ( ! $item_id) { |
|
| 591 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525)); |
|
| 592 | 592 | } |
| 593 | 593 | |
| 594 | 594 | // Allow plugins to add order item meta |
| 595 | - do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key ); |
|
| 595 | + do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key); |
|
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | // Store fees |
| 599 | - foreach ( WC()->cart->get_fees() as $fee_key => $fee ) { |
|
| 600 | - $item_id = $order->add_fee( $fee ); |
|
| 599 | + foreach (WC()->cart->get_fees() as $fee_key => $fee) { |
|
| 600 | + $item_id = $order->add_fee($fee); |
|
| 601 | 601 | |
| 602 | - if ( ! $item_id ) { |
|
| 603 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 526 ) ); |
|
| 602 | + if ( ! $item_id) { |
|
| 603 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526)); |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | // Allow plugins to add order item meta to fees |
| 607 | - do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key ); |
|
| 607 | + do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key); |
|
| 608 | 608 | } |
| 609 | 609 | |
| 610 | 610 | // Store tax rows |
| 611 | - foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) { |
|
| 612 | - if ( $tax_rate_id && ! $order->add_tax( $tax_rate_id, WC()->cart->get_tax_amount( $tax_rate_id ), WC()->cart->get_shipping_tax_amount( $tax_rate_id ) ) && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) { |
|
| 613 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) ); |
|
| 611 | + foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) { |
|
| 612 | + if ($tax_rate_id && ! $order->add_tax($tax_rate_id, WC()->cart->get_tax_amount($tax_rate_id), WC()->cart->get_shipping_tax_amount($tax_rate_id)) && apply_filters('woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated') !== $tax_rate_id) { |
|
| 613 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528)); |
|
| 614 | 614 | } |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | // Store coupons |
| 618 | - foreach ( WC()->cart->get_coupons() as $code => $coupon ) { |
|
| 619 | - if ( ! $order->add_coupon( $code, WC()->cart->get_coupon_discount_amount( $code ), WC()->cart->get_coupon_discount_tax_amount( $code ) ) ) { |
|
| 620 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) ); |
|
| 618 | + foreach (WC()->cart->get_coupons() as $code => $coupon) { |
|
| 619 | + if ( ! $order->add_coupon($code, WC()->cart->get_coupon_discount_amount($code), WC()->cart->get_coupon_discount_tax_amount($code))) { |
|
| 620 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529)); |
|
| 621 | 621 | } |
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | // Billing address |
| 625 | 625 | $billing_address = array(); |
| 626 | - if ( ! empty( $data['token']['card'] ) ) { |
|
| 626 | + if ( ! empty($data['token']['card'])) { |
|
| 627 | 627 | // Name from Stripe is a full name string. |
| 628 | - $name = explode( ' ', $data['token']['card']['name'] ); |
|
| 629 | - $lastname = array_pop( $name ); |
|
| 630 | - $firstname = implode( ' ', $name ); |
|
| 628 | + $name = explode(' ', $data['token']['card']['name']); |
|
| 629 | + $lastname = array_pop($name); |
|
| 630 | + $firstname = implode(' ', $name); |
|
| 631 | 631 | $billing_address['first_name'] = $firstname; |
| 632 | 632 | $billing_address['last_name'] = $lastname; |
| 633 | 633 | $billing_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -642,7 +642,7 @@ discard block |
||
| 642 | 642 | |
| 643 | 643 | // Shipping address. |
| 644 | 644 | $shipping_address = array(); |
| 645 | - if ( WC()->cart->needs_shipping() && ! empty( $data['shippingContact'] ) ) { |
|
| 645 | + if (WC()->cart->needs_shipping() && ! empty($data['shippingContact'])) { |
|
| 646 | 646 | $shipping_address['first_name'] = $data['shippingContact']['givenName']; |
| 647 | 647 | $shipping_address['last_name'] = $data['shippingContact']['familyName']; |
| 648 | 648 | $shipping_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -653,7 +653,7 @@ discard block |
||
| 653 | 653 | $shipping_address['city'] = $data['shippingContact']['locality']; |
| 654 | 654 | $shipping_address['state'] = $data['shippingContact']['administrativeArea']; |
| 655 | 655 | $shipping_address['postcode'] = $data['shippingContact']['postalCode']; |
| 656 | - } elseif ( ! empty( $data['shippingContact'] ) ) { |
|
| 656 | + } elseif ( ! empty($data['shippingContact'])) { |
|
| 657 | 657 | $shipping_address['first_name'] = $firstname; |
| 658 | 658 | $shipping_address['last_name'] = $lastname; |
| 659 | 659 | $shipping_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -666,34 +666,34 @@ discard block |
||
| 666 | 666 | $shipping_address['postcode'] = $data['token']['card']['address_zip']; |
| 667 | 667 | } |
| 668 | 668 | |
| 669 | - $order->set_address( $billing_address, 'billing' ); |
|
| 670 | - $order->set_address( $shipping_address, 'shipping' ); |
|
| 669 | + $order->set_address($billing_address, 'billing'); |
|
| 670 | + $order->set_address($shipping_address, 'shipping'); |
|
| 671 | 671 | |
| 672 | - WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() ); |
|
| 672 | + WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages()); |
|
| 673 | 673 | |
| 674 | 674 | // Get the rate object selected by user. |
| 675 | - foreach ( WC()->shipping->get_packages() as $package_key => $package ) { |
|
| 676 | - foreach ( $package['rates'] as $key => $rate ) { |
|
| 675 | + foreach (WC()->shipping->get_packages() as $package_key => $package) { |
|
| 676 | + foreach ($package['rates'] as $key => $rate) { |
|
| 677 | 677 | // Loop through user chosen shipping methods. |
| 678 | - foreach( WC()->session->get( 'chosen_shipping_methods' ) as $method ) { |
|
| 679 | - if ( $method === $key ) { |
|
| 680 | - $order->add_shipping( $rate ); |
|
| 678 | + foreach (WC()->session->get('chosen_shipping_methods') as $method) { |
|
| 679 | + if ($method === $key) { |
|
| 680 | + $order->add_shipping($rate); |
|
| 681 | 681 | } |
| 682 | 682 | } |
| 683 | 683 | } |
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 687 | - $order->set_payment_method( $available_gateways['stripe'] ); |
|
| 688 | - $order->set_total( WC()->cart->shipping_total, 'shipping' ); |
|
| 689 | - $order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' ); |
|
| 690 | - $order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' ); |
|
| 691 | - $order->set_total( WC()->cart->tax_total, 'tax' ); |
|
| 692 | - $order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' ); |
|
| 693 | - $order->set_total( WC()->cart->total ); |
|
| 687 | + $order->set_payment_method($available_gateways['stripe']); |
|
| 688 | + $order->set_total(WC()->cart->shipping_total, 'shipping'); |
|
| 689 | + $order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount'); |
|
| 690 | + $order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax'); |
|
| 691 | + $order->set_total(WC()->cart->tax_total, 'tax'); |
|
| 692 | + $order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax'); |
|
| 693 | + $order->set_total(WC()->cart->total); |
|
| 694 | 694 | |
| 695 | 695 | // If we got here, the order was created without problems! |
| 696 | - wc_transaction_query( 'commit' ); |
|
| 696 | + wc_transaction_query('commit'); |
|
| 697 | 697 | |
| 698 | 698 | return $order; |
| 699 | 699 | } |