← All changes
|
payment/admin/settings/VippsAdminSettings.class.php
+69
-26
5.4.2
→
6.2.5
View file →
| @@ -71,24 +71,36 @@ | ||
| 71 | 71 | echo json_encode(array('ok' => 0, 'options' => [], 'msg' => __('You don\'t have sufficient rights to edit these settings', 'woo-vipps'))); |
| 72 | 72 | exit(); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - // Decode the settings from the values sents, then save them to "woocommerce_vipps_settings" | |
| 75 | + // Decode the settings from the values sents, then save them to "woocommerce_vipps_settings" and "woocommerce_vipps_card_settings" | |
| 76 | 76 | $new_settings = $_POST['values']; |
| 77 | 77 | |
| 78 | - // IOK FIXME This will ensure sanitization etc works as it is supposed to using the | |
| 78 | + | |
| 79 | + // IOK TODO This will ensure sanitization etc works as it is supposed to using the | |
| 79 | 80 | // admin settings api of WooCommerce. We will however want to run this code independently, so we'll handle this |
| 80 | 81 | // by ourselves at a later point, ending it like so: |
| 81 | 82 | // update_option('woocommerce_vipps_settings', $new_settings); // After sanitation etc |
| 83 | + // update_option('woocommerce_vipps_card_settings', $card_settings); // Separated out | |
| 84 | + | |
| 82 | 85 | $admin_options = []; |
| 86 | + $card_admin_options= []; | |
| 83 | 87 | foreach ($new_settings as $key => $value) { |
| 84 | 88 | // Checkbox settings (yes/no) can't be passed directly to set_post_data, because *any* value will be interpreted as "yes" |
| 85 | 89 | // because of this, checkbox settings with the value "no" will be completely ignored |
| 86 | 90 | if($value !== 'no') { |
| 87 | - // Because settings are processed manually, their keys need to prefixed with "woocommerce_vipps_" | |
| 88 | - $admin_options['woocommerce_vipps_' . $key] = $value; | |
| 91 | + // Because settings are processed manually, their keys need to prefixed with "woocommerce_<gatewayid>_" | |
| 92 | + // options with prefix cc_ are for the credit card gateway. | |
| 93 | + if (preg_match("!^cc_!", $key)) { | |
| 94 | + $key = preg_replace("!^cc_!", "", $key); | |
| 95 | + $card_admin_options['woocommerce_vipps_card_' . $key] = $value; | |
| 96 | + } else { | |
| 97 | + $admin_options['woocommerce_vipps_' . $key] = $value; | |
| 98 | + } | |
| 89 | 99 | } |
| 90 | 100 | } |
| 101 | + | |
| 102 | + // Save options for the main gateway first | |
| 91 | 103 | // We need to initialize these again so "conditional" options are available |
| 92 | 104 | // IOK 2024-06-05 |
| 93 | 105 | $this->gateway()->init_form_fields(); |
| 94 | 106 | $this->gateway()->set_post_data($admin_options); |
| @@ -94,8 +106,17 @@ | ||
| 94 | 106 | $this->gateway()->set_post_data($admin_options); |
| 95 | 107 | $this->gateway()->process_admin_options(); |
| 96 | 108 | // $this->gateway()->add_error("Jaboloko!"); // Also add_warning, add_notice plz |
| 97 | 109 | $form_errors = $this->gateway()->get_errors(); |
| 110 | + | |
| 111 | + // Then the card gateway | |
| 112 | + $cards= WC_Gateway_VippsCard::instance(); | |
| 113 | + $cards->init_form_fields(); | |
| 114 | + $cards->set_post_data($card_admin_options); | |
| 115 | + $cards->process_admin_options(); | |
| 116 | + $form_errors = array_merge($form_errors, $cards->get_errors()); | |
| 117 | + | |
| 118 | + | |
| 98 | 119 | $form_ok = empty($form_errors); |
| 99 | 120 | // end use of process_admin_options IOK 2024-01-03 |
| 100 | 121 | |
| 101 | 122 | $connection_msg = ""; |
| @@ -108,8 +129,13 @@ | ||
| 108 | 129 | } |
| 109 | 130 | |
| 110 | 131 | // Get the current options |
| 111 | 132 | $options = get_option('woocommerce_vipps_settings'); |
| 133 | + // Augment with card gateway, with prefix | |
| 134 | + $card_options = get_option('woocommerce_vipps_card_settings'); | |
| 135 | + foreach($card_options as $key => $data) { | |
| 136 | + $options["cc_$key"] = $data; | |
| 137 | + } | |
| 112 | 138 | |
| 113 | 139 | // Add receipt image URL if receipt image exists |
| 114 | 140 | if (!empty($new_settings['receiptimage'])) { |
| 115 | 141 | $options['receiptimage_url'] = wp_get_attachment_url($new_settings['receiptimage']); |
| @@ -128,10 +154,9 @@ | ||
| 128 | 154 | exit(); |
| 129 | 155 | } |
| 130 | 156 | |
| 131 | 157 | // Initializes the admin settings UI for VippsMobilePay |
| 132 | - function init_admin_settings_page_react_ui() | |
| 133 | - { | |
| 158 | + function init_admin_settings_page_react_ui() { | |
| 134 | 159 | global $Vipps; |
| 135 | 160 | echo "<div class='wrap vipps-admin-settings-page'>"; |
| 136 | 161 | // Add nonce first. |
| 137 | 162 | wp_nonce_field('vippsadmin_nonce', 'vippsadmin_nonce'); |
| @@ -143,8 +168,9 @@ | ||
| 143 | 168 | |
| 144 | 169 | // Initializing the wordpress media plugin, so we can upload images |
| 145 | 170 | wp_enqueue_media(); |
| 146 | 171 | $gw = $this->gateway(); |
| 172 | + $card_gw = WC_Gateway_VippsCard::instance(); | |
| 147 | 173 | |
| 148 | 174 | // Loads the React UI |
| 149 | 175 | $reactpath = "dist"; |
| 150 | 176 | wp_enqueue_script('vipps-mobilepay-react-ui', plugins_url($reactpath . '/plugin.js', __FILE__), array('wp-element'), filemtime(__DIR__ . "/$reactpath/plugin.js"), true); |
| @@ -172,14 +198,21 @@ | ||
| 172 | 198 | 'receipt_image_error' => __('The uploaded image is too small. It must be at least 167 pixels in height.', 'woo-vipps'), |
| 173 | 199 | 'settings_saved' => __('Settings saved', 'woo-vipps'), |
| 174 | 200 | |
| 175 | 201 | 'kustom_sale_1' => __('Checkout - Important Update', 'woo-vipps'), |
| 176 | - 'kustom_sale_2' => __('Vipps MobilePay has entered into an agreement to sell the Checkout solution to <a href="https://Kustom.co" target="_blank">Kustom</a>', 'woo-vipps'), | |
| 177 | - 'kustom_sale_3' => __('As part of this transition, <b>Vipps MobilePay Checkout</b> will become <b>Kustom Checkout</b>. This means the Checkout product you ordered will be delivered and developed by Kustom going forward.', 'woo-vipps'), | |
| 178 | - 'kustom_sale_4' => __('If your account is newer than March 27. 2026, it will <b>not</b> support Vipps MobilePay Checkout in this plugin.', 'woo-vipps'), | |
| 179 | - 'kustom_sale_5' => __('If you have questions, you can check our <a href="https://vippsmobilepay.com/vippsmobilepay-kustom" target="_blank">FAQ</a>.', 'woo-vipps') | |
| 202 | + 'kustom_sale_2' => __('Vipps MobilePay has entered into an agreement to sell the Checkout solution to Kustom. As part of this transition, <b>Vipps MobilePay Checkout will become Kustom Checkout</b>. You can follow <a href="https://docs.kustom.co/contents/partners/e-commerce-platforms/woocommerce-vipps-guide#switch-from-vipps-checkout-to-kustom-checkoutguide" target="_blank">this guide</a> to migrate over to Kustom Checkout.', 'woo-vipps'), | |
| 203 | + 'kustom_sale_3' => __('Going forward, Kustom will be responsible for delivering and developing the Checkout solution. <b>Vipps MobilePay will remain available as a payment method in Kustom Checkout</b>, so your customers can continue to pay with Vipps MobilePay in the familiar way.', 'woo-vipps'), | |
| 204 | + 'kustom_sale_4' => __('Please note that <b>accounts created after March 27, 2026 will not support Checkout in this plugin</b>.', 'woo-vipps'), | |
| 205 | + 'kustom_sale_5' => __('If you have any questions about what the transition means for you, please see our <a href="https://vippsmobilepay.com/en-NO/vippsmobilepay-kustom" target="_blank">FAQ</a>.', 'woo-vipps'), | |
| 206 | + 'kustom_sale_6' => sprintf(__('For help you can reach out to <a href="mailto:%1$s">%1$s</a> and <a href="tel:%2$s">%3$s</a>. You can also find the Kustom portal <a href="%4$s" target="_blank">here</a>.', 'woo-vipps'), '[email protected]', '+4721564684', '+47 21 56 46 84', 'https://portal.kustom.co/'), | |
| 180 | 207 | ); |
| 181 | 208 | |
| 209 | + /* We need to postprocess the settings for.. various reasons IOK 2024-06-04 */ | |
| 210 | + /* Also we need to run init_form_fields here, because for whatever reason the | |
| 211 | + * first time it is called, it does wrong things in this context. IOK 2024-06-04 */ | |
| 212 | + $gw->init_form_fields(); | |
| 213 | + $settings = $gw->settings; | |
| 214 | + | |
| 182 | 215 | $wizardTranslations = [ |
| 183 | 216 | 'wizard_header' => [ |
| 184 | 217 | 'title' => __('Initial settings', 'woo-vipps'), |
| 185 | 218 | 'description' => sprintf(__('Welcome! You are almost ready to accept payments with %1$s', 'woo-vipps'), Vipps::CompanyName()), |
| @@ -187,16 +220,8 @@ | ||
| 187 | 220 | 'checkout_options_wizard' => array( |
| 188 | 221 | 'title' => sprintf(__('Get started with %1$s', 'woo-vipps'), Vipps::CheckoutName()), |
| 189 | 222 | 'description' => sprintf(__('%1$s is a service from %2$s, which allows you to replace the usual WooCommerce checkout page with a super simple checkout screen, where your customers can pay with Vipps, Visa, and MasterCard!', 'woo-vipps'), Vipps::CheckoutName(), Vipps::CompanyName()), |
| 190 | 223 | ), |
| 191 | - /* | |
| 192 | - 'vipps_checkout_enabled_wizard' => array( | |
| 193 | - 'title' => Vipps::CheckoutName(), | |
| 194 | - 'label' => sprintf(__('Yes, I want to start using %1$s', 'woo-vipps'), Vipps::CheckoutName()), | |
| 195 | - 'description' => sprintf(__('If activated, this will <strong>replace</strong> the standard Woo checkout screen with %1$s, providing easy checkout using %1$s or credit card, with no need to type in addresses.', 'woo-vipps'), Vipps::CheckoutName()), | |
| 196 | - 'default' => 'no', | |
| 197 | - ), | |
| 198 | - */ | |
| 199 | 224 | 'enablestaticshipping_checkout_wizard' => array( |
| 200 | 225 | 'title' => __('Are you going to base shipping price on the customers address?', 'woo-vipps'), |
| 201 | 226 | 'label' => __('Yes, I want dynamic shipping calculation', 'woo-vipps'), |
| 202 | 227 | 'description' => __('If your shipping prices are the same no matter where the customer lives, you don\'t need dynamic shipping calculation.'), |
| @@ -275,16 +300,19 @@ | ||
| 275 | 300 | ], |
| 276 | 301 | 'accept' => sprintf(__('Start using %1$s', 'woo-vipps'), Vipps::CheckoutName()), |
| 277 | 302 | 'skip' => __('Skip & save', 'woo-vipps'), |
| 278 | 303 | ], |
| 304 | + 'express_options_wizard' => array( | |
| 305 | + 'title' => sprintf(__('Get started with %1$s', 'woo-vipps'), Vipps::ExpressCheckoutName()), | |
| 306 | + 'description' => sprintf(__("%1\$s allows you to buy products by a single click from the cart, checkout, or directly from product or catalog pages. Product will get a 'buy now' button which will start the purchase process immediately.", 'woo-vipps'), Vipps::ExpressCheckoutName()), | |
| 307 | + 'readmore' => __('Read more', 'woo-vipps'), | |
| 308 | + ), | |
| 309 | + 'singleproductexpressarchives_wizard' => [ | |
| 310 | + 'title' => sprintf(__('%s on product catalog pages', 'woo-vipps'), Vipps::ExpressCheckoutName()), | |
| 311 | + 'label' => sprintf(__('Enable a %s button for relevant products on catalog pages', 'woo-vipps'), Vipps::ExpressCheckoutName()), | |
| 312 | + ], | |
| 313 | + ]; | |
| 279 | 314 | |
| 280 | - ]; | |
| 281 | - | |
| 282 | - /* We need to postprocess the settings for.. various reasons IOK 2024-06-04 */ | |
| 283 | - /* Also we need to run init_form_fields here, because for whatever reason the | |
| 284 | - * first time it is called, it does wrong things in this context. IOK 2024-06-04 */ | |
| 285 | - $gw->init_form_fields(); | |
| 286 | - $settings = $gw->settings; | |
| 287 | 315 | if (!empty($settings['receiptimage'])) { |
| 288 | 316 | $settings['receiptimage_url'] = wp_get_attachment_url($settings['receiptimage']); |
| 289 | 317 | } |
| 290 | 318 | if (!$gw->allow_external_payments_in_checkout()) { |
| @@ -292,9 +320,24 @@ | ||
| 292 | 320 | } else { |
| 293 | 321 | // nop right now |
| 294 | 322 | } |
| 295 | 323 | |
| 296 | - wp_localize_script('vipps-mobilepay-react-ui', 'VippsMobilePayReactTranslations', array_merge($gw->form_fields, $commonTranslations, $wizardTranslations)); | |
| 324 | + /* Add the options from the credit card gateway too, with a cc_prefix which we strip on process_payments. IOK 2026-05-27*/ | |
| 325 | + $card_gw->init_form_fields(); | |
| 326 | + $cc_translations = []; | |
| 327 | + foreach($card_gw->settings as $key => $data) { | |
| 328 | + $settings["cc_$key"] = $data; | |
| 329 | + } | |
| 330 | + foreach($card_gw->form_fields as $key => $data) { | |
| 331 | + $cc_translations["cc_$key"] = $data; | |
| 332 | + } | |
| 333 | + $cc_translations['cc_options'] = [ | |
| 334 | + 'title' => __('Card payments', 'woo-vipps'), | |
| 335 | + 'description' => __("Provide a card payment method for customers that haven't got the app (yet!)", 'woo-vipps'), | |
| 336 | + 'test_mode_warning' => sprintf(__('Warning: card payments may not yet be available in the test environment, please check the %1$s <a href="https://developer.vippsmobilepay.com/docs/knowledge-base/test-environment/">knowledge base</a> for updated status about the test environment.'), Vipps::CompanyName()), | |
| 337 | + ]; | |
| 338 | + | |
| 339 | + wp_localize_script('vipps-mobilepay-react-ui', 'VippsMobilePayReactTranslations', array_merge($gw->form_fields, $cc_translations, $commonTranslations, $wizardTranslations)); | |
| 297 | 340 | wp_localize_script('vipps-mobilepay-react-ui', 'VippsMobilePayReactOptions', $settings); |
| 298 | 341 | wp_localize_script('vipps-mobilepay-react-ui', 'VippsMobilePayReactMetadata', $metadata); |
| 299 | 342 | |
| 300 | 343 | echo "</div>"; |