diff --git a/changelog.md b/changelog.md deleted file mode 100644 index 6c99e50c..00000000 --- a/changelog.md +++ /dev/null @@ -1,322 +0,0 @@ -# Changelog - -## 3.6.0 (2019-11-13) -* Feature - Selected payment method in Billmate Checkout is shown in WooCommerce order details -* Fix - Aditional rules for checkout url to not be overwritten by billmatecheckout url - -## 3.5.1 (2019-11-12) -* Fix - Checking orders for used coupons - -## 3.5.0 (2019-11-11) -* Fix - WooCommerce built-in Checkout are using Billmate's new logos -* Feature - Show/hide overlay in store when in Billmate Checkout - -## 3.4.18 (2019-11-08) -* Fix - Billmate Checkout page does not overwrite checkout page in WooCommerce settings - -## 3.4.17 (2019-11-06) -* Enhancement library file to use wordpress built-in functions instead of php curl - -## 3.4.16 (2019-11-04) -* Fix - plugin to comply with Wordpress standards -* Enhancement Added security and input sanitation - -## 3.4.15 (2019-10-30) - * Fix - Sanitization issues - -## 3.4.14 (2019-10-24) - * Fix - Revert back - loopback health problem - -## 3.4.13 (2019-10-23) - * Fix - Revert back to 3.4.11 state - -## 3.4.12 (2019-10-18) - * Enhancement - Discount Code - * Tweak - Remove pre-check from Invoice/Partpayment email validation checkbox - * Fix - Loopback request that failure in WP built in site health - -## 3.4.11 (2019-10-04) - * Fix - WooCommerce built-in Checkout are using Billmate's new logos - -## 3.4.10 (2019-09-27) - * Fix - Reverse back to 3.4.7 state - -## 3.4.7 (2019-07-15) - * Fix - WhooCommerce built-in checkout use Billmates new logos - * Fix WhooCommerce shows correct company delivery address - * Fix Wocommerce Subription sets the currency based on the order instead of the defualt currency - -## 3.4.6 (2019-05-22) -* Fix - Removed browser scrolls to Billmate Checkout after refresh - -## 3.4.5 (2019-05-20) -* Fix - Clear Billmate Checkout Session after a payment is made - -## 3.4.4 (2019-03-05) -* Enhancement - Only get Billmate Checkout page when language is sv -* Fix - Only define WOOCOMMERCE_CHECKOUT on Billmate Checkout page -* Fix - Fix product partpayment info_link shortcode url - -## 3.4.3 (2019-01-16) -* Enhancement - HTML decode order item titles -* Enhancement - Keep Billmate Checkout in sync when multiple browser tabs -* Fix - Fix subscription with invoice when not test mode -* Fix - Add generic support for sequental order number - -## 3.4.2 (2019-01-08) -* Fix - Check if cart exists before checking if having items in stock -* Fix - Prevent invoice pno validation on store checkout page load -* Fix - Prevent duplicated wc checkout error messages - -## 3.4.1 (2019-01-07) -* Enhancement - Add trigger JS event getaddresserror -* Enhancement - Add tested WooCommerce version 3.5 -* Tweak - Remove pre-check from Invoice/Partpayment email validation checkbox -* Fix - Improve support for sequential order numbers -* Fix - Fix undefined variables on Billmate Checkout page -* Refactor - Move logic of hide payment option pno input to backend - -## 3.4.0 (2018-10-15) -* Feature - Order Comments on Billamte Checkout page -* Feature - Invoice support for WooCommerce Subscription -* Feature - Show/hide overlay in store when in Billmate Checkout -* Enhancement - Improve open apps in IOS for Billmate Checkout -* Enhancement - Partpayment on product page also show when checkout is active -* Fix - Remove org.nr from Partpayment pno input label - -## 3.3.2 (2018-06-14) -* Fix - Check if session exists before try fetching customer postcode -* Enhancement - When saved address in Billmate Checkout Only update Checkout order when Shipping fee is affected -* Enhancement - Minor code refactoring Use same function to calculate shipping fee when update Checkout - -## 3.3.1 (2018-06-07) -* Fix - Use WooCommerce cart get tax functions when wc above version 3.2 -* Fix - Improve check if cart items is in stock -* Fix - Init new Billmate Checkout if current cant be found -* Enhancement - Decrease amount of API requests for Billmate Checkout -* Enhancement - Remove PaymentInfo.paymentdate from Billmate API requests - -## 3.3.0 (2018-05-24) -* Feature - Privacy policy support for payment methods and Billmate Checkout -* Fix - Do not display Billmate Checkout when cart have item out of stock -* Fix - User better method to get permalinks -* Enhancement - Tweak Billmate Checkout iframe permissions - -## 3.2.0 (2018-04-25) -* Feature - Support for WooCommerc cart shipping calculator for Billmate Checkout -* Feature - Show Select another payment button above Billmate Checkout when available -* Fix - Improve clear cart when complete order with Billmate Checkout -* Fix - Make sure file with function is_plugin_active is included -* Fix - Set custom order status when paid after order is set as paid -* Enhancement - Show paid with Billmate Checkout on order for recent version of WC -* Enhancement - Update store order address from Billmate checkout -* Enhancement - Improve admin notifications -* Enhancement - Improve remind administrator about admin settings - -## 3.1.1 (2018-01-29) -* Fix - Bank payments now always use the same string where it's referenced. -* Fix - Rounding improvements. Under some rare circumstances the amount can be different from payment window to callback and/or accept url. -* Enhancement - Improved loading animation for Checkout - The loading animation is more precise triggered when needed. -* Feature - Support for plugin "Product Add-Ons" in combination with Billmate Checkout. - -## 3.1.0 (2017-12-19) -* Fix - BC add handling fee on store order when set orderstatus is not default -* Fix - BC support for autoactivate order on creation -* Fix - Tax calculation when free shipping -* Enhancement - Improve rounding accuracy for prices set including tax and zero decimals -* Enhancement - WooCommerce subscription support for change card information and manually pay failed subscription order -* Enhancement - Invoice fee support for WPML currency -* Enhancement - Improve shipping tax calculation -* Enhancement - Replace Cardpayment logo - - -## 3.0.8 (2017-10-10) -* Fix - Fix order completed when not paid with Billmate - -## 3.0.7 (2017-10-09) -* Fix - Add missing handling fee on order paid with checkout and rely on callback -* Enhancement - Use method 2 if 1 is unavailable -* Fix - handle shipping with no tax -* Enhancement - Prevent cache of checkout page -* Enhancement - Improve error messages on order note if order activation not success -* Enhancement - Change order of getAddress to be done after try first with addPayment -* Fix - Add handling fee to store order when pay_for_order isset -* Fix - Display partpayment info on product page once - -## 3.0.6 (2017-09-14) -* Improve - Improve the selected currency check when display payment methods -* Improve - Support for additional get parameters -* Improve - Support for activate Billmate Checkout invoice on callback - -## 3.0.5 (2017-07-28) -* Fix - Improve Billmate Checkout speed and communication - -## 3.0.4 (2017-07-15) -* Fix - WooCommerce Subscription 2.2.8 compatibility -* Enhancement - Add links in plugin list - -## 3.0.3 (2017-06-12) -* Fix - Support discount 12% vat -* Enhancement - Discount can be on item level or order level -* Enhancement - Use order item name if standard product - -## 3.0.2 (2017-06-07) -* Fix - Improve compatibility with WC 3 -* Fix - Improve Billmate Checkout - -## 3.0.1 (2017-05-16) -* Fix - Improve compatibility with WC 3 -* Fix - Improve compatibility with PHP 7 -* Fix - Improve Billmate Checkout - -## 3.0 (2017-04-24) -* Feature - Add support for Billmate Checkout -* Fix - Prevent admin menu would be affected -* Fix - Prevent handling fee added as order item - -## 2.2.11 (2017-01-03) -* Fix - New Years issue with update payment plans. -* Fix - Payment link issue invoice and partpay. - -## 2.2.10 (2016-12-21) -* Fix - Abort payment, then do a new with same method. - -## 2.2.9 (2016-12-14) -* Fix - Adjust som styling in checkout for smaller devices -* Enhancement - Add product option to order -* Enhancement - Add additional fees to order as products - -## 2.2.8 (2016-11-18) -* Fix - Get address support for IE8 IE9 -* Enhancement - Display message in checkout when cancel/fail cardpayment -* Enhancement - Display message in checkout when cancel/fail bankpayment -* Enhancement - Links to manual in settings -* Enhancement - Button to reset Pclasses in settings - -## 2.2.7 (2016-08-05) -* Fix - Discount and VAT. - -## 2.2.6 (2016-04-07) -* Fix - Address popup utf8. -* Enhancement - Not send in zero fees. -* Enhancement - Fixed some rounding issues. - -## 2.2.5 (2016-03-21) -* Fix - Not send in Payment terms. - -## 2.2.4 (2016-02-29) -* Fix - Subscriptions -* Fix - Status for subscriptions. - -## 2.2.3 (2016-02-25) -* Fix - Callback with post. - -## 2.2.2 (2016-02-16) -* Fix - Exit after all redirects. - -## 2.2.1 (2016-02-12) -* Fix - Recurring number on order. - -## 2.2 (2016-01-08) -* Enhancement - Autoactivate invoices on complete. -* Enhancement - Compatibility with Woocommerce Subscription. Recurring payment. -* Translation - Improved the translations. -* Enhancement - Update totals on getAddress click. -* Engancement - Better tracking of invoices in order history. - -## 2.1.7(2016-01-21) -* Fix - Rounding totals. - -## 2.1.6(2015-12-10) -* Fix - Customer Nr. -* Fix - Compatibility wc_seq_order_number. - -## 2.1.5 (2015-12-09) -* Fix - Rounding. -* Fix - Callback issue. - -## 2.1.4 (2015-10-29) -* Fix - Fix bank and partpayment calculations. -* Enhancement - Change classname from Encoding to BillmateStringEncoding, compatibility with Duplicator Pro plugin. - -## 2.1.3 (2015-10-12) -* Fix - Php 5.4 compatibility, activate plugin issue. - -## 2.1.2 (2015-10-07) -* Fix - Activate plugin issue. -* Enhancement - Added filters for our icons. - -## 2.1.1 (2015-10-05) -* Fix - UTF-8 encoding, payment denied message and Card and Bank payment addresses. -* Fix - Rounding calculations. - -## 2.1 (2015-10-01) -* Enhancement - Possibility to Choose logo on the invoice created in Billmate Online. -* Optimization - Less load time when show partpayment from on product/shop page. -* Enhancement - Communication error messages. -* Fix - Cancel callback. - -## 2.0.6.2 (2015-09-25) -* Fix - Callback issue with GET setting -* Fix - Terms for invoice -* Fix - Sequential Order number compatibility - -## 2.0.6 (2015-09-04) -2 commits -* Fix - Order status when order is denied. -* Fix - Order note when order is denied. - -## 2.0.5 (2015-09-04) -2 commits -* Fix - Added transaction method on card again. - -## 2.0.4 (2015-08-24) -2 commits -* Enchancement - Prettified if no email is input in invoice and partpayment. -* Fix - Order status Issue with partpayment and invoice. - -## 2.0.3 (2015-08-17) -1 commit 2 issues closed. -* Enchangement - Clean up logging. -* Fix - Same encoding on all error messages. - -## 2.0.2 (2015-08-14) -1 commit -* Fix - Corrected a typo. - -## 2.0.1 (2015-08-13) -1 commit -* Compatibility - WooCommerce above 2.4 - -## 2.0 (2015-08-05) -110 commits and 79 issues closed. -* Compatibility - WooCommerce 2.0 and above. -* Enchancement - Get Address for customers in the Checkout. -* Tweak - Layout improvements. -* Tweak - Automatic update of paymentplans. -* Tweak - Clearify Invoice fee in Invoice payment title. -* Tweak - Validation of Billmate Credentials. -* Tweak - Can choose status of payment. -* Tweak - Remove need of product for the Invoice Fee. -* Fix - Consequent display of testmode. -* Fix - Added better support for plugin dynamic pricing. -* Fix - Discount is now divided per Vat rate. -* Fix - Can now order when create account on checkout. - -## 1.23.2 (2015-01-30) -* Fix - Fixed a bug that if you entered a matching adress, the verification of the adress popup still appeared. - -## 1.23.1 (2015-01-19) -* Fix - The payment status is set to the correct on all payment methods. - -## 1.23 (2015-01-08) -* Feature - Added the functionality so that if you put a file called billmatecustom.css in the plugin it will include that. Useful if you need to overwrite some CSS to make the Billmate plugin look good in you checkout without everwriting the themes css. -* Fix - Fixed so that an error on the checkout page does not occur if you enter wrong "personnummer" twice. -* Fix - If you enter a wroong ID for the invoice fee the checkout and settings page does not crash. -* Fix - Removed references to WPLANG and now uses get_locale function instead. According to Wordpres coding standard. -* Tweak - Updated to new company name : Billmate AB. -* Tweak - Change to correct include of colorbox.css to follow Wordpress coding standard -* Tweak - Fixed so that partpayment prices is shown as 12 mounths instead of 3 - ---- -Original code created by Niklas Högefjord - http://krokedil.com/ diff --git a/src/Readme.txt b/src/Readme.txt index 8da9eb82..51faea4e 100644 --- a/src/Readme.txt +++ b/src/Readme.txt @@ -86,6 +86,10 @@ https://www.billmate.se/press-och-media/ == Changelog == += 3.6.2 (2019-11-20) +* Feature - Selected payment method in Billmate Checkout is shown in WooCommerce order details +* Fix - Additional rules for checkout url to not be overwritten by billmatecheckout url + = 3.6.0 (2019-11-13) * Feature - Selected payment method in Billmate Checkout is shown in WooCommerce order details * Fix - Aditional rules for checkout url to not be overwritten by billmatecheckout url diff --git a/src/class-billmate-account.php b/src/class-billmate-account.php index 00102363..560d4a20 100755 --- a/src/class-billmate-account.php +++ b/src/class-billmate-account.php @@ -409,8 +409,69 @@ function get_title(){ global $woocommerce; if(is_object($woocommerce->cart)) { + $cart_total = $woocommerce->cart->total; - $pclasses = get_option('wc_gateway_billmate_partpayment_pclasses'); + + + + $storedPclassesSum = WC()->session->get('billmate_pclasses_sum'); + $storedPclasses = WC()->session->get('billmate_pclasses'); + + if ($storedPclasses == null || $storedPclassesSum !== WC_Payment_Gateway::get_order_total()*100) { + + $settings = get_option('woocommerce_billmate_partpayment_settings'); + if ($settings['testmode'] == 'yes'): + // Disable SSL if in testmode + $billmate_ssl = 'false'; + $billmate_mode = 'test'; + else : + // Set SSL if used in webshop + if (is_ssl()) { + $billmate_ssl = 'true'; + } else { + $billmate_ssl = 'false'; + } + $billmate_mode = 'live'; + endif; + $eid = (int)get_option('billmate_common_eid'); + + if (empty($eid)) { + return false; + } + + $secret = get_option('billmate_common_secret'); + $country = self::$country; + $currency = get_woocommerce_currency(); + $language = explode('_', get_locale()); + if (!defined('BILLMATE_LANGUAGE')) define('BILLMATE_LANGUAGE', strtolower($language[0])); + global $wp_version; + + // Meta to add to API requests, will be used for debug + $meta = array( + 'PHP_VERSION' => phpversion(), + 'WORDPRESS_VERSION' => $wp_version, + 'WOOCOMMERCE_VERSION' => WC_VERSION + ); + $bm = new BillMate($eid, $secret, true, $settings['testmode'] == 'yes', false, $meta); + + $values['PaymentData'] = array( + 'currency' => $currency, + 'language' => $language[0], + 'country' => $country, + 'totalwithtax' => WC_Payment_Gateway::get_order_total() * 100 + ); + $pclasses = $bm->getPaymentPlans($values); + + WC()->session->set('billmate_pclasses_sum', WC_Payment_Gateway::get_order_total() * 100); + WC()->session->set('billmate_pclasses', $pclasses); + } + else { + $pclasses = $storedPclasses; + } + + + + $flags = BillmateFlags::CHECKOUT_PAGE; $pclass = BillmateCalc::getCheapestPClass($cart_total, $flags, $pclasses); $billmate_partpayment_monthly_cost_message = false; @@ -488,8 +549,61 @@ function is_available() { } $pclasses_not_available = true; - $pclasses = get_option('wc_gateway_billmate_partpayment_pclasses',false); + $storedPclassesSum = WC()->session->get('billmate_pclasses_sum'); + $storedPclasses = WC()->session->get('billmate_pclasses'); + if ($storedPclasses == null || $storedPclassesSum !== WC_Payment_Gateway::get_order_total()*100) { + $settings = get_option('woocommerce_billmate_partpayment_settings'); + + if ($settings['testmode'] == 'yes'): + // Disable SSL if in testmode + $billmate_ssl = 'false'; + $billmate_mode = 'test'; + else : + // Set SSL if used in webshop + if (is_ssl()) { + $billmate_ssl = 'true'; + } else { + $billmate_ssl = 'false'; + } + $billmate_mode = 'live'; + endif; + $eid = (int)get_option('billmate_common_eid'); + + if (empty($eid)) { + return false; + } + + $secret = get_option('billmate_common_secret'); + $country = self::$country; + $currency = get_woocommerce_currency(); + $language = explode('_', get_locale()); + if (!defined('BILLMATE_LANGUAGE')) define('BILLMATE_LANGUAGE', strtolower($language[0])); + global $wp_version; + + // Meta to add to API requests, will be used for debug + $meta = array( + 'PHP_VERSION' => phpversion(), + 'WORDPRESS_VERSION' => $wp_version, + 'WOOCOMMERCE_VERSION' => WC_VERSION + ); + $bm = new BillMate($eid, $secret, true, $settings['testmode'] == 'yes', false, $meta); + + $values['PaymentData'] = array( + 'currency' => $currency, + 'language' => $language[0], + 'country' => $country, + 'totalwithtax' => WC_Payment_Gateway::get_order_total() * 100 + ); + + $pclasses = $bm->getPaymentPlans($values); + + WC()->session->set('billmate_pclasses_sum', WC_Payment_Gateway::get_order_total() * 100); + WC()->session->set('billmate_pclasses', $pclasses); + } + else { + $pclasses = $storedPclasses; + } if($pclasses){ $billmate_cart_total = WC_Payment_Gateway::get_order_total(); $sum = apply_filters( 'billmate_cart_total', $billmate_cart_total ); // Cart total. @@ -512,6 +626,8 @@ function is_available() { $sum -= ($availableFees[sanitize_title(__('Invoice fee','billmate'))]['amount'] + $availableFees[sanitize_title(__('Invoice fee','billmate'))]['tax']); } + $sum = $sum*100; + foreach ($pclasses as $pclass) { if (strlen($pclass['description']) > 0 ) { // If sum over minamount and not over maxamount or maxamount is 0 @@ -571,17 +687,22 @@ function is_available() { } /** - * Retrieve the PClasses from Billmate and store it in the file billmatepclasses.json. - */ - function update_billmatepclasses_from_billmate( ) { + * Retrieve the PClasses from Billmate and store it in the file billmatepclasses.json. + */ + function update_billmatepclasses_from_billmate( ) + { + global $woocommerce; - register_setting('wc_gateway_billmate_partpayment','pclasses'); + register_setting('wc_gateway_billmate_partpayment', 'pclasses'); + if (isset($_GET['billmatePclassListener']) && $_GET['billmatePclassListener'] == '1'): - if(isset($_GET['resetPclasses']) && $_GET['resetPclasses'] == '1'): - update_option('wc_gateway_billmate_partpayment_pclasses',false); + if (isset($_GET['resetPclasses']) && $_GET['resetPclasses'] == '1'): + update_option('wc_gateway_billmate_partpayment_pclasses', false); endif; + + // Test mode or Live mode - if ( $this->testmode == 'yes' ): + if ($this->testmode == 'yes'): // Disable SSL if in testmode $billmate_ssl = 'false'; $billmate_mode = 'test'; @@ -594,17 +715,22 @@ function update_billmatepclasses_from_billmate( ) { } $billmate_mode = 'live'; endif; - if( empty( $this->eid) ){ + if (empty($this->eid)) { return false; } + $eid = (int)$this->eid; $secret = $this->secret; $country = $this->billmate_country; $language = $this->billmate_language; $currency = $this->billmate_currency; - $k = new BillMate( $eid, $secret, true, $this->testmode == 'yes', false, $this->getRequestMeta() ); + + + $k = new BillMate($eid, $secret, true, $this->testmode == 'yes', false, $this->getRequestMeta()); + + try { - $language = explode('_',get_locale()); + $language = explode('_', get_locale()); $values = array( 'PaymentData' => array( 'currency' => $currency, @@ -612,28 +738,31 @@ function update_billmatepclasses_from_billmate( ) { 'country' => strtolower($country) ) ); + $data = $k->getPaymentplans($values); - if(!is_array($data)){ + if (!is_array($data)) { throw new Exception($data); } - if(isset($data['code'])){ + if (isset($data['code'])) { throw new Exception($data['message']); } $output = array(); - array_walk($data, array($this,'correct_lang_billmate')); - foreach( $data as $row ){ + array_walk($data, array($this, 'correct_lang_billmate')); + foreach ($data as $row) { $row['eid'] = $eid; - $output[]=$row; + $output[] = $row; } - update_option('wc_gateway_billmate_partpayment_pclasses',$output); + update_option('wc_gateway_billmate_partpayment_pclasses', $output); + // Redirect to settings page - wp_redirect(admin_url('admin.php?page='.$_GET['page'].'&tab='.$_GET['tab'].'§ion=WC_Gateway_Billmate_Partpayment&billmate_error_status=0')); - } - catch(Exception $e) { + wp_redirect(admin_url('admin.php?page=' . $_GET['page'] . '&tab=' . $_GET['tab'] . '§ion=WC_Gateway_Billmate_Partpayment&billmate_error_status=0')); + } catch (Exception $e) { //Something went wrong, print the message: - wc_bm_errors( sprintf(__('Billmate PClass problem: %s. Error code: ', 'billmate'), utf8_encode($e->getMessage()) ) . '"' . $e->getCode() . '"', 'error' ); + wc_bm_errors(sprintf(__('Billmate PClass problem: %s. Error code: ', 'billmate'), utf8_encode($e->getMessage())) . '"' . $e->getCode() . '"', 'error'); //$billmate_error_code = utf8_encode($e->getMessage()) . 'Error code: ' . $e->getCode(); - $redirect_url = 'admin.php?page='.$_GET['page'].'&tab='.$_GET['tab'].'§ion=WC_Gateway_Billmate_Partpayment&billmate_error_status=1&billmate_error_code=' . $e->getCode().'&message='.($e->getMessage()); + + $redirect_url = 'admin.php?page=' . $_GET['page'] . '&tab=' . $_GET['tab'] . '§ion=WC_Gateway_Billmate_Partpayment&billmate_error_status=1&billmate_error_code=' . $e->getCode() . '&message=' . ($e->getMessage()); + //wp_redirect(admin_url($redirect_url)); wp_redirect(admin_url($redirect_url)); } @@ -645,7 +774,7 @@ function update_billmatepclasses_from_billmate( ) { */ function payment_fields( ) { - global $woocommerce; + global $woocommerce; $enabled_plcass = 'no'; // Test mode or Live mode @@ -708,7 +837,61 @@ function payment_fields( ) { session->get('billmate_pclasses_sum'); + $storedPclasses = WC()->session->get('billmate_pclasses'); + + if ($storedPclasses == null || $storedPclassesSum !== $sum*100) { + $settings = get_option('woocommerce_billmate_partpayment_settings'); + + if ($settings['testmode'] == 'yes'): + // Disable SSL if in testmode + $billmate_ssl = 'false'; + $billmate_mode = 'test'; + else : + // Set SSL if used in webshop + if (is_ssl()) { + $billmate_ssl = 'true'; + } else { + $billmate_ssl = 'false'; + } + $billmate_mode = 'live'; + endif; + $eid = (int)get_option('billmate_common_eid'); + + if (empty($eid)) { + return false; + } + + $secret = get_option('billmate_common_secret'); + $country = self::$country; + $currency = get_woocommerce_currency(); + $language = explode('_', get_locale()); + if (!defined('BILLMATE_LANGUAGE')) define('BILLMATE_LANGUAGE', strtolower($language[0])); + global $wp_version; + + // Meta to add to API requests, will be used for debug + $meta = array( + 'PHP_VERSION' => phpversion(), + 'WORDPRESS_VERSION' => $wp_version, + 'WOOCOMMERCE_VERSION' => WC_VERSION + ); + $bm = new BillMate($eid, $secret, true, $settings['testmode'] == 'yes', false, $meta); + + $values['PaymentData'] = array( + 'currency' => $currency, + 'language' => $language[0], + 'country' => $country, + 'totalwithtax' => $sum * 100 + ); + + $pclasses = $bm->getPaymentPlans($values); + WC()->session->set('billmate_pclasses_sum', $sum * 100); + WC()->session->set('billmate_pclasses', $pclasses); + } + else { + $pclasses = $storedPclasses; + } if(!$pclasses) return false; /*$pclass = BillmateCalc::getCheapestPClass($sum, $flag, $pclasses); @@ -963,7 +1146,8 @@ public static function update_billmatepclasses_from_frontend(){ 'country' => strtolower($country) ) ); - $data = $k->getPaymentplans($values); + + $data = $k->getPaymentplans($values); if(!is_array($data)){ throw new Exception($data); } @@ -998,11 +1182,65 @@ public static function update_billmatepclasses_from_frontend(){ **/ public static function payment_fields_options( $sum, $label = true ,$flag = BillmateFlags::CHECKOUT_PAGE){ + $pclasses_not_available = true; + $enabled_plcass = 'no'; + $storedPclassesSum = WC()->session->get('billmate_pclasses_sum'); + $storedPclasses = WC()->session->get('billmate_pclasses'); + + if ($storedPclasses == null || $storedPclassesSum !== $sum*100) { + $settings = get_option('woocommerce_billmate_partpayment_settings'); + + if ($settings['testmode'] == 'yes'): + // Disable SSL if in testmode + $billmate_ssl = 'false'; + $billmate_mode = 'test'; + else : + // Set SSL if used in webshop + if (is_ssl()) { + $billmate_ssl = 'true'; + } else { + $billmate_ssl = 'false'; + } + $billmate_mode = 'live'; + endif; + $eid = (int)get_option('billmate_common_eid'); + + if (empty($eid)) { + return false; + } + + $secret = get_option('billmate_common_secret'); + $country = self::$country; + $currency = get_woocommerce_currency(); + $language = explode('_', get_locale()); + if (!defined('BILLMATE_LANGUAGE')) define('BILLMATE_LANGUAGE', strtolower($language[0])); + global $wp_version; + + // Meta to add to API requests, will be used for debug + $meta = array( + 'PHP_VERSION' => phpversion(), + 'WORDPRESS_VERSION' => $wp_version, + 'WOOCOMMERCE_VERSION' => WC_VERSION + ); + $bm = new BillMate($eid, $secret, true, $settings['testmode'] == 'yes', false, $meta); + + $values['PaymentData'] = array( + 'currency' => $currency, + 'language' => $language[0], + 'country' => $country, + 'totalwithtax' => $sum * 100 + ); $pclasses_not_available = true; $enabled_plcass = 'no'; - $pclasses = get_option('wc_gateway_billmate_partpayment_pclasses',false); + $pclasses = $bm->getPaymentPlans($values); + WC()->session->set('billmate_pclasses_sum', $sum * 100); + WC()->session->set('billmate_pclasses', $pclasses); + } + else { + $pclasses = $storedPclasses; + } if(date('Y-m-d',strtotime('+1 week')) >= $pclasses[0]['expirydate']){ $_GET['billmatePclassListener'] = 1; self::update_billmatepclasses_from_frontend(); @@ -1016,6 +1254,62 @@ public static function payment_fields_options( $sum, $label = true ,$flag = Bill $pclasses = array($pclasses); $flag = BillmateFlags::CHECKOUT_PAGE; } + + $storedPclassesSum = WC()->session->get('billmate_pclasses_sum'); + $storedPclasses = WC()->session->get('billmate_pclasses'); + + if ($storedPclasses == null || $storedPclassesSum !== $sum*100) { + $settings = get_option('woocommerce_billmate_partpayment_settings'); + + if ($settings['testmode'] == 'yes'): + // Disable SSL if in testmode + $billmate_ssl = 'false'; + $billmate_mode = 'test'; + else : + // Set SSL if used in webshop + if (is_ssl()) { + $billmate_ssl = 'true'; + } else { + $billmate_ssl = 'false'; + } + $billmate_mode = 'live'; + endif; + $eid = (int)get_option('billmate_common_eid'); + + if (empty($eid)) { + return false; + } + + $secret = get_option('billmate_common_secret'); + $country = self::$country; + $currency = get_woocommerce_currency(); + $language = explode('_', get_locale()); + if (!defined('BILLMATE_LANGUAGE')) define('BILLMATE_LANGUAGE', strtolower($language[0])); + global $wp_version; + + // Meta to add to API requests, will be used for debug + $meta = array( + 'PHP_VERSION' => phpversion(), + 'WORDPRESS_VERSION' => $wp_version, + 'WOOCOMMERCE_VERSION' => WC_VERSION + ); + $bm = new BillMate($eid, $secret, true, $settings['testmode'] == 'yes', false, $meta); + + $values['PaymentData'] = array( + 'currency' => $currency, + 'language' => $language[0], + 'country' => $country, + 'totalwithtax' => $sum * 100 + ); + + $pclasses = $bm->getPaymentPlans($values); + WC()->session->set('billmate_pclasses_sum', $sum * 100); + WC()->session->set('billmate_pclasses', $pclasses); + } + else { + $pclasses = $storedPclasses; + } + // Check if we have any PClasses if(!$pclasses_not_available) { if( $label ) { @@ -1025,7 +1319,7 @@ public static function payment_fields_options( $sum, $label = true ,$flag = Bill session->get('billmate_pclasses_sum'); + $storedPclasses = WC()->session->get('billmate_pclasses'); + if ($storedPclasses == null || $storedPclassesSum !== WC_Payment_Gateway::get_order_total()*100) { - // apply_filters to product price so we can filter this if needed - $billmate_product_total = $product->get_price(); - $sum = apply_filters( 'billmate_product_total', $billmate_product_total ); // Product price. - $flag = BillmateFlags::PRODUCT_PAGE; //or BillmateFlags::PRODUCT_PAGE, if you want to do it for one item. - $pclass = BillmateCalc::getCheapestPClass($sum, $flag, $pclasses); + $settings = get_option('woocommerce_billmate_partpayment_settings'); + if ($settings['testmode'] == 'yes'): + // Disable SSL if in testmode + $billmate_ssl = 'false'; + $billmate_mode = 'test'; + else : + // Set SSL if used in webshop + if (is_ssl()) { + $billmate_ssl = 'true'; + } else { + $billmate_ssl = 'false'; + } + $billmate_mode = 'live'; + endif; + $eid = (int)get_option('billmate_common_eid'); - //Did we get a PClass? (it is false if we didn't) - if($pclass) { - //Here we reuse the same values as above: - $value = BillmateCalc::calc_monthly_cost( - $sum, - $pclass, - $flag - ); - - /* $value is now a rounded monthly cost amount to be displayed to the customer. */ - if ( $lower_threshold_monthly_cost < $sum && $upper_threshold_monthly_cost > $sum ) { - - // Asign values to variables used for shortcodes. - $billmate_partpayment_shortcode_currency = $billmate_currency; - $billmate_partpayment_shortcode_price = $value; - $billmate_shortcode_img = $icon_basic; - $billmate_partpayment_country = $billmate_country; - - echo '