| @@ -16,15 +16,15 @@ | ||
| 16 | 16 | const MC_REFUNDED = 'REFUNDED'; |
| 17 | 17 | |
| 18 | 18 | const module_name = 'MakeCommerce'; |
| 19 | 19 | |
| 20 | - const billing_descriptor_dba = ''; | |
| 20 | + const billing_descriptor_dba = ''; | |
| 21 | 21 | const currencies_allowed = 'EUR'; |
| 22 | 22 | const module_homepage_url = 'https://maksekeskus.ee/en/integration-modules/makecommerce-woocommerce-payment-plugin/'; |
| 23 | 23 | const testenv_homepage_url = 'http://maksekeskus.ee/en/for-developers/test-environment/'; |
| 24 | 24 | |
| 25 | 25 | public $id = 'makecommerce'; |
| 26 | - public $version = '2.2.0'; | |
| 26 | + public $version = '2.5.3'; | |
| 27 | 27 | |
| 28 | 28 | public $payment_return_url; |
| 29 | 29 | public $payment_return_url_m2m; |
| 30 | 30 | public $payment_return_url_cancel; |
| @@ -37,19 +37,23 @@ | ||
| 37 | 37 | protected $_banklinks = array(); |
| 38 | 38 | protected $_banklinks_grouped; |
| 39 | 39 | protected $_cards = array(); |
| 40 | 40 | |
| 41 | - protected $MK; | |
| 41 | + protected $MK; | |
| 42 | 42 | protected $_init; |
| 43 | 43 | |
| 44 | 44 | |
| 45 | - public function __construct($init = false) { | |
| 45 | + public function __construct($init = false) { | |
| 46 | 46 | $this->_init = $init; |
| 47 | - | |
| 48 | - $this->payment_return_url = site_url('/?makecommerce_return=1'); | |
| 49 | - $this->payment_return_url_m2m = site_url('/?makecommerce_return=1&ajax_content=1'); | |
| 50 | - $this->payment_return_url_cancel = site_url('/?makecommerce_return=1'); | |
| 51 | - | |
| 47 | + if(function_exists('pll_current_language')) { | |
| 48 | + $this->payment_return_url = site_url('/'.ICL_LANGUAGE_CODE.'/?makecommerce_return=1'); | |
| 49 | + $this->payment_return_url_m2m = site_url('/'.ICL_LANGUAGE_CODE.'/?makecommerce_return=1&ajax_content=1'); | |
| 50 | + $this->payment_return_url_cancel = site_url('/'.ICL_LANGUAGE_CODE.'/?makecommerce_return=1'); | |
| 51 | + } else { | |
| 52 | + $this->payment_return_url = site_url('/?makecommerce_return=1'); | |
| 53 | + $this->payment_return_url_m2m = site_url('/?makecommerce_return=1&ajax_content=1'); | |
| 54 | + $this->payment_return_url_cancel = site_url('/?makecommerce_return=1'); | |
| 55 | + } | |
| 52 | 56 | // Load the form fields. |
| 53 | 57 | $this->init_form_fields(); |
| 54 | 58 | |
| 55 | 59 | // Load the settings. |
| @@ -56,15 +60,21 @@ | ||
| 56 | 60 | $this->init_settings(); |
| 57 | 61 | |
| 58 | 62 | $this->initBanklinks(); |
| 59 | 63 | |
| 60 | - $this->title = $this->settings['ui_widget_title']; | |
| 61 | 64 | if (defined('ICL_LANGUAGE_CODE') && !empty($this->settings['ui_widget_title_'.ICL_LANGUAGE_CODE])) { |
| 62 | 65 | $this->title = $this->settings['ui_widget_title_'.ICL_LANGUAGE_CODE]; |
| 66 | + } else if (!empty($this->settings['ui_widget_title'])) { | |
| 67 | + $this->title = $this->settings['ui_widget_title']; | |
| 68 | + } else { | |
| 69 | + $this->title = ''; | |
| 63 | 70 | } |
| 71 | + | |
| 64 | 72 | $this->method_title = 'MakeCommerce'; |
| 65 | 73 | $this->description = true; |
| 66 | 74 | |
| 75 | + $this->enabled = $this->settings['active']; | |
| 76 | + | |
| 67 | 77 | $this->MK = mk_get_api(); |
| 68 | 78 | if (!$this->MK && $this->_init) { |
| 69 | 79 | add_action( 'admin_notices', array(&$this, 'makecommerce_api_info_missing') ); |
| 70 | 80 | } |
| @@ -69,14 +79,23 @@ | ||
| 69 | 79 | add_action( 'admin_notices', array(&$this, 'makecommerce_api_info_missing') ); |
| 70 | 80 | } |
| 71 | 81 | |
| 72 | 82 | $this->supports = array( |
| 83 | + 'subscriptions', | |
| 84 | + 'subscription_cancellation', | |
| 85 | + 'subscription_suspension', | |
| 86 | + 'subscription_reactivation', | |
| 87 | + 'subscription_amount_changes', | |
| 88 | + 'subscription_date_changes', | |
| 89 | + 'subscription_payment_method_change', | |
| 73 | 90 | 'products', |
| 74 | - 'refunds', | |
| 91 | + 'refunds' | |
| 75 | 92 | ); |
| 76 | 93 | |
| 77 | 94 | add_filter('query_vars', array(&$this, 'makecommerce_return_trigger')); |
| 78 | 95 | add_action('template_redirect', array(&$this, 'makecommerce_return_trigger_check')); |
| 96 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'process_subscripion_payment_start'), 10, 2); | |
| 97 | + add_action('scheduled_subscription_payment_' . $this->id, array($this, 'process_subscripion_payment_start'), 10, 2); | |
| 79 | 98 | |
| 80 | 99 | if($this->_init == false) { |
| 81 | 100 | add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options')); |
| 82 | 101 | add_action('woocommerce_update_options_payment_gateways_' . $this->id, array(&$this, 'process_admin_options')); |
| @@ -88,8 +107,9 @@ | ||
| 88 | 107 | wp_enqueue_style('makecommerce', plugins_url('/css/makecommerce.css', __FILE__), array(), $this->version); |
| 89 | 108 | } |
| 90 | 109 | if (is_admin()) { |
| 91 | 110 | add_action( 'wp_ajax_mc_banklinks_reload', array(&$this, 'mc_banklinks_reload') ); |
| 111 | + | |
| 92 | 112 | require_once(ABSPATH.'wp-admin/includes/plugin.php'); |
| 93 | 113 | $wc_version = get_plugin_data(__DIR__.'/../woocommerce/woocommerce.php'); |
| 94 | 114 | if ((double)$wc_version['Version'] < 2.6) { |
| 95 | 115 | function sample_admin_notice__error() { |
| @@ -118,11 +138,12 @@ | ||
| 118 | 138 | return true; |
| 119 | 139 | } |
| 120 | 140 | |
| 121 | 141 | public function is_available() { |
| 122 | - if ($this->settings['active'] == "yes" && mk_is_api_set()) { | |
| 123 | - return true; | |
| 142 | + if (!($this->settings['active'] == "yes" && mk_is_api_set())) { | |
| 143 | + return false; | |
| 124 | 144 | } |
| 145 | + return parent::is_available(); | |
| 125 | 146 | } |
| 126 | 147 | |
| 127 | 148 | private function initBanklinks() { |
| 128 | 149 | global $wpdb; |
| @@ -127,8 +148,9 @@ | ||
| 127 | 148 | private function initBanklinks() { |
| 128 | 149 | global $wpdb; |
| 129 | 150 | global $mkDbTable; |
| 130 | 151 | $this->_banklinks = array(); |
| 152 | + $has_subscriptions = class_exists('WC_Subscriptions_Cart') && WC_Subscriptions_Cart::cart_contains_subscription(); | |
| 131 | 153 | |
| 132 | 154 | $tableName = $wpdb->prefix . $mkDbTable; |
| 133 | 155 | $methods = $wpdb->get_results('SELECT * FROM '.$tableName); |
| 134 | 156 | |
| @@ -141,9 +163,11 @@ | ||
| 141 | 163 | $banklinks_grouped = array(); |
| 142 | 164 | $cards = array(); |
| 143 | 165 | foreach($methods as $method) { |
| 144 | 166 | if($method->type == 'banklink') { |
| 145 | - $banklinks[] = $banklinks_grouped[$method->country][] = $method; | |
| 167 | + if (!$has_subscriptions) { | |
| 168 | + $banklinks[] = $banklinks_grouped[$method->country][] = $method; | |
| 169 | + } | |
| 146 | 170 | } elseif($method->type == 'card') { |
| 147 | 171 | $cards[] = $method; |
| 148 | 172 | } |
| 149 | 173 | } |
| @@ -184,9 +208,13 @@ | ||
| 184 | 208 | ?> |
| 185 | 209 | <div class="notice notice-error is-dismissible"> |
| 186 | 210 | <p> |
| 187 | 211 | <?php echo __('You have not entered the Shop ID and keys for the MakeCommerce payment module. The module will not work without them.', 'wc_makecommerce_domain'); ?> |
| 212 | + <?php if (mk_wc_version("3.4.0")) { ?> | |
| 213 | + <a href="<?php echo admin_url('admin.php?page=wc-settings&tab=advanced§ion=mk_api'); ?>"><?php echo __('Click here to enter them', 'wc_makecommerce_domain'); ?></a> | |
| 214 | + <?php } else { ?> | |
| 188 | 215 | <a href="<?php echo admin_url('admin.php?page=wc-settings&tab=api§ion=mk_api'); ?>"><?php echo __('Click here to enter them', 'wc_makecommerce_domain'); ?></a> |
| 216 | + <?php } ?> | |
| 189 | 217 | </p> |
| 190 | 218 | </div> |
| 191 | 219 | <?php |
| 192 | 220 | } |
| @@ -235,11 +263,12 @@ | ||
| 235 | 263 | 'type' => 'checkbox', |
| 236 | 264 | 'label' => __('Enable MakeCommerce payments', 'wc_makecommerce_domain'), |
| 237 | 265 | 'default' => 'no' |
| 238 | 266 | ); |
| 267 | + if (mk_wc_version("3.4.0")) $a = admin_url('admin.php?page=wc-settings&tab=advanced§ion=mk_api'); else $a = admin_url('admin.php?page=wc-settings&tab=api§ion=mk_api'); | |
| 239 | 268 | $this->form_fields['api_title'] = array( |
| 240 | 269 | 'title' => __('MakeCommerce API', 'wc_makecommerce_domain'), |
| 241 | - 'description' => sprintf(__('Go to <a href="%s">API settings</a> to fill in the credentials', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=api§ion=mk_api')), | |
| 270 | + 'description' => sprintf(__('Go to <a href="%s">API settings</a> to fill in the credentials', 'wc_makecommerce_domain'), $a), | |
| 242 | 271 | 'type' => 'title', |
| 243 | 272 | ); |
| 244 | 273 | $this->form_fields['ui_title'] = array( |
| 245 | 274 | 'title' => '<br>'.__('User Interface', 'wc_makecommerce_domain'), |
| @@ -480,13 +509,19 @@ | ||
| 480 | 509 | return false; |
| 481 | 510 | } |
| 482 | 511 | |
| 483 | 512 | $tableName = $wpdb->prefix . $mkDbTable; |
| 513 | + $sql = "select count(*) as isLogoUrlSet from information_schema.columns where table_name='".$tableName."' and column_name='logo_url'"; | |
| 514 | + $methodstruct = $wpdb->get_results( $sql ); | |
| 515 | + if ($methodstruct[0]->isLogoUrlSet == 0) { | |
| 516 | + $wpdb->query('ALTER TABLE '.$tableName.' ADD COLUMN logo_url varchar(250)'); | |
| 517 | + } | |
| 518 | + | |
| 484 | 519 | $wpdb->query('TRUNCATE TABLE '.$tableName); |
| 485 | 520 | |
| 486 | 521 | if(isset($methods->banklinks)) { |
| 487 | 522 | foreach($methods->banklinks as $method) { |
| 488 | - $wpdb->insert($tableName, array('type' => 'banklink', 'country' => $method->country, 'name' => $method->name, 'url' => $method->url)); | |
| 523 | + $wpdb->insert($tableName, array('type' => 'banklink', 'country' => $method->country, 'name' => $method->name, 'url' => $method->url, 'logo_url' => $method->logo_url)); | |
| 489 | 524 | } |
| 490 | 525 | $updated = true; |
| 491 | 526 | } |
| 492 | 527 | |
| @@ -491,9 +526,9 @@ | ||
| 491 | 526 | } |
| 492 | 527 | |
| 493 | 528 | if(isset($methods->cards)) { |
| 494 | 529 | foreach($methods->cards as $method) { |
| 495 | - $wpdb->insert($tableName, array('type' => 'card', 'name' => $method->name)); | |
| 530 | + $wpdb->insert($tableName, array('type' => 'card', 'name' => $method->name, 'logo_url' => $method->logo_url)); | |
| 496 | 531 | } |
| 497 | 532 | $updated = true; |
| 498 | 533 | } |
| 499 | 534 | |
| @@ -520,8 +555,64 @@ | ||
| 520 | 555 | } |
| 521 | 556 | die(); |
| 522 | 557 | } |
| 523 | 558 | |
| 559 | + | |
| 560 | + public function process_subscripion_payment_start($amount_to_charge, $renewal_order, $product_id = '') { | |
| 561 | + $result = $this->process_subscription_payment($renewal_order, $amount_to_charge); | |
| 562 | + if ( is_wp_error( $result ) ) { | |
| 563 | + WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($renewal_order, $product_id); | |
| 564 | + } else { | |
| 565 | + WC_Subscriptions_Manager::process_subscription_payments_on_order($renewal_order); | |
| 566 | + } | |
| 567 | + } | |
| 568 | + | |
| 569 | + public function process_subscription_payment($order, $amount = 0) { | |
| 570 | + if (0 === $amount) { | |
| 571 | + $order->payment_complete(); | |
| 572 | + return true; | |
| 573 | + } // if ('processing' === $order->get_status() || 'completed' === $order->get_status()){ // ('processing' === $order->get_status()) | |
| 574 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status()){ | |
| 575 | + return true; | |
| 576 | + } | |
| 577 | + $oorder_id = @WC_Subscriptions_Renewal_Order::get_parent_order_id($order); | |
| 578 | + $payment_token = get_post_meta($oorder_id, '_makecommerce_payment_token', true); | |
| 579 | + $payment_token_valid_until = get_post_meta($oorder_id, '_makecommerce_payment_token_valid_until', true); | |
| 580 | + error_log($payment_token.'=>'. $payment_token_valid_until.'=>'. $order->get_status()); | |
| 581 | + $body = array( | |
| 582 | + 'transaction' => array( | |
| 583 | + 'amount' => (string)sprintf("%.2f", $amount), | |
| 584 | + 'currency' => method_exists($order, 'get_currency') ? $order->get_currency() : $order->currency, | |
| 585 | + 'reference' => $order->get_order_number(), | |
| 586 | + ), | |
| 587 | + 'customer' => array( | |
| 588 | + 'email' => $order->get_billing_email(), | |
| 589 | + 'ip' => $order->get_customer_ip_address(), | |
| 590 | + 'country' => strtolower($order->get_billing_country()), | |
| 591 | + 'locale' => strtolower(substr(get_locale(), 0, 2)), | |
| 592 | + ) | |
| 593 | + ); | |
| 594 | + $transaction = $this->MK->createTransaction($body); | |
| 595 | + $paymentRequest = array( | |
| 596 | + 'amount' => (string)sprintf("%.2f", $transaction->amount), | |
| 597 | + 'currency' => $transaction->currency, | |
| 598 | + 'token' => $payment_token | |
| 599 | + ); | |
| 600 | + try { | |
| 601 | + $payment = $this->MK->createPayment($transaction->id, $paymentRequest); | |
| 602 | + } catch (Exception $e) { | |
| 603 | + error_log('Payment failed ['.$e->getMessage().']'); | |
| 604 | + $order->add_order_note(__('Unable to renew subscription', 'wc_makecommerce_domain')."\r\n".$e->getMessage()); | |
| 605 | + return new WP_Error('makecommerce_payment_declined', __( 'Renewal payment was declined', 'wc_makecommerce_domain' ) ); | |
| 606 | + } | |
| 607 | + $orderNote = array(); | |
| 608 | + $orderNote[] = __('Transaction ID', 'wc_makecommerce_domain') . ': <a target=_blank href="'.$this->MK->getEnvUrls()->merchantUrl.'/merchant/shop/deals/detail.html?id='. $transaction->id .'">'.$transaction->id.'</a>'; | |
| 609 | + $orderNote[] = __('Payment option', 'wc_makecommerce_domain') . ': ' . get_post_meta($order->get_order_number(), '_makecommerce_preselected_method', true); | |
| 610 | + $order->add_order_note(implode("\r\n", $orderNote)); | |
| 611 | + $order->payment_complete($transaction->id); | |
| 612 | + return true; | |
| 613 | + } | |
| 614 | + | |
| 524 | 615 | public function admin_order_page($order) { |
| 525 | 616 | // |
| 526 | 617 | } |
| 527 | 618 | |
| @@ -534,9 +625,9 @@ | ||
| 534 | 625 | if ( empty($transactionId) ) { |
| 535 | 626 | $transactionId = get_post_meta( $order_id, '_makecommerce_transaction_id', true); |
| 536 | 627 | } |
| 537 | 628 | |
| 538 | - if($response = $this->MK->createRefund($transactionId, array('amount' => $amount, 'comment' => ($comment ? : 'refund')))) { | |
| 629 | + if($response = $this->MK->createRefund($transactionId, array('amount' => sprintf("%.2f", $amount), 'comment' => ($comment ? : 'refund')))) { | |
| 539 | 630 | if($status = (string)$response->transaction->status) { |
| 540 | 631 | switch($status) { |
| 541 | 632 | case self::MC_REFUNDED: |
| 542 | 633 | $order->add_order_note(sprintf(__('Refund completed for amount %s', 'wc_makecommerce_domain'), $amount)); |
| @@ -623,8 +714,9 @@ | ||
| 623 | 714 | <?php |
| 624 | 715 | } |
| 625 | 716 | |
| 626 | 717 | public function payment_fields() { |
| 718 | + | |
| 627 | 719 | |
| 628 | 720 | if($this->settings['ui_mode'] == 'inline') { |
| 629 | 721 | |
| 630 | 722 | ?> |
| @@ -634,9 +726,9 @@ | ||
| 634 | 726 | <input type="radio" id="makecommerce_method_picker_<?php echo $method->country.'_'.$method->name; ?>" name="PRESELECTED_METHOD_<?php echo $this->id; ?>" value="<?php echo $method->country.'_'.$method->name; ?>"/> |
| 635 | 727 | <label for="makecommerce_method_picker_<?php echo $method->country.'_'.$method->name; ?>"> |
| 636 | 728 | <span class="makecommerce-method-title"><?php if(in_array($this->settings['ui_inline_uselogo'], array('text', 'text_logo'))) { echo ucfirst($method->name); if(count($this->_banklinks_grouped) > 1) { echo ' ('.$this->getCountryName($method->country).')'; } } ?></span> |
| 637 | 729 | <?php if(in_array($this->settings['ui_inline_uselogo'], array('logo', 'text_logo'))) : ?> |
| 638 | - <div><img src="<?php echo $this->getImageUrl($method->name); ?>" title="<?php echo ucfirst($method->name); ?>" /></div> | |
| 730 | + <div><img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" /></div> | |
| 639 | 731 | <?php endif; ?> |
| 640 | 732 | </label> |
| 641 | 733 | </li> |
| 642 | 734 | <?php endforeach; ?> |
| @@ -645,9 +737,9 @@ | ||
| 645 | 737 | <input type="radio" id="makecommerce_method_picker_<?php echo 'card_'.$method->name; ?>" name="PRESELECTED_METHOD_<?php echo $this->id; ?>" value="<?php echo 'card_'.$method->name; ?>"/> |
| 646 | 738 | <label for="makecommerce_method_picker_<?php echo 'card_'.$method->name; ?>"> |
| 647 | 739 | <span class="makecommerce-method-title"><?php if(in_array($this->settings['ui_inline_uselogo'], array('text', 'text_logo'))) { echo ucfirst($method->name); } ?></span> |
| 648 | 740 | <?php if(in_array($this->settings['ui_inline_uselogo'], array('logo', 'text_logo'))) : ?> |
| 649 | - <div><img src="<?php echo $this->getImageUrl($method->name); ?>" title="<?php echo ucfirst($method->name); ?>" /></div> | |
| 741 | + <div><img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" /></div> | |
| 650 | 742 | <?php endif; ?> |
| 651 | 743 | </label> |
| 652 | 744 | </li> |
| 653 | 745 | <?php endforeach; ?> |
| @@ -697,9 +789,9 @@ | ||
| 697 | 789 | <?php endif; ?> |
| 698 | 790 | <div class="makecommerce_country_picker_methods" id="makecommerce_country_picker_methods_<?php echo $country; ?>"> |
| 699 | 791 | <?php foreach($methods as $method): ?> |
| 700 | 792 | <div class="makecommerce-banklink-picker" banklink_id="<?php echo $method->country.'_'.$method->name; ?>"> |
| 701 | - <img src="<?php echo $this->getImageUrl($method->name); ?>" title="<?php echo ucfirst($method->name); ?>" /> | |
| 793 | + <img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" /> | |
| 702 | 794 | </div> |
| 703 | 795 | <?php endforeach; ?> |
| 704 | 796 | <?php if($this->_cards && $this->settings['ui_widget_groupcc'] == 'no') : ?> |
| 705 | 797 | <div class="breaker"></div> |
| @@ -704,9 +796,9 @@ | ||
| 704 | 796 | <?php if($this->_cards && $this->settings['ui_widget_groupcc'] == 'no') : ?> |
| 705 | 797 | <div class="breaker"></div> |
| 706 | 798 | <?php foreach($this->_cards as $method): ?> |
| 707 | 799 | <div class="makecommerce-banklink-picker" banklink_id="card_<?php echo $method->name; ?>"> |
| 708 | - <img src="<?php echo $this->getImageUrl($method->name); ?>" title="<?php echo ucfirst($method->name); ?>" /> | |
| 800 | + <img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" /> | |
| 709 | 801 | </div> |
| 710 | 802 | <?php endforeach; ?> |
| 711 | 803 | <?php elseif($country == 'other') :?> |
| 712 | 804 | <p class="no-methods"><?php _e('No payment methods for selected country' ,'wc_makecommerce_domain');?></p> |
| @@ -719,9 +811,9 @@ | ||
| 719 | 811 | <input type="radio" id="makecommerce_country_picker_card" name="makecommerce_country_picker" value="card"/><label for="makecommerce_country_picker_card"><?php echo $this->settings['ui_widget_groupcc_title']; ?></label> |
| 720 | 812 | <div class="makecommerce_country_picker_methods" id="makecommerce_country_picker_methods_card"> |
| 721 | 813 | <?php foreach($this->_cards as $method): ?> |
| 722 | 814 | <div class="makecommerce-banklink-picker" banklink_id="card_<?php echo $method->name; ?>"> |
| 723 | - <img src="<?php echo $this->getImageUrl($method->name); ?>" title="<?php echo ucfirst($method->name); ?>" /> | |
| 815 | + <img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" /> | |
| 724 | 816 | </div> |
| 725 | 817 | <?php endforeach; ?> |
| 726 | 818 | </div> |
| 727 | 819 | </li> |
| @@ -826,9 +918,9 @@ | ||
| 826 | 918 | return key($this->_banklinks_grouped); |
| 827 | 919 | } |
| 828 | 920 | |
| 829 | 921 | |
| 830 | - protected function getImageUrl($methodName) { | |
| 922 | + protected function getImageUrl($methodName) { // remove it | |
| 831 | 923 | //$imageUrlPath = 'https://static.maksekeskus.ee/img/channel/lnd/'; |
| 832 | 924 | $imageUrlPath = $this->MK->getEnvUrls()->staticsUrl.'img/channel/lnd/'; |
| 833 | 925 | return $imageUrlPath.$methodName.'.png'; |
| 834 | 926 | } |
| @@ -854,15 +946,15 @@ | ||
| 854 | 946 | $selected = isset($_POST['PRESELECTED_METHOD_' . $this->id]) ? sanitize_text_field($_POST['PRESELECTED_METHOD_' . $this->id]) : false; |
| 855 | 947 | |
| 856 | 948 | if (!empty($selected)) { |
| 857 | 949 | |
| 858 | - update_post_meta($order->id, '_makecommerce_preselected_method', $selected); | |
| 950 | + update_post_meta($order->get_order_number(), '_makecommerce_preselected_method', $selected); | |
| 859 | 951 | |
| 860 | 952 | $request_body = array( |
| 861 | 953 | 'transaction' => array( |
| 862 | - 'amount' => round($order->order_total, 2), | |
| 863 | - 'currency' => $order->get_order_currency(), | |
| 864 | - 'reference' => $order->id, | |
| 954 | + 'amount' => (string)sprintf("%.2f", $order->get_total()), | |
| 955 | + 'currency' => method_exists($order, 'get_currency') ? $order->get_currency() : $order->currency, | |
| 956 | + 'reference' => $order->get_order_number(), | |
| 865 | 957 | 'transaction_url' => array( |
| 866 | 958 | 'return_url' => array( |
| 867 | 959 | 'url' => $this->payment_return_url, |
| 868 | 960 | 'method' => 'POST', |
| @@ -878,9 +970,9 @@ | ||
| 878 | 970 | ), |
| 879 | 971 | ), |
| 880 | 972 | 'customer' => array( |
| 881 | 973 | 'ip' => $_SERVER['REMOTE_ADDR'], |
| 882 | - 'country' => strtolower($order->billing_country), | |
| 974 | + 'country' => strtolower($order->get_billing_country()), | |
| 883 | 975 | 'locale' => strtolower(substr(get_locale(), 0, 2)), |
| 884 | 976 | ), |
| 885 | 977 | ); |
| 886 | 978 | $transaction = $this->MK->createTransaction($request_body); |
| @@ -885,9 +977,9 @@ | ||
| 885 | 977 | ); |
| 886 | 978 | $transaction = $this->MK->createTransaction($request_body); |
| 887 | 979 | |
| 888 | 980 | if(isset($transaction->id)) { |
| 889 | - update_post_meta($order->id, '_makecommerce_transaction_id', $transaction->id); | |
| 981 | + update_post_meta($order->get_order_number(), '_makecommerce_transaction_id', $transaction->id); | |
| 890 | 982 | if (substr($selected, 0, 5) == 'card_') { |
| 891 | 983 | $redirect_url = $order->get_checkout_payment_url( true ); |
| 892 | 984 | } else { |
| 893 | 985 | $redirect_url = false; |
| @@ -935,13 +1027,13 @@ | ||
| 935 | 1027 | $lang = strtolower(substr(get_locale(), 0, 2)); |
| 936 | 1028 | } |
| 937 | 1029 | $url = add_query_arg( array( |
| 938 | 1030 | 'makecommerce_card_pay' => '1', |
| 939 | - 'order_id' => $order->id, | |
| 1031 | + 'order_id' => $order->get_order_number(), | |
| 940 | 1032 | 'lang' => $lang, |
| 941 | 1033 | ), $baseUrl); |
| 942 | 1034 | |
| 943 | - // $url = site_url('?makecommerce_card_pay=1&order_id='.$order->id.'&lang='.(defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : strtolower(substr(get_locale(), 0, 2)))); | |
| 1035 | + // $url = site_url('?makecommerce_card_pay=1&order_id='.$order->get_order_number().'&lang='.(defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : strtolower(substr(get_locale(), 0, 2)))); | |
| 944 | 1036 | return $url; |
| 945 | 1037 | } |
| 946 | 1038 | |
| 947 | 1039 | */ |
| @@ -956,20 +1048,21 @@ | ||
| 956 | 1048 | |
| 957 | 1049 | |
| 958 | 1050 | public function generateCardForm($orderId) { |
| 959 | 1051 | $order = new WC_Order($orderId); |
| 1052 | + $has_subscription = function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order); | |
| 960 | 1053 | $scriptSrc = htmlspecialchars($this->MK->getEnvUrls()->checkoutjsUrl.'checkout.js'); |
| 961 | - $transactionId = get_post_meta($order->id, '_makecommerce_transaction_id', true); | |
| 962 | - $idReference = $order->id; | |
| 1054 | + $transactionId = get_post_meta($order->get_order_number(), '_makecommerce_transaction_id', true); | |
| 1055 | + $idReference = $order->get_order_number(); | |
| 963 | 1056 | $jsParams = array( |
| 964 | 1057 | 'key' => $this->MK->getPublishableKey(), |
| 965 | 1058 | 'transaction' => $transactionId, |
| 966 | 1059 | 'selector' => '#submit_banklinkmakecommerce_payment_form', |
| 967 | - 'amount' => round($order->order_total, 2), | |
| 1060 | + 'amount' => sprintf("%.2f", $order->get_total()), | |
| 968 | 1061 | 'locale' => !empty($_GET['lang']) ? $_GET['lang'] : (defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : strtolower(substr(get_locale(), 0, 2))), |
| 969 | 1062 | 'open-on-load' => 'true', |
| 970 | - 'client-name' => ($this->settings['cc_pass_cust_data'] == 'yes' ? (string) ($order->billing_first_name . ' ' . $order->billing_last_name) : ''), | |
| 971 | - 'email' => ($this->settings['cc_pass_cust_data'] == 'yes' ? (string) $order->billing_email : ''), | |
| 1063 | + 'client-name' => ($this->settings['cc_pass_cust_data'] == 'yes' ? (string) ((method_exists($order, 'get_billing_first_name') ? $order->get_billing_first_name() : $order->billing_first_name) . ' ' . (method_exists($order, 'get_billing_last_name') ? $order->get_billing_last_name() : $order->billing_last_name)) : ''), | |
| 1064 | + 'email' => ($this->settings['cc_pass_cust_data'] == 'yes' ? (string) (method_exists($order, 'get_billing_email') ? $order->get_billing_email() : $order->billing_email) : ''), | |
| 972 | 1065 | 'name' => get_option('mc_shop_name', ''), |
| 973 | 1066 | 'description' => __('Order', 'woocommerce') . ' ' . (string) $idReference, |
| 974 | 1067 | 'completed' => 'makecommerce_cc_complete', |
| 975 | 1068 | 'currency' => 'EUR', |
| @@ -974,8 +1067,14 @@ | ||
| 974 | 1067 | 'completed' => 'makecommerce_cc_complete', |
| 975 | 1068 | 'currency' => 'EUR', |
| 976 | 1069 | 'backdrop-close' => 'false', |
| 977 | 1070 | ); |
| 1071 | + if ($has_subscription) { | |
| 1072 | + $jsParams['recurring-required'] = 'true'; | |
| 1073 | + $jsParams['recurring-title'] = __('Pay for subscription', 'wc_makecommerce_domain'); | |
| 1074 | + $jsParams['recurring-description'] = __('This order contains subscriptions', 'wc_makecommerce_domain'); | |
| 1075 | + $jsParams['recurring-confirmation'] = __('I agree that my card will be recurringly billed by this store', 'wc_makecommerce_domain'); | |
| 1076 | + } | |
| 978 | 1077 | ?> |
| 979 | 1078 | <script type="text/javascript"> |
| 980 | 1079 | function makecommerce_cc_complete(data) { |
| 981 | 1080 | if(data.paymentToken) { |
| @@ -1048,15 +1147,13 @@ | ||
| 1048 | 1147 | |
| 1049 | 1148 | add_action('plugins_loaded', 'woocommerce_payment_makecommerce_init'); |
| 1050 | 1149 | add_action('woocommerce_payment_gateways', 'woocommerce_payment_makecommerce_add'); |
| 1051 | 1150 | |
| 1052 | - | |
| 1053 | 1151 | // Banklinks update wrapper for action |
| 1054 | 1152 | function update_mc_banklinks() { |
| 1055 | 1153 | $obj = new woocommerce_makecommerce(true); |
| 1056 | 1154 | $obj->mc_banklinks_reload(true); |
| 1057 | 1155 | } |
| 1058 | - | |
| 1059 | 1156 | |
| 1060 | 1157 | function mc_override_payment_method_string( $check, $object_id, $meta_key, $single ){ |
| 1061 | 1158 | if($meta_key == '_payment_method_title') { |
| 1062 | 1159 | $payment_method = get_post_meta( $object_id, '_payment_method', true ); |